]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix detection of 'emulator' cgroup
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 24 Jul 2013 16:41:44 +0000 (17:41 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 25 Jul 2013 18:55:46 +0000 (19:55 +0100)
When a VM has an 'emulator' child cgroup present, we must
strip off that suffix when detecting the cgroup for a
machine

Rename the virCgroupIsValidMachineGroup method to
virCgroupValidateMachineGroup to make a bit clearer
that this isn't simply a boolean check, it will make
changes to the object.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/util/vircgroup.c

index 3332a397759a01101df83bc58022a756032aefe8..86d7e44d25a52735d84e7db8c223ebb83acc894d 100644 (file)
@@ -96,9 +96,10 @@ bool virCgroupAvailable(void)
 }
 
 static bool
-virCgroupIsValidMachineGroup(virCgroupPtr group,
-                             const char *name,
-                             const char *drivername)
+virCgroupValidateMachineGroup(virCgroupPtr group,
+                              const char *name,
+                              const char *drivername,
+                              bool stripEmulatorSuffix)
 {
     size_t i;
     bool valid = false;
@@ -120,12 +121,26 @@ virCgroupIsValidMachineGroup(virCgroupPtr group,
         tmp = strrchr(group->controllers[i].placement, '/');
         if (!tmp)
             goto cleanup;
+
+        if (stripEmulatorSuffix &&
+            (i == VIR_CGROUP_CONTROLLER_CPU ||
+             i == VIR_CGROUP_CONTROLLER_CPUACCT ||
+             i == VIR_CGROUP_CONTROLLER_CPUSET)) {
+            if (STREQ(tmp, "/emulator"))
+                *tmp = '\0';
+            tmp = strrchr(group->controllers[i].placement, '/');
+            if (!tmp)
+                goto cleanup;
+        }
+
         tmp++;
 
         if (STRNEQ(tmp, name) &&
-            STRNEQ(tmp, partname))
+            STRNEQ(tmp, partname)) {
+            VIR_DEBUG("Name '%s' does not match '%s' or '%s'",
+                      tmp, name, partname);
             goto cleanup;
-
+        }
     }
 
     valid = true;
@@ -1590,7 +1605,9 @@ int virCgroupNewDetectMachine(const char *name,
         return -1;
     }
 
-    if (!virCgroupIsValidMachineGroup(*group, name, drivername)) {
+    if (!virCgroupValidateMachineGroup(*group, name, drivername, true)) {
+        VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
+                  name, drivername);
         virCgroupFree(group);
         return 0;
     }