From 71e9a0ec2c57ef3ed1c5d98e9ccdda100c429e01 Mon Sep 17 00:00:00 2001 From: Radoslaw Smigielski Date: Mon, 13 Jul 2026 12:14:51 +0200 Subject: [PATCH] virsh: Add missing TAB completers for 'attach-disk' command Add enum and static-list completers for 'attach-disk' options targetbus, type, cache, io, mode, and sourcetype, and reuse the existing storage file format completer for subdriver. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski Reviewed-by: Peter Krempa --- tools/virsh-completer-domain.c | 74 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 30 ++++++++++++++ tools/virsh-domain.c | 8 ++++ 3 files changed, 112 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index f2fbe121b5..6e86f29987 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1183,3 +1183,77 @@ virshDomainXMLNativeFormatCompleter(vshControl *ctl, return vshCommaStringListComplete(NULL, formats); } + + +char ** +virshDomainDiskBusCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_BUS_LAST, + virDomainDiskBusTypeToString); +} + + +char ** +virshDomainDiskDeviceTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_DEVICE_LAST, + virDomainDiskDeviceTypeToString); +} + + +char ** +virshDomainDiskCacheCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_CACHE_LAST, + virDomainDiskCacheTypeToString); +} + + +char ** +virshDomainDiskIoCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_IO_LAST, + virDomainDiskIoTypeToString); +} + + +char ** +virshDomainAttachDiskModeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + static const char *modes[] = {"readonly", "shareable", NULL}; + + virCheckFlags(0, NULL); + + return vshCommaStringListComplete(NULL, modes); +} + + +char ** +virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + static const char *types[] = {"file", "block", "network", NULL}; + + virCheckFlags(0, NULL); + + return vshCommaStringListComplete(NULL, types); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 40de90afb7..aa2e826490 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -214,3 +214,33 @@ char ** virshDomainXMLNativeFormatCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshDomainDiskBusCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskDeviceTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskCacheCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskIoCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainAttachDiskModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dcd4362e36..688df75f81 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -435,6 +435,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "targetbus", .type = VSH_OT_STRING, + .completer = virshDomainDiskBusCompleter, .help = N_("target bus of disk device") }, {.name = "driver", @@ -443,6 +444,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "subdriver", .type = VSH_OT_STRING, + .completer = virshDomainStorageFileFormatCompleter, .help = N_("subdriver of disk device") }, {.name = "iothread", @@ -452,14 +454,17 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "cache", .type = VSH_OT_STRING, + .completer = virshDomainDiskCacheCompleter, .help = N_("cache mode of disk device") }, {.name = "io", .type = VSH_OT_STRING, + .completer = virshDomainDiskIoCompleter, .help = N_("io policy of disk device") }, {.name = "type", .type = VSH_OT_STRING, + .completer = virshDomainDiskDeviceTypeCompleter, .help = N_("target device type") }, {.name = "shareable", @@ -468,10 +473,12 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "mode", .type = VSH_OT_STRING, + .completer = virshDomainAttachDiskModeCompleter, .help = N_("mode of device reading and writing") }, {.name = "sourcetype", .type = VSH_OT_STRING, + .completer = virshDomainAttachDiskSourceTypeCompleter, .help = N_("type of source (block|file|network)") }, {.name = "serial", @@ -521,6 +528,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "source-host-socket", .type = VSH_OT_STRING, + .completer = vshCompletePathLocalExisting, .help = N_("host socket for source of disk device") }, {.name = "throttle-groups",