[PATCH v2 5/5] lxc: replace old cgroup

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

 



---
 src/lxc/lxc_cgroup.c     |  40 +++--------
 src/lxc/lxc_cgroup.h     |   2 +-
 src/lxc/lxc_controller.c |  31 ++++++++-
 src/lxc/lxc_driver.c     | 177 +++++++++++++++++------------------------------
 src/lxc/lxc_process.c    |  19 +++--
 5 files changed, 111 insertions(+), 158 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 1984c5f..d1a1f16 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -242,7 +242,7 @@ int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo)
     int ret;
     virCgroupPtr cgroup;
 
-    ret = virCgroupGetAppRoot(&cgroup);
+    ret = virCgroupGetAppRoot(&cgroup, true);
     if (ret < 0) {
         virReportSystemError(-ret, "%s",
                              _("Unable to get cgroup for container"));
@@ -469,53 +469,29 @@ cleanup:
 }
 
 
-int virLXCCgroupSetup(virDomainDefPtr def)
+int virLXCCgroupSetup(virCgroupPtr cgroup, virDomainDefPtr def)
 {
-    virCgroupPtr driver = NULL;
-    virCgroupPtr cgroup = NULL;
-    int ret = -1;
     int rc;
 
-    rc = virCgroupForDriver("lxc", &driver, 1, 0);
-    if (rc != 0) {
-        virReportSystemError(-rc, "%s",
-                             _("Unable to get cgroup for driver"));
-        goto cleanup;
-    }
-
-    rc = virCgroupForDomain(driver, def->name, &cgroup, 1);
-    if (rc != 0) {
-        virReportSystemError(-rc,
-                             _("Unable to create cgroup for domain %s"),
-                             def->name);
-        goto cleanup;
-    }
-
     if (virLXCCgroupSetupCpuTune(def, cgroup) < 0)
-        goto cleanup;
+        return -1;
 
     if (virLXCCgroupSetupBlkioTune(def, cgroup) < 0)
-        goto cleanup;
+        return -1;
 
     if (virLXCCgroupSetupMemTune(def, cgroup) < 0)
-        goto cleanup;
+        return -1;
 
     if (virLXCCgroupSetupDeviceACL(def, cgroup) < 0)
-        goto cleanup;
+        return -1;
 
     rc = virCgroupAddTask(cgroup, getpid());
     if (rc != 0) {
         virReportSystemError(-rc,
                              _("Unable to add task %d to cgroup for domain %s"),
                              getpid(), def->name);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
-cleanup:
-    virCgroupFree(&cgroup);
-    virCgroupFree(&driver);
-
-    return ret;
+    return 0;
 }
diff --git a/src/lxc/lxc_cgroup.h b/src/lxc/lxc_cgroup.h
index 97b94e5..cd02b46 100644
--- a/src/lxc/lxc_cgroup.h
+++ b/src/lxc/lxc_cgroup.h
@@ -26,7 +26,7 @@
 # include "lxc_fuse.h"
 # include "virusb.h"
 
-int virLXCCgroupSetup(virDomainDefPtr def);
+int virLXCCgroupSetup(virCgroupPtr cgroup, virDomainDefPtr def);
 int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo);
 
 int
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 2673f72..4a7a63b 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -130,6 +130,8 @@ struct _virLXCController {
     int timerShutdown;
 
     virLXCFusePtr fuse;
+
+    virCgroupPtr cgroup;
 };
 
 #include "lxc_controller_dispatch.h"
@@ -272,6 +274,8 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
 
     VIR_FREE(ctrl->devptmx);
 
+    virCgroupFree(&ctrl->cgroup);
+
     virDomainDefFree(ctrl->def);
     VIR_FREE(ctrl->name);
 
@@ -548,6 +552,31 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
     return 0;
 }
 
