[libvirt] [PATCH 5/5] Add virsh nodedev-dettach, nodedev-reattach and nodedev-reset

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

 



Add virsh commands corresponding to each of the new methods.

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>
---
 ChangeLog   |    5 ++
 src/virsh.c |  126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 62a286f..4f2c125 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Feb 24 22:09:40 GMT 2009 Mark McLoughlin <markmc@xxxxxxxxxx>
+
+	* src/virsh.c: add new commands for each of the new
+	node device methods
+
 Tue Feb 24 22:08:15 GMT 2009 Mark McLoughlin <markmc@xxxxxxxxxx>
 
 	* src/qemu_driver.c: implement the new methods in the
diff --git a/src/virsh.c b/src/virsh.c
index 298dde0..8ae79c5 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -4433,6 +4433,129 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "nodedev-dettach" command
+ */
+static const vshCmdInfo info_node_device_dettach[] = {
+    {"help", gettext_noop("dettach node device its device driver")},
+    {"desc", gettext_noop("Dettach node device its device driver before assigning to a domain.")},
+    {NULL, NULL}
+};
+
+
+static const vshCmdOptDef opts_node_device_dettach[] = {
+    {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name;
+    virNodeDevicePtr device;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+    if (!(name = vshCommandOptString(cmd, "device", NULL)))
+        return FALSE;
+    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+        vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name);
+        return FALSE;
+    }
+
+    if (virNodeDeviceDettach(device) == 0) {
+        vshPrint(ctl, _("Device %s dettached\n"), name);
+    } else {
+        vshError(ctl, FALSE, _("Failed to dettach device %s"), name);
+        ret = FALSE;
+    }
+    virNodeDeviceFree(device);
+    return ret;
+}
+
+/*
+ * "nodedev-reattach" command
+ */
+static const vshCmdInfo info_node_device_reattach[] = {
+    {"help", gettext_noop("reattach node device its device driver")},
+    {"desc", gettext_noop("Dettach node device its device driver before assigning to a domain.")},
+    {NULL, NULL}
+};
+
+
+static const vshCmdOptDef opts_node_device_reattach[] = {
+    {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceReAttach (vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name;
+    virNodeDevicePtr device;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+    if (!(name = vshCommandOptString(cmd, "device", NULL)))
+        return FALSE;
+    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+        vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name);
+        return FALSE;
+    }
+
+    if (virNodeDeviceReAttach(device) == 0) {
+        vshPrint(ctl, _("Device %s re-attached\n"), name);
+    } else {
+        vshError(ctl, FALSE, _("Failed to re-attach device %s"), name);
+        ret = FALSE;
+    }
+    virNodeDeviceFree(device);
+    return ret;
+}
+
+/*
+ * "nodedev-reset" command
+ */
+static const vshCmdInfo info_node_device_reset[] = {
+    {"help", gettext_noop("reset node device")},
+    {"desc", gettext_noop("Reset node device before or after assigning to a domain.")},
+    {NULL, NULL}
+};
+
+
+static const vshCmdOptDef opts_node_device_reset[] = {
+    {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNodeDeviceReset (vshControl *ctl, const vshCmd *cmd)
+{
+    const char *name;
+    virNodeDevicePtr device;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+    if (!(name = vshCommandOptString(cmd, "device", NULL)))
+        return FALSE;
+    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+        vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name);
+        return FALSE;
+    }
+
+    if (virNodeDeviceReset(device) == 0) {
+        vshPrint(ctl, _("Device %s reset\n"), name);
+    } else {
+        vshError(ctl, FALSE, _("Failed to reset device %s"), name);
+        ret = FALSE;
+    }
+    virNodeDeviceFree(device);
+    return ret;
+}
+
+/*
  * "hostkey" command
  */
 static const vshCmdInfo info_hostname[] = {
@@ -5576,6 +5699,9 @@ static const vshCmdDef commands[] = {
 
     {"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices},
     {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml, info_node_device_dumpxml},
+    {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach, info_node_device_dettach},
+    {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach, info_node_device_reattach},
+    {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset, info_node_device_reset},
 
     {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart},
     {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},
-- 
1.6.0.6

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]