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

[libvirt] [PATCH 7/8] schedinfo: Support new API for lxc driver



---
 src/lxc/lxc_driver.c |   41 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 72c0a0a..5db1035 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2244,21 +2244,28 @@ static char *lxcGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
     return schedulerType;
 }
 
-static int lxcSetSchedulerParameters(virDomainPtr domain,
-                                     virSchedParameterPtr params,
-                                     int nparams)
+static int lxcSetSchedulerParametersFlags(virDomainPtr domain,
+                                          virSchedParameterPtr params,
+                                          int nparams,
+                                          unsigned int flags)
 {
     lxc_driver_t *driver = domain->conn->privateData;
     int i;
     virCgroupPtr group = NULL;
     virDomainObjPtr vm = NULL;
+    virDomainDefPtr persistentDef = NULL;
     int ret = -1;
+    bool isActive;
+
+    virCheckFlags(VIR_DOMAIN_SCHED_PARAMS_LIVE |
+                  VIR_DOMAIN_SCHED_PARAMS_PERSISTENT, -1);
 
     if (driver->cgroup == NULL)
         return -1;
 
     lxcDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, domain->uuid);
+    lxcDriverUnlock(driver);
 
     if (vm == NULL) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -2268,9 +2275,20 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
         goto cleanup;
     }
 
+    /* Could find cgroup for domain implies the domain is running. */
     if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0)
         goto cleanup;
 
+    if (flags & VIR_DOMAIN_SCHED_PARAMS_PERSISTENT) {
+        if (!vm->persistent) {
+            lxcError(VIR_ERR_OPERATION_INVALID, "%s",
+                            _("cannot change persistent config of a transient domain"));
+            goto cleanup;
+        }
+        if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
+            goto cleanup;
+    }
+
     for (i = 0; i < nparams; i++) {
         virSchedParameterPtr param = &params[i];
 
@@ -2294,17 +2312,30 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
         }
 
         vm->def->cputune.shares = params[i].value.ul;
+
+        if (flags & VIR_DOMAIN_SCHED_PARAMS_PERSISTENT) {
+            persistentDef->cputune.shares = params[i].value.ul;
+            ret = virDomainSaveConfig(driver->configDir, persistentDef);
+            goto cleanup;
+        }
     }
     ret = 0;
 
 cleanup:
-    lxcDriverUnlock(driver);
     virCgroupFree(&group);
     if (vm)
         virDomainObjUnlock(vm);
     return ret;
 }
 
+static int lxcSetSchedulerParameters(virDomainPtr domain,
+                                     virSchedParameterPtr params,
+                                     int nparams)
+{
+    return lxcSetSchedulerParametersFlags(domain, params, nparams,
+                                          VIR_DOMAIN_SCHED_PARAMS_LIVE);
+}
+
 static int lxcGetSchedulerParameters(virDomainPtr domain,
                                      virSchedParameterPtr params,
                                      int *nparams)
@@ -2860,7 +2891,7 @@ static virDriver lxcDriver = {
     lxcGetSchedulerType, /* domainGetSchedulerType */
     lxcGetSchedulerParameters, /* domainGetSchedulerParameters */
     lxcSetSchedulerParameters, /* domainSetSchedulerParameters */
-    NULL, /* domainSetSchedulerParametersFlags */
+    lxcSetSchedulerParametersFlags, /* domainSetSchedulerParametersFlags */
     NULL, /* domainMigratePrepare */
     NULL, /* domainMigratePerform */
     NULL, /* domainMigrateFinish */
-- 
1.7.4


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