+static int virLXCControllerSetupCgroup(virLXCControllerPtr ctrl)
+{
+    virCgroupPtr appCgroup = NULL;
+    int rc;
+
+    rc = virCgroupGetAppRoot(&appCgroup, true);
+    if (rc != 0) {
+        virReportSystemError(-rc, "%s",
+                             _("Unable to get cgroup for libvirt"));
+        goto cleanup;
+    }
+
+    rc = virCgroupNew("lxc", appCgroup, &ctrl->cgroup);
+    if (rc != 0) {
+        virReportSystemError(-rc, "%s",
+                             _("Unable to get cgroup for driver"));
+        goto cleanup;
+    }
+
+    rc = virLXCCgroupSetup(ctrl->cgroup, ctrl->def);
+
+cleanup:
+    virCgroupFree(&appCgroup);
+    return rc;
+}
 
 /**
  * virLXCControllerSetupResourceLimits
@@ -567,7 +596,7 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl)
     if (virLXCControllerSetupNUMAPolicy(ctrl) < 0)
         return -1;
 
-    return virLXCCgroupSetup(ctrl->def);
+    return virLXCControllerSetupCgroup(ctrl);
 }
 
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 1fe8039..7afe969 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -527,7 +527,6 @@ static int lxcDomainGetInfo(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    virCgroupPtr cgroup = NULL;
     int ret = -1, rc;
 
     lxcDriverLock(driver);
@@ -543,22 +542,16 @@ static int lxcDomainGetInfo(virDomainPtr dom,
 
     info->state = virDomainObjGetState(vm, NULL);
 
-    if (!virDomainObjIsActive(vm) || driver->cgroup == NULL) {
+    if (!virDomainObjIsActive(vm) || vm->cgroup == NULL) {
         info->cpuTime = 0;
         info->memory = vm->def->mem.cur_balloon;
     } else {
-        if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Unable to get cgroup for %s"), vm->def->name);
-            goto cleanup;
-        }
-
-        if (virCgroupGetCpuacctUsage(cgroup, &(info->cpuTime)) < 0) {
+        if (virCgroupGetCpuacctUsage(vm->cgroup, &(info->cpuTime)) < 0) {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            "%s", _("Cannot read cputime for domain"));
             goto cleanup;
         }
-        if ((rc = virCgroupGetMemoryUsage(cgroup, &(info->memory))) < 0) {
+        if ((rc = virCgroupGetMemoryUsage(vm->cgroup, &(info->memory))) < 0) {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            "%s", _("Cannot read memory usage for domain"));
             if (rc == -ENOENT) {
@@ -576,8 +569,6 @@ static int lxcDomainGetInfo(virDomainPtr dom,
 
 cleanup:
     lxcDriverUnlock(driver);
-    if (cgroup)
-        virCgroupFree(&cgroup);
     if (vm)
         virObjectUnlock(vm);
     return ret;
@@ -708,7 +699,6 @@ cleanup:
 static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
     virLXCDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    virCgroupPtr cgroup = NULL;
     int ret = -1;
 
     lxcDriverLock(driver);
@@ -734,19 +724,13 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
         goto cleanup;
     }
 
-    if (driver->cgroup == NULL) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("cgroups must be configured on the host"));
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to get cgroup for %s"), vm->def->name);
-        goto cleanup;
-    }
-
-    if (virCgroupSetMemory(cgroup, newmem) < 0) {
+    if (virCgroupSetMemory(vm->cgroup, newmem) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        "%s", _("Failed to set memory for domain"));
         goto cleanup;
@@ -757,8 +741,6 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-    if (cgroup)
-        virCgroupFree(&cgroup);
     return ret;
 }
 
@@ -770,7 +752,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     int i;
-    virCgroupPtr cgroup = NULL;
     virDomainObjPtr vm = NULL;
     int ret = -1;
     int rc;
@@ -797,7 +778,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -808,21 +789,21 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
         virTypedParameterPtr param = &params[i];
 
         if (STREQ(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
-            rc = virCgroupSetMemoryHardLimit(cgroup, params[i].value.ul);
+            rc = virCgroupSetMemoryHardLimit(vm->cgroup, params[i].value.ul);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to set memory hard_limit tunable"));
                 ret = -1;
             }
         } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
-            rc = virCgroupSetMemorySoftLimit(cgroup, params[i].value.ul);
+            rc = virCgroupSetMemorySoftLimit(vm->cgroup, params[i].value.ul);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to set memory soft_limit tunable"));
                 ret = -1;
             }
         } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
-            rc = virCgroupSetMemSwapHardLimit(cgroup, params[i].value.ul);
+            rc = virCgroupSetMemSwapHardLimit(vm->cgroup, params[i].value.ul);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to set swap_hard_limit tunable"));
@@ -832,8 +813,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
     }
 
 cleanup:
-    if (cgroup)
-        virCgroupFree(&cgroup);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -848,7 +827,6 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     int i;
-    virCgroupPtr cgroup = NULL;
     virDomainObjPtr vm = NULL;
     unsigned long long val;
     int ret = -1;
@@ -874,7 +852,7 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to get cgroup for %s"), vm->def->name);
         goto cleanup;
@@ -886,7 +864,7 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
 
         switch (i) {
         case 0: /* fill memory hard limit here */
