]> xenbits.xensource.com Git - libvirt.git/commitdiff
tools: Add virsh iothreadset command
authorJohn Ferlan <jferlan@redhat.com>
Fri, 5 Oct 2018 12:53:09 +0000 (08:53 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 19 Nov 2018 12:26:40 +0000 (07:26 -0500)
Add a command to allow for setting various dynamic IOThread polling
interval scope (poll-max-ns, poll-grow, and poll-shrink). Describe
the values in the virsh.pod in as generic terms as possible. The
more specific QEMU algorithm has been divulged in the previous patch.

Based heavily on code originally posted by Pavel Hrdina
<phrdina@redhat.com>, but altered to only provide one command
and to not managed a poll disabled state.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-domain.c
tools/virsh.pod

index 372bdb95d3fc548b3af968845b707c85dd58a86b..4ee6ddf9561ad2a33419918a66af6dab1d400b0f 100644 (file)
@@ -7734,6 +7734,110 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+
+ /*
+ * "iothreadset" command
+ */
+static const vshCmdInfo info_iothreadset[] = {
+    {.name = "help",
+     .data = N_("modifies an existing IOThread of the guest domain")
+    },
+    {.name = "desc",
+     .data = N_("Modifies an existing IOThread of the guest domain.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_iothreadset[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL(0),
+    {.name = "id",
+     .type = VSH_OT_INT,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("iothread id of existing IOThread")
+    },
+    {.name = "poll-max-ns",
+     .type = VSH_OT_INT,
+     .help = N_("set the maximum IOThread polling time in ns")
+    },
+    {.name = "poll-grow",
+     .type = VSH_OT_INT,
+     .help = N_("set the value to increase the IOThread polling time")
+    },
+    {.name = "poll-shrink",
+     .type = VSH_OT_INT,
+     .help = N_("set the value for reduction of the IOThread polling time ")
+    },
+    VIRSH_COMMON_OPT_DOMAIN_LIVE,
+    VIRSH_COMMON_OPT_DOMAIN_CURRENT,
+    {.name = NULL}
+};
+
+static bool
+cmdIOThreadSet(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    int id = 0;
+    bool ret = false;
+    bool live = vshCommandOptBool(cmd, "live");
+    unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    int maxparams = 0;
+    unsigned long long poll_max;
+    unsigned int poll_val;
+    int rc;
+
+    if (live)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (vshCommandOptInt(ctl, cmd, "id", &id) < 0)
+        goto cleanup;
+    if (id <= 0) {
+        vshError(ctl, _("Invalid IOThread id value: '%d'"), id);
+        goto cleanup;
+    }
+
+    poll_val = 0;
+    if ((rc = vshCommandOptULongLong(ctl, cmd, "poll-max-ns", &poll_max)) < 0)
+        goto cleanup;
+    if (rc > 0 && virTypedParamsAddULLong(&params, &nparams, &maxparams,
+                                          VIR_DOMAIN_IOTHREAD_POLL_MAX_NS,
+                                          poll_max) < 0)
+        goto save_error;
+
+#define VSH_IOTHREAD_SET_UINT_PARAMS(opt, param) \
+    poll_val = 0; \
+    if ((rc = vshCommandOptUInt(ctl, cmd, opt, &poll_val)) < 0) \
+        goto cleanup; \
+    if (rc > 0 && \
+        virTypedParamsAddUInt(&params, &nparams, &maxparams, \
+                              param, poll_val) < 0) \
+        goto save_error;
+
+    VSH_IOTHREAD_SET_UINT_PARAMS("poll-grow", VIR_DOMAIN_IOTHREAD_POLL_GROW)
+    VSH_IOTHREAD_SET_UINT_PARAMS("poll-shrink", VIR_DOMAIN_IOTHREAD_POLL_SHRINK)
+
+#undef VSH_IOTHREAD_SET_UINT_PARAMS
+
+    if (virDomainSetIOThreadParams(dom, id, params, nparams, flags) < 0)
+        goto cleanup;
+
+    ret = true;
+
+ cleanup:
+    virTypedParamsFree(params, nparams);
+    virshDomainFree(dom);
+    return ret;
+
+ save_error:
+    vshSaveLibvirtError();
+    goto cleanup;
+}
+
+
 /*
  * "iothreaddel" command
  */
@@ -14149,6 +14253,12 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_iothreadadd,
      .flags = 0
     },
+    {.name = "iothreadset",
+     .handler = cmdIOThreadSet,
+     .opts = opts_iothreadset,
+     .info = info_iothreadset,
+     .flags = 0
+    },
     {.name = "iothreaddel",
      .handler = cmdIOThreadDel,
      .opts = opts_iothreaddel,
index 90f3c1ef5c1bf453091a585eeef75dabd2041619..48766567f8a38ac759f303ec2af3fae942b35bfa 100644 (file)
@@ -1732,6 +1732,27 @@ If I<--config> is specified, affect the next boot of a persistent guest.
 If I<--current> is specified or I<--live> and I<--config> are not specified,
 affect the current guest state.
 
+=item B<iothreadset> I<domain> I<iothread_id>
+[[I<--poll-max-ns> B<ns>] [I<--poll-grow> B<factor>]
+[I<--poll-shrink> B<divisor>]]
+[[I<--config>] [I<--live>] | [I<--current>]]
+
+Modifies an existing iothread of the domain using the specified
+I<iothread_id>. The I<--poll-max-ns> provides the maximum polling
+interval to be allowed for an IOThread in ns. If a 0 (zero) is provided,
+then polling for the IOThread is disabled.  The I<--poll-grow> is the
+factor by which the current polling time will be adjusted in order to
+reach the maximum polling time. If a 0 (zero) is provided, then the
+default factor will be used. The I<--poll-shrink> is the quotient
+by which the current polling time will be reduced in order to get
+below the maximum polling interval. If a 0 (zero) is provided, then
+the default quotient will be used.
+
+If I<--live> is specified, affect a running guest. If the guest is not
+running an error is returned.
+If I<--current> is specified or I<--live> is not specified, then handle
+as if I<--live> was specified.
+
 =item B<iothreaddel> I<domain> I<iothread_id>
 [[I<--config>] [I<--live>] | [I<--current>]]