From nobody Thu May 15 01:29:48 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.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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512437957061204.86901033703248; Mon, 4 Dec 2017 17:39:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB05C13A53; Tue, 5 Dec 2017 01:39:15 +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 A81B61880D; Tue, 5 Dec 2017 01:39:15 +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 6C87E4A468; Tue, 5 Dec 2017 01:39:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB51dCgn029279 for ; Mon, 4 Dec 2017 20:39:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id C532261559; Tue, 5 Dec 2017 01:39:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-84.phx2.redhat.com [10.3.117.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ACEB62464 for ; Tue, 5 Dec 2017 01:39:12 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 4 Dec 2017 20:38:52 -0500 Message-Id: <20171205013907.8563-3-jferlan@redhat.com> In-Reply-To: <20171205013907.8563-1-jferlan@redhat.com> References: <20171205013907.8563-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/17] qemu: Introduce qemuDomainDeviceDefSkipController 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 05 Dec 2017 01:39:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In order to be able to reuse some code for both controller def validation and command line building, create a convenience helper that will perform the "skip" avoidance checks. It will also set some flags to allow the caller to specifically skip (or fail) depending on the result of the flag (as opposed to building up some ever growing list of variables). Signed-off-by: John Ferlan --- src/qemu/qemu_command.c | 61 +++++------------------------------ src/qemu/qemu_domain.c | 84 +++++++++++++++++++++++++++++++++++++++++++++= +++- src/qemu/qemu_domain.h | 12 +++++++ 3 files changed, 102 insertions(+), 55 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6a8da1d58..5a6a671a1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3180,8 +3180,8 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, virQEMUCapsPtr qemuCaps) { size_t i, j; + unsigned int flags =3D 0; int usbcontroller =3D 0; - bool usblegacy =3D false; int contOrder[] =3D { /* * List of controller types that we add commandline args for, @@ -3216,61 +3216,14 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, if (cont->type !=3D contOrder[j]) continue; =20 - /* skip USB controllers with type none.*/ - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && - cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { - usbcontroller =3D -1; /* mark we don't want a controller */ - continue; - } - - /* skip pcie-root */ - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && - cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) { - continue; - } + if (qemuDomainDeviceDefSkipController(cont, def, &flags)) { + /* mark we don't want a controller */ + if (flags & QEMU_DOMAIN_DEVICE_SKIP_USB_CONTROLLER_FLAG) + usbcontroller =3D -1; =20 - /* Skip pci-root, except for pSeries guests (which actually - * support more than one PCI Host Bridge per guest) */ - if (!qemuDomainIsPSeries(def) && - cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && - cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) { - continue; - } - - /* first SATA controller on Q35 machines is implicit */ - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_SATA && - cont->idx =3D=3D 0 && qemuDomainIsQ35(def)) - continue; - - /* first IDE controller is implicit on various machines */ - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_IDE && - cont->idx =3D=3D 0 && qemuDomainHasBuiltinIDE(def)) - continue; - - if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && - cont->model =3D=3D -1 && - !qemuDomainIsQ35(def) && - !qemuDomainIsVirt(def)) { - - /* An appropriate default USB controller model should alre= ady - * have been selected in qemuDomainDeviceDefPostParse(); if - * we still have no model by now, we have to fall back to = the - * legacy USB controller. - * - * Note that we *don't* want to end up with the legacy USB - * controller for q35 and virt machines, so we go ahead and - * fail in qemuBuildControllerDevStr(); on the other hand, - * for s390 machines we want to ignore any USB controller - * (see 548ba43028 for the full story), so we skip - * qemuBuildControllerDevStr() but we don't ultimately end - * up adding the legacy USB controller */ - if (usblegacy) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Multiple legacy USB controllers are " - "not supported")); + if (flags & QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FAIL_FLAG) goto cleanup; - } - usblegacy =3D true; + continue; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 569bbd29e..d4c7674c0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3884,10 +3884,92 @@ qemuDomainDeviceDefValidateDisk(const virDomainDisk= Def *disk) } =20 =20 +/** + * qemuDomainDeviceDefSkipController: + * @controller: Controller to check + * @def: Domain definition + * @flags: qemuDomainDeviceSkipFlags to set if specific condition found + * + * Returns true if this controller can be skipped for command line generat= ion + * or device validation + */ +bool +qemuDomainDeviceDefSkipController(const virDomainControllerDef *controller, + const virDomainDef *def, + unsigned int *flags) +{ + /* skip USB controllers with type none.*/ + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && + controller->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { + *flags |=3D QEMU_DOMAIN_DEVICE_SKIP_USB_CONTROLLER_FLAG; + return true; + } + + /* skip pcie-root */ + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && + controller->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) + return true; + + /* Skip pci-root, except for pSeries guests (which actually + * support more than one PCI Host Bridge per guest) */ + if (!qemuDomainIsPSeries(def) && + controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI && + controller->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) + return true; + + /* first SATA controller on Q35 machines is implicit */ + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_SATA && + controller->idx =3D=3D 0 && qemuDomainIsQ35(def)) + return true; + + /* first IDE controller is implicit on various machines */ + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_IDE && + controller->idx =3D=3D 0 && qemuDomainHasBuiltinIDE(def)) + return true; + + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && + controller->model =3D=3D -1 && + !qemuDomainIsQ35(def) && + !qemuDomainIsVirt(def)) { + + /* An appropriate default USB controller model should already + * have been selected in qemuDomainDeviceDefPostParse(); if + * we still have no model by now, we have to fall back to the + * legacy USB controller. + * + * Note that we *don't* want to end up with the legacy USB + * controller for q35 and virt machines, so we go ahead and + * fail in qemuBuildControllerDevStr(); on the other hand, + * for s390 machines we want to ignore any USB controller + * (see 548ba43028 for the full story), so we skip + * qemuBuildControllerDevStr() but we don't ultimately end + * up adding the legacy USB controller */ + if (*flags & QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FLAG) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Multiple legacy USB controllers are " + "not supported")); + *flags |=3D QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FAIL_FLAG; + } + *flags |=3D QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FLAG; + return true; + } + + return false; +} + + static int qemuDomainDeviceDefValidateController(const virDomainControllerDef *contro= ller, - const virDomainDef *def ATTRIBUTE_UN= USED) + const virDomainDef *def) { + unsigned int flags =3D 0; + + if (qemuDomainDeviceDefSkipController(controller, def, &flags)) + return 0; + + if (flags & QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FAIL_FLAG) + return -1; + switch ((virDomainControllerType) controller->type) { case VIR_DOMAIN_CONTROLLER_TYPE_IDE: case VIR_DOMAIN_CONTROLLER_TYPE_FDC: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c33af3671..5c9c55d38 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -999,4 +999,16 @@ qemuDomainPrepareDiskSource(virConnectPtr conn, qemuDomainObjPrivatePtr priv, virQEMUDriverConfigPtr cfg); =20 +typedef enum { + QEMU_DOMAIN_DEVICE_SKIP_USB_CONTROLLER_FLAG =3D (1 << 0), + QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FLAG =3D (1 << 1), + QEMU_DOMAIN_DEVICE_SKIP_USB_LEGACY_FAIL_FLAG =3D (1 << 2), +} qemuDomainDeviceSkipFlags; + +bool +qemuDomainDeviceDefSkipController(const virDomainControllerDef *controller, + const virDomainDef *def, + unsigned int *flags); + + #endif /* __QEMU_DOMAIN_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list