-            rc = virCgroupGetMemoryHardLimit(cgroup, &val);
+            rc = virCgroupGetMemoryHardLimit(vm->cgroup, &val);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get memory hard limit"));
@@ -897,7 +875,7 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
                 goto cleanup;
             break;
         case 1: /* fill memory soft limit here */
-            rc = virCgroupGetMemorySoftLimit(cgroup, &val);
+            rc = virCgroupGetMemorySoftLimit(vm->cgroup, &val);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get memory soft limit"));
@@ -908,7 +886,7 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
                 goto cleanup;
             break;
         case 2: /* fill swap hard limit here */
-            rc = virCgroupGetMemSwapHardLimit(cgroup, &val);
+            rc = virCgroupGetMemSwapHardLimit(vm->cgroup, &val);
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get swap hard limit"));
@@ -932,8 +910,6 @@ lxcDomainGetMemoryParameters(virDomainPtr dom,
     ret = 0;
 
 cleanup:
-    if (cgroup)
-        virCgroupFree(&cgroup);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -1408,6 +1384,7 @@ static int lxcStartup(bool privileged,
                       virStateInhibitCallback callback ATTRIBUTE_UNUSED,
                       void *opaque ATTRIBUTE_UNUSED)
 {
+    virCgroupPtr appCgroup = NULL;
     char *ld;
     int rc;
 
@@ -1452,15 +1429,19 @@ static int lxcStartup(bool privileged,
     lxc_driver->log_libvirtd = 0; /* by default log to container logfile */
     lxc_driver->have_netns = lxcCheckNetNsSupport();
 
-    rc = virCgroupForDriver("lxc", &lxc_driver->cgroup, privileged, 1);
-    if (rc < 0) {
-        char buf[1024] ATTRIBUTE_UNUSED;
-        VIR_DEBUG("Unable to create cgroup for LXC driver: %s",
-                  virStrerror(-rc, buf, sizeof(buf)));
-        /* Don't abort startup. We will explicitly report to
-         * the user when they try to start a VM
-         */
+    rc = virCgroupGetAppRoot(&appCgroup, privileged);
+    if (appCgroup) {
+        rc = virCgroupNew("lxc", appCgroup, &lxc_driver->cgroup);
+        if (rc < 0) {
+            char buf[1024];
+            VIR_DEBUG("Unable to create cgroup for LXC driver: %s",
+                      virStrerror(-rc, buf, sizeof(buf)));
+            /* Don't abort startup. We will explicitly report to
+             * the user when they try to start a VM
+             */
+        }
     }
+    virCgroupFree(&appCgroup);
 
     /* Call function to load lxc driver configuration information */
     if (lxcLoadDriverConfig(lxc_driver) < 0)
@@ -1565,6 +1546,7 @@ static int lxcShutdown(void)
     VIR_FREE(lxc_driver->autostartDir);
     VIR_FREE(lxc_driver->stateDir);
     VIR_FREE(lxc_driver->logDir);
+    virCgroupFree(&lxc_driver->cgroup);
     lxcDriverUnlock(lxc_driver);
     virMutexDestroy(&lxc_driver->lock);
     VIR_FREE(lxc_driver);
@@ -1754,7 +1736,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     int i;
-    virCgroupPtr group = NULL;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr vmdef = NULL;
     int ret = -1;
@@ -1799,7 +1780,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
                            "%s", _("cgroup CPU controller is not mounted"));
             goto cleanup;
         }
-        if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+        if (vm->cgroup == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("cannot find cgroup for domain %s"),
                            vm->def->name);
@@ -1812,7 +1793,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
 
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-                rc = virCgroupSetCpuShares(group, params[i].value.ul);
+                rc = virCgroupSetCpuShares(vm->cgroup, params[i].value.ul);
                 if (rc != 0) {
                     virReportSystemError(-rc, "%s",
                                          _("unable to set cpu shares tunable"));
@@ -1827,7 +1808,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
             }
         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-                rc = lxcSetVcpuBWLive(group, params[i].value.ul, 0);
+                rc = lxcSetVcpuBWLive(vm->cgroup, params[i].value.ul, 0);
                 if (rc != 0)
                     goto cleanup;
 
@@ -1840,7 +1821,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
             }
         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-                rc = lxcSetVcpuBWLive(group, 0, params[i].value.l);
+                rc = lxcSetVcpuBWLive(vm->cgroup, 0, params[i].value.l);
                 if (rc != 0)
                     goto cleanup;
 
@@ -1871,7 +1852,6 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom,
 
 cleanup:
     virDomainDefFree(vmdef);
-    virCgroupFree(&group);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -1893,7 +1873,6 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
                                unsigned int flags)
 {
     virLXCDriverPtr driver = dom->conn->privateData;
-    virCgroupPtr group = NULL;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr persistentDef;
     unsigned long long shares = 0;
@@ -1943,13 +1922,13 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
     }
 
