Only nodedev-destroy and nodedev-dumpxml can benifit from the
new API, other commands like nodedev-detach only works for
PCI devices, WWN makes no sense for them.
---
tools/virsh-nodedev.c | 91 ++++++++++++++++++++++++++++++++++++------------
tools/virsh.pod | 15 +++++---
2 files changed, 77 insertions(+), 29 deletions(-)
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index f9517cc..0090261 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -97,8 +97,9 @@ static const vshCmdInfo info_node_device_destroy[] = {
};
static const vshCmdOptDef opts_node_device_destroy[] = {
- {"name", VSH_OT_DATA, VSH_OFLAG_REQ,
- N_("name of the device to be destroyed")},
+ {"name", VSH_OT_ALIAS, 0, "device"},
+ {"device", VSH_OT_DATA, VSH_OFLAG_REQ,
+ N_("device name or wwn pair in 'wwnn,wwpn' format")},
{NULL, 0, 0, NULL}
};
@@ -106,21 +107,44 @@ static bool
cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
{
virNodeDevicePtr dev = NULL;
- bool ret = true;
- const char *name = NULL;
+ bool ret = false;
+ const char *device_value = NULL;
+ char **arr = NULL;
+ int narr;
- if (vshCommandOptString(cmd, "name", &name) <= 0)
+ if (vshCommandOptString(cmd, "device", &device_value) <= 0)
return false;
- dev = virNodeDeviceLookupByName(ctl->conn, name);
+ if (strchr(device_value, ',')) {
+ narr = vshStringToArray(device_value, &arr);
+ if (narr != 2) {
+ vshError(ctl, _("Malformed device value '%s'"),
device_value);
+ goto cleanup;
+ }
+
+ dev = virNodeDeviceLookupSCSIHostByWWN(ctl->conn, arr[0], arr[1], 0);
+ } else {
+ dev = virNodeDeviceLookupByName(ctl->conn, device_value);
+ }
+
+ if (!dev) {
+ vshError(ctl, "%s '%s'", _("Could not find matching
device"), device_value);
+ goto cleanup;
+ }
if (virNodeDeviceDestroy(dev) == 0) {
- vshPrint(ctl, _("Destroyed node device '%s'\n"), name);
+ vshPrint(ctl, _("Destroyed node device '%s'\n"),
device_value);
} else {
- vshError(ctl, _("Failed to destroy node device '%s'"), name);
- ret = false;
+ vshError(ctl, _("Failed to destroy node device '%s'"),
device_value);
+ goto cleanup;
}
+ ret = true;
+cleanup:
+ if (arr) {
+ VIR_FREE(*arr);
+ VIR_FREE(arr);
+ }
virNodeDeviceFree(dev);
return ret;
}
@@ -459,34 +483,55 @@ static const vshCmdInfo info_node_device_dumpxml[] = {
static const vshCmdOptDef opts_node_device_dumpxml[] = {
- {"device", VSH_OT_DATA, VSH_OFLAG_REQ, N_("device key")},
+ {"device", VSH_OT_DATA, VSH_OFLAG_REQ,
+ N_("device name or wwn pair in 'wwnn,wwpn' format")},
{NULL, 0, 0, NULL}
};
static bool
cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
{
- const char *name = NULL;
- virNodeDevicePtr device;
- char *xml;
-
- if (vshCommandOptString(cmd, "device", &name) <= 0)
- return false;
- if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
- vshError(ctl, "%s '%s'", _("Could not find matching
device"), name);
+ virNodeDevicePtr device = NULL;
+ char *xml = NULL;
+ const char *device_value = NULL;
+ char **arr = NULL;
+ int narr;
+ bool ret = false;
+
+ if (vshCommandOptString(cmd, "device", &device_value) <= 0)
return false;
+
+ if (strchr(device_value, ',')) {
+ narr = vshStringToArray(device_value, &arr);
+ if (narr != 2) {
+ vshError(ctl, _("Malformed device value '%s'"),
device_value);
+ goto cleanup;
+ }
+
+ device = virNodeDeviceLookupSCSIHostByWWN(ctl->conn, arr[0], arr[1], 0);
+ } else {
+ device = virNodeDeviceLookupByName(ctl->conn, device_value);
}
- xml = virNodeDeviceGetXMLDesc(device, 0);
- if (!xml) {
- virNodeDeviceFree(device);
- return false;
+ if (!device) {
+ vshError(ctl, "%s '%s'", _("Could not find matching
device"), device_value);
+ goto cleanup;
}
+ if (!(xml = virNodeDeviceGetXMLDesc(device, 0)))
+ goto cleanup;
+
vshPrint(ctl, "%s\n", xml);
+ ret = true;
+
+cleanup:
+ if (arr) {
+ VIR_FREE(*arr);
+ VIR_FREE(arr);
+ }
VIR_FREE(xml);
virNodeDeviceFree(device);
- return true;
+ return ret;
}
/*
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 3687a4d..a2da9ef 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1950,11 +1950,12 @@ host nodes are available for use, but this allows registration of
host hardware that libvirt did not automatically detect. I<file>
contains xml for a top-level <device> description of a node device.
-=item B<nodedev-destroy> I<nodedev>
+=item B<nodedev-destroy> I<device>
-Destroy (stop) a device on the host. Note that this makes libvirt
-quit managing a host device, and may even make that device unusable
-by the rest of the physical host until a reboot.
+Destroy (stop) a device on the host. I<device> can be either device
+name or wwn pair in "wwnn,wwpn" format (only works for HBA). Note
+that this makes libvirt quit managing a host device, and may even make
+that device unusable by the rest of the physical host until a reboot.
=item B<nodedev-detach> I<nodedev>
@@ -1964,12 +1965,14 @@ B<nodedev-reattach>, and is done automatically for managed
devices.
For compatibility purposes, this command can also be spelled
B<nodedev-dettach>.
-=item B<nodedev-dumpxml> I<nodedev>
+=item B<nodedev-dumpxml> I<device>
Dump a <device> XML representation for the given node device, including
such information as the device name, which bus owns the device, the
vendor and product id, and any capabilities of the device usable by
-libvirt (such as whether device reset is supported).
+libvirt (such as whether device reset is supported). I<device> can
+be either device name or wwn pair in "wwnn,wwpn" format (only works
+for HBA).
=item B<nodedev-list> I<cap> I<--tree>
--
1.7.7.6