[libvirt PATCH v2 16/16] virsh: add "nodedev-start" command

Jonathon Jongsma posted 16 patches 5 years, 5 months ago
There is a newer version of this series
[libvirt PATCH v2 16/16] virsh: add "nodedev-start" command
Posted by Jonathon Jongsma 5 years, 5 months ago
This virsh command maps to virNodeDeviceCreate(), which starts a node
device that has been previously defined by virNodeDeviceDefineXML().
This is only supported for mediated devices.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 tools/virsh-nodedev.c | 61 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index db56fbc5e9..eea576ff89 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1113,6 +1113,61 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
 }
 
 
+/*
+ * "nodedev-start" command
+ */
+static const vshCmdInfo info_node_device_start[] = {
+    {.name = "help",
+     .data = N_("Start a previously defined inactive node device")
+    },
+    {.name = "desc",
+     .data = N_("Starts the configuration for an inactive node device")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_node_device_start[] = {
+    {.name = "name",
+     .type = VSH_OT_ALIAS,
+     .help = "device"
+    },
+    {.name = "device",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("device name"),
+     .completer = virshNodeDeviceNameCompleter,
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name = NULL;
+    virNodeDevicePtr device;
+    bool ret = true;
+    virshControlPtr priv = ctl->privData;
+
+    if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
+        return false;
+
+    if (!(device = virNodeDeviceLookupByName(priv->conn, name))) {
+        vshError(ctl, _("Could not find matching device '%s'"), name);
+        return false;
+    }
+
+    if (virNodeDeviceCreate(device) == 0) {
+        vshPrintExtra(ctl, _("Device %s started\n"), name);
+    } else {
+        vshError(ctl, _("Failed to start device %s"), name);
+        ret = false;
+    }
+
+    virNodeDeviceFree(device);
+    return ret;
+}
+
+
 const vshCmdDef nodedevCmds[] = {
     {.name = "nodedev-create",
      .handler = cmdNodeDeviceCreate,
@@ -1178,5 +1233,11 @@ const vshCmdDef nodedevCmds[] = {
      .info = info_node_device_undefine,
      .flags = 0
     },
+    {.name = "nodedev-start",
+     .handler = cmdNodeDeviceStart,
+     .opts = opts_node_device_start,
+     .info = info_node_device_start,
+     .flags = 0
+    },
     {.name = NULL}
 };
-- 
2.26.2

Re: [libvirt PATCH v2 16/16] virsh: add "nodedev-start" command
Posted by Erik Skultety 5 years, 5 months ago
On Tue, Aug 18, 2020 at 09:48:06AM -0500, Jonathon Jongsma wrote:
> This virsh command maps to virNodeDeviceCreate(), which starts a node
> device that has been previously defined by virNodeDeviceDefineXML().
> This is only supported for mediated devices.
>
> Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
> ---
>  tools/virsh-nodedev.c | 61 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
>
> diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
> index db56fbc5e9..eea576ff89 100644
> --- a/tools/virsh-nodedev.c
> +++ b/tools/virsh-nodedev.c
> @@ -1113,6 +1113,61 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
>  }
>
>
> +/*
> + * "nodedev-start" command
> + */
> +static const vshCmdInfo info_node_device_start[] = {
> +    {.name = "help",
> +     .data = N_("Start a previously defined inactive node device")
> +    },
> +    {.name = "desc",
> +     .data = N_("Starts the configuration for an inactive node device")

How about
"Takes an inactive node device configuration and creates a device based on it"

would that work as a description?

Regards,
Erik