[libvirt PATCH v2 04/16] virsh: Add --active, --inactive, --all to nodedev-list

Jonathon Jongsma jjongsma at redhat.com
Tue Aug 18 14:47:54 UTC 2020


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 at 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 e576b3c847..e87761188f 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -378,6 +378,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}
 };
 
@@ -393,18 +405,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"));
@@ -466,6 +488,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.26.2




More information about the libvir-list mailing list