]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: Resolve issue with GetScheduler APIs for non running domain
authorJohn Ferlan <jferlan@redhat.com>
Tue, 28 May 2013 19:00:59 +0000 (15:00 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 20 Jun 2013 13:38:47 +0000 (09:38 -0400)
Cherry-picked from 38ada092d1ad5f27a24e511173308d568b6b085f

As a consequence of the cgroup layout changes from commit 'cfed9ad4', the
lxcDomainGetSchedulerParameters[Flags]()' and lxcGetSchedulerType() APIs
failed to return data for a non running domain.  This can be seen through
a 'virsh schedinfo <domain>' command which returns:

Scheduler      : Unknown
error: Requested operation is not valid: cgroup CPU controller is not mounted

Prior to that change a non running domain would return:

Scheduler      : posix
cpu_shares     : 0
vcpu_period    : 0
vcpu_quota     : 0
emulator_period: 0
emulator_quota : 0

This patch will restore the capability to return configuration only data
for a non running domain regardless of whether cgroups are available.

Conflicts:
src/lxc/lxc_driver.c

  * Resolved conflict by using former lxcCgroupHasController() rather than
    virCgroupHasController()
  * Needed to add the code to fetch the 'vm'
     vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
     if (vm == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("No such domain %s"), domain->uuid);
         goto cleanup;
     }
  * Used 'ret = strdup("posix");' rather than VIR_STRDUP(ret, "posix");
    and added the virReportOOMError(); on failure.

src/lxc/lxc_driver.c

index ba14db7a9911aaa83c45f7e2c4d4e99af0f92aff..92c78f392d0ddea0e811357fd08d2bbe4c30adfb 100644 (file)
@@ -1662,8 +1662,26 @@ static char *lxcGetSchedulerType(virDomainPtr domain,
     virLXCDriverPtr driver = domain->conn->privateData;
     char *ret = NULL;
     int rc;
+    virDomainObjPtr vm;
 
     lxcDriverLock(driver);
+    vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
+    if (vm == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("No such domain %s"), domain->uuid);
+        goto cleanup;
+    }
+
+    /* Domain not running, thus no cgroups - return defaults */
+    if (!virDomainObjIsActive(vm)) {
+        if (nparams)
+            *nparams = 3;
+        ret = strdup("posix");
+        if (!ret)
+            virReportOOMError();
+        goto cleanup;
+    }
+
     if (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("cgroup CPU controller is not mounted"));
@@ -1947,9 +1965,10 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom,
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
         shares = persistentDef->cputune.shares;
-        if (*nparams > 1 && cpu_bw_status) {
+        if (*nparams > 1) {
             period = persistentDef->cputune.period;
             quota = persistentDef->cputune.quota;
+            cpu_bw_status = true; /* Allow copy of data to params[] */
         }
         goto out;
     }