Now that we can filter active and inactive node devices in
virConnectListAllNodeDevices(), add these switches to the virsh command.
Eventual output (once everything is hooked up):
virsh # nodedev-list --inactive --cap mdev
mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c
mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c
virsh # nodedev-list --active --cap mdev
mdev_bd2ea955_3402_4252_8c17_7468083a0f26
virsh # nodedev-list --all --cap mdev
mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c
mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c
mdev_bd2ea955_3402_4252_8c17_7468083a0f26
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
tools/virsh-nodedev.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 7f091d7cf8..2fb6be504b 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -379,6 +379,18 @@ static const vshCmdOptDef opts_node_list_devices[] = {
.completer = virshNodeDeviceCapabilityNameCompleter,
.help = N_("capability names, separated by comma")
},
+ {.name = "active",
+ .type = VSH_OT_BOOL,
+ .help = N_("list active devices")
+ },
+ {.name = "inactive",
+ .type = VSH_OT_BOOL,
+ .help = N_("list inactive devices")
+ },
+ {.name = "all",
+ .type = VSH_OT_BOOL,
+ .help = N_("list inactive & active devices")
+ },
{.name = NULL}
};
@@ -394,18 +406,28 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd
G_GNUC_UNUSED)
int ncaps = 0;
virshNodeDeviceListPtr list = NULL;
int cap_type = -1;
+ bool active, inactive, all;
+ active = vshCommandOptBool(cmd, "active");
+ inactive = vshCommandOptBool(cmd, "inactive");
+ all = vshCommandOptBool(cmd, "all");
ignore_value(vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str));
if (cap_str) {
- if (tree) {
- vshError(ctl, "%s", _("Options --tree and --cap are
incompatible"));
- return false;
- }
if ((ncaps = vshStringToArray(cap_str, &caps)) < 0)
return false;
}
+ if (all && (inactive || active)) {
+ vshError(ctl, "%s", _("Option --all is incompatible with --active
and --inactive"));
+ return false;
+ }
+
+ if (tree && (cap_str || active || inactive)) {
+ vshError(ctl, "%s", _("Option --tree is incompatible with other
options"));
+ return false;
+ }
+
for (i = 0; i < ncaps; i++) {
if ((cap_type = virNodeDevCapTypeFromString(caps[i])) < 0) {
vshError(ctl, "%s", _("Invalid capability type"));
@@ -467,6 +489,11 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
}
}
+ if (inactive || all)
+ flags |= VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE;
+ if (active || all)
+ flags |= VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE;
+
if (!(list = virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) {
ret = false;
goto cleanup;
--
2.21.3