]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add option "throttle-groups" to "attach_disk"
authorChun Feng Wu <danielwuwy@163.com>
Wed, 19 Feb 2025 16:57:22 +0000 (22:27 +0530)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Mar 2025 16:43:44 +0000 (17:43 +0100)
Update "attach_disk" to support new option: throttle-groups to
form filter chain in QEMU for specific disk

Signed-off-by: Chun Feng Wu <danielwuwy@163.com>
* apply suggested coding style changes.

Signed-off-by: Harikumar Rajkumar <harirajkumar230@gmail.com>
* Fixed alignment of child elements in the XML
* Fixed placement of the throttlegroups element
* Removed completer wrapper

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/manpages/virsh.rst
tools/virsh-completer-domain.c
tools/virsh-completer-domain.h
tools/virsh-domain.c

index 1d2f5834442a1e82d63c226d7fad2dc60af8f9a7..a8966994482259945ad587f4ad9d25d5f3438924 100644 (file)
@@ -5071,7 +5071,7 @@ attach-disk
       [--source-protocol protocol] [--source-host-name hostname:port]
       [--source-host-transport transport] [--source-host-socket socket]
       [--serial serial] [--wwn wwn] [--rawio] [--address address]
-      [--multifunction] [--print-xml]
+      [--multifunction] [--print-xml] [--throttle-groups groups]
 
 Attach a new disk device to the domain.
 *source* is path for the files and devices unless *--source-protocol*
@@ -5111,6 +5111,7 @@ ide:controller.bus.unit, usb:bus.port, sata:controller.bus.unit or
 ccw:cssid.ssid.devno. Virtio-ccw devices must have their cssid set to 0xfe.
 *multifunction* indicates specified pci address is a multifunction pci device
 address.
+*throttle-groups* is comma separated list of throttle groups to be applied.
 
 There is also support for using a network disk. As specified, the user can
 provide a *--source-protocol* in which case the *source* parameter will
index 8c5fbb1e1b23fbdb9e2aacbf4c31471e42080faa..0a3a113dcaf72eba1ae49f8eb5c8ad3eca50471c 100644 (file)
@@ -293,6 +293,24 @@ virshDomainThrottleGroupCompleter(vshControl *ctl,
 }
 
 
+char **
+virshDomainThrottleGroupsCompleter(vshControl *ctl,
+                                   const vshCmd *cmd,
+                                   unsigned int completeflags G_GNUC_UNUSED)
+{
+    const char *curval = NULL;
+    g_auto(GStrv) groups = virshDomainThrottleGroupCompleter(ctl, cmd, 0);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "throttle-groups", &curval) < 0)
+        return NULL;
+
+    if (!groups)
+        return NULL;
+
+    return virshCommaStringListComplete(curval, (const char **) groups);
+}
+
+
 char **
 virshDomainUndefineStorageDisksCompleter(vshControl *ctl,
                                  const vshCmd *cmd,
index 82c907e4fe993acec989612bb3bcb4bdf2cc34f2..f5cda4dd15b24b2cc8de0183fc0bdaca4b27d603 100644 (file)
@@ -50,6 +50,11 @@ virshDomainThrottleGroupCompleter(vshControl *ctl,
                                   const vshCmd *cmd,
                                   unsigned int flags);
 
+char **
+virshDomainThrottleGroupsCompleter(vshControl *ctl,
+                                   const vshCmd *cmd,
+                                   unsigned int flags);
+
 char **
 virshDomainInterfaceStateCompleter(vshControl *ctl,
                                    const vshCmd *cmd,
index 1991fc6739103708ef5f79458a73e4f3a6c7a2bc..f07260f21740ce3b0b37b0a9bbb28bffa24d3e78 100644 (file)
@@ -522,6 +522,11 @@ static const vshCmdOptDef opts_attach_disk[] = {
      .type = VSH_OT_STRING,
      .help = N_("host socket for source of disk device")
     },
+    {.name = "throttle-groups",
+     .type = VSH_OT_STRING,
+     .completer = virshDomainThrottleGroupsCompleter,
+     .help = N_("comma separated list of throttle groups to be applied")
+    },
     VIRSH_COMMON_OPT_DOMAIN_PERSISTENT,
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
     VIRSH_COMMON_OPT_DOMAIN_LIVE,
@@ -611,6 +616,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     const char *host_name = NULL;
     const char *host_transport = NULL;
     const char *host_socket = NULL;
+    const char *throttle_groups_str = NULL;
     int ret;
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
     const char *stype = NULL;
@@ -665,7 +671,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         vshCommandOptString(ctl, cmd, "source-protocol", &source_protocol) < 0 ||
         vshCommandOptString(ctl, cmd, "source-host-name", &host_name) < 0 ||
         vshCommandOptString(ctl, cmd, "source-host-transport", &host_transport) < 0 ||
-        vshCommandOptString(ctl, cmd, "source-host-socket", &host_socket) < 0)
+        vshCommandOptString(ctl, cmd, "source-host-socket", &host_socket) < 0 ||
+        vshCommandOptString(ctl, cmd, "throttle-groups", &throttle_groups_str) < 0)
         return false;
 
     if (stype &&
@@ -756,6 +763,18 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         virBufferAsprintf(&diskChildBuf, " bus='%s'", targetbus);
     virBufferAddLit(&diskChildBuf, "/>\n");
 
+    if (throttle_groups_str) {
+        g_auto(GStrv) throttle_groups = g_strsplit(throttle_groups_str, ",", 0);
+        g_auto(virBuffer) throttleChildBuf = VIR_BUFFER_INIT_CHILD(&diskChildBuf);
+        char **iter;
+        for (iter = throttle_groups; *iter != NULL; iter++) {
+            g_auto(virBuffer) throttleAttrBuf = VIR_BUFFER_INITIALIZER;
+            virBufferAsprintf(&throttleAttrBuf, " group='%s'", *iter);
+            virXMLFormatElement(&throttleChildBuf, "throttlefilter", &throttleAttrBuf, NULL);
+        }
+        virXMLFormatElement(&diskChildBuf, "throttlefilters", NULL, &throttleChildBuf);
+    }
+
     if (mode)
         virBufferAsprintf(&diskChildBuf, "<%s/>\n", mode);