From 0cb4550305e5a798439f06c3023da00e0e3b5b7c Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Wed, 2 Jun 2021 15:27:41 -0500 Subject: [PATCH] virsh: add nodedev-info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is currently the only way to view the 'autostart' property for a node device in virsh. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrangé --- docs/manpages/virsh.rst | 12 ++++++++ tools/virsh-nodedev.c | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 5e82c6d9fb..ce98283ae3 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -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 ------------ diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 0a70029fc7..f1b4eb94bf 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -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} };