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

[libvirt PATCH v2 14/16] virsh: add nodedev-undefine command



Add a virsh command that maps to virNodeDeviceUndefine().

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

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 34203c0e91..db56fbc5e9 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1002,6 +1002,65 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd)
 }
 
 
+/*
+ * "nodedev-undefine" command
+ */
+static const vshCmdInfo info_node_device_undefine[] = {
+    {.name = "help",
+     .data = N_("Undefine an inactive node device")
+    },
+    {.name = "desc",
+     .data = N_("Undefines the configuration for an inactive node device")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_node_device_undefine[] = {
+    {.name = "name",
+     .type = VSH_OT_ALIAS,
+     .help = "device"
+    },
+    {.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
+cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
+{
+    virNodeDevicePtr dev = NULL;
+    bool ret = false;
+    const char *device_value = NULL;
+
+    if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
+        return false;
+
+    dev = vshFindNodeDevice(ctl, device_value);
+
+    if (!dev) {
+        vshError(ctl, "%s '%s'", _("Could not find matching device"), device_value);
+        goto cleanup;
+    }
+
+    if (virNodeDeviceUndefine(dev) == 0) {
+        vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value);
+    } else {
+        vshError(ctl, _("Failed to undefine node device '%s'"), device_value);
+        goto cleanup;
+    }
+
+    ret = true;
+ cleanup:
+    if (dev)
+        virNodeDeviceFree(dev);
+    return ret;
+}
+
+
 /*
  * "nodedev-define" command
  */
@@ -1113,5 +1172,11 @@ const vshCmdDef nodedevCmds[] = {
      .info = info_node_device_define,
      .flags = 0
     },
+    {.name = "nodedev-undefine",
+     .handler = cmdNodeDeviceUndefine,
+     .opts = opts_node_device_undefine,
+     .info = info_node_device_undefine,
+     .flags = 0
+    },
     {.name = NULL}
 };
-- 
2.26.2


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