diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index f85bded7709c34a0ef980526fcebbadf7f71e857..7c51a5628b25506406dbcb458c8da178d1e8e3c2 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -101,9 +101,14 @@ static const vshCmdInfo info_node_device_destroy[] = { static const vshCmdOptDef opts_node_device_destroy[] = { {.name = "name", + .type = VSH_OT_ALIAS, + .flags = 0, + .help = "device" + }, + {.name = "device", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, - .help = N_("name of the device to be destroyed") + .help = N_("device name or wwn pair in 'wwnn,wwpn' format") }, {.name = NULL} }; @@ -112,21 +117,47 @@ 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 (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) + if (vshCommandOptStringReq(ctl, 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; + } + + if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) + 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; } @@ -476,7 +507,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = { {.name = "device", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, - .help = N_("device key") + .help = N_("device name or wwn pair in 'wwnn,wwpn' format"), }, {.name = NULL} }; @@ -484,26 +515,47 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = { static bool cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) { - const char *name = NULL; virNodeDevicePtr device = NULL; char *xml = NULL; + const char *device_value = NULL; + char **arr = NULL; + int narr; bool ret = false; - if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) - return false; + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; - if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { - vshError(ctl, _("Could not find matching device '%s'"), name); - return false; + if (strchr(device_value, ',')) { + narr = vshStringToArray(device_value, &arr); + if (narr != 2) { + vshError(ctl, _("Malformed device value '%s'"), device_value); + goto cleanup; + } + + if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) + goto cleanup; + + device = virNodeDeviceLookupSCSIHostByWWN(ctl->conn, arr[0], arr[1], 0); + } else { + device = virNodeDeviceLookupByName(ctl->conn, device_value); + } + + 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; + ret = true; cleanup: + if (arr) { + VIR_FREE(*arr); + VIR_FREE(arr); + } VIR_FREE(xml); virNodeDeviceFree(device); return ret; diff --git a/tools/virsh.pod b/tools/virsh.pod index ec1772d3f9e71f10152fa52a1e86a9609876cb42..96666c491e2f4a5e78bf827b56eb4b9cd48a1f5f 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1953,11 +1953,12 @@ host nodes are available for use, but this allows registration of host hardware that libvirt did not automatically detect. I contains xml for a top-level description of a node device. -=item B I +=item B I -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 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 I @@ -1967,12 +1968,14 @@ B, and is done automatically for managed devices. For compatibility purposes, this command can also be spelled B. -=item B I +=item B I Dump a 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 can +be either device name or wwn pair in "wwnn,wwpn" format (only works +for HBA). =item B I I<--tree>