]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix starting domains when kernel has no cgroups support
authorJim Fehlig <jfehlig@suse.com>
Fri, 10 May 2013 18:05:00 +0000 (12:05 -0600)
committerJim Fehlig <jfehlig@suse.com>
Thu, 11 Jul 2013 16:38:45 +0000 (10:38 -0600)
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 propagate errors returned by
its callees.  Also check for ENOENT in qemuInitCgroup() when determining
if cgroups support is available.
(cherry picked from commit bbe97ae968eba60b71e0066d49f9fc909966d9d6)

src/qemu/qemu_cgroup.c
src/util/vircgroup.c

index 400a2b39b874bb48d37f87ec8d349cfacee37050..5745085c767927913c4750022c021befe099502b 100644 (file)
@@ -415,7 +415,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;
             }
index 028ef2c40e673732e16b74dbbc84d9b95a5c0ae2..4abe1b17c7c108b28e17add36031b2bca26253a3 100644 (file)
@@ -1180,14 +1180,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
@@ -1206,20 +1206,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);
@@ -1254,9 +1261,9 @@ int virCgroupNewPartition(const char *path,
 
     /* XXX convert all cgroups APIs to use error report
      * APIs instead of returning errno */
-    if (!(newpath = virCgroupSetPartitionSuffix(path))) {
+    rc = virCgroupSetPartitionSuffix(path, &newpath);
+    if (rc < 0) {
         virResetLastError();
-        rc = -ENOMEM;
         goto cleanup;
     }