[libvirt] [PATCH] Fix starting domains when kernel has no cgroups support

Jim Fehlig jfehlig at suse.com
Fri May 10 18:40:40 UTC 2013


Found that I was unable to start existing domains after updating
to a kernel with no cgroups support

  # zgrep CGROUP /proc/config.gz
  # CONFIG_CGROUPS is not set
  # virsh start test
  error: Failed to start domain test
  error: Unable to initialize /machine cgroup: Cannot allocate memory

virCgroupPartitionNeedsEscaping() correctly returns errno (ENOENT) when
attempting to open /proc/cgroups on such a system, but it was being
dropped in virCgroupSetPartitionSuffix().

Change virCgroupSetPartitionSuffix() to propogate errors returned by
its callees.  Also check for ENOENT in qemuInitCgroup() when determining
if cgroups support is available.
---
 src/qemu/qemu_cgroup.c |  3 ++-
 src/util/vircgroup.c   | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 9c45b76..40777aa 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -414,7 +414,8 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
         if (rc != 0) {
             if (rc == -ENXIO ||
                 rc == -EPERM ||
-                rc == -EACCES) { /* No cgroups mounts == success */
+                rc == -EACCES ||
+                rc == -ENOENT) { /* No cgroups mounts == success */
                 VIR_DEBUG("No cgroups present/configured/accessible, ignoring error");
                 goto done;
             }
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 473d2fc..ef619dc 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1167,14 +1167,14 @@ static int virCgroupPartitionEscape(char **path)
     return 0;
 }
 
-static char *virCgroupSetPartitionSuffix(const char *path)
+static int virCgroupSetPartitionSuffix(const char *path, char **res)
 {
     char **tokens = virStringSplit(path, "/", 0);
     size_t i;
-    char *ret = NULL;
+    int ret = -1;
 
     if (!tokens)
-        return NULL;
+        return ret;
 
     for (i = 0 ; tokens[i] != NULL ; i++) {
         /* Whitelist the 3 top level fixed dirs
@@ -1193,20 +1193,27 @@ static char *virCgroupSetPartitionSuffix(const char *path)
             !strchr(tokens[i], '.')) {
             if (VIR_REALLOC_N(tokens[i],
                               strlen(tokens[i]) + strlen(".partition") + 1) < 0) {
+                ret = -ENOMEM;
                 virReportOOMError();
                 goto cleanup;
             }
             strcat(tokens[i], ".partition");
         }
 
-        if (virCgroupPartitionEscape(&(tokens[i])) < 0) {
-            virReportOOMError();
+        ret = virCgroupPartitionEscape(&(tokens[i]));
+        if (ret < 0) {
+            if (ret == -ENOMEM)
+                virReportOOMError();
             goto cleanup;
         }
     }
 
-    if (!(ret = virStringJoin((const char **)tokens, "/")))
+    if (!(*res = virStringJoin((const char **)tokens, "/"))) {
+        ret = -ENOMEM;
         goto cleanup;
+    }
+
+    ret = 0;
 
 cleanup:
     virStringFreeList(tokens);
-- 
1.8.0.1




More information about the libvir-list mailing list