-    rc = virCgroupGetCpuShares(group, &shares);
+    rc = virCgroupGetCpuShares(vm->cgroup, &shares);
     if (rc != 0) {
         virReportSystemError(-rc, "%s",
                              _("unable to get cpu shares tunable"));
@@ -1957,7 +1936,7 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
     }
 
     if (*nparams > 1 && cpu_bw_status) {
-        rc = lxcGetVcpuBWLive(group, &period, &quota);
+        rc = lxcGetVcpuBWLive(vm->cgroup, &period, &quota);
         if (rc != 0)
             goto cleanup;
     }
@@ -1990,7 +1969,6 @@ out:
     ret = 0;
 
 cleanup:
-    virCgroupFree(&group);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -2014,7 +1992,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     int i;
-    virCgroupPtr group = NULL;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr persistentDef = NULL;
     int ret = -1;
@@ -2048,7 +2025,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
             goto cleanup;
         }
 
-        if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+        if (vm->cgroup == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("cannot find cgroup for domain %s"), vm->def->name);
             goto cleanup;
@@ -2066,7 +2043,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
                     goto cleanup;
                 }
 
-                rc = virCgroupSetBlkioWeight(group, params[i].value.ui);
+                rc = virCgroupSetBlkioWeight(vm->cgroup, params[i].value.ui);
                 if (rc != 0) {
                     virReportSystemError(-rc, "%s",
                                          _("unable to set blkio weight tunable"));
@@ -2099,7 +2076,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
 
     ret = 0;
 cleanup:
-    virCgroupFree(&group);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -2116,7 +2092,6 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
 {
     virLXCDriverPtr driver = dom->conn->privateData;
     int i;
-    virCgroupPtr group = NULL;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr persistentDef = NULL;
     unsigned int val;
@@ -2153,7 +2128,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
             goto cleanup;
         }
 
-        if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+        if (vm->cgroup == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("cannot find cgroup for domain %s"), vm->def->name);
             goto cleanup;
@@ -2165,7 +2140,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
 
             switch (i) {
             case 0: /* fill blkio weight here */
-                rc = virCgroupGetBlkioWeight(group, &val);
+                rc = virCgroupGetBlkioWeight(vm->cgroup, &val);
                 if (rc != 0) {
                     virReportSystemError(-rc, "%s",
                                          _("unable to get blkio weight"));
@@ -2207,8 +2182,6 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
     ret = 0;
 
 cleanup:
-    if (group)
-        virCgroupFree(&group);
     if (vm)
         virObjectUnlock(vm);
     lxcDriverUnlock(driver);
@@ -2378,7 +2351,7 @@ cleanup:
     return ret;
 }
 
-static int lxcFreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm)
+static int lxcFreezeContainer(virDomainObjPtr vm)
 {
     int timeout = 1000; /* In milliseconds */
     int check_interval = 1; /* In milliseconds */
@@ -2388,8 +2361,7 @@ static int lxcFreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm)
     char *state = NULL;
     virCgroupPtr cgroup = NULL;
 
-    if (!(driver->cgroup &&
-          virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0))
+    if (!vm->cgroup)
         return -1;
 
     /* From here on, we know that cgroup != NULL.  */
@@ -2496,7 +2468,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
     }
 
     if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
