From nobody Tue Dec 16 08:05:27 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 15028872719761010.6216577324967; Wed, 16 Aug 2017 05:41:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2197774EE3; Wed, 16 Aug 2017 12:41:10 +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 EFB2A7DFC0; Wed, 16 Aug 2017 12:41:09 +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 B38A83FAD3; Wed, 16 Aug 2017 12:41:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCeuGB021751 for ; Wed, 16 Aug 2017 08:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D4A57D978; Wed, 16 Aug 2017 12:40:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8809B7FA5B for ; Wed, 16 Aug 2017 12:40:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2197774EE3 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:43 +0200 Message-Id: <7b7f23d166f2e80dc79ecd12db17c48da02300f1.1502887192.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/10] conf: use virXMLPropString for boot parsing 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 Aug 2017 12:41:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" XPath is good for random search of elements, not for accessing attributes of one node. Signed-off-by: Pavel Hrdina --- Notes: hint: review with -b src/conf/domain_conf.c | 95 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 90f3f55f25..917ea004e5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16039,6 +16039,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virDomainDefPtr def) { xmlNodePtr *nodes =3D NULL; + xmlNodePtr node; size_t i; int n; char *tmp =3D NULL; @@ -16088,62 +16089,66 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, def->os.bootDevs[0] =3D VIR_DOMAIN_BOOT_DISK; } =20 - tmp =3D virXPathString("string(./os/bootmenu[1]/@enable)", ctxt); - if (tmp) { - def->os.bootmenu =3D virTristateBoolTypeFromString(tmp); - if (def->os.bootmenu <=3D 0) { - /* In order not to break misconfigured machines, this - * should not emit an error, but rather set the bootmenu - * to disabled */ - VIR_WARN("disabling bootmenu due to unknown option '%s'", - tmp); - def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; - } - VIR_FREE(tmp); - } - - tmp =3D virXPathString("string(./os/bootmenu[1]/@timeout)", ctxt); - if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 || - def->os.bm_timeout > 65535) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for boot menu timeout, " - "must be in range [0,65535]")); - goto cleanup; + if ((node =3D virXPathNode("./os/bootmenu[1]", ctxt))) { + tmp =3D virXMLPropString(node, "enable"); + if (tmp) { + def->os.bootmenu =3D virTristateBoolTypeFromString(tmp); + if (def->os.bootmenu <=3D 0) { + /* In order not to break misconfigured machines, this + * should not emit an error, but rather set the bootmenu + * to disabled */ + VIR_WARN("disabling bootmenu due to unknown option '%s'", + tmp); + def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; + } + VIR_FREE(tmp); } - def->os.bm_timeout_set =3D true; - } - VIR_FREE(tmp); =20 - tmp =3D virXPathString("string(./os/bios[1]/@useserial)", ctxt); - if (tmp) { - if (STREQ(tmp, "yes")) { - if (virXPathULong("count(./devices/serial)", - ctxt, &serialPorts) < 0) { + tmp =3D virXMLPropString(node, "timeout"); + if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { + if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 || + def->os.bm_timeout > 65535) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("need at least one serial port " - "for useserial")); + _("invalid value for boot menu timeout, " + "must be in range [0,65535]")); goto cleanup; } - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_YES; - } else { - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; + def->os.bm_timeout_set =3D true; } VIR_FREE(tmp); } =20 - tmp =3D virXPathString("string(./os/bios[1]/@rebootTimeout)", ctxt); - if (tmp) { - /* that was really just for the check if it is there */ + if ((node =3D virXPathNode("./os/bios[1]", ctxt))) { + tmp =3D virXMLPropString(node, "useserial"); + if (tmp) { + if (STREQ(tmp, "yes")) { + if (virXPathULong("count(./devices/serial)", + ctxt, &serialPorts) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("need at least one serial port " + "for useserial")); + goto cleanup; + } + def->os.bios.useserial =3D VIR_TRISTATE_BOOL_YES; + } else { + def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; + } + VIR_FREE(tmp); + } + + tmp =3D virXMLPropString(node, "rebootTimeout"); + if (tmp) { + /* that was really just for the check if it is there */ =20 - if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 || - def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 65535) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for rebootTimeout, " - "must be in range [-1,65535]")); - goto cleanup; + if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 || + def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 6553= 5) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("invalid value for rebootTimeout, " + "must be in range [-1,65535]")); + goto cleanup; + } + def->os.bios.rt_set =3D true; } - def->os.bios.rt_set =3D true; } =20 ret =3D 0; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list