]> xenbits.xensource.com Git - libvirt.git/commitdiff
host-validate: Be more careful when checking for cgroup mounts
authorAndrea Bolognani <abologna@redhat.com>
Mon, 4 Apr 2016 14:25:15 +0000 (16:25 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 8 Apr 2016 11:06:23 +0000 (13:06 +0200)
The existing code is built on the assumption that no cgroup
name can appear as part of another cgroup name; moreover, cgroups
are expected to always be listed in a specific order.

If that's not the case, eg. 'cpuacct' is listed before 'cpu', the
algorithm fails to detect the cgroup mount point.

Rewrite it to get rid of such assumptions.

tools/virt-host-validate-common.c

index ed6e74d3464bb6af5fd4c0b662363921081abf3d..95ae64a1db2e784d1551be935e2cc686851a5086 100644 (file)
@@ -343,16 +343,24 @@ static int virHostValidateCGroupMount(const char *hvname,
         goto error;
 
     while (getmntent_r(fp, &ent, mntbuf, sizeof(mntbuf)) && !matched) {
-        char *tmp = strstr(ent.mnt_opts, cg_name);
-        if (!tmp)
+        char **opts;
+        size_t nopts;
+        size_t i;
+
+        /* Ignore non-cgroup mounts */
+        if (STRNEQ(ent.mnt_type, "cgroup"))
             continue;
 
-        tmp += strlen(cg_name);
-        if (*tmp != ',' &&
-            *tmp != '\0')
+        if (!(opts = virStringSplitCount(ent.mnt_opts, ",", 0, &nopts)))
             continue;
 
-        matched = true;
+        /* Look for a mount option matching the cgroup name */
+        for (i = 0; i < nopts; i++) {
+            if (STREQ(opts[i], cg_name))
+                matched = true;
+        }
+
+        virStringFreeListCount(opts, nopts);
     }
     endmntent(fp);
     if (!matched)