From nobody Fri May 16 06:33:23 2025 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1497606616318493.00301846558784; Fri, 16 Jun 2017 02:50:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C4F7334584; Fri, 16 Jun 2017 09:50:14 +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 5ABCB7F35A; Fri, 16 Jun 2017 09:50:14 +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 44E484A497; Fri, 16 Jun 2017 09:50:08 +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 v5G9ntY6031387 for ; Fri, 16 Jun 2017 05:49:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D3267F34E; Fri, 16 Jun 2017 09:49:55 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FE737F35B for ; Fri, 16 Jun 2017 09:49:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C4F7334584 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8C4F7334584 From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 16 Jun 2017 17:48:58 +0800 Message-Id: <1497606548-18870-15-git-send-email-abologna@redhat.com> In-Reply-To: <1497606548-18870-1-git-send-email-abologna@redhat.com> References: <1497606548-18870-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 14/24] qemu: Automatically pick target index and model for pci-root controllers 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 16 Jun 2017 09:50:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" pSeries guests will soon need the new information; luckily, we can figure it out automatically most of the time, so users won't have to worry about it. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_domain_address.c | 88 ++++++++++++++++++= +++- .../qemuargv2xmldata/qemuargv2xml-pseries-disk.xml | 5 +- .../qemuargv2xml-pseries-nvram.xml | 5 +- .../qemuxml2xmlout-panic-pseries.xml | 5 +- .../qemuxml2xmlout-ppc64-usb-controller-legacy.xml | 5 +- .../qemuxml2xmlout-ppc64-usb-controller.xml | 5 +- .../qemuxml2xmlout-pseries-nvram.xml | 5 +- .../qemuxml2xmlout-pseries-panic-missing.xml | 5 +- .../qemuxml2xmlout-pseries-panic-no-address.xml | 5 +- 9 files changed, 118 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index b5b863f..960ea04 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1861,6 +1861,7 @@ qemuDomainSupportsPCI(virDomainDefPtr def, =20 static void qemuDomainPCIControllerSetDefaultModelName(virDomainControllerDefPtr cont, + virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { int *modelName =3D &cont->opts.pciopts.modelName; @@ -1897,6 +1898,9 @@ qemuDomainPCIControllerSetDefaultModelName(virDomainC= ontrollerDefPtr cont, *modelName =3D VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_PXB_PCIE; break; case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: + if (qemuDomainIsPSeries(def)) + *modelName =3D VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_SPAPR_PCI_= HOST_BRIDGE; + break; case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT: case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST: break; @@ -1904,6 +1908,63 @@ qemuDomainPCIControllerSetDefaultModelName(virDomain= ControllerDefPtr cont, } =20 =20 +/** + * qemuDomainAddressFindNewTargetIndex: + * @def: domain definition + * + * Find a target index that can be used for a PCI controller. + * + * Returns: an unused target index, or -1 if all available target + * indexes are already taken. + */ +static int +qemuDomainAddressFindNewTargetIndex(virDomainDefPtr def) +{ + int idx; + int ret =3D -1; + + /* Try all indexes between 1 and 31 - QEMU only supports 32 + * PHBs, and 0 is reserved for the default, implicit one */ + for (idx =3D 1; idx <=3D 31; idx++) { + bool found =3D false; + size_t i; + + for (i =3D 0; i < def->ncontrollers; i++) { + virDomainControllerDefPtr cont =3D def->controllers[i]; + virDomainPCIControllerOptsPtr opts; + + /* We only care about pci-root controllers */ + if (cont->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI || + cont->model !=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) { + continue; + } + + opts =3D &cont->opts.pciopts; + + /* More specifically, we only care about PHBs */ + if (opts->modelName !=3D VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_= SPAPR_PCI_HOST_BRIDGE) + continue; + + /* Stop looking as soon as we find a PHB that's + * already using this specific target index */ + if (opts->idx =3D=3D idx) { + found =3D true; + break; + } + } + + /* If no existing PCI controller uses this index, great, + * it means it's free and we can return it to the caller */ + if (!found) { + ret =3D idx; + break; + } + } + + return ret; +} + + static int qemuDomainAddressFindNewBusNr(virDomainDefPtr def) { @@ -2164,7 +2225,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, * device in qemu) for any controller that doesn't yet * have it set. */ - qemuDomainPCIControllerSetDefaultModelName(cont, qemuCaps); + qemuDomainPCIControllerSetDefaultModelName(cont, def, qemuCaps= ); =20 /* set defaults for any other auto-generated config * options for this controller that haven't been @@ -2201,9 +2262,32 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, goto cleanup; } break; + case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: + if (!qemuDomainIsPSeries(def)) + break; + if (options->idx =3D=3D -1) { + if (cont->idx =3D=3D 0) { + /* The pci-root controller with controller index 0 + * must always be assigned target index 0, because + * it represents the implicit PHB which is treated + * differently than all other PHBs */ + options->idx =3D 0; + } else { + /* For all other PHBs the target index doesn't need + * to match the controller index or have any + * particular value, really */ + options->idx =3D qemuDomainAddressFindNewTargetInd= ex(def); + } + } + if (options->idx =3D=3D -1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("No usable target index found for %d"= ), + addr->bus); + goto cleanup; + } + break; case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE: case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT: - case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT: case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST: break; diff --git a/tests/qemuargv2xmldata/qemuargv2xml-pseries-disk.xml b/tests/q= emuargv2xmldata/qemuargv2xml-pseries-disk.xml index 1bad8ee..601d0f7 100644 --- a/tests/qemuargv2xmldata/qemuargv2xml-pseries-disk.xml +++ b/tests/qemuargv2xmldata/qemuargv2xml-pseries-disk.xml @@ -30,7 +30,10 @@
- + + + +
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-pseries-nvram.xml b/tests/= qemuargv2xmldata/qemuargv2xml-pseries-nvram.xml index 7e9f864..7787847 100644 --- a/tests/qemuargv2xmldata/qemuargv2xml-pseries-nvram.xml +++ b/tests/qemuargv2xmldata/qemuargv2xml-pseries-nvram.xml @@ -17,7 +17,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml b/te= sts/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml index 1ed11ce..7fb49fe 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml @@ -17,7 +17,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller-l= egacy.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller-le= gacy.xml index b7bde24..673b81d 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller-legacy.x= ml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller-legacy.x= ml @@ -22,7 +22,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller.x= ml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller.xml index 82aaaca..68995a9 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-ppc64-usb-controller.xml @@ -22,7 +22,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-nvram.xml b/te= sts/qemuxml2xmloutdata/qemuxml2xmlout-pseries-nvram.xml index 713f31c..f89b23b 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-nvram.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-nvram.xml @@ -17,7 +17,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.= xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml index 1ed11ce..7fb49fe 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml @@ -17,7 +17,10 @@
- + + + +
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-addre= ss.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.x= ml index 1ed11ce..7fb49fe 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml @@ -17,7 +17,10 @@
- + + + +
--=20 2.7.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list