]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Adding blkiotune command to virsh tool
authorGui Jianfeng <guijianfeng@cn.fujitsu.com>
Tue, 22 Feb 2011 05:33:24 +0000 (13:33 +0800)
committerEric Blake <eblake@redhat.com>
Fri, 11 Mar 2011 00:54:08 +0000 (17:54 -0700)
Adding blkiotune command to virsh tool

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
tools/virsh.c
tools/virsh.pod

index 3213b57b7fb2a6d4ce425605f07070b6be33f4e1..a5e9c4f39df0f2952b2ca758d9550b4e63f282cb 100644 (file)
@@ -3035,6 +3035,136 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "blkiotune" command
+ */
+static const vshCmdInfo info_blkiotune[] = {
+    {"help", N_("Get or set blkio parameters")},
+    {"desc", N_("Get or set the current blkio parameters for a guest" \
+                " domain.\n" \
+                "    To get the blkio parameters use following command: \n\n" \
+                "    virsh # blkiotune <domain>")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_blkiotune[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"weight", VSH_OT_INT, VSH_OFLAG_NONE,
+     N_("IO Weight in range [100, 1000]")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
+{
+    virDomainPtr dom;
+    int weight = 0;
+    int nparams = 0;
+    unsigned int i = 0;
+    virBlkioParameterPtr params = NULL, temp = NULL;
+    int ret = FALSE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return FALSE;
+
+    if (vshCommandOptInt(cmd, "weight", &weight) < 0) {
+        vshError(ctl, "%s",
+                 _("Unable to parse integer parameter"));
+        goto cleanup;
+    }
+
+    if (weight) {
+        nparams++;
+        if (weight < 0) {
+            virDomainFree(dom);
+            vshError(ctl, _("Invalid value of %d for I/O weight"), weight);
+            goto cleanup;
+        }
+    }
+
+    if (nparams == 0) {
+        /* get the number of blkio parameters */
+        if (virDomainGetBlkioParameters(dom, NULL, &nparams, 0) != 0) {
+            vshError(ctl, "%s",
+                     _("Unable to get number of blkio parameters"));
+            goto cleanup;
+        }
+
+        if (nparams == 0) {
+            /* nothing to output */
+            ret = TRUE;
+            goto cleanup;
+        }
+
+        /* now go get all the blkio parameters */
+        params = vshCalloc(ctl, nparams, sizeof(*params));
+        if (virDomainGetBlkioParameters(dom, params, &nparams, 0) != 0) {
+            vshError(ctl, "%s", _("Unable to get blkio parameters"));
+            goto cleanup;
+        }
+
+        for (i = 0; i < nparams; i++) {
+            switch (params[i].type) {
+                case VIR_DOMAIN_BLKIO_PARAM_INT:
+                    vshPrint(ctl, "%-15s: %d\n", params[i].field,
+                             params[i].value.i);
+                    break;
+                case VIR_DOMAIN_BLKIO_PARAM_UINT:
+                    vshPrint(ctl, "%-15s: %u\n", params[i].field,
+                             params[i].value.ui);
+                    break;
+                case VIR_DOMAIN_BLKIO_PARAM_LLONG:
+                    vshPrint(ctl, "%-15s: %lld\n", params[i].field,
+                             params[i].value.l);
+                    break;
+                case VIR_DOMAIN_BLKIO_PARAM_ULLONG:
+                    vshPrint(ctl, "%-15s: %llu\n", params[i].field,
+                                 params[i].value.ul);
+                    break;
+                case VIR_DOMAIN_BLKIO_PARAM_DOUBLE:
+                    vshPrint(ctl, "%-15s: %f\n", params[i].field,
+                             params[i].value.d);
+                    break;
+                case VIR_DOMAIN_BLKIO_PARAM_BOOLEAN:
+                    vshPrint(ctl, "%-15s: %d\n", params[i].field,
+                             params[i].value.b);
+                    break;
+                default:
+                    vshPrint(ctl, "unimplemented blkio parameter type\n");
+            }
+        }
+
+        ret = TRUE;
+    } else {
+        /* set the blkio parameters */
+        params = vshCalloc(ctl, nparams, sizeof(*params));
+
+        for (i = 0; i < nparams; i++) {
+            temp = &params[i];
+            temp->type = VIR_DOMAIN_BLKIO_PARAM_UINT;
+
+            if (weight) {
+                temp->value.ui = weight;
+                strncpy(temp->field, VIR_DOMAIN_BLKIO_WEIGHT,
+                        sizeof(temp->field));
+                weight = 0;
+            }
+        }
+        if (virDomainSetBlkioParameters(dom, params, nparams, 0) != 0)
+            vshError(ctl, "%s", _("Unable to change blkio parameters"));
+        else
+            ret = TRUE;
+    }
+
+  cleanup:
+    VIR_FREE(params);
+    virDomainFree(dom);
+    return ret;
+}
+
 /*
  * "memtune" command
  */
@@ -10289,6 +10419,7 @@ static const vshCmdDef domManagementCmds[] = {
     {"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk},
     {"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
     {"autostart", cmdAutostart, opts_autostart, info_autostart},
+    {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune},
 #ifndef WIN32
     {"console", cmdConsole, opts_console, info_console},
 #endif
index 7c12399ba6f95cba78c2d9c71c439e1d831c62cb..d332676a39f2f94f4090873be32b319212797bda 100644 (file)
@@ -618,6 +618,11 @@ flags, the current settings are displayed; with a flag, the
 appropriate limit is adjusted if supported by the hypervisor.  LXC and
 QEMU/KVM supports I<--hard-limit>, I<--soft-limit>, and I<--swap-hard-limit>.
 
+=item B<blkiotune> I<domain-id> optional I<--weight> B<weight>
+
+Display or set the blkio parameters. QEMU/KVM supports I<--weight>.
+I<--weight> is in range [100, 1000].
+
 =item B<setvcpus> I<domain-id> I<count> optional I<--maximum> I<--config>
 I<--live>