From nobody Thu May 16 19:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530673534634996.033968848995; Tue, 3 Jul 2018 20:05:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C5F58553F; Wed, 4 Jul 2018 03:05:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E12D66017A; Wed, 4 Jul 2018 03:05:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8FB6C18037EF; Wed, 4 Jul 2018 03:05:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6435CxX017977 for ; Tue, 3 Jul 2018 23:05:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE6AE111C482; Wed, 4 Jul 2018 03:05:11 +0000 (UTC) Received: from hansolo.nay.redhat.com (wlan-69-196.nay.redhat.com [10.66.69.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7719111C4A2; Wed, 4 Jul 2018 03:05:10 +0000 (UTC) From: Han Han To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:04:59 +0800 Message-Id: <20180704030500.21740-2-hhan@redhat.com> In-Reply-To: <20180704030500.21740-1-hhan@redhat.com> References: <20180704030500.21740-1-hhan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Han Han Subject: [libvirt] [PATCH 1/2] virsh: usb support for virsh attach-disk --address X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Jul 2018 03:05:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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, }; =20 struct PCIAddress { @@ -346,6 +347,11 @@ struct CCWAddress { unsigned int devno; }; =20 +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; }; =20 @@ -460,10 +467,32 @@ static int str2CCWAddress(const char *str, struct CCW= Address *ccwAddr) return 0; } =20 +static int str2USBAddress(const char *str, struct USBAddress *usbAddr) +{ + char *bus, *port; + + if (!usbAddr) + return -1; + if (!str) + return -1; + + bus =3D (char *)str; + + if (virStrToLong_uip(bus, &port, 10, &usbAddr->bus) !=3D 0) + return -1; + + port++; + if (virStrToLong_uip(port, NULL, 10, &usbAddr->port) !=3D 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) */ =20 static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) @@ -492,6 +521,9 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr) } else if (STREQLEN(type, "ccw", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_CCW; return str2CCWAddress(addr + 1, &diskAddr->addr.ccw); + } else if (STREQLEN(type, "usb", addr - type)) { + diskAddr->type =3D DISK_ADDR_TYPE_USB; + return str2USBAddress(addr + 1, &diskAddr->addr.usb); } =20 return -1; @@ -648,8 +680,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) " bus=3D'%u' unit=3D'%llu' />\n", diskAddr.addr.scsi.controller, diskAddr.= addr.scsi.bus, diskAddr.addr.scsi.unit); + } else if (diskAddr.type =3D=3D 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 dc100db9f3..2ca1b8f7a2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3060,7 +3060,7 @@ 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.slo= t.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:css= id.ssid.devno. Virtio-ccw devices must have their cssid set to 0xfe. I indicates specified pci address is a multifunction pci de= vice address. --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 16 19:43:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530673518797397.27259369151466; Tue, 3 Jul 2018 20:05:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21967308626B; Wed, 4 Jul 2018 03:05:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB3F9308BDB2; Wed, 4 Jul 2018 03:05:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1461A4A460; Wed, 4 Jul 2018 03:05:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6435E8x017991 for ; Tue, 3 Jul 2018 23:05:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 954AA111C4A9; Wed, 4 Jul 2018 03:05:14 +0000 (UTC) Received: from hansolo.nay.redhat.com (wlan-69-196.nay.redhat.com [10.66.69.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7926111C482; Wed, 4 Jul 2018 03:05:12 +0000 (UTC) From: Han Han To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 11:05:00 +0800 Message-Id: <20180704030500.21740-3-hhan@redhat.com> In-Reply-To: <20180704030500.21740-1-hhan@redhat.com> References: <20180704030500.21740-1-hhan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Han Han Subject: [libvirt] [PATCH 2/2] virsh: sata support for virsh attach-disk --address X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 04 Jul 2018 03:05:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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, }; =20 struct PCIAddress { @@ -352,6 +353,12 @@ struct USBAddress { unsigned int port; }; =20 +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; }; =20 @@ -488,11 +496,37 @@ static int str2USBAddress(const char *str, struct USB= Address *usbAddr) return 0; } =20 +static int str2SATAAddress(const char *str, struct SATAAddress *sataAddr) +{ + char *controller, *bus, *unit; + + if (!sataAddr) + return -1; + if (!str) + return -1; + + controller =3D (char *)str; + + if (virStrToLong_uip(controller, &bus, 10, &sataAddr->controller) !=3D= 0) + return -1; + + bus++; + if (virStrToLong_uip(bus, &unit, 10, &sataAddr->bus) !=3D 0) + return -1; + + unit++; + if (virStrToLong_ullp(unit, NULL, 10, &sataAddr->unit) !=3D 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) */ =20 static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) @@ -524,6 +558,9 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr) } else if (STREQLEN(type, "usb", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_USB; return str2USBAddress(addr + 1, &diskAddr->addr.usb); + } else if (STREQLEN(type, "sata", addr - type)) { + diskAddr->type =3D DISK_ADDR_TYPE_SATA; + return str2SATAAddress(addr + 1, &diskAddr->addr.sata); } =20 return -1; @@ -684,8 +721,15 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAsprintf(&buf, "
\n", diskAddr.addr.usb.bus, diskAddr.addr.usb= .port); + } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SATA) { + virBufferAsprintf(&buf, + "
\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 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.slo= t.function, -scsi:controller.bus.unit, ide:controller.bus.unit, usb:bus:port or ccw:css= id.ssid.devno. +scsi:controller.bus.unit, ide:controller.bus.unit, usb:bus:port, sata:cont= roller.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 de= vice address. --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list