From nobody Mon Feb 9 00:30:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605803296; cv=none; d=zohomail.com; s=zohoarc; b=cMny78R77T94aYFx9pmvNazE1Aq45iOKR0Iy8XKzL9istNP7xvaWUHnlYB61Jj5QQRM47DxmbU4S1MCw61jW5DXVDTzjMBLw2TAipNtz4BBNdqcAbQbfY6MFlQpRmXQf2QxN/L48VR5G3LOeZnw0HhMMkXbdh22LsnE2ou/Cquk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605803296; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+rluipugJN/dq3b1mw3Pot/62S0C276Q514Oa6Y/ito=; b=Z/8gpL1A1rbKqk45ImHP+d81/rNmPvMZrTMFe3bDXcmsxWnLlZvnfonwnZR4dpsy2wyJByv9FrtArG+uy88jakuDYQmTp70/y77N7ja0z1pUOPmO0752MrsXiegoOq0fDCtw6bvUYhZPBxWc0Izt5QSIWDF31Q54glO89moAEOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605803296845956.0183410255643; Thu, 19 Nov 2020 08:28:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-YLD6ajrdNQ-UmJa1rivR-Q-1; Thu, 19 Nov 2020 11:26:53 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B4318797DC; Thu, 19 Nov 2020 16:26:47 +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 590665D9C6; Thu, 19 Nov 2020 16:26:47 +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 254E25003D; Thu, 19 Nov 2020 16:26:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AJGQcMs030702 for ; Thu, 19 Nov 2020 11:26:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 29FD75C1B4; Thu, 19 Nov 2020 16:26:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C1605C1A1; Thu, 19 Nov 2020 16:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605803295; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+rluipugJN/dq3b1mw3Pot/62S0C276Q514Oa6Y/ito=; b=epOvOv9qTUty7cNtD33ivyybHUdS8CIBX4hzKArrGnTe57RjpDGJ8gV/m3yfjtXmB3m7YC 7RyQ8ARt7AMbKNy5qKtuWRqxjSaJnhut0lkcwhahmc4MyUxYKReYrwXHETAyJeumB12BwL bfUCqRBPS5D8LqXiOyg+Ge0yLX8ThFQ= X-MC-Unique: YLD6ajrdNQ-UmJa1rivR-Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/16] virsh: Extract address formatting from cmdAttachDiskFormatAddress Date: Thu, 19 Nov 2020 17:26:13 +0100 Message-Id: <231acfd039260e3bd30cba9042e224331bc03f68.1605802531.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Ryan Gahagan 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Introduce virshAddressFormat with code from cmdAttachDiskFormatAddress to format the address. Note that this patch fixes some whitespace inconsistencies in the formatted addresses. Signed-off-by: Peter Krempa --- tests/virsh-output.out | 42 +++++++------- tools/virsh-domain.c | 122 ++++++++++++++++++++++++++--------------- 2 files changed, 99 insertions(+), 65 deletions(-) diff --git a/tests/virsh-output.out b/tests/virsh-output.out index a93492e8f8..6af7600a9c 100644 --- a/tests/virsh-output.out +++ b/tests/virsh-output.out @@ -182,7 +182,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target hda --sourcetype file --type disk --address ide:1.2= .4 @@ -190,7 +190,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target hda --sourcetype file --type disk --address ide:1:2= :5 @@ -198,7 +198,7 @@ error: No support for whatever in command 'attach-disk' -
+
+ attach_disk --target sda --sourcetype file --type disk --address ide:1.2= .3 @@ -214,7 +214,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address usb:12.3 @@ -222,7 +222,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address usb:12:= 34 @@ -230,7 +230,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address usb:12.= 34 @@ -246,7 +246,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target sda --sourcetype file --type disk --address scsi:1.= 2.4 @@ -254,7 +254,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target sda --sourcetype file --type disk --address scsi:1:= 2:5 @@ -262,7 +262,7 @@ error: expecting an ide:00.00.00 address. -
+
+ attach_disk --target hda --sourcetype file --type disk --address scsi:1.= 2.3 @@ -278,7 +278,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address sata:1.= 2.4 @@ -286,7 +286,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target sda --sourcetype file --type disk --address sata:1:= 2:5 @@ -294,7 +294,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target hda --sourcetype file --type disk --address sata:1.= 2.3 @@ -310,7 +310,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 @@ -318,7 +318,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa @@ -326,7 +326,7 @@ error: expecting a pci:0000.00.00.00 or ccw:00.0.0000 a= ddress. -
+
+ attach_disk --target hda --sourcetype file --type disk --address pci:12.= 34.56.aa @@ -342,7 +342,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12:= 34:56:78 --multifunction @@ -350,7 +350,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address pci:12.= 34.56.aa --multifunction @@ -358,7 +358,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 @@ -366,7 +366,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12:= 34:56 @@ -374,7 +374,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target vda --sourcetype file --type disk --address ccw:12.= 34.56 @@ -382,7 +382,7 @@ error: expecting a scsi:00.00.00 or usb:00.00 or sata:0= 0.00.00 address. -
+
+ attach_disk --target hda --sourcetype file --type disk --address ccw:12.= 34.56 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 84b8a6fb52..e1a0b9087b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -305,7 +305,7 @@ static const vshCmdOptDef opts_attach_disk[] =3D { {.name =3D NULL} }; -enum { +enum diskAddrType { DISK_ADDR_TYPE_INVALID, DISK_ADDR_TYPE_PCI, DISK_ADDR_TYPE_SCSI, @@ -320,6 +320,7 @@ struct PCIAddress { unsigned int bus; unsigned int slot; unsigned int function; + bool multifunction; }; struct SCSIAddress { @@ -521,7 +522,7 @@ static int str2SATAAddress(const char *str, struct SATA= Address *sataAddr) * sata disk address: sata:00.00.0 (controller:bus:unit) */ -static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr) +static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr, = bool multifunction) { char *type, *addr; @@ -537,6 +538,7 @@ static int str2DiskAddress(const char *str, struct Disk= Address *diskAddr) if (STREQLEN(type, "pci", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_PCI; + diskAddr->addr.pci.multifunction =3D multifunction; return str2PCIAddress(addr + 1, &diskAddr->addr.pci); } else if (STREQLEN(type, "scsi", addr - type)) { diskAddr->type =3D DISK_ADDR_TYPE_SCSI; @@ -559,6 +561,71 @@ static int str2DiskAddress(const char *str, struct Dis= kAddress *diskAddr) } +static void +virshAddressFormat(virBufferPtr buf, + struct DiskAddress *addr) +{ + switch ((enum diskAddrType) addr->type) { + case DISK_ADDR_TYPE_PCI: + virBufferAsprintf(buf, + "
addr.pci.domain, + addr->addr.pci.bus, + addr->addr.pci.slot, + addr->addr.pci.function); + + if (addr->addr.pci.multifunction) + virBufferAddLit(buf, " multifunction=3D'on'"); + + virBufferAddLit(buf, "/>\n"); + break; + + case DISK_ADDR_TYPE_SCSI: + virBufferAsprintf(buf, + "
\n", + addr->addr.scsi.controller, + addr->addr.scsi.bus, + addr->addr.scsi.unit); + break; + + case DISK_ADDR_TYPE_IDE: + virBufferAsprintf(buf, + "
\n", + addr->addr.ide.controller, + addr->addr.ide.bus, + addr->addr.ide.unit); + break; + + case DISK_ADDR_TYPE_CCW: + virBufferAsprintf(buf, + "
\n", + addr->addr.ccw.cssid, + addr->addr.ccw.ssid, + addr->addr.ccw.devno); + break; + + case DISK_ADDR_TYPE_USB: + virBufferAsprintf(buf, + "
\= n", + addr->addr.usb.bus, + addr->addr.usb.port); + break; + + case DISK_ADDR_TYPE_SATA: + virBufferAsprintf(buf, + "
\n", + addr->addr.sata.controller, + addr->addr.sata.bus, + addr->addr.sata.unit); + break; + + case DISK_ADDR_TYPE_INVALID: + default: + return; + } +} + + static int cmdAttachDiskFormatAddress(vshControl *ctl, virBufferPtr buf, @@ -568,67 +635,34 @@ cmdAttachDiskFormatAddress(vshControl *ctl, { struct DiskAddress diskAddr; - if (str2DiskAddress(straddr, &diskAddr) !=3D 0) { + if (str2DiskAddress(straddr, &diskAddr, multifunction) !=3D 0) { vshError(ctl, _("Invalid address.")); return -1; } if (STRPREFIX((const char *)target, "vd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_PCI) { - virBufferAsprintf(buf, - "
\n"); - } else if (diskAddr.type =3D=3D DISK_ADDR_TYPE_CCW) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.ccw.cssid, diskAddr.addr.ccw.s= sid, - diskAddr.addr.ccw.devno); - } else { + if (diskAddr.type !=3D DISK_ADDR_TYPE_PCI && + diskAddr.type !=3D DISK_ADDR_TYPE_CCW) { vshError(ctl, "%s", _("expecting a pci:0000.00.00.00 or ccw:00.0.0000 add= ress.")); return -1; } } else if (STRPREFIX((const char *)target, "sd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_SCSI) { - virBufferAsprintf(buf, - "
\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.por= t); - } 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 { + if (diskAddr.type !=3D DISK_ADDR_TYPE_SCSI && + diskAddr.type !=3D DISK_ADDR_TYPE_USB && + diskAddr.type !=3D DISK_ADDR_TYPE_SATA) { vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 or sata:00.= 00.00 address.")); return -1; } } else if (STRPREFIX((const char *)target, "hd")) { - if (diskAddr.type =3D=3D DISK_ADDR_TYPE_IDE) { - virBufferAsprintf(buf, - "
\n", - diskAddr.addr.ide.controller, diskAddr.addr.= ide.bus, - diskAddr.addr.ide.unit); - } else { + if (diskAddr.type !=3D DISK_ADDR_TYPE_IDE) { vshError(ctl, "%s", _("expecting an ide:00.00.00 address.")); return -1; } } + virshAddressFormat(buf, &diskAddr); return 0; } @@ -1006,7 +1040,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: { - struct PCIAddress pciAddr =3D {0, 0, 0, 0}; + struct PCIAddress pciAddr =3D {0, 0, 0, 0, false}; if (str2PCIAddress(source, &pciAddr) < 0) { vshError(ctl, _("cannot parse pci address '%s' for network " --=20 2.28.0