]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add nodedev-autostart
authorJonathon Jongsma <jjongsma@redhat.com>
Thu, 27 May 2021 21:20:13 +0000 (16:20 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 14 Sep 2021 19:24:07 +0000 (14:24 -0500)
Add ability to set node devices to autostart on boot or parent device
availability.

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 9561b3f59d89fd220e2a812b1af8f3345b34caf0..5e82c6d9fb24ba937b05dec9d934b7c039a5b67a 100644 (file)
@@ -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
 ========================
 
index 945ccc7f45face54fe8ebda6e4298b8868dfad7c..0a70029fc7e324281d1bfcf7367421c409cd33c1 100644 (file)
@@ -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}
 };