[libvirt] PATCH: Fix startup of LXC vms without cgroups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If cgroups was not mounted at all, LXC would fail to start any VM, since
we missed an error code check

Daniel

commit 8713c7e8111e73879f8380b920995ff3d1f3f9e9
Author: Daniel P. Berrange <berrange@xxxxxxxxxx>
Date:   Fri Jul 31 14:37:25 2009 +0100

    Don't try to activate cgroups if not present for LXC
    
    * src/lxc_controller.c: Don't throw error in LXC startup if
      the cgroups driver mount isn't available. Improve error
      logging for resource setup

diff --git a/src/lxc_controller.c b/src/lxc_controller.c
index 9ad48a7..8d11238 100644
--- a/src/lxc_controller.c
+++ b/src/lxc_controller.c
@@ -84,25 +84,38 @@ static int lxcSetContainerResources(virDomainDefPtr def)
 
     rc = virCgroupForDriver("lxc", &driver, 1, 0);
     if (rc != 0) {
-        lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
-                 _("Unable to get cgroup for driver"));
+        /* Skip all if no driver cgroup is configured */
+        if (rc == -ENXIO || rc == -ENOENT)
+            return 0;
+
+        virReportSystemError(NULL, -rc, "%s",
+                             _("Unable to get cgroup for driver"));
         return rc;
     }
 
     rc = virCgroupForDomain(driver, def->name, &cgroup, 1);
     if (rc != 0) {
-        lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                 _("Unable to create cgroup for domain %s"), def->name);
+        virReportSystemError(NULL, -rc,
+                             _("Unable to create cgroup for domain %s"),
+                             def->name);
         goto cleanup;
     }
 
     rc = virCgroupSetMemory(cgroup, def->maxmem);
-    if (rc != 0)
-        goto out;
+    if (rc != 0) {
+        virReportSystemError(NULL, -rc,
+                             _("Unable to set memory limit for domain %s"),
+                             def->name);
+        goto cleanup;
+    }
 
     rc = virCgroupDenyAllDevices(cgroup);
-    if (rc != 0)
-        goto out;
+    if (rc != 0) {
+        virReportSystemError(NULL, -rc,
+                             _("Unable to deny devices for domain %s"),
+                             def->name);
+        goto cleanup;
+    }
 
     for (i = 0; devices[i].type != 0; i++) {
         struct cgroup_device_policy *dev = &devices[i];
@@ -110,19 +123,27 @@ static int lxcSetContainerResources(virDomainDefPtr def)
                                   dev->type,
                                   dev->major,
                                   dev->minor);
-        if (rc != 0)
-            goto out;
+        if (rc != 0) {
+            virReportSystemError(NULL, -rc,
+                                 _("Unable to allow device %c:%d:%d for domain %s"),
+                                 dev->type, dev->major, dev->minor, def->name);
+            goto cleanup;
+        }
     }
 
     rc = virCgroupAllowDeviceMajor(cgroup, 'c', LXC_DEV_MAJ_PTY);
-    if (rc != 0)
-        goto out;
+    if (rc != 0) {
+        virReportSystemError(NULL, -rc,
+                             _("Unable to allow PYT devices for domain %s"),
+                             def->name);
+        goto cleanup;
+    }
 
     rc = virCgroupAddTask(cgroup, getpid());
-out:
     if (rc != 0) {
-        virReportSystemError(NULL, -rc, "%s",
-                             _("Failed to set lxc resources"));
+        virReportSystemError(NULL, -rc,
+                             _("Unable to add task %d to cgroup for domain %s"),
+                             getpid(), def->name);
     }
 
 cleanup:


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]