1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-31 22:50:30 +03:00

virsh: Add option "throttle-groups" to "attach_disk"

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>
This commit is contained in:
Chun Feng Wu 2025-02-19 22:27:22 +05:30 committed by Peter Krempa
parent 180d41934c
commit 9cbc2b9c51
4 changed files with 45 additions and 2 deletions

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

@ -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,

@ -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,

@ -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);