From nobody Mon Dec 15 23:20:35 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; 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 152751565627941.14308733922792; Mon, 28 May 2018 06:54:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E49B30D17C1; Mon, 28 May 2018 13:54:14 +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 44662100190D; Mon, 28 May 2018 13:54: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 EB8021800C99; Mon, 28 May 2018 13:54:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4SDsAa1013000 for ; Mon, 28 May 2018 09:54:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5A832166BB6; Mon, 28 May 2018 13:54:09 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8949B2166BB2 for ; Mon, 28 May 2018 13:54:09 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 15:54:03 +0200 Message-Id: <57c3ea8374d0dbd979c246700b95a2f39643df98.1527515594.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] conf: introduce virDomainDefCheckBootOrder 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: , Content-Type: text/plain; charset="utf-8" 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 28 May 2018 13:54:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Move the check for boot elements into a separate function and remove its dependency on the parser-supplied bootHash table. Reconstructing the hash table from the domain definition effectively duplicates the check for duplicate boot order values, also present in virDomainDeviceBootParseXML. Signed-off-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 89 +++++++++++++++++++++++-= ---- tests/qemuargv2xmldata/nomachine-aarch64.xml | 1 + tests/qemuargv2xmldata/nomachine-ppc64.xml | 1 + tests/qemuargv2xmldata/nomachine-x86_64.xml | 1 + tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml | 1 + 5 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d6ac47c629..f087a3680f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4939,10 +4939,79 @@ virDomainDefPostParseCPU(virDomainDefPtr def) } =20 =20 +static int +virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED, + virDomainDeviceInfoPtr info, + void *data) +{ + virHashTablePtr bootHash =3D data; + char *order =3D NULL; + int ret =3D -1; + + if (info->bootIndex =3D=3D 0) + return 0; + + if (virAsprintf(&order, "%u", info->bootIndex) < 0) + goto cleanup; + + if (virHashLookup(bootHash, order)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("boot order '%s' used for more than one device"), + order); + goto cleanup; + } + + if (virHashAddEntry(bootHash, order, (void *) 1) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(order); + return ret; +} + + +static int +virDomainDefCheckBootOrder(virDomainDefPtr def) +{ + virHashTablePtr bootHash =3D NULL; + int ret =3D -1; + + if (def->os.type !=3D VIR_DOMAIN_OSTYPE_HVM) + return 0; + + if (!(bootHash =3D virHashCreate(5, NULL))) + goto cleanup; + + if (virDomainDeviceInfoIterate(def, virDomainDefCollectBootOrder, boot= Hash) < 0) + goto cleanup; + + if (def->os.nBootDevs > 0 && virHashSize(bootHash) > 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("per-device boot elements cannot be used" + " together with os/boot elements")); + goto cleanup; + } + + if (def->os.nBootDevs =3D=3D 0 && virHashSize(bootHash) =3D=3D 0) { + def->os.nBootDevs =3D 1; + def->os.bootDevs[0] =3D VIR_DOMAIN_BOOT_DISK; + } + + ret =3D 0; + + cleanup: + virHashFree(bootHash); + return ret; +} + + static int virDomainDefPostParseCommon(virDomainDefPtr def, struct virDomainDefPostParseDeviceIteratorData= *data, - virHashTablePtr bootHash) + virHashTablePtr bootHash ATTRIBUTE_UNUSED) { size_t i; =20 @@ -4953,20 +5022,6 @@ virDomainDefPostParseCommon(virDomainDefPtr def, return -1; } =20 - if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM && bootHash) { - if (def->os.nBootDevs > 0 && virHashSize(bootHash) > 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("per-device boot elements cannot be used" - " together with os/boot elements")); - return -1; - } - - if (def->os.nBootDevs =3D=3D 0 && virHashSize(bootHash) =3D=3D 0) { - def->os.nBootDevs =3D 1; - def->os.bootDevs[0] =3D VIR_DOMAIN_BOOT_DISK; - } - } - if (virDomainVcpuDefPostParse(def) < 0) return -1; =20 @@ -4979,6 +5034,10 @@ virDomainDefPostParseCommon(virDomainDefPtr def, if (virDomainDefRejectDuplicatePanics(def) < 0) return -1; =20 + if (!(data->xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_NO_BOOT_O= RDER) && + virDomainDefCheckBootOrder(def) < 0) + return -1; + if (virDomainDefPostParseTimer(def) < 0) return -1; =20 diff --git a/tests/qemuargv2xmldata/nomachine-aarch64.xml b/tests/qemuargv2= xmldata/nomachine-aarch64.xml index eb8f9db803..9492423389 100644 --- a/tests/qemuargv2xmldata/nomachine-aarch64.xml +++ b/tests/qemuargv2xmldata/nomachine-aarch64.xml @@ -6,6 +6,7 @@ 1 hvm + diff --git a/tests/qemuargv2xmldata/nomachine-ppc64.xml b/tests/qemuargv2xm= ldata/nomachine-ppc64.xml index 439f9e9ac6..1f15a950e3 100644 --- a/tests/qemuargv2xmldata/nomachine-ppc64.xml +++ b/tests/qemuargv2xmldata/nomachine-ppc64.xml @@ -6,6 +6,7 @@ 1 hvm + destroy diff --git a/tests/qemuargv2xmldata/nomachine-x86_64.xml b/tests/qemuargv2x= mldata/nomachine-x86_64.xml index 71a36f0833..33cde4c55a 100644 --- a/tests/qemuargv2xmldata/nomachine-x86_64.xml +++ b/tests/qemuargv2xmldata/nomachine-x86_64.xml @@ -6,6 +6,7 @@ 1 hvm + diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml b/tests/sexpr2xmld= ata/sexpr2xml-fv-kernel.xml index afb9030681..a3d54ae3c1 100644 --- a/tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml +++ b/tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml @@ -10,6 +10,7 @@ /var/lib/xen/vmlinuz.2Dn2YT /var/lib/xen/initrd.img.0u-Vhq method=3Dhttp://download.fedora.devel.redhat.com/pub/fedora/= linux/core/test/5.91/x86_64/os + destroy --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list