From 31cd4dd8e7b1aef1384b94b70bbb0cc262f3d3a5 Mon Sep 17 00:00:00 2001 From: Han Han Date: Wed, 4 Jul 2018 11:04:59 +0800 Subject: [PATCH] virsh: usb support for virsh attach-disk --address Adding usb bus address support to the optional address parameter of virsh attach-disk. The address is used as bus:port. e.g. usb:1:1. Signed-off-by: Han Han Signed-off-by: Michal Privoznik --- tools/virsh-domain.c | 38 +++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 10 +++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e9b88f0013..5a445eff44 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -319,6 +319,7 @@ enum { DISK_ADDR_TYPE_SCSI, DISK_ADDR_TYPE_IDE, DISK_ADDR_TYPE_CCW, + DISK_ADDR_TYPE_USB, }; struct PCIAddress { @@ -346,6 +347,11 @@ struct CCWAddress { unsigned int devno; }; +struct USBAddress { + unsigned int bus; + unsigned int port; +}; + struct DiskAddress { int type; union { @@ -353,6 +359,7 @@ struct DiskAddress { struct SCSIAddress scsi; struct IDEAddress ide; struct CCWAddress ccw; + struct USBAddress usb; } addr; }; @@ -460,10 +467,32 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr) return 0; } +static int str2USBAddress(const char *str, struct USBAddress *usbAddr) +{ + char *bus, *port; + + if (!usbAddr) + return -1; + if (!str) + return -1; + + bus = (char *)str; + + if (virStrToLong_uip(bus, &port, 10, &usbAddr->bus) != 0) + return -1; + + port++; + if (virStrToLong_uip(port, NULL, 10, &usbAddr->port) != 0) + return -1; + + return 0; +} + /* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function) * ide disk address: ide:00.00.0 (controller:bus:unit) * scsi disk address: scsi:00.00.0 (controller:bus:unit) * ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno) + * usb disk address: usb:00.00 (bus:port) */ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) @@ -492,6 +521,9 @@ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) } else if (STREQLEN(type, "ccw", addr - type)) { diskAddr->type = DISK_ADDR_TYPE_CCW; return str2CCWAddress(addr + 1, &diskAddr->addr.ccw); + } else if (STREQLEN(type, "usb", addr - type)) { + diskAddr->type = DISK_ADDR_TYPE_USB; + return str2USBAddress(addr + 1, &diskAddr->addr.usb); } return -1; @@ -648,8 +680,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) " bus='%u' unit='%llu' />\n", diskAddr.addr.scsi.controller, diskAddr.addr.scsi.bus, diskAddr.addr.scsi.unit); + } else if (diskAddr.type == DISK_ADDR_TYPE_USB) { + virBufferAsprintf(&buf, + "
\n", + diskAddr.addr.usb.bus, diskAddr.addr.usb.port); } else { - vshError(ctl, "%s", _("expecting a scsi:00.00.00 address.")); + vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 address.")); goto cleanup; } } else if (STRPREFIX((const char *)target, "hd")) { diff --git a/tools/virsh.pod b/tools/virsh.pod index 003becb7c3..6cb5a76b4d 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3059,11 +3059,11 @@ I is the number within the range of domain IOThreads to which this disk may be attached (QEMU only). I is the serial of disk device. I is the wwn of disk device. I indicates the disk needs rawio capability. -I
is the address of disk device in the form of pci:domain.bus.slot.function, -scsi:controller.bus.unit, ide:controller.bus.unit or ccw:cssid.ssid.devno. -Virtio-ccw devices must have their cssid set to 0xfe. -I indicates specified pci address is a multifunction pci device -address. +I
is the address of disk device in the form of +pci:domain.bus.slot.function, scsi:controller.bus.unit, +ide:controller.bus.unit, usb:bus.port or ccw:cssid.ssid.devno. Virtio-ccw +devices must have their cssid set to 0xfe. I indicates +specified pci address is a multifunction pci device address. If I<--print-xml> is specified, then the XML of the disk that would be attached is printed instead.