[libvirt] [PATCH 0/2] Usb and sata for virsh attach-disk --address

Add usb and sata support for attach-disk of address parameter in virsh. Han Han (2): virsh: usb support for virsh attach-disk --address virsh: sata support for virsh attach-disk --address tools/virsh-domain.c | 82 +++++++++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 82 insertions(+), 2 deletions(-) -- 2.17.1

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 <hhan@redhat.com> --- tools/virsh-domain.c | 38 +++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 38 insertions(+), 2 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, + "<address type='usb' bus='%u' port='%u' />\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 dc100db9f3..2ca1b8f7a2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3060,7 +3060,7 @@ this disk may be attached (QEMU only). I<serial> is the serial of disk device. I<wwn> is the wwn of disk device. I<rawio> indicates the disk needs rawio capability. I<address> 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. +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<multifunction> indicates specified pci address is a multifunction pci device address. -- 2.17.1

On 07/04/2018 05:04 AM, Han Han wrote:
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 <hhan@redhat.com> --- tools/virsh-domain.c | 38 +++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 38 insertions(+), 2 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, + "<address type='usb' bus='%u' port='%u' />\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 dc100db9f3..2ca1b8f7a2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3060,7 +3060,7 @@ this disk may be attached (QEMU only). I<serial> is the serial of disk device. I<wwn> is the wwn of disk device. I<rawio> indicates the disk needs rawio capability. I<address> 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. +scsi:controller.bus.unit, ide:controller.bus.unit, usb:bus:port or ccw:cssid.ssid.devno.
Actually, it's usb:bus.port ;-) And also I'm breaking this long line (which gets even longer after next patch). Fixed and ACKed. Michal

Sorry for this stupid mistake. Thank you for reviewing. On Mon, Jul 9, 2018 at 11:20 PM, Michal Privoznik <mprivozn@redhat.com> wrote:
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 <hhan@redhat.com> --- tools/virsh-domain.c | 38 +++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 38 insertions(+), 2 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, + "<address type='usb' bus='%u'
+ 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 dc100db9f3..2ca1b8f7a2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3060,7 +3060,7 @@ this disk may be attached (QEMU only). I<serial> is the serial of disk device. I<wwn> is the wwn of disk device. I<rawio> indicates the disk needs rawio capability. I<address> is the address of disk device in the form of
On 07/04/2018 05:04 AM, Han Han wrote: port='%u' />\n", pci:domain.bus.slot.function,
-scsi:controller.bus.unit, ide:controller.bus.unit or ccw:cssid.ssid.devno. +scsi:controller.bus.unit, ide:controller.bus.unit, usb:bus:port or ccw:cssid.ssid.devno.
Actually, it's usb:bus.port ;-) And also I'm breaking this long line (which gets even longer after next patch).
Fixed and ACKed.
Michal
-- Best regards, ----------------------------------- Han Han Quality Engineer Redhat. Email: hhan@redhat.com Phone: +861065339333

Adding sata bus address support to the optional address parameter of virsh attach-disk. The address is used as controller.bus.unit. e.g. sata:0.0.0 Signed-off-by: Han Han <hhan@redhat.com> --- tools/virsh-domain.c | 46 +++++++++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5a445eff44..3959b5475b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -320,6 +320,7 @@ enum { DISK_ADDR_TYPE_IDE, DISK_ADDR_TYPE_CCW, DISK_ADDR_TYPE_USB, + DISK_ADDR_TYPE_SATA, }; struct PCIAddress { @@ -352,6 +353,12 @@ struct USBAddress { unsigned int port; }; +struct SATAAddress { + unsigned int controller; + unsigned int bus; + unsigned long long unit; +}; + struct DiskAddress { int type; union { @@ -360,6 +367,7 @@ struct DiskAddress { struct IDEAddress ide; struct CCWAddress ccw; struct USBAddress usb; + struct SATAAddress sata; } addr; }; @@ -488,11 +496,37 @@ static int str2USBAddress(const char *str, struct USBAddress *usbAddr) return 0; } +static int str2SATAAddress(const char *str, struct SATAAddress *sataAddr) +{ + char *controller, *bus, *unit; + + if (!sataAddr) + return -1; + if (!str) + return -1; + + controller = (char *)str; + + if (virStrToLong_uip(controller, &bus, 10, &sataAddr->controller) != 0) + return -1; + + bus++; + if (virStrToLong_uip(bus, &unit, 10, &sataAddr->bus) != 0) + return -1; + + unit++; + if (virStrToLong_ullp(unit, NULL, 10, &sataAddr->unit) != 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) + * sata disk address: sata:00.00.0 (controller:bus:unit) */ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) @@ -524,6 +558,9 @@ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) } else if (STREQLEN(type, "usb", addr - type)) { diskAddr->type = DISK_ADDR_TYPE_USB; return str2USBAddress(addr + 1, &diskAddr->addr.usb); + } else if (STREQLEN(type, "sata", addr - type)) { + diskAddr->type = DISK_ADDR_TYPE_SATA; + return str2SATAAddress(addr + 1, &diskAddr->addr.sata); } return -1; @@ -684,8 +721,15 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAsprintf(&buf, "<address type='usb' bus='%u' port='%u' />\n", diskAddr.addr.usb.bus, diskAddr.addr.usb.port); + } else if (diskAddr.type == DISK_ADDR_TYPE_SATA) { + virBufferAsprintf(&buf, + "<address type='drive' controller='%u'" + " bus='%u' unit='%llu' />\n", + diskAddr.addr.sata.controller, diskAddr.addr.sata.bus, + diskAddr.addr.sata.unit); } else { - vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 address.")); + vshError(ctl, "%s", + _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address.")); goto cleanup; } } else if (STRPREFIX((const char *)target, "hd")) { diff --git a/tools/virsh.pod b/tools/virsh.pod index 2ca1b8f7a2..9343b0d99f 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3060,7 +3060,7 @@ this disk may be attached (QEMU only). I<serial> is the serial of disk device. I<wwn> is the wwn of disk device. I<rawio> indicates the disk needs rawio capability. I<address> 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. +scsi:controller.bus.unit, ide:controller.bus.unit, usb:bus:port, sata:controller.bus.unit or ccw:cssid.ssid.devno. Virtio-ccw devices must have their cssid set to 0xfe. I<multifunction> indicates specified pci address is a multifunction pci device address. -- 2.17.1

Could anyone help review it? On Wed, Jul 4, 2018 at 11:04 AM, Han Han <hhan@redhat.com> wrote:
Add usb and sata support for attach-disk of address parameter in virsh.
Han Han (2): virsh: usb support for virsh attach-disk --address virsh: sata support for virsh attach-disk --address
tools/virsh-domain.c | 82 +++++++++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 82 insertions(+), 2 deletions(-)
-- 2.17.1
-- Best regards, ----------------------------------- Han Han Quality Engineer Redhat. Email: hhan@redhat.com Phone: +861065339333

On 07/04/2018 05:04 AM, Han Han wrote:
Add usb and sata support for attach-disk of address parameter in virsh.
Han Han (2): virsh: usb support for virsh attach-disk --address virsh: sata support for virsh attach-disk --address
tools/virsh-domain.c | 82 +++++++++++++++++++++++++++++++++++++++++++- tools/virsh.pod | 2 +- 2 files changed, 82 insertions(+), 2 deletions(-)
ACKed and pushed. Michal
participants (2)
-
Han Han
-
Michal Privoznik