[libvirt] [PATCH 11/23] virsh: Implement 'domblkthreshold' command to call virDomainSetBlockThreshold

Peter Krempa posted 23 patches 8 years, 11 months ago
[libvirt] [PATCH 11/23] virsh: Implement 'domblkthreshold' command to call virDomainSetBlockThreshold
Posted by Peter Krempa 8 years, 11 months ago
Add a simple wrapper which will allow to set the threshold for
delivering the event.
---
 tools/virsh-domain.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod      |  8 +++++++
 2 files changed, 72 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ee702f3c4..36629523b 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -7097,6 +7097,64 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd)


 /*
+ * "domblkthreshold" command
+ */
+static const vshCmdInfo info_domblkthreshold[] = {
+    {.name = "help",
+     .data = N_("set the threshold for block-threshold event for a given block "
+                "device or it's backing chain element")
+    },
+    {.name = "desc",
+     .data = N_("set threshold for ")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_domblkthreshold[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL,
+    {.name = "dev",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("device to set threshold for")
+    },
+    {.name = "threshold",
+     .type = VSH_OT_INT,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("threshold as a scaled number (by default bytes)")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd)
+{
+    unsigned long long threshold;
+    const char *dev = NULL;
+    virDomainPtr dom;
+    bool ret = false;
+
+    if (vshCommandOptStringReq(ctl, cmd, "dev", &dev))
+        return false;
+
+    if (vshCommandOptScaledInt(ctl, cmd, "threshold",
+                               &threshold, 1, ULLONG_MAX) < 0)
+        return false;
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0)
+        goto cleanup;
+
+    ret = true;
+
+ cleanup:
+    virDomainFree(dom);
+    return ret;
+}
+
+
+/*
  * "iothreadinfo" command
  */
 static const vshCmdInfo info_iothreadinfo[] = {
@@ -14060,5 +14118,11 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_setvcpu,
      .flags = 0
     },
+    {.name = "domblkthreshold",
+     .handler = cmdDomblkthreshold,
+     .opts = opts_domblkthreshold,
+     .info = info_domblkthreshold,
+     .flags = 0
+    },
     {.name = NULL}
 };
diff --git a/tools/virsh.pod b/tools/virsh.pod
index ee7904611..48be19234 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1274,6 +1274,14 @@ I<--bytes> with a scaled value allows to use finer granularity. A scaled value
 used without I<--bytes> will be rounded down to MiB/s. Note that the
 I<--bytes> may be unsupported by the hypervisor.

+
+=item B<domblkthreshold> I<domain> I<dev> I<threshold>
+
+Set the threshold value for delivering the block-threshold event. I<dev>
+specifies the disk device target or backing chain element of given device using
+the 'target[1]' syntax. I<threshold> is a scaled value of the offset. If the
+block device should write beyond that offset the event will be delivered.
+
 =item B<blockresize> I<domain> I<path> I<size>

 Resize a block device of domain while the domain is running, I<path>
-- 
2.12.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/23] virsh: Implement 'domblkthreshold' command to call virDomainSetBlockThreshold
Posted by Eric Blake 8 years, 10 months ago
On 03/15/2017 11:37 AM, Peter Krempa wrote:
> Add a simple wrapper which will allow to set the threshold for
> delivering the event.
> ---
>  tools/virsh-domain.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod      |  8 +++++++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index ee702f3c4..36629523b 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -7097,6 +7097,64 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd)
> 
> 
>  /*
> + * "domblkthreshold" command
> + */
> +static const vshCmdInfo info_domblkthreshold[] = {
> +    {.name = "help",
> +     .data = N_("set the threshold for block-threshold event for a given block "
> +                "device or it's backing chain element")
> +    },
> +    {.name = "desc",
> +     .data = N_("set threshold for ")

Incomplete thought?

> +
> +=item B<domblkthreshold> I<domain> I<dev> I<threshold>
> +
> +Set the threshold value for delivering the block-threshold event. I<dev>
> +specifies the disk device target or backing chain element of given device using
> +the 'target[1]' syntax. I<threshold> is a scaled value of the offset. If the
> +block device should write beyond that offset the event will be delivered.
> +

Should virsh check that the event is actually available from the server
(that is, that a registration for the event succeeds) before trying the
threshold?  Or are we not worried about that?  At the lower level, it is
reasonable to assume that any driver will either implement all or none
of the threshold setting and event in the same release, so if the
command succeeds, then you are right that the event should work.

So, once you fix the "desc" text, ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/23] virsh: Implement 'domblkthreshold' command to call virDomainSetBlockThreshold
Posted by Peter Krempa 8 years, 10 months ago
On Thu, Mar 23, 2017 at 14:34:04 -0500, Eric Blake wrote:
> On 03/15/2017 11:37 AM, Peter Krempa wrote:
> > Add a simple wrapper which will allow to set the threshold for
> > delivering the event.
> > ---
> >  tools/virsh-domain.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tools/virsh.pod      |  8 +++++++
> >  2 files changed, 72 insertions(+)

[...]

> > +=item B<domblkthreshold> I<domain> I<dev> I<threshold>
> > +
> > +Set the threshold value for delivering the block-threshold event. I<dev>
> > +specifies the disk device target or backing chain element of given device using
> > +the 'target[1]' syntax. I<threshold> is a scaled value of the offset. If the
> > +block device should write beyond that offset the event will be delivered.
> > +
> 
> Should virsh check that the event is actually available from the server
> (that is, that a registration for the event succeeds) before trying the
> threshold?  Or are we not worried about that?  At the lower level, it is
> reasonable to assume that any driver will either implement all or none
> of the threshold setting and event in the same release, so if the
> command succeeds, then you are right that the event should work.

Hypervisors which don't support the event don't have this API
implemented. Additionally the qemu implementation checks the capability
prior to returning success here. This would catch only the case where
somebody would do a botched backport of this. Since it's not a good idea
to backport APIs I don't think that situation will ever happen.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list