]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add nodedev-info
authorJonathon Jongsma <jjongsma@redhat.com>
Wed, 2 Jun 2021 20:27:41 +0000 (15:27 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 14 Sep 2021 19:25:56 +0000 (14:25 -0500)
This is currently the only way to view the 'autostart' property for a
node device in virsh.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
docs/manpages/virsh.rst
tools/virsh-nodedev.c

index 5e82c6d9fb24ba937b05dec9d934b7c039a5b67a..ce98283ae32cdccffe133c176ee08f572735c1c7 100644 (file)
@@ -5057,6 +5057,18 @@ be either device name or wwn pair in "wwnn,wwpn" format (only works
 for HBA).
 
 
+nodedev-info
+------------
+
+**Syntax:**
+
+::
+
+   nodedev-info device
+
+Returns basic information about the *device* object.
+
+
 nodedev-list
 ------------
 
index 0a70029fc7e324281d1bfcf7367421c409cd33c1..f1b4eb94bf75673e55b81924373265253ad2e27b 100644 (file)
@@ -1218,6 +1218,68 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
 }
 
 
+/*
+ * "nodedev-info" command
+ */
+static const vshCmdInfo info_node_device_info[] = {
+    {.name = "help",
+     .data = N_("node device information")
+    },
+    {.name = "desc",
+     .data = N_("Returns basic information about the node device")
+    },
+    {.name = NULL}
+};
+
+
+static const vshCmdOptDef opts_node_device_info[] = {
+    {.name = "device",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
+     .completer = virshNodeDeviceNameCompleter,
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
+{
+    virNodeDevicePtr device = NULL;
+    const char *device_value = NULL;
+    bool ret = false;
+    int autostart;
+    const char *parent = NULL;
+
+    if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
+         return false;
+
+    device = vshFindNodeDevice(ctl, device_value);
+
+    if (!device)
+        goto cleanup;
+
+    parent = virNodeDeviceGetParent(device);
+    vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
+    vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "");
+    vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device) ?
+             _("yes") : _("no"));
+    vshPrint(ctl, "%-15s %s\n", _("Persistent:"),
+             virNodeDeviceIsPersistent(device) ? _("yes") : _("no"));
+    if (virNodeDeviceGetAutostart(device, &autostart) < 0)
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+    else
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
+
+    ret = true;
+ cleanup:
+    if (device)
+        virNodeDeviceFree(device);
+    return ret;
+}
+
+
+
 const vshCmdDef nodedevCmds[] = {
     {.name = "nodedev-create",
      .handler = cmdNodeDeviceCreate,
@@ -1295,5 +1357,11 @@ const vshCmdDef nodedevCmds[] = {
      .info = info_node_device_autostart,
      .flags = 0
     },
+    {.name = "nodedev-info",
+     .handler = cmdNodeDeviceInfo,
+     .opts = opts_node_device_info,
+     .info = info_node_device_info,
+     .flags = 0
+    },
     {.name = NULL}
 };