[PATCH v2 2/3] test: Implement setNumaParameters and getNumaParameters

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

 



supportFeatures is also added for the requirement of
VIR_DRV_FEATURE_TYPED_PARAM_STRING support.
---
 src/test/test_driver.c |  177 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 177 insertions(+), 0 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b3b774d..f3c06a7 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2884,6 +2884,169 @@ error:
     return ret;
 }
 
+static int
+testDomainSetNumaParameters(virDomainPtr dom,
+                            virTypedParameterPtr params,
+                            int nparams,
+                            unsigned int flags)
+{
+    testConnPtr privconn = dom->conn->privateData;
+    int i;
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE, -1);
+    if (virTypedParameterArrayValidate(params, nparams,
+                                       VIR_DOMAIN_NUMA_MODE,
+                                       VIR_TYPED_PARAM_INT,
+                                       VIR_DOMAIN_NUMA_NODESET,
+                                       VIR_TYPED_PARAM_STRING,
+                                       NULL) < 0)
+        return -1;
+
+    testDriverLock(privconn);
+
+    vm = virDomainFindByUUID(&privconn->domains, dom->uuid);
+
+    if (vm == NULL) {
+        testError(VIR_ERR_INTERNAL_ERROR,
+                  _("No such domain %s"), dom->uuid);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+    for (i = 0; i < nparams; i++) {
+        virTypedParameterPtr param = &params[i];
+
+        if (STREQ(param->field, VIR_DOMAIN_NUMA_MODE)) {
+            vm->def->numatune.memory.mode = params[i].value.i;
+        } else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) {
+            bool savedmask;
+            char oldnodemask[VIR_DOMAIN_CPUMASK_LEN];
+
+            /* update vm->def here so that dumpxml can read the new
+             * values from vm->def. */
+            savedmask = false;
+            if (!vm->def->numatune.memory.nodemask) {
+                if (VIR_ALLOC_N(vm->def->numatune.memory.nodemask,
+                                VIR_DOMAIN_CPUMASK_LEN) < 0) {
+                    virReportOOMError();
+                    ret = -1;
+                    goto cleanup;
+                }
+            } else {
+                memcpy(oldnodemask, vm->def->numatune.memory.nodemask,
+                       VIR_DOMAIN_CPUMASK_LEN);
+                savedmask = true;
+            }
+
+            if (virDomainCpuSetParse(params[i].value.s,
+                                     0,
+                                     vm->def->numatune.memory.nodemask,
+                                     VIR_DOMAIN_CPUMASK_LEN) < 0) {
+                if (savedmask)
+                    memcpy(vm->def->numatune.memory.nodemask,
+                           oldnodemask, VIR_DOMAIN_CPUMASK_LEN);
+                else
+                    VIR_FREE(vm->def->numatune.memory.nodemask);
+                ret = -1;
+                continue;
+            }
+        }
+    }
+
+    if (ret == 0)
+        virDomainObjAssignDef(vm, vm->def, false);
+cleanup:
+    if (vm)
+        virDomainObjUnlock(vm);
+    testDriverUnlock(privconn);
+    return ret;
+}
+
+#define TEST_NB_NUMA_PARAM 2
+
+static int
+testDomainGetNumaParameters(virDomainPtr dom,
+                            virTypedParameterPtr params,
+                            int *nparams,
+                            unsigned int flags)
+{
+    testConnPtr privconn = dom->conn->privateData;
+    int i;
+    virDomainObjPtr vm = NULL;
+    char *nodeset = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_TYPED_PARAM_STRING_OKAY, -1);
+
+    testDriverLock(privconn);
+
+    /* We blindly return a string, and let libvirt.c and
+     * remote_driver.c do the filtering on behalf of older clients
+     * that can't parse it.  */
+    flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
+
+    vm = virDomainFindByUUID(&privconn->domains, dom->uuid);
+
+    if (vm == NULL) {
+        testError(VIR_ERR_INTERNAL_ERROR,
+                  _("No such domain %s"), dom->uuid);
+        goto cleanup;
+    }
+
+    if ((*nparams) == 0) {
+        *nparams = TEST_NB_NUMA_PARAM;
+        ret = 0;
+        goto cleanup;
+    }
+
+    for (i = 0; i < TEST_NB_NUMA_PARAM && i < *nparams; i++) {
+        virMemoryParameterPtr param = &params[i];
+
+        switch (i) {
+        case 0: /* fill numa mode here */
+            if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_MODE,
+                                        VIR_TYPED_PARAM_INT, 0) < 0)
+                goto cleanup;
+            param->value.i = vm->def->numatune.memory.mode;
+            break;
+
+        case 1: /* fill numa nodeset here */
+            if (vm->def->numatune.memory.nodemask)
+                nodeset = virDomainCpuSetFormat(vm->def->numatune.memory.nodemask,
+                                                VIR_DOMAIN_CPUMASK_LEN);
+            else
+                nodeset = strdup("");
+
+            if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_NODESET,
+                                        VIR_TYPED_PARAM_STRING, nodeset) < 0)
+                goto cleanup;
+
+            nodeset = NULL;
+
+            break;
+
+        default:
+            break;
+            /* should not hit here */
+        }
+    }
+
+    if (*nparams > TEST_NB_NUMA_PARAM)
+        *nparams = TEST_NB_NUMA_PARAM;
+    ret = 0;
+
+cleanup:
+    VIR_FREE(nodeset);
+    if (vm)
+        virDomainObjUnlock(vm);
+    testDriverUnlock(privconn);
+    return ret;
+}
+
 static virDrvOpenStatus testOpenNetwork(virConnectPtr conn,
                                         virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                         unsigned int flags)
@@ -5534,12 +5697,24 @@ static int testListAllDomains(virConnectPtr conn,
     return ret;
 }
 
+/* Which features are supported by this driver? */
+static int
+testSupportsFeature (virConnectPtr conn ATTRIBUTE_UNUSED, int feature)
+{
+    switch (feature) {
+    case VIR_DRV_FEATURE_TYPED_PARAM_STRING:
+        return 1;
+    default:
+        return 0;
+    }
+}
 
 static virDriver testDriver = {
     .no = VIR_DRV_TEST,
     .name = "Test",
     .open = testOpen, /* 0.1.1 */
     .close = testClose, /* 0.1.1 */
+    .supports_feature = testSupportsFeature, /* 0.5.0 */
     .version = testGetVersion, /* 0.1.1 */
     .getHostname = virGetHostname, /* 0.6.3 */
     .getMaxVcpus = testGetMaxVCPUs, /* 0.3.2 */
@@ -5603,6 +5778,8 @@ static virDriver testDriver = {
     .domainEventRegisterAny = testDomainEventRegisterAny, /* 0.8.0 */
     .domainEventDeregisterAny = testDomainEventDeregisterAny, /* 0.8.0 */
     .isAlive = testIsAlive, /* 0.9.8 */
+    .domainSetNumaParameters = testDomainSetNumaParameters, /* 0.9.9 */
+    .domainGetNumaParameters = testDomainGetNumaParameters, /* 0.9.9 */
 };
 
 static virNetworkDriver testNetworkDriver = {
-- 
1.7.7.3

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