-        if (lxcFreezeContainer(driver, vm) < 0) {
+        if (lxcFreezeContainer(vm) < 0) {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            "%s", _("Suspend operation failed"));
             goto cleanup;
@@ -2521,18 +2493,15 @@ cleanup:
     return ret;
 }
 
-static int lxcUnfreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm)
+static int lxcUnfreezeContainer(virDomainObjPtr vm)
 {
     int ret;
-    virCgroupPtr cgroup = NULL;
 
-    if (!(driver->cgroup &&
-        virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0))
+    if (!(vm->cgroup))
         return -1;
 
-    ret = virCgroupSetFreezerState(cgroup, "THAWED");
+    ret = virCgroupSetFreezerState(vm->cgroup, "THAWED");
 
-    virCgroupFree(&cgroup);
     return ret;
 }
 
@@ -2561,7 +2530,7 @@ static int lxcDomainResume(virDomainPtr dom)
     }
 
     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
-        if (lxcUnfreezeContainer(driver, vm) < 0) {
+        if (lxcUnfreezeContainer(vm) < 0) {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            "%s", _("Resume operation failed"));
             goto cleanup;
@@ -3104,7 +3073,6 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainDiskDefPtr def = dev->data.disk;
-    virCgroupPtr group = NULL;
     int ret = -1;
     char *dst = NULL;
     struct stat sb;
@@ -3195,13 +3163,13 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
     }
 
-    if (virCgroupAllowDevicePath(group, def->src,
+    if (virCgroupAllowDevicePath(vm->cgroup, def->src,
                                  (def->readonly ?
                                   VIR_CGROUP_DEVICE_READ :
                                   VIR_CGROUP_DEVICE_RW) |
@@ -3219,8 +3187,6 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 cleanup:
     def->src = tmpsrc;
     virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
-    if (group)
-        virCgroupFree(&group);
     if (dst && created && ret < 0)
         unlink(dst);
     return ret;
@@ -3374,7 +3340,6 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
     mode_t mode;
     bool created = false;
     usbDevice *usb = NULL;
-    virCgroupPtr group = NULL;
 
     if (virDomainHostdevFind(vm->def, def, NULL) >= 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -3415,7 +3380,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -3462,7 +3427,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
 
     if (usbDeviceFileIterate(usb,
                              virLXCSetupHostUsbDeviceCgroup,
-                             &group) < 0)
+                             &vm->cgroup) < 0)
         goto cleanup;
 
     ret = 0;
@@ -3473,7 +3438,6 @@ cleanup:
         unlink(dstfile);
 
     usbFreeDevice(usb);
-    virCgroupFree(&group);
     VIR_FREE(src);
     VIR_FREE(dstfile);
     VIR_FREE(dstdir);
@@ -3489,7 +3453,6 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevDefPtr def = dev->data.hostdev;
-    virCgroupPtr group = NULL;
     int ret = -1;
     char *dst = NULL;
     char *vroot = NULL;
@@ -3564,13 +3527,13 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
     }
 
-    if (virCgroupAllowDevicePath(group, def->source.caps.u.storage.block,
+    if (virCgroupAllowDevicePath(vm->cgroup, def->source.caps.u.storage.block,
                                  VIR_CGROUP_DEVICE_RW |
                                  VIR_CGROUP_DEVICE_MKNOD) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3585,8 +3548,6 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
 
 cleanup:
     virDomainAuditHostdev(vm, def, "attach", ret == 0);
-    if (group)
-        virCgroupFree(&group);
     if (dst && created && ret < 0)
         unlink(dst);
     VIR_FREE(dst);
@@ -3602,7 +3563,6 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevDefPtr def = dev->data.hostdev;
-    virCgroupPtr group = NULL;
     int ret = -1;
     char *dst = NULL;
     char *vroot = NULL;
@@ -3677,13 +3637,13 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
     }
 
-    if (virCgroupAllowDevicePath(group, def->source.caps.u.misc.chardev,
+    if (virCgroupAllowDevicePath(vm->cgroup, def->source.caps.u.misc.chardev,
                                  VIR_CGROUP_DEVICE_RW |
                                  VIR_CGROUP_DEVICE_MKNOD) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3698,8 +3658,6 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
 
 cleanup:
     virDomainAuditHostdev(vm, def, "attach", ret == 0);
-    if (group)
-        virCgroupFree(&group);
     if (dst && created && ret < 0)
         unlink(dst);
     VIR_FREE(dst);
@@ -3822,7 +3780,6 @@ lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainDiskDefPtr def = NULL;
-    virCgroupPtr group = NULL;
     int i, ret = -1;
     char *dst = NULL;
 
@@ -3854,7 +3811,7 @@ lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -3869,7 +3826,7 @@ lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver,
     }
     virDomainAuditDisk(vm, def->src, NULL, "detach", true);
 
-    if (virCgroupDenyDevicePath(group, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
+    if (virCgroupDenyDevicePath(vm->cgroup, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
         VIR_WARN("cannot deny device %s for domain %s",
                  def->src, vm->def->name);
 
@@ -3880,8 +3837,6 @@ lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver,
 
 cleanup:
     VIR_FREE(dst);
-    if (group)
-        virCgroupFree(&group);
     return ret;
 }
 
@@ -3959,7 +3914,6 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevDefPtr def = NULL;
-    virCgroupPtr group = NULL;
     int idx, ret = -1;
     char *dst = NULL;
     char *vroot;
@@ -3993,7 +3947,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -4014,7 +3968,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
 
     if (usbDeviceFileIterate(usb,
                              virLXCTeardownHostUsbDeviceCgroup,
-                             &group) < 0)
+                             &vm->cgroup) < 0)
         VIR_WARN("cannot deny device %s for domain %s",
                  dst, vm->def->name);
 
@@ -4028,7 +3982,6 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
 cleanup:
     usbFreeDevice(usb);
     VIR_FREE(dst);
-    virCgroupFree(&group);
     return ret;
 }
 
@@ -4040,7 +3993,6 @@ lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevDefPtr def = NULL;
-    virCgroupPtr group = NULL;
     int i, ret = -1;
     char *dst = NULL;
 
@@ -4072,7 +4024,7 @@ lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -4087,7 +4039,8 @@ lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver,
     }
     virDomainAuditHostdev(vm, def, "detach", true);
 
-    if (virCgroupDenyDevicePath(group, def->source.caps.u.storage.block, VIR_CGROUP_DEVICE_RWM) != 0)
+    if (virCgroupDenyDevicePath(vm->cgroup, def->source.caps.u.storage.block,
+                                VIR_CGROUP_DEVICE_RWM) != 0)
         VIR_WARN("cannot deny device %s for domain %s",
                  def->source.caps.u.storage.block, vm->def->name);
 
@@ -4098,8 +4051,6 @@ lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver,
 
 cleanup:
     VIR_FREE(dst);
-    if (group)
-        virCgroupFree(&group);
     return ret;
 }
 
@@ -4111,7 +4062,6 @@ lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver,
 {
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virDomainHostdevDefPtr def = NULL;
-    virCgroupPtr group = NULL;
     int i, ret = -1;
     char *dst = NULL;
 
@@ -4143,7 +4093,7 @@ lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+    if (vm->cgroup == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find cgroup for domain %s"), vm->def->name);
         goto cleanup;
@@ -4158,7 +4108,8 @@ lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver,
     }
     virDomainAuditHostdev(vm, def, "detach", true);
 
-    if (virCgroupDenyDevicePath(group, def->source.caps.u.misc.chardev, VIR_CGROUP_DEVICE_RWM) != 0)
+    if (virCgroupDenyDevicePath(vm->cgroup, def->source.caps.u.misc.chardev,
+                                VIR_CGROUP_DEVICE_RWM) != 0)
         VIR_WARN("cannot deny device %s for domain %s",
                  def->source.caps.u.misc.chardev, vm->def->name);
 
@@ -4169,8 +4120,6 @@ lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver,
 
 cleanup:
     VIR_FREE(dst);
-    if (group)
-        virCgroupFree(&group);
     return ret;
 }
 
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 5598a86..f28fd63 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -218,7 +218,6 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
                                  virDomainObjPtr vm,
                                  virDomainShutoffReason reason)
 {
-    virCgroupPtr cgroup;
     int i;
     virLXCDomainObjPrivatePtr priv = vm->privateData;
     virNetDevVPortProfilePtr vport = NULL;
@@ -276,11 +275,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
 
     virDomainConfVMNWFilterTeardown(vm);
 
-    if (driver->cgroup &&
-        virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0) {
-        virCgroupRemove(cgroup);
-        virCgroupFree(&cgroup);
-    }
+    virCgroupFree(&vm->cgroup);
 
     /* now that we know it's stopped call the hook if present */
     if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
@@ -685,7 +680,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
                       virDomainObjPtr vm,
                       virDomainShutoffReason reason)
 {
-    virCgroupPtr group = NULL;
     int rc;
 
     VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d",
@@ -707,8 +701,8 @@ int virLXCProcessStop(virLXCDriverPtr driver,
         VIR_FREE(vm->def->seclabels[0]->imagelabel);
     }
 
-    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) == 0) {
-        rc = virCgroupKillPainfully(group);
+    if (vm->cgroup) {
+        rc = virCgroupKillPainfully(vm->cgroup);
         if (rc < 0) {
             virReportSystemError(-rc, "%s",
                                  _("Failed to kill container PIDs"));
@@ -732,7 +726,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
     rc = 0;
 
 cleanup:
-    virCgroupFree(&group);
     return rc;
 }
 
@@ -945,6 +938,12 @@ int virLXCProcessStart(virConnectPtr conn,
         return -1;
     }
 
+    if (virCgroupNew(vm->def->name, driver->cgroup, &vm->cgroup) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("Unable to find cgroup for domain"));
+        return -1;
+    }
+
     if (virFileMakePath(driver->logDir) < 0) {
         virReportSystemError(errno,
                              _("Cannot create log directory '%s'"),
-- 
1.8.0.1.240.ge8a1f5a

--
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]