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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 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 87668f2b9a..e9023ba17b 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -5135,6 +5135,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 8c2086b71f..845effcb81 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1162,6 +1162,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,
@@ -1233,5 +1298,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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux