[PATCH 08/12] virsh: Use virTypedParams* APIs in numatune

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

 



---
 tools/virsh-domain.c | 88 +++++++++++++++++++++-------------------------------
 1 file changed, 35 insertions(+), 53 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ff620b6..bcb855f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6313,8 +6313,9 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
 {
     virDomainPtr dom;
     int nparams = 0;
+    int maxparams = 0;
     unsigned int i = 0;
-    virTypedParameterPtr params = NULL, temp = NULL;
+    virTypedParameterPtr params = NULL;
     const char *nodeset = NULL;
     bool ret = false;
     unsigned int flags = 0;
@@ -6341,18 +6342,32 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
 
     if (vshCommandOptString(cmd, "nodeset", &nodeset) < 0) {
         vshError(ctl, "%s", _("Unable to parse nodeset."));
-        virDomainFree(dom);
-        return false;
+        goto cleanup;
     }
-    if (nodeset)
-        nparams++;
+    if (nodeset &&
+        virTypedParamsAddString(&params, &nparams, &maxparams,
+                                VIR_DOMAIN_NUMA_NODESET, nodeset) < 0)
+        goto save_error;
+
     if (vshCommandOptString(cmd, "mode", &mode) < 0) {
         vshError(ctl, "%s", _("Unable to parse mode."));
-        virDomainFree(dom);
-        return false;
+        goto cleanup;
+    }
+    if (mode) {
+        int m;
+        /* Accept string or integer, in case server understands newer
+         * integer than what strings we were compiled with
+         */
+        if ((m = virDomainNumatuneMemModeTypeFromString(mode)) < 0 &&
+            virStrToLong_i(mode, NULL, 0, &m) < 0) {
+            vshError(ctl, _("Invalid mode: %s"), mode);
+            goto cleanup;
+        }
+
+        if (virTypedParamsAddInt(&params, &nparams, &maxparams,
+                                 VIR_DOMAIN_NUMA_MODE, m) < 0)
+            goto save_error;
     }
-    if (mode)
-        nparams++;
 
     if (nparams == 0) {
         /* get the number of numa parameters */
@@ -6386,56 +6401,23 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
                 VIR_FREE(str);
             }
         }
-
-        ret = true;
     } else {
-        /* set the numa parameters */
-        params = vshCalloc(ctl, nparams, sizeof(*params));
-
-        for (i = 0; i < nparams; i++) {
-            temp = &params[i];
-
-            /*
-             * Some magic here, this is used to fill the params structure with
-             * the valid arguments passed, after filling the particular
-             * argument we purposely make them 0, so on the next pass it goes
-             * to the next valid argument and so on.
-             */
-            if (mode) {
-                /* Accept string or integer, in case server
-                 * understands newer integer than what strings we were
-                 * compiled with */
-                if ((temp->value.i =
-                    virDomainNumatuneMemModeTypeFromString(mode)) < 0 &&
-                    virStrToLong_i(mode, NULL, 0, &temp->value.i) < 0) {
-                    vshError(ctl, _("Invalid mode: %s"), mode);
-                    goto cleanup;
-                }
-                if (!virStrcpy(temp->field, VIR_DOMAIN_NUMA_MODE,
-                               sizeof(temp->field)))
-                    goto cleanup;
-                temp->type = VIR_TYPED_PARAM_INT;
-                mode = NULL;
-            } else if (nodeset) {
-                temp->value.s = vshStrdup(ctl, nodeset);
-                temp->type = VIR_TYPED_PARAM_STRING;
-                if (!virStrcpy(temp->field, VIR_DOMAIN_NUMA_NODESET,
-                               sizeof(temp->field)))
-                    goto cleanup;
-                nodeset = NULL;
-            }
-        }
         if (virDomainSetNumaParameters(dom, params, nparams, flags) != 0)
-            vshError(ctl, "%s", _("Unable to change numa parameters"));
-        else
-            ret = true;
+            goto error;
     }
 
-  cleanup:
-    virTypedParameterArrayClear(params, nparams);
-    VIR_FREE(params);
+    ret = true;
+
+cleanup:
+    virTypedParamsFree(params, nparams);
     virDomainFree(dom);
     return ret;
+
+save_error:
+    vshSaveLibvirtError();
+error:
+    vshError(ctl, "%s", _("Unable to change numa parameters"));
+    goto cleanup;
 }
 
 /*
-- 
1.8.1.1

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