[libvirt PATCH v3 4/7] virsh: add nodedev-autostart

Jonathon Jongsma jjongsma at redhat.com
Fri Aug 20 22:29:32 UTC 2021


Add ability to set node devices to autostart on boot or parent device
availability.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange at redhat.com>
---
 docs/manpages/virsh.rst | 15 +++++++++
 tools/virsh-nodedev.c   | 71 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index e0cdabf3aa..08097a45bf 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -5131,6 +5131,21 @@ When *--timestamp* is used, a human-readable timestamp will be printed
 before the event.
 
 
+nodedev-autostart
+-----------------
+
+**Syntax:**
+
+::
+
+   nodedev-autostart [--disable] device
+
+Configure a device to be automatically started when the host machine boots or
+the parent device becomes available. With *--disable*, the device will be set
+to manual mode and will no longer be automatically started by the host. This
+command is only supported for persistently-defined mediated devices.
+
+
 VIRTUAL NETWORK COMMANDS
 ========================
 
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 945ccc7f45..0a70029fc7 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1153,6 +1153,71 @@ cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd)
 }
 
 
+/*
+ * "nodedev-autostart" command
+ */
+static const vshCmdInfo info_node_device_autostart[] = {
+    {.name = "help",
+     .data = N_("autostart a defined node device")
+    },
+    {.name = "desc",
+     .data = N_("Configure a node device to be automatically started at boot.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_node_device_autostart[] = {
+    {.name = "device",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
+     .completer = virshNodeDeviceNameCompleter,
+    },
+    {.name = "disable",
+     .type = VSH_OT_BOOL,
+     .help = N_("disable autostarting")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
+{
+    virNodeDevice *dev = NULL;
+    bool ret = false;
+    const char *name = NULL;
+    int autostart;
+
+    if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
+        return false;
+
+    dev = vshFindNodeDevice(ctl, name);
+
+    if (!dev) goto cleanup;
+
+    autostart = !vshCommandOptBool(cmd, "disable");
+
+    if (virNodeDeviceSetAutostart(dev, autostart) < 0) {
+        if (autostart)
+            vshError(ctl, _("failed to mark device %s as autostarted"), name);
+        else
+            vshError(ctl, _("failed to unmark device %s as autostarted"), name);
+        goto cleanup;
+    }
+
+    if (autostart)
+        vshPrintExtra(ctl, _("Device %s marked as autostarted\n"), name);
+    else
+        vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name);
+
+    ret = true;
+ cleanup:
+    if (dev)
+        virNodeDeviceFree(dev);
+    return ret;
+}
+
+
 const vshCmdDef nodedevCmds[] = {
     {.name = "nodedev-create",
      .handler = cmdNodeDeviceCreate,
@@ -1224,5 +1289,11 @@ const vshCmdDef nodedevCmds[] = {
      .info = info_node_device_start,
      .flags = 0
     },
+    {.name = "nodedev-autostart",
+     .handler = cmdNodeDeviceAutostart,
+     .opts = opts_node_device_autostart,
+     .info = info_node_device_autostart,
+     .flags = 0
+    },
     {.name = NULL}
 };
-- 
2.31.1




More information about the libvir-list mailing list