From nobody Tue Apr 23 20:20:07 2024 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=1620128524; cv=none; d=zohomail.com; s=zohoarc; b=YRI6G+Q0ConfFFaPd7n6Zp441cS1EFWEtTFH8MHz0qsnMLcl9qW8dz+LFiai/bgJs7Dm8iLRM0597LerBLzBkXtDlIKZ9FRTsyrfrDcZgv/cuT9XG34QHoLLPGrAhaepmrO1JxWLHomPiNOmegBwn+kn/tayGQQteqG4uSpTA74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128524; h=Content-Type:Content-Transfer-Encoding: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=y6etTsHtaZ1ilGoU+ORkm06owr7edxkqvA39GcBpK2s=; b=UG+jHFoYnujb71P/QY6Fk8j6dfq0Ga+0jguzsSqaR61F3NpI/Uosc6wFwbBRRgDBJmtXzwVECjzbOq6UjRZx2ZD39/6TwrSpiWk6kaU38dwLLrf8Hqf/j5HpIqaHL1gdo8Q1F7aoKLy+RATFg42xLujY/JfkIT7vlkt8rMtQOsI= 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 1620128524952741.267066544593; Tue, 4 May 2021 04:42:04 -0700 (PDT) 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-593-mrVJvFuaOqy0-YyLP6FWgA-1; Tue, 04 May 2021 07:41:08 -0400 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 DC7118030D0; Tue, 4 May 2021 11:41:02 +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 B910A5D9D5; Tue, 4 May 2021 11:41:02 +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 8506C1800FFC; Tue, 4 May 2021 11:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BejSF000687 for ; Tue, 4 May 2021 07:40:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E2575D9DD; Tue, 4 May 2021 11:40:45 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A374B5D9D5 for ; Tue, 4 May 2021 11:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128523; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=y6etTsHtaZ1ilGoU+ORkm06owr7edxkqvA39GcBpK2s=; b=cTtyyVHKoCdKdsYHzpSsn9dTM7pfpfo+Jt/CBNfdfVVDhxlXp2FTp30dO7PkWgtxAWtmge EzFInDwjI3hkt6+nnjXfawkocCuUR8GyWZSMj9gS8QGDuOrsqPFHv+jIdm6Uhi/8n0MQKl TifS6bpcU8lyxAmF2glDIYrGP8wIdmc= X-MC-Unique: mrVJvFuaOqy0-YyLP6FWgA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 01/19] conf: Propagate xmlXPathContextPtr into virDomainHostdevSubsysUSBDefParseXML() Date: Tue, 4 May 2021 13:39:55 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cb668d3d5e..e073644810 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6709,6 +6709,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOption *xmlop= t, =20 static int virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, virDomainHostdevDef *def) { bool got_product, got_vendor; @@ -7435,7 +7436,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, break; =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - if (virDomainHostdevSubsysUSBDefParseXML(sourcenode, def) < 0) + if (virDomainHostdevSubsysUSBDefParseXML(sourcenode, ctxt, def) < = 0) return -1; break; =20 --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128475; cv=none; d=zohomail.com; s=zohoarc; b=erSH8/Jg+TOAqEIR/ktn7SXCKWN8YnW3h0PhTZS1yN87AA/BmcZnKuY9THjOJun81WdNfs9D99/UlcXE2Uf1fzrtHb+nGoqLPdSqQD/KnA2qMhtba7x47ePGjLkmTAiQwS3pu/ETZiVznTVQUMGTea932GFgDzAp+10bnwDTIEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128475; h=Content-Type:Content-Transfer-Encoding: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=FxVMqDnIHOZs3GOtX+zcdk4W1PQsE907nbNdG3f+8Tk=; b=E0uEoBAWBgElWFaxTyOKBSUxQoM3bidFivjN96TwXIctQ2Srt0W9GLKnPlcS6aSJd7kuVpdHTsRYa+g9xOdNKVCvzppzfqiKP6uCzm+GPlDMKRF8UiLV4w4b1z2cx970jEdVf8wkpdiZ0EMKFTxSLhEadE2SZrozK2E3EY5b6yU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128475136571.8040817157765; Tue, 4 May 2021 04:41:15 -0700 (PDT) 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-116-3wFQI18lNEuQ_pT2eI-RuA-1; Tue, 04 May 2021 07:41:10 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A545C6D50F; Tue, 4 May 2021 11:41:05 +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 80C3D5C22A; Tue, 4 May 2021 11:41:05 +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 48B811800FFC; Tue, 4 May 2021 11:41:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bekqu000697 for ; Tue, 4 May 2021 07:40:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B94D25D9DD; Tue, 4 May 2021 11:40:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB53F5D9D5 for ; Tue, 4 May 2021 11:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128473; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=FxVMqDnIHOZs3GOtX+zcdk4W1PQsE907nbNdG3f+8Tk=; b=XiXF2RjzB2BmJP0Xynw1r4onHY+0MsV2jTeM6Yy3V8jaqiUmcTLNNUloe+TAZJ6Kef2I8P 3SCGTHRnrVIOArWGpl7HkF1tA63gXm3umshX8IL2lzgYabM6GUuaGTOz3CQDsuhL+OtpxX r9sJylHIqyQBTgEhtgT7hR7QeKDDl0c= X-MC-Unique: 3wFQI18lNEuQ_pT2eI-RuA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 02/19] Refactoring virDomainHostdevSubsysUSBDefParseXML() to use XPath Date: Tue, 4 May 2021 13:39:56 +0200 Message-Id: <9be44355ee82897120858387a67ce5e574290642.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.16 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 130 +++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e073644810..5c5b4ad6d7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6709,14 +6709,16 @@ virDomainDeviceInfoParseXML(virDomainXMLOption *xml= opt, =20 static int virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, + xmlXPathContextPtr ctxt, virDomainHostdevDef *def) { bool got_product, got_vendor; - xmlNodePtr cur; virDomainHostdevSubsysUSB *usbsrc =3D &def->source.subsys.u.usb; g_autofree char *startupPolicy =3D NULL; g_autofree char *autoAddress =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D node; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -6737,79 +6739,67 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr nod= e, got_product =3D false; got_vendor =3D false; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "vendor")) { - g_autofree char *vendor =3D virXMLPropString(cur, "id"); - - if (vendor) { - got_vendor =3D true; - if (virStrToLong_ui(vendor, NULL, 0, &usbsrc->vendor) = < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vendor id %s"), ven= dor); - return -1; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("usb vendor needs id")); - return -1; - } - } else if (virXMLNodeNameEqual(cur, "product")) { - g_autofree char *product =3D virXMLPropString(cur, "id"); - - if (product) { - got_product =3D true; - if (virStrToLong_ui(product, NULL, 0, - &usbsrc->product) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse product %s"), - product); - return -1; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("usb product needs id")); - return -1; - } - } else if (virXMLNodeNameEqual(cur, "address")) { - g_autofree char *bus =3D NULL; - g_autofree char *device =3D NULL; - - bus =3D virXMLPropString(cur, "bus"); - if (bus) { - if (virStrToLong_ui(bus, NULL, 0, &usbsrc->bus) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse bus %s"), bus); - return -1; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("usb address needs bus id")); - return -1; - } + if (virXPathNode("./vendor", ctxt)) { + g_autofree char *vendor =3D NULL; =20 - device =3D virXMLPropString(cur, "device"); - if (device) { - if (virStrToLong_ui(device, NULL, 0, &usbsrc->device) = < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse device %s"), - device); - return -1; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("usb address needs device id")); - return -1; - } - } else { + if ((vendor =3D virXPathString("string(./vendor/@id)", ctxt))) { + got_vendor =3D true; + if (virStrToLong_ui(vendor, NULL, 0, &usbsrc->vendor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown usb source type '%s'"), - cur->name); + _("cannot parse vendor id %s"), vendor); return -1; } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("usb vendor needs id")); + return -1; + } + } + + if (virXPathNode("./product", ctxt)) { + g_autofree char *product =3D NULL; + + if ((product =3D virXPathString("string(./product/@id)", ctxt))) { + got_product =3D true; + if (virStrToLong_ui(product, NULL, 0, &usbsrc->product) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse product %s"), product); + return -1; + } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("usb product needs id")); + return -1; + } + } + + if (virXPathNode("./address", ctxt)) { + g_autofree char *bus =3D NULL; + g_autofree char *device =3D NULL; + + if ((bus =3D virXPathString("string(./address/@bus)", ctxt))) { + if (virStrToLong_ui(bus, NULL, 0, &usbsrc->bus) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse bus %s"), bus); + return -1; + } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("usb address needs bus id")); + return -1; + } + + if ((device =3D virXPathString("string(./address/@device)", ctxt))= ) { + if (virStrToLong_ui(device, NULL, 0, &usbsrc->device) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse device %s"), device); + return -1; + } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("usb address needs device id")); + return -1; } - cur =3D cur->next; } =20 if (got_vendor && usbsrc->vendor =3D=3D 0) { --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128460; cv=none; d=zohomail.com; s=zohoarc; b=e0jHsEx1yo0KsdXYqwTwdO7NhNEgUyoHZ6Kf4LpPmkRCmc2zkXfd7QA81BKw2naQuFW05zcBUnropx9gBk7OVb6dUk+y9HnL54rVhGQcXDZ5itzIuWAbAM1yqSB+9c6YstZRp9MTTu0fQ+CrBYJdC3Z9GMfaZs+w8XkstRitLmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128460; h=Content-Type:Content-Transfer-Encoding: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=4rUbDAb4d5ykRG2wVvqQbwMhR5vwE+Pl7YkuOgOXfDM=; b=g6bFc0/rZFZsJpv9OdZqGG+GWZgBNd9VXLds4h1714oSJyFXHfNfrwqGXDNCTGqeMZQm18mqjsmN6UatDDQdsru1rXWoHv6jGeJtGzN3nkQna+vnGRlXY9ECbkLLauHYU9oVjNdNaH/t/VMHYcw+hr9P8bei9MgRuXeb0WN9lH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128460116524.9504255672215; Tue, 4 May 2021 04:41:00 -0700 (PDT) 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-282-9yl1eMJaPtmz0SJFms4ycg-1; Tue, 04 May 2021 07:40:57 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96B321008065; Tue, 4 May 2021 11:40:51 +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 6D52A10190AA; Tue, 4 May 2021 11:40:51 +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 79AE0E20C; Tue, 4 May 2021 11:40:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bemt0000714 for ; Tue, 4 May 2021 07:40:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E9C55D9DD; Tue, 4 May 2021 11:40:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84C825D9D5 for ; Tue, 4 May 2021 11:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128458; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=4rUbDAb4d5ykRG2wVvqQbwMhR5vwE+Pl7YkuOgOXfDM=; b=gU2P2AuMVIl7j8OYxACQ1u0k8LEiI3JYFiPG8JiEgcdqYyQWlXJG2N9v+zix/RRmFtnMPh DSQ7SoOaU29IDJG6U6VQS5KnnMv7EE64n6a2ZboEB3rkNKdttorc7AuVYANc5Pf7e9jKd+ Tg+fWrqviU9DH/AH1g2N3TAnhEfk6Nc= X-MC-Unique: 9yl1eMJaPtmz0SJFms4ycg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 03/19] conf: Propagate xmlXPathContextPtr into virDomainBlkioDeviceParseXML() Date: Tue, 4 May 2021 13:39:57 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5c5b4ad6d7..b369c49b05 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1666,6 +1666,7 @@ virBlkioDeviceArrayClear(virBlkioDevice *devices, */ static int virDomainBlkioDeviceParseXML(xmlNodePtr root, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, virBlkioDevice *dev) { xmlNodePtr node; @@ -19730,7 +19731,7 @@ virDomainDefTunablesParse(virDomainDef *def, def->blkio.devices =3D g_new0(virBlkioDevice, n); =20 for (i =3D 0; i < n; i++) { - if (virDomainBlkioDeviceParseXML(nodes[i], + if (virDomainBlkioDeviceParseXML(nodes[i], ctxt, &def->blkio.devices[i]) < 0) return -1; def->blkio.ndevices++; --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128461; cv=none; d=zohomail.com; s=zohoarc; b=dmz9R/BD0P/va9tJnI7EelQ+bfAWf+M5ywqLUvECnfxIKlhCvIzj+lsEw7w4SOuBzkUYAqYw3oboVLUBdCFNaZ9XlNTuMlurKiA5dfuLmNwBT2F3KjdLTlfslOavp7BYYF2+wHvPzmryHb4HX3G5EctuUVAUtUitlJ9OozxAIxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128461; h=Content-Type:Content-Transfer-Encoding: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=DwlXlb+PO43zGCM77lN4WcwJRdkYTmYAWYhwGWbYeeE=; b=AsocvykoH9yZxdQ6gLguw+/1NxWzkEQWBQO20fxvkX13CDKla3acPIBzp4RUtkOTKtl6/74w/0SXTONIdMIDwuKP+DbgeJG50wnWzivTi7IGJsEC4GRr941rA44rOeHFf0wcRa4hz7s0Jr8VybSgi5G1eKnjE53zrQ7ZlwlxXdA= 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 1620128461042345.379636639266; Tue, 4 May 2021 04:41:01 -0700 (PDT) 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-479-zP6pw8DrP-GrQ1mB-qC3Pg-1; Tue, 04 May 2021 07:40:58 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1C2E801817; Tue, 4 May 2021 11:40:52 +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 7DF055D703; Tue, 4 May 2021 11:40:51 +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 0A756E221; Tue, 4 May 2021 11:40:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BenBS000727 for ; Tue, 4 May 2021 07:40:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD4D85D9DD; Tue, 4 May 2021 11:40:49 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF06D5D9D5 for ; Tue, 4 May 2021 11:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128460; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=DwlXlb+PO43zGCM77lN4WcwJRdkYTmYAWYhwGWbYeeE=; b=NeuUh26EzLwwQLEfnAqW7IZBC8ml0cuZeGf7hatpP6nR7xtRfLeMXmcQ+e2rcbqXd9H76v J5Do1OtAmqI80lPD4aLpbs3CX9d8dg/OMeDIUiZ427GKxcQdZfYUuHCCcjD0NmozTL9vfS 29x8ogqk7TRQYZamNM3oe1RdD9NsPVE= X-MC-Unique: zP6pw8DrP-GrQ1mB-qC3Pg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 04/19] Refactoring virDomainBlkioDeviceParseXML() to use XPath Date: Tue, 4 May 2021 13:39:58 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.15 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 116 +++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 68 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b369c49b05..f658cf49e7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1666,85 +1666,65 @@ virBlkioDeviceArrayClear(virBlkioDevice *devices, */ static int virDomainBlkioDeviceParseXML(xmlNodePtr root, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, + xmlXPathContextPtr ctxt, virBlkioDevice *dev) { - xmlNodePtr node; g_autofree char *path =3D NULL; + g_autofree char *weight =3D NULL; + g_autofree char *read_bytes_sec =3D NULL; + g_autofree char *write_bytes_sec =3D NULL; + g_autofree char *read_iops_sec =3D NULL; + g_autofree char *write_iops_sec =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 - for (node =3D root->children; node !=3D NULL; node =3D node->next) { - g_autofree char *c =3D NULL; - - if (node->type !=3D XML_ELEMENT_NODE) - continue; - - if (!(c =3D virXMLNodeContentString(node))) - return -1; - - if (virXMLNodeNameEqual(node, "path")) { - /* To avoid the need for explicit cleanup on failure, - * don't set dev->path until we're assured of - * success. Until then, store it in an autofree pointer. - */ - if (!path) - path =3D g_steal_pointer(&c); - continue; - } + ctxt->node =3D root; =20 - if (virXMLNodeNameEqual(node, "weight")) { - if (virStrToLong_ui(c, NULL, 10, &dev->weight) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not parse weight %s"), - c); - return -1; - } - continue; - } + /* To avoid the need for explicit cleanup on failure, + * don't set dev->path until we're assured of + * success. Until then, store it in an autofree pointer. + */ + if (!(path =3D virXPathString("string(./path)", ctxt))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("missing per-device path")); + return -1; + } =20 - if (virXMLNodeNameEqual(node, "read_bytes_sec")) { - if (virStrToLong_ull(c, NULL, 10, &dev->rbps) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not parse read bytes sec %s"), - c); - return -1; - } - continue; - } + if ((weight =3D virXPathString("string(./weight)", ctxt)) && + (virStrToLong_ui(weight, NULL, 10, &dev->weight) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("could not parse weight %s"), weight); + return -1; + } =20 - if (virXMLNodeNameEqual(node, "write_bytes_sec")) { - if (virStrToLong_ull(c, NULL, 10, &dev->wbps) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not parse write bytes sec %s"), - c); - return -1; - } - continue; - } + if ((read_bytes_sec =3D virXPathString("string(./read_bytes_sec)", ctx= t)) && + (virStrToLong_ull(read_bytes_sec, NULL, 10, &dev->rbps) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("could not parse read bytes sec %s"), + read_bytes_sec); + return -1; + } =20 - if (virXMLNodeNameEqual(node, "read_iops_sec")) { - if (virStrToLong_ui(c, NULL, 10, &dev->riops) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not parse read iops sec %s"), - c); - return -1; - } - continue; - } + if ((write_bytes_sec =3D virXPathString("string(./write_bytes_sec)", c= txt)) && + (virStrToLong_ull(write_bytes_sec, NULL, 10, &dev->wbps) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("could not parse write bytes sec %s"), + write_bytes_sec); + return -1; + } =20 - if (virXMLNodeNameEqual(node, "write_iops_sec")) { - if (virStrToLong_ui(c, NULL, 10, &dev->wiops) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not parse write iops sec %s"), - c); - return -1; - } - continue; - } + if ((read_iops_sec =3D virXPathString("string(./read_iops_sec)", ctxt)= ) && + (virStrToLong_ui(read_iops_sec, NULL, 10, &dev->riops) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("could not parse read iops sec %s"), + read_iops_sec); + return -1; } =20 - if (!path) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("missing per-device path")); + if ((write_iops_sec =3D virXPathString("string(./write_iops_sec)", ctx= t)) && + (virStrToLong_ui(write_iops_sec, NULL, 10, &dev->wiops) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("could not parse write iops sec %s"), + write_iops_sec); return -1; } =20 --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128472; cv=none; d=zohomail.com; s=zohoarc; b=VHvrtCM7Evuy3tW2wTfelfkbF49hazJt52xpsF1hIcoTphObX7I4y1xvIISz3RjgEzFxnCCQdXlbfCp4V30xHwwMsDWYckZRP1JSOjW8vaE//znUnan+BQp3b2Cz25JYEI8/xzd5PsZInOzcrOzZRQtT9T8HDHcz01SmCAzDwjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128472; h=Content-Type:Content-Transfer-Encoding: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=+zlNSYRRR4L1Sk7e6RFW24fbvMluBQ+1zQtEgvotXks=; b=ZzC7ezxTG6BvMK7uaTATJVMvbpdOyrDpeKmc21Me6h2qY9N/Vey5QJjPgvepjWOpiwNkYRMsRsBKTUXMFXFjOZggl30Xk2eNoiMxmuYfXjFhNTj45Vm2N26q7YRxygCn3LZ+KkblYggm00tLOw+VdQjgmwGP2KrSBAv0+DVZedw= 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 1620128472373830.4796356428966; Tue, 4 May 2021 04:41:12 -0700 (PDT) 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-593-3Ahkgk_YMgiN1F-bYVGaWg-1; Tue, 04 May 2021 07:41:08 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E64F36D4E6; Tue, 4 May 2021 11:41:02 +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 C123F60C0F; Tue, 4 May 2021 11:41:02 +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 8765A8DFE; Tue, 4 May 2021 11:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BepUD000742 for ; Tue, 4 May 2021 07:40:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5AFC95D9C0; Tue, 4 May 2021 11:40:51 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E2DC5D9D5 for ; Tue, 4 May 2021 11:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128471; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=+zlNSYRRR4L1Sk7e6RFW24fbvMluBQ+1zQtEgvotXks=; b=d6kvV5Y4m5xvxdCAGWulh9c03bRFY0naNtnk4YF6SMnsdBAsi+hSj2rADxYPuHBOMwjdoo CDGg5p1e/2pz36j1Fvo5yot4/ON5+dvst9T1Dx3p3lGQlnpKVSK+IZRGvlqGc7k7MS9Ub5 sKl+3Sxr0usCymfXEYPfx6fdp7OHgvM= X-MC-Unique: 3Ahkgk_YMgiN1F-bYVGaWg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 05/19] conf: Propagate xmlXPathContextPtr into virDomainHostdevSubsysPCIDefParseXML() Date: Tue, 4 May 2021 13:39:59 +0200 Message-Id: <095ba363382a3484f8502b50b73c9c9ce08dc556.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.12 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f658cf49e7..3ca5211a35 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6841,6 +6841,7 @@ virDomainHostdevSubsysPCIOrigStatesDefParseXML(xmlNod= ePtr node, =20 static int virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, virDomainHostdevDef *def, unsigned int flags) { @@ -7390,7 +7391,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, =20 switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) <= 0) + if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, fl= ags) < 0) return -1; =20 backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128652; cv=none; d=zohomail.com; s=zohoarc; b=aBK8/RwLPsYRqe3I6wSJ9/FIFbk19LMlqWxYhkzxrh3al+cqKHVf+I8ubXKqIkTcgIy+e06AEpujCRONsSA0LtIglpyDwLhIkPUJHpRY5DYudezPGiXHB7FhYzW1gLPwZkpdnvV5ZS6w6HBHJWFG1Refb/7aK/xHOW9Ru3r0y/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128652; h=Content-Type:Content-Transfer-Encoding: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=+XpUTcwU6g/BstLwEcHm+DEbsFiiTML4gRFluHj8OjI=; b=Um1vGMBh/1wJ175Yx9J8njH+VPs/vBcxMuUjaAOuAQeBt8XOsm5mYBYY0tSP3cuiaIQWNcB3FxmEV8NER9ChsKCNRPhO7CqrzTZHNvle1RzN5E4l8WPnScbfGRgKAYuf9vclEgMGi8OWAGER7Nu9mmzJmqOs4U6O04ibOa3FWkI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 16201286528711013.0091785774429; Tue, 4 May 2021 04:44:12 -0700 (PDT) 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-453-1Ux8sna0NricMObmVgtZ_Q-1; Tue, 04 May 2021 07:41:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 275AE8042A3; Tue, 4 May 2021 11: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 0A32659446; Tue, 4 May 2021 11:41:10 +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 C60C555352; Tue, 4 May 2021 11:41:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Beq1l000747 for ; Tue, 4 May 2021 07:40:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 935AD5D9D5; Tue, 4 May 2021 11:40:52 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5AF45D9C0 for ; Tue, 4 May 2021 11:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128651; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=+XpUTcwU6g/BstLwEcHm+DEbsFiiTML4gRFluHj8OjI=; b=XzN8t5mopSe8j6o6m5Eya4tTMZGGDa2jhg8B5RMxIpLg5o5TmtU6mcjXJ13mfyhWZgAzrk t28YsUdv1AjePGA2Q1BotBVRqgyNj32POqU6vRA+S5OOl8mY5P7kw1qHvRunZC3qXSfoCF AWIWpuYT4c9qxw5tDrDd8FL+EeqDhJk= X-MC-Unique: 1Ux8sna0NricMObmVgtZ_Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 06/19] Refactoring virDomainHostdevSubsysPCIDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:00 +0200 Message-Id: <4e39751632952abe4c42dfe150d969924a11fe39.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.11 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3ca5211a35..c5d4469b72 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6841,12 +6841,16 @@ virDomainHostdevSubsysPCIOrigStatesDefParseXML(xmlN= odePtr node, =20 static int virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, + xmlXPathContextPtr ctxt, virDomainHostdevDef *def, unsigned int flags) { g_autofree char *filtering =3D NULL; - xmlNodePtr cur; + xmlNodePtr address =3D NULL; + xmlNodePtr origstates =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D node; =20 if ((filtering =3D virXMLPropString(node, "writeFiltering"))) { int val; @@ -6859,29 +6863,14 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, def->writeFiltering =3D val; } =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "address")) { - virPCIDeviceAddress *addr =3D - &def->source.subsys.u.pci.addr; + if ((address =3D virXPathNode("./address", ctxt)) && + virPCIDeviceAddressParseXML(address, &def->source.subsys.u.pci.add= r) < 0) + return -1; =20 - if (virPCIDeviceAddressParseXML(cur, addr) < 0) - return -1; - } else if ((flags & VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES) && - virXMLNodeNameEqual(cur, "origstates")) { - virDomainHostdevOrigStates *states =3D &def->origstates; - if (virDomainHostdevSubsysPCIOrigStatesDefParseXML(cur, st= ates) < 0) - return -1; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown pci source type '%s'"), - cur->name); - return -1; - } - } - cur =3D cur->next; - } + if ((flags & VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES) && + (origstates =3D virXPathNode("./origstates", ctxt)) && + virDomainHostdevSubsysPCIOrigStatesDefParseXML(origstates, &def->o= rigstates) < 0) + return -1; =20 return 0; } --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128653; cv=none; d=zohomail.com; s=zohoarc; b=Pz84V0H6w9zsqOQzzOYT01moKL0Fqn3Y/VBHYe8joN2OxJCgNK7OJCE4/BP3dIiZ1KQyNhjkEbU1lY3p5E7f5VhDT8gnqEuX48T4/5snvE/yZ3Yk/aXUUTeMNHH7dwyqvvvJxTYOT+7+TdVLWW/Bs2siNXhErnLpZvz1cJnKof8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128653; h=Content-Type:Content-Transfer-Encoding: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=4wdotbte3RY+ALcuDwJQy8q7Jnv2YNQnlu1nAgI33nQ=; b=kHs5txI/3057zqj1dkyUew6pI5q6P9Kx+sWsUYM6rON4lOtcZ23deYbn69aQVuKbfKA8JUYOF1uK/zAXUKUpHmUTk4WEuCFNZpqK1NQw/q/Ztw3OebTNSu8pQMkqIBgg60pbeCmgCtXH//SyEzuIj3EfAZPqmsnjrPtz6c5+Peg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128653294859.1050400603502; Tue, 4 May 2021 04:44:13 -0700 (PDT) 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-538-4sKdq-goMyqe_bFb4rS5Lg-1; Tue, 04 May 2021 07:41:07 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1108E1008065; Tue, 4 May 2021 11:41:03 +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 DF5891037E8B; Tue, 4 May 2021 11:41:02 +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 A91021800FF0; Tue, 4 May 2021 11:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BesnZ000758 for ; Tue, 4 May 2021 07:40:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 279B25D9D0; Tue, 4 May 2021 11:40:54 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30B645D9C0 for ; Tue, 4 May 2021 11:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128651; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=4wdotbte3RY+ALcuDwJQy8q7Jnv2YNQnlu1nAgI33nQ=; b=BiM9iJ6nBnXI+9EIyLpaDdkyXDUFtV/xq4MFUZQYnaf8fjplpKWLKCCT8gstWcN/CYSzWW 7037onOBMYILD7pcTybwqHI9UJKoJ2R5ikJce/lVlH8sF6dcTUYJjEy6C7XFEv8JULvsoA GDE+i57pP6cToPa/n/q4YfAZ4J5ieCo= X-MC-Unique: 4sKdq-goMyqe_bFb4rS5Lg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 07/19] conf: Propagate xmlXPathContextPtr into virDomainLeaseDefParseXML() Date: Tue, 4 May 2021 13:40:01 +0200 Message-Id: <6d312a32ecf18b3fbb0056ae6a6392d29ab7851b.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c5d4469b72..1142b1214a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8084,7 +8084,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDef ***seclabels_rtn, /* Parse the XML definition for a lease */ static virDomainLeaseDef * -virDomainLeaseDefParseXML(xmlNodePtr node) +virDomainLeaseDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED) { virDomainLeaseDef *def; xmlNodePtr cur; @@ -15508,7 +15509,7 @@ virDomainDeviceDefParse(const char *xmlStr, return NULL; break; case VIR_DOMAIN_DEVICE_LEASE: - if (!(dev->data.lease =3D virDomainLeaseDefParseXML(node))) + if (!(dev->data.lease =3D virDomainLeaseDefParseXML(node, ctxt))) return NULL; break; case VIR_DOMAIN_DEVICE_FS: @@ -20276,7 +20277,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (n) def->leases =3D g_new0(virDomainLeaseDef *, n); for (i =3D 0; i < n; i++) { - virDomainLeaseDef *lease =3D virDomainLeaseDefParseXML(nodes[i]); + virDomainLeaseDef *lease =3D virDomainLeaseDefParseXML(nodes[i], c= txt); if (!lease) goto error; =20 --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128644; cv=none; d=zohomail.com; s=zohoarc; b=kQVrure1ApL2VvO97c5IlXu4ZYtRCuR+zshJVP6XBecKzOLIXETcqnGE9gltVqBYwuS8C7Fg52MBQLQ9Itp4JQ0+I4UMxMDuu8EjGwVs+6BZat4qF84J+rTQp2P/zMVqsodQohj42yeZlxkPkEpeKb9nKzCMN4p0PurJNFQx7sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128644; h=Content-Type:Content-Transfer-Encoding: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=NbqcnL2Tp/3lNW1UIVWLHLHV2QNPtmSXvcvSPpXkLH0=; b=EiKRlOFycTTIdW6jnHS4YrmtziDFLvwXZ9vAee1NmyQgPCselHmDOngwbRkWuH0j+crwOOCpZGxTjisHoS3SEMu4QkCZvvRvu504539QQKaRABvEi9Vac8iDyLcKwI0TtUmaJTxkS3TKGxCsqCvFbIapvAoz8D+0+ZVquNSTKbo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128644199142.52470621003317; Tue, 4 May 2021 04:44:04 -0700 (PDT) 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-25-0rYCb4TlOIen_78M04evtw-1; Tue, 04 May 2021 07:41:20 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02EB4107ACFE; Tue, 4 May 2021 11:41:13 +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 D5CE15B685; Tue, 4 May 2021 11:41:12 +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 9D5A555352; Tue, 4 May 2021 11:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BetkM000774 for ; Tue, 4 May 2021 07:40:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 565D15D9D0; Tue, 4 May 2021 11:40:55 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AFD55D9C0 for ; Tue, 4 May 2021 11:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128643; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=NbqcnL2Tp/3lNW1UIVWLHLHV2QNPtmSXvcvSPpXkLH0=; b=NkGpPtUsvzrHDKDQ30GAggGpv6vroPgLwW07Pu3lcSiHw9NrVr+K/Oni3QP7jdCFojFxal bJf3UV+3UVcp8uGfzcfUKWwGYJE73LRTxujFlSIWQJoV0b5Ly0usUYwi6ioBEqFpuFH6nJ 4x5Y4HqN0ayGOJIXcC0gGGWl7KTgO7E= X-MC-Unique: 0rYCb4TlOIen_78M04evtw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 08/19] Refactoring virDomainLeaseDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:02 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.15 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 189 ++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 107 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1142b1214a..365879ea98 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8085,48 +8085,34 @@ virSecurityDeviceLabelDefParseXML(virSecurityDevice= LabelDef ***seclabels_rtn, */ static virDomainLeaseDef * virDomainLeaseDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED) + xmlXPathContextPtr ctxt) { virDomainLeaseDef *def; - xmlNodePtr cur; g_autofree char *lockspace =3D NULL; g_autofree char *key =3D NULL; g_autofree char *path =3D NULL; g_autofree char *offset =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 + ctxt->node =3D node; def =3D g_new0(virDomainLeaseDef, 1); =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!key && virXMLNodeNameEqual(cur, "key")) { - if (!(key =3D virXMLNodeContentString(cur))) - goto error; - } else if (!lockspace && - virXMLNodeNameEqual(cur, "lockspace")) { - if (!(lockspace =3D virXMLNodeContentString(cur))) - goto error; - } else if (!path && - virXMLNodeNameEqual(cur, "target")) { - path =3D virXMLPropString(cur, "path"); - offset =3D virXMLPropString(cur, "offset"); - } - } - cur =3D cur->next; - } - - if (!key) { + if (!(key =3D virXPathString("string(./key)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'key' element for lease")); goto error; } - if (!path) { + + if (!(lockspace =3D virXPathString("string(./lockspace)", ctxt))) + goto error; + + if (!(path =3D virXPathString("string(./target/@path)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'target' element for lease")); goto error; } =20 - if (offset && + if ((offset =3D virXPathString("string(./target/@offset)", ctxt)) && virStrToLong_ull(offset, NULL, 10, &def->offset) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Malformed lease target offset %s"), offset); @@ -9464,9 +9450,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, { g_autoptr(virDomainControllerDef) def =3D NULL; virDomainControllerType type =3D 0; - xmlNodePtr cur =3D NULL; - bool processedModel =3D false; - bool processedTarget =3D false; + xmlNodePtr driver =3D NULL; + xmlNodePtr target =3D NULL; int numaNode =3D -1; int ports =3D -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -9502,94 +9487,84 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, def->idx =3D idxVal; } =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "driver")) { - if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, - &def->queues) < 0) - return NULL; + if ((driver =3D virXPathNode("./driver", ctxt)) && + (virDomainVirtioOptionsParseXML(driver, &def->virtio) < 0)) + return NULL; =20 - if (virXMLPropUInt(cur, "cmd_per_lun", 10, VIR_XML_PROP_NO= NE, - &def->cmd_per_lun) < 0) - return NULL; + if (virXMLPropUInt(driver, "queues", 10, VIR_XML_PROP_NONE, + &def->queues) < 0) + return NULL; =20 - if (virXMLPropUInt(cur, "max_sectors", 10, VIR_XML_PROP_NO= NE, - &def->max_sectors) < 0) - return NULL; + if (virXMLPropUInt(driver, "cmd_per_lun", 10, VIR_XML_PROP_NONE, + &def->cmd_per_lun) < 0) + return NULL; =20 - if (virXMLPropTristateSwitch(cur, "ioeventfd", - VIR_XML_PROP_NONE, - &def->ioeventfd) < 0) - return NULL; + if (virXMLPropUInt(driver, "max_sectors", 10, VIR_XML_PROP_NONE, + &def->max_sectors) < 0) + return NULL; =20 - if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONE, - &def->iothread) < 0) - return NULL; + if (virXMLPropTristateSwitch(driver, "ioeventfd", + VIR_XML_PROP_NONE, + &def->ioeventfd) < 0) + return NULL; =20 - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - return NULL; - } else if (virXMLNodeNameEqual(cur, "model")) { - if (processedModel) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); - return NULL; - } + if (virXMLPropUInt(driver, "iothread", 10, VIR_XML_PROP_NONE, + &def->iothread) < 0) + return NULL; =20 - if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { - if (virXMLPropEnum(cur, "name", - virDomainControllerPCIModelNameType= FromString, - VIR_XML_PROP_NONE, - &def->opts.pciopts.modelName) < 0) - return NULL; - } + if (virXPathBoolean("boolean(count(./model) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Multiple elements in " + "controller definition not allowed")); + return NULL; + } =20 - processedModel =3D true; - } else if (virXMLNodeNameEqual(cur, "target")) { - if (processedTarget) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); - return NULL; - } - if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { - if (virXMLPropInt(cur, "chassisNr", 0, VIR_XML_PROP_NO= NE, - &def->opts.pciopts.chassisNr) < 0) - return NULL; - - if (virXMLPropInt(cur, "chassis", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.chassis) < 0) - return NULL; - - if (virXMLPropInt(cur, "port", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.port) < 0) - return NULL; - - if (virXMLPropInt(cur, "busNr", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.busNr) < 0) - return NULL; - - if (virXMLPropTristateSwitch(cur, "hotplug", - VIR_XML_PROP_NONE, - &def->opts.pciopts.hotplu= g) < 0) - return NULL; - - if ((rc =3D virXMLPropInt(cur, "index", 0, VIR_XML_PRO= P_NONE, - &def->opts.pciopts.targetIndex)) < 0) - return NULL; - - if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D= =3D -1) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid target index '%i' in PCI= controller"), - def->opts.pciopts.targetIndex); - } - } + if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropEnum(virXPathNode("./model", ctxt), "name", + virDomainControllerPCIModelNameTypeFromString, + VIR_XML_PROP_NONE, + &def->opts.pciopts.modelName) < 0) + return NULL; + } =20 - processedTarget =3D true; - } - } - cur =3D cur->next; + if (virXPathBoolean("boolean(count(./target) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Multiple elements in " + "controller definition not allowed")); + return NULL; + } + + if ((target =3D virXPathNode("./target", ctxt)) && + def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropInt(target, "chassisNr", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.chassisNr) < 0) + return NULL; + + if (virXMLPropInt(target, "chassis", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.chassis) < 0) + return NULL; + + if (virXMLPropInt(target, "port", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.port) < 0) + return NULL; + + if (virXMLPropInt(target, "busNr", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.busNr) < 0) + return NULL; + + if (virXMLPropTristateSwitch(target, "hotplug", + VIR_XML_PROP_NONE, + &def->opts.pciopts.hotplug) < 0) + return NULL; + + if ((rc =3D virXMLPropInt(target, "index", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.targetIndex)) < 0) + return NULL; + + if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D=3D -1) + virReportError(VIR_ERR_XML_ERROR, + _("Invalid target index '%i' in PCI controller"= ), + def->opts.pciopts.targetIndex); } =20 /* node is parsed differently from target attributes because --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128474; cv=none; d=zohomail.com; s=zohoarc; b=dGL/STIs3Hs6FoROR+4sLsywhKDpIq3TopxN917Hmcgw2HM23KebG0aDNRuVM8KFMWcFThn9vHxf64oGb6QKJjHKFgLjSLrAK4p91QS3oWwLMj3eKGPlstSURgMFU6nQcJWcYdU2bnxsyw1C+vvo/9c5Z6yox0zw/9YAePa+oPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128474; h=Content-Type:Content-Transfer-Encoding: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=pVQoVQGDjnXScJCbFMO/y23+5KgjL61947zTfCW+9wM=; b=PrHj8etikLLVOOJ4e0emk79VXc/wOgvdIANVTRb8aLWPfQeijP+G12ESZK7WT9UJHwLCNvr1S//+mGktvMrxv/WJgl6gsuFTTeqtk0d2AoMl7kENIYDpujwPGtJgCWaMXG7BisBg+zSBHVQIrRS3recCQgxgbpMWeJUHWFlHeYk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128474562235.04921651708287; Tue, 4 May 2021 04:41:14 -0700 (PDT) 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-134-CLfJ6Me_MV-MFIHPf-Vh2g-1; Tue, 04 May 2021 07:41:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E06261008076; Tue, 4 May 2021 11:41:05 +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 B87F519D9B; Tue, 4 May 2021 11:41:05 +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 7AD7755350; Tue, 4 May 2021 11:41:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BeuRq000779 for ; Tue, 4 May 2021 07:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93F6F5D9DD; Tue, 4 May 2021 11:40:56 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7B765D9D5 for ; Tue, 4 May 2021 11:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128473; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=pVQoVQGDjnXScJCbFMO/y23+5KgjL61947zTfCW+9wM=; b=FzpsVPx2o2Eec7KCdL+IQlHElBYbGq8vgnJP2XyU6v737hKeCbJJnOAQUSrZZHXMsJYF+o ztw0sGoAV4xuchRxkLzKG4fbbCtKxp9buGAe5UjuRFs9qJiNTn8PUFAuKZgZkVIlRwi80L XpxeR2tzfCjC6qPcpb41Z2qIL3MXrjU= X-MC-Unique: CLfJ6Me_MV-MFIHPf-Vh2g-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 09/19] Refactoring virDomainFSDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:03 +0200 Message-Id: <25b86d9daabcb75bc24306f19ce46a9b3ace4055.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.23 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 110 ++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 365879ea98..d7bee155e7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9714,7 +9714,8 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, { VIR_XPATH_NODE_AUTORESTORE(ctxt) virDomainFSDef *def; - xmlNodePtr cur; + xmlNodePtr driver_node =3D NULL; + xmlNodePtr source_node =3D NULL; g_autofree char *type =3D NULL; g_autofree char *fsdriver =3D NULL; g_autofree char *source =3D NULL; @@ -9808,57 +9809,62 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, 1, ULLONG_MAX, false) < 0) goto error; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!source && !sock && - virXMLNodeNameEqual(cur, "source")) { - sock =3D virXMLPropString(cur, "socket"); - if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_MOUNT || - def->type =3D=3D VIR_DOMAIN_FS_TYPE_BIND) { - source =3D virXMLPropString(cur, "dir"); - } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_FILE) { - source =3D virXMLPropString(cur, "file"); - } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_BLOCK) { - source =3D virXMLPropString(cur, "dev"); - } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_TEMPLATE) { - source =3D virXMLPropString(cur, "name"); - } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_RAM) { - usage =3D virXMLPropString(cur, "usage"); - units =3D virXMLPropString(cur, "units"); - } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_VOLUME) { - def->src->type =3D VIR_STORAGE_TYPE_VOLUME; - if (virDomainDiskSourcePoolDefParse(cur, &def->src->sr= cpool) < 0) - goto error; - } - } else if (!target && - virXMLNodeNameEqual(cur, "target")) { - target =3D virXMLPropString(cur, "dir"); - } else if (virXMLNodeNameEqual(cur, "readonly")) { - def->readonly =3D true; - } else if (virXMLNodeNameEqual(cur, "driver")) { - if (!fsdriver) - fsdriver =3D virXMLPropString(cur, "type"); - if (!wrpolicy) - wrpolicy =3D virXMLPropString(cur, "wrpolicy"); - if (!format) - format =3D virXMLPropString(cur, "format"); - - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - goto error; - } + if ((source_node =3D virXPathNode("./source", ctxt))) { + sock =3D virXMLPropString(source_node, "socket"); + if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_MOUNT || + def->type =3D=3D VIR_DOMAIN_FS_TYPE_BIND) { + source =3D virXMLPropString(source_node, "dir"); + } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_FILE) { + source =3D virXMLPropString(source_node, "file"); + } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_BLOCK) { + source =3D virXMLPropString(source_node, "dev"); + } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_TEMPLATE) { + source =3D virXMLPropString(source_node, "name"); + } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_RAM) { + usage =3D virXMLPropString(source_node, "usage"); + units =3D virXMLPropString(source_node, "units"); + } else if (def->type =3D=3D VIR_DOMAIN_FS_TYPE_VOLUME) { + def->src->type =3D VIR_STORAGE_TYPE_VOLUME; + if (virDomainDiskSourcePoolDefParse(source_node, &def->src->sr= cpool) < 0) + goto error; } - cur =3D cur->next; } =20 - if (fsdriver) { - if ((def->fsdriver =3D virDomainFSDriverTypeFromString(fsdriver)) = <=3D 0) { + target =3D virXPathString("string(./target/@dir)", ctxt); + + if (virXPathNode("./readonly", ctxt)) + def->readonly =3D true; + + if ((driver_node =3D virXPathNode("./driver", ctxt))) { + if (virDomainVirtioOptionsParseXML(driver_node, &def->virtio) < 0) + goto error; + + if ((fsdriver =3D virXMLPropString(driver_node, "type")) && + ((def->fsdriver =3D virDomainFSDriverTypeFromString(fsdriver))= <=3D 0)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown fs driver type '%s'"), fsdriver); goto error; } + + if ((wrpolicy =3D virXMLPropString(driver_node, "wrpolicy"))) { + if ((def->wrpolicy =3D virDomainFSWrpolicyTypeFromString(wrpol= icy)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown filesystem write policy '%s'"), = wrpolicy); + goto error; + } + } else { + def->wrpolicy =3D VIR_DOMAIN_FS_WRPOLICY_DEFAULT; + } + + if ((format =3D virXMLPropString(driver_node, "format")) && + ((def->format =3D virStorageFileFormatTypeFromString(format)) = <=3D 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown driver format value '%s'"), format); + goto error; + } } =20 + if (def->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) { g_autofree char *queue_size =3D virXPathString("string(./driver/@q= ueue)", ctxt); g_autofree char *binary =3D virXPathString("string(./binary/@path)= ", ctxt); @@ -9927,24 +9933,6 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, } } =20 - if (format) { - if ((def->format =3D virStorageFileFormatTypeFromString(format)) <= =3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown driver format value '%s'"), format); - goto error; - } - } - - if (wrpolicy) { - if ((def->wrpolicy =3D virDomainFSWrpolicyTypeFromString(wrpolicy)= ) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown filesystem write policy '%s'"), wrpo= licy); - goto error; - } - } else { - def->wrpolicy =3D VIR_DOMAIN_FS_WRPOLICY_DEFAULT; - } - if (source =3D=3D NULL && def->type !=3D VIR_DOMAIN_FS_TYPE_RAM && def->type !=3D VIR_DOMAIN_FS_TYPE_VOLUME && !sock) { virReportError(VIR_ERR_NO_SOURCE, --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128486; cv=none; d=zohomail.com; s=zohoarc; b=gN2x7NONWwzCny7m8j2Fng+Nn3jKOFSZbi7jhW04Qw/p59uHvEB5/ZBsghyTpu1XV9nwxHtXx2g2jkw/l5zKaqACcvERHHOy1ZjFIJePuKroQxayHUKRNQVsp0oP/O8FaxaqF0m0ibi6RHEMPxb6mZbt5VZ3KBSRHcqlw2vej0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128486; h=Content-Type:Content-Transfer-Encoding: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=nmSxsq4sJvngOprxhFCI1EqZf/Odg9ACeA6F0w8X9k0=; b=c9+Buomt9iQRkYzcJRIcoGdI4pKl7ChWopkVCOFul6SH6kqekK5l6vdbF9Acmo1aku8ex9V3Do3jRdlmdtmHfmy935j6AMdUlNZooOWd1ix8wE8qY404PX19pdy5G/esMEK2N+5TV6oTJ/ERV1/xSq7EcPeI5zU9Ge/GjCp8LbM= 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 1620128486446673.1172575424023; Tue, 4 May 2021 04:41:26 -0700 (PDT) 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-267-hIH4oQHaOgCBZr0YCaySsg-1; Tue, 04 May 2021 07:41:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC871801AC9; Tue, 4 May 2021 11:41:05 +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 9E33460854; Tue, 4 May 2021 11:41:05 +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 689151801028; Tue, 4 May 2021 11:41:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bew9V000790 for ; Tue, 4 May 2021 07:40:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21A475D9DD; Tue, 4 May 2021 11:40:58 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E71D5D9D5 for ; Tue, 4 May 2021 11:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128485; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=nmSxsq4sJvngOprxhFCI1EqZf/Odg9ACeA6F0w8X9k0=; b=UixAjZ05Y0vogI3JkHFqcUI+5P/TCIeOLR3c3N2hHQHbFd+LLon2za/7Ejr2bjdYYb4y6/ PcfamUMk3xLrxxjBENHEaNryQDDv52OuVn0K/+m7f3cYuY3RvdIp9MvT5FLiSixtShWOz3 O7yQNqMXodIf8pI0sVZrKIilS4JV5kE= X-MC-Unique: hIH4oQHaOgCBZr0YCaySsg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 10/19] Refactoring virDomainNetDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.13 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 340 +++++++++++++++++++---------------------- 1 file changed, 157 insertions(+), 183 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d7bee155e7..dc72a91d8d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10245,7 +10245,13 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, { virDomainNetDef *def; virDomainHostdevDef *hostdev; - xmlNodePtr cur; + xmlNodePtr source_node =3D NULL; + xmlNodePtr virtualport_node =3D NULL; + xmlNodePtr driver_node =3D NULL; + xmlNodePtr filterref_node =3D NULL; + xmlNodePtr actual_node =3D NULL; + xmlNodePtr vlan_node =3D NULL; + xmlNodePtr bandwidth_node =3D NULL; xmlNodePtr tmpNode; GHashTable *filterparams =3D NULL; virDomainActualNetDef *actual =3D NULL; @@ -10288,6 +10294,8 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *vhostuser_path =3D NULL; g_autofree char *vhostuser_type =3D NULL; g_autofree char *vhost_path =3D NULL; + g_autofree char *tap =3D NULL; + g_autofree char *vhost =3D NULL; const char *prefix =3D xmlopt ? xmlopt->config.netPrefix : NULL; =20 if (!(def =3D virDomainNetDefNew(xmlopt))) @@ -10306,195 +10314,158 @@ virDomainNetDefParseXML(virDomainXMLOption *xml= opt, &def->trustGuestRxFilters) < 0) goto error; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "source")) { - xmlNodePtr tmpnode =3D ctxt->node; + if ((source_node =3D virXPathNode("./source", ctxt))) { + xmlNodePtr tmpnode =3D ctxt->node; + ctxt->node =3D source_node; + if (virDomainNetIPInfoParseXML(_("interface host IP"), ctxt, &def-= >hostIP) < 0) + goto error; + ctxt->node =3D tmpnode; =20 - ctxt->node =3D cur; - if (virDomainNetIPInfoParseXML(_("interface host IP"), - ctxt, &def->hostIP) < 0) - goto error; - ctxt->node =3D tmpnode; - } - if (!macaddr && virXMLNodeNameEqual(cur, "mac")) { - macaddr =3D virXMLPropString(cur, "address"); - macaddr_type =3D virXMLPropString(cur, "type"); - macaddr_check =3D virXMLPropString(cur, "check"); - } else if (!network && - def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virXMLNodeNameEqual(cur, "source")) { - network =3D virXMLPropString(cur, "network"); - portgroup =3D virXMLPropString(cur, "portgroup"); - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - portid =3D virXMLPropString(cur, "portid"); - } else if (!internal && - def->type =3D=3D VIR_DOMAIN_NET_TYPE_INTERNAL && - virXMLNodeNameEqual(cur, "source")) { - internal =3D virXMLPropString(cur, "name"); - } else if (!bridge && - def->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - virXMLNodeNameEqual(cur, "source")) { - bridge =3D virXMLPropString(cur, "bridge"); - } else if (!dev && def->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT= && - virXMLNodeNameEqual(cur, "source")) { - dev =3D virXMLPropString(cur, "dev"); - mode =3D virXMLPropString(cur, "mode"); - } else if (!dev && def->type =3D=3D VIR_DOMAIN_NET_TYPE_ETHERN= ET && - virXMLNodeNameEqual(cur, "source")) { - /* This clause is only necessary because from 2010 to - * 2016 it was possible (but never documented) to - * configure the name of the guest-side interface of - * an openvz domain with . That - * was blatant misuse of , so was likely - * (hopefully) never used, but just in case there was - * somebody using it, we need to generate an error. If - * the openvz driver is ever deprecated, this clause - * can be removed from here. - */ - if ((dev =3D virXMLPropString(cur, "dev"))) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid attempt to set " - "device name with . " - "Use (for host-s= ide) " - "or (for guest-si= de) instead."), - dev, dev, dev); - goto error; - } - } else if (!vhostuser_path && !vhostuser_mode && !vhostuser_ty= pe - && def->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER - && virXMLNodeNameEqual(cur, "source")) { - vhostuser_type =3D virXMLPropString(cur, "type"); - vhostuser_path =3D virXMLPropString(cur, "path"); - vhostuser_mode =3D virXMLPropString(cur, "mode"); - if (virDomainChrSourceReconnectDefParseXML(&reconnect, cur= , ctxt) < 0) - goto error; + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + network =3D virXMLPropString(source_node, "network"); + portgroup =3D virXMLPropString(source_node, "portgroup"); + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + portid =3D virXMLPropString(source_node, "portid"); + } =20 - } else if (!dev - && def->type =3D=3D VIR_DOMAIN_NET_TYPE_VDPA - && virXMLNodeNameEqual(cur, "source")) { - dev =3D virXMLPropString(cur, "dev"); - } else if (!def->virtPortProfile - && virXMLNodeNameEqual(cur, "virtualport")) { - if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - if (!(def->virtPortProfile - =3D virNetDevVPortProfileParse(cur, - VIR_VPORT_XML_GENER= ATE_MISSING_DEFAULTS))) { - goto error; - } - } else if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || - def->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT || - def->type =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { - if (!(def->virtPortProfile - =3D virNetDevVPortProfileParse(cur, - VIR_VPORT_XML_GENER= ATE_MISSING_DEFAULTS| - VIR_VPORT_XML_REQUI= RE_ALL_ATTRIBUTES| - VIR_VPORT_XML_REQUI= RE_TYPE))) { - goto error; - } - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _(" element unsupported fo= r" - " "), - virDomainNetTypeToString(def->type)); - goto error; - } - } else if (!address && - (def->type =3D=3D VIR_DOMAIN_NET_TYPE_SERVER || - def->type =3D=3D VIR_DOMAIN_NET_TYPE_CLIENT || - def->type =3D=3D VIR_DOMAIN_NET_TYPE_MCAST || - def->type =3D=3D VIR_DOMAIN_NET_TYPE_UDP) && - virXMLNodeNameEqual(cur, "source")) { - address =3D virXMLPropString(cur, "address"); - port =3D virXMLPropString(cur, "port"); - if (!localaddr && def->type =3D=3D VIR_DOMAIN_NET_TYPE_UDP= ) { - xmlNodePtr tmpnode =3D ctxt->node; - ctxt->node =3D cur; - if ((tmpNode =3D virXPathNode("./local", ctxt))) { - localaddr =3D virXMLPropString(tmpNode, "address"); - localport =3D virXMLPropString(tmpNode, "port"); - } - ctxt->node =3D tmpnode; - } - } else if (!ifname && - virXMLNodeNameEqual(cur, "target")) { - ifname =3D virXMLPropString(cur, "dev"); - managed_tap =3D virXMLPropString(cur, "managed"); - } else if ((!ifname_guest || !ifname_guest_actual) && - virXMLNodeNameEqual(cur, "guest")) { - ifname_guest =3D virXMLPropString(cur, "dev"); - ifname_guest_actual =3D virXMLPropString(cur, "actual"); - } else if (!linkstate && - virXMLNodeNameEqual(cur, "link")) { - linkstate =3D virXMLPropString(cur, "state"); - } else if (!script && - virXMLNodeNameEqual(cur, "script")) { - script =3D virXMLPropString(cur, "path"); - } else if (!downscript && - virXMLNodeNameEqual(cur, "downscript")) { - downscript =3D virXMLPropString(cur, "path"); - } else if (!domain_name && - virXMLNodeNameEqual(cur, "backenddomain")) { - domain_name =3D virXMLPropString(cur, "name"); - } else if (virXMLNodeNameEqual(cur, "model")) { - model =3D virXMLPropString(cur, "type"); - } else if (virXMLNodeNameEqual(cur, "driver")) { - backend =3D virXMLPropString(cur, "name"); - txmode =3D virXMLPropString(cur, "txmode"); - ioeventfd =3D virXMLPropString(cur, "ioeventfd"); - event_idx =3D virXMLPropString(cur, "event_idx"); - queues =3D virXMLPropString(cur, "queues"); - rx_queue_size =3D virXMLPropString(cur, "rx_queue_size"); - tx_queue_size =3D virXMLPropString(cur, "tx_queue_size"); + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_INTERNAL) + internal =3D virXMLPropString(source_node, "name"); =20 - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - goto error; - } else if (virXMLNodeNameEqual(cur, "filterref")) { - if (filter) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid specification of multiple s " - "in a single ")); - goto error; - } - filter =3D virXMLPropString(cur, "filter"); - virHashFree(filterparams); - filterparams =3D virNWFilterParseParamAttributes(cur); - } else if (virXMLNodeNameEqual(cur, "boot")) { - /* boot is parsed as part of virDomainDeviceInfoParseXML */ - } else if (!actual && - (flags & VIR_DOMAIN_DEF_PARSE_ACTUAL_NET) && - def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && - virXMLNodeNameEqual(cur, "actual")) { - if (virDomainActualNetDefParseXML(cur, ctxt, def, - &actual, flags, xmlopt) = < 0) { - goto error; - } - } else if (virXMLNodeNameEqual(cur, "bandwidth")) { - if (virNetDevBandwidthParse(&def->bandwidth, - NULL, - cur, - def->type =3D=3D VIR_DOMAIN_NE= T_TYPE_NETWORK) < 0) - goto error; - } else if (virXMLNodeNameEqual(cur, "vlan")) { - if (virNetDevVlanParse(cur, ctxt, &def->vlan) < 0) - goto error; - } else if (virXMLNodeNameEqual(cur, "backend")) { - char *tmp =3D NULL; + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) + bridge =3D virXMLPropString(source_node, "bridge"); =20 - if ((tmp =3D virXMLPropString(cur, "tap"))) - def->backend.tap =3D virFileSanitizePath(tmp); - VIR_FREE(tmp); + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { + dev =3D virXMLPropString(source_node, "dev"); + mode =3D virXMLPropString(source_node, "mode"); + } =20 - if (!vhost_path && (tmp =3D virXMLPropString(cur, "vhost")= )) - vhost_path =3D virFileSanitizePath(tmp); - VIR_FREE(tmp); + /* This clause is only necessary because from 2010 to 2016 it was + * possible (but never documented) to configure the name of the + * guest-side interface of an openvz domain with . + * That was blatant misuse of , so was likely (hopefully) + * never used, but just in case there was somebody using it, we + * need to generate an error. If the openvz driver is ever + * deprecated, this clause can be removed from here. + */ + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET && + (dev =3D virXMLPropString(source_node, "dev"))) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid attempt to set " + "device name with . " + "Use (for host-side) " + "or (for guest-side) inst= ead."), + dev, dev, dev); + goto error; + } + + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { + vhostuser_type =3D virXMLPropString(source_node, "type"); + vhostuser_path =3D virXMLPropString(source_node, "path"); + vhostuser_mode =3D virXMLPropString(source_node, "mode"); + if (virDomainChrSourceReconnectDefParseXML(&reconnect, source_= node, ctxt) < 0) + goto error; + } + + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_VDPA) + dev =3D virXMLPropString(source_node, "dev"); + + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_SERVER || + def->type =3D=3D VIR_DOMAIN_NET_TYPE_CLIENT || + def->type =3D=3D VIR_DOMAIN_NET_TYPE_MCAST || + def->type =3D=3D VIR_DOMAIN_NET_TYPE_UDP) { + + address =3D virXMLPropString(source_node, "address"); + port =3D virXMLPropString(source_node, "port"); + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_UDP) { + xmlNodePtr tmp_node =3D ctxt->node; + ctxt->node =3D source_node; + if ((tmpNode =3D virXPathNode("./local", ctxt))) { + localaddr =3D virXMLPropString(tmpNode, "address"); + localport =3D virXMLPropString(tmpNode, "port"); + } + ctxt->node =3D tmp_node; } } - cur =3D cur->next; } =20 - if (macaddr) { + if ((virtualport_node =3D virXPathNode("./virtualport", ctxt))) { + if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + if (!(def->virtPortProfile + =3D virNetDevVPortProfileParse(virtualport_node, + VIR_VPORT_XML_GENERATE_MISS= ING_DEFAULTS))) { + goto error; + } + } else if (def->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || + def->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT || + def->type =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { + if (!(def->virtPortProfile + =3D virNetDevVPortProfileParse(virtualport_node, VIR_VPO= RT_XML_GENERATE_MISSING_DEFAULTS| + VIR_VPORT_XML_REQUIRE_ALL_A= TTRIBUTES| + VIR_VPORT_XML_REQUIRE_TYPE)= )) { + goto error; + } + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(" element unsupported for" + " "), + virDomainNetTypeToString(def->type)); + goto error; + } + } + + ifname =3D virXPathString("string(./target/@dev)", ctxt); + managed_tap =3D virXPathString("string(./target/@managed)", ctxt); + + ifname_guest =3D virXPathString("string(./guest/@dev)", ctxt); + ifname_guest_actual =3D virXPathString("string(./guest/@actual)", ctxt= ); + + linkstate =3D virXPathString("string(./link/@state)", ctxt); + script =3D virXPathString("string(./script/@path)", ctxt); + downscript =3D virXPathString("string(./downscript/@path)", ctxt); + domain_name =3D virXPathString("string(./backenddomain/@name)", ctxt); + model =3D virXPathString("string(./model/@type)", ctxt); + + if ((driver_node =3D virXPathNode("./driver", ctxt)) && + (virDomainVirtioOptionsParseXML(driver_node, &def->virtio) < 0)) + goto error; + + backend =3D virXMLPropString(driver_node, "name"); + txmode =3D virXMLPropString(driver_node, "txmode"); + ioeventfd =3D virXMLPropString(driver_node, "ioeventfd"); + event_idx =3D virXMLPropString(driver_node, "event_idx"); + queues =3D virXMLPropString(driver_node, "queues"); + rx_queue_size =3D virXMLPropString(driver_node, "rx_queue_size"); + tx_queue_size =3D virXMLPropString(driver_node, "tx_queue_size"); + + if ((filterref_node =3D virXPathNode("./filterref", ctxt))) { + filter =3D virXMLPropString(filterref_node, "filter"); + virHashFree(filterparams); + filterparams =3D virNWFilterParseParamAttributes(filterref_node); + } + + if ((flags & VIR_DOMAIN_DEF_PARSE_ACTUAL_NET) && + def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + (actual_node =3D virXPathNode("./actual", ctxt)) && + (virDomainActualNetDefParseXML(actual_node, ctxt, def, + &actual, flags, xmlopt) < 0)) + goto error; + + if ((bandwidth_node =3D virXPathNode("./bandwidth", ctxt)) && + (virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidth_node, + def->type =3D=3D VIR_DOMAIN_NET_TYPE_NETW= ORK) < 0)) + goto error; + + if ((vlan_node =3D virXPathNode("./vlan", ctxt)) && + (virNetDevVlanParse(vlan_node, ctxt, &def->vlan) < 0)) + goto error; + + if ((tap =3D virXPathString("string(./backend/@tap)", ctxt))) + def->backend.tap =3D virFileSanitizePath(tap); + + if ((vhost =3D virXPathString("string(./backend/@vhost)", ctxt))) + vhost_path =3D virFileSanitizePath(vhost); + + if ((macaddr =3D virXPathString("string(./mac/@address)", ctxt))) { if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unable to parse mac address '%s'"), @@ -10512,8 +10483,9 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, def->mac_generated =3D true; } =20 - if (macaddr_type) { + if ((macaddr_type =3D virXPathString("string(./mac/@type)", ctxt))) { int tmp; + if ((tmp =3D virDomainNetMacTypeTypeFromString(macaddr_type)) <=3D= 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid mac address type value: '%s'. Valid " @@ -10523,8 +10495,10 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, } def->mac_type =3D tmp; } - if (macaddr_check) { + + if ((macaddr_check =3D virXPathString("string(./mac/@check)", ctxt))) { int tmpCheck; + if ((tmpCheck =3D virTristateBoolTypeFromString(macaddr_check)) < = 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid mac address check value: '%s'"), --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128477; cv=none; d=zohomail.com; s=zohoarc; b=TARJS4A+nxm4Flx5SJb5HTqI+PwL3csK0nGuqCdE1AM+BOp2CUk/nRQi24iQy6cr3oPowsL5H0dmL5IeszziNl4zoGIYFbF5Gg9fbMFKYV+m8So89g0EwhvTUbxCjS4AmKpJC4YxGPYzrzPvoh+DwL6oCuVoCghPX623xE8lPS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128477; h=Content-Type:Content-Transfer-Encoding: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=OrMOshiT7/Hru/+YhLL6MwHnqN0rVV+oH2wCSTTyZ2E=; b=jzmC/Fs9lX8rFM/ijxkzWIq4dKvwU8ValU2kz3OaQNPRBqetbjkuLbNnZUIGgJmnPvHDys1Dh4ex1VdKtXS7e6VMxD62HMcnSMBMckPwVMUGMblA6WXLlSDg364cIbFZ11YnL1peJjc1qFVUnD9NmaejWubEhMz3hCP/F9jTBq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128477824996.7822947750494; Tue, 4 May 2021 04:41:17 -0700 (PDT) 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-376-f9l_C0w0OpqJb-ubxmJDOA-1; Tue, 04 May 2021 07:41:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5F7910866C2; Tue, 4 May 2021 11:41:08 +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 C900059446; Tue, 4 May 2021 11:41:08 +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 8C63355354; Tue, 4 May 2021 11:41:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bexkt000800 for ; Tue, 4 May 2021 07:40:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 759C45D9DD; Tue, 4 May 2021 11:40:59 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DD6E5D9D5 for ; Tue, 4 May 2021 11:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128476; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=OrMOshiT7/Hru/+YhLL6MwHnqN0rVV+oH2wCSTTyZ2E=; b=HtmjFFwI4hhSEepv1xg92a5BBn71G7PZ6cFvA7KT7jeQnYsj+L3ReX8SMA0nK9mpQEJ/R9 +kp07A5QBIzlMTmyBnleoinsAu6MhsZBr6RrvaL21+bCq5DU1+Kz8ekLBbw9LREdX1m9Dg 0MRIxNH1XeAihKX7NXdR3sLYiYCfo7Y= X-MC-Unique: f9l_C0w0OpqJb-ubxmJDOA-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 11/19] conf: Propagate xmlXPathContextPtr into virDomainChrDefParseTargetXML() Date: Tue, 4 May 2021 13:40:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.11 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dc72a91d8d..df7079c7e6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11063,6 +11063,7 @@ virDomainChrTargetModelFromString(int devtype, static int virDomainChrDefParseTargetXML(virDomainChrDef *def, xmlNodePtr cur, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, unsigned int flags) { xmlNodePtr child; @@ -11602,7 +11603,7 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt, if (cur->type =3D=3D XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "target")) { seenTarget =3D true; - if (virDomainChrDefParseTargetXML(def, cur, flags) < 0) + if (virDomainChrDefParseTargetXML(def, cur, ctxt, flags) <= 0) goto error; } } --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128481; cv=none; d=zohomail.com; s=zohoarc; b=k/OCv+b/YxOchxij0P329obyRE5VMPmL4jJtxlx0rdojmYiE+1wvajlZ3ToHxbQY0jLGFAlt5ZHXVDNyqCg9BR8ONeKIIPY3pTFjB53fDhaYgW1KstAggv5Wh3JKSfaUP0hHClbok50kbpVALwDbjKZZ64jP87QhFPJTtANSFpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128481; h=Content-Type:Content-Transfer-Encoding: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=9wZISSj4mpaMxTBhOiS59/wZnCGLWtivSdIPoT/VaQU=; b=KxT2bIH7Znnuazyr2SMC8EB4AHH+Co327bMPheHJV1xH9TdhmIdoNJTILZpuSnZaNcjQa5v2fktojdXTLhT5d0AsGlsZrmFzpQ4lozwVkt+90Rn0OAFc0uAFX2PshRJ5nqHhFZ54bAnjUp9uazPWOpG6vB/u8CPzFoi6J465ZCQ= 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 1620128481026392.24272641218056; Tue, 4 May 2021 04:41:21 -0700 (PDT) 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-307-pmnmMbtKPnei3blk6W_s1Q-1; Tue, 04 May 2021 07:41:18 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A747802938; Tue, 4 May 2021 11:41:10 +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 3D70D5D703; Tue, 4 May 2021 11:41:10 +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 0814D1801263; Tue, 4 May 2021 11:41:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf4IC000820 for ; Tue, 4 May 2021 07:41:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C2125D9DD; Tue, 4 May 2021 11:41:04 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DFF15D9D5 for ; Tue, 4 May 2021 11:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128480; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=9wZISSj4mpaMxTBhOiS59/wZnCGLWtivSdIPoT/VaQU=; b=WqriQ62BPb610zkL1TOkkuknUpSUWuIIVwl5D+vpOA0dG//u9KkWdXfLE5IcWiRW7n+Fr7 JDyMuLLPPwst7lJzilHkKzXzEjJsx+0aLNPh+zVqkOKQLoLBt8b7HM7NmesVeHctYpA0hj FejoAt+Z04mf9H9o6/+acE47v8TjlVw= X-MC-Unique: pmnmMbtKPnei3blk6W_s1Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 12/19] Refactoring virDomainChrDefParseTargetXML() to use XPath Date: Tue, 4 May 2021 13:40:06 +0200 Message-Id: <3c47d094b4535a8a936c86744928680b78656638.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.15 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index df7079c7e6..5ac15fe9e8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11063,16 +11063,18 @@ virDomainChrTargetModelFromString(int devtype, static int virDomainChrDefParseTargetXML(virDomainChrDef *def, xmlNodePtr cur, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, + xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr child; unsigned int port; g_autofree char *targetType =3D virXMLPropString(cur, "type"); g_autofree char *targetModel =3D NULL; g_autofree char *addrStr =3D NULL; g_autofree char *portStr =3D NULL; g_autofree char *stateStr =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D cur; =20 if ((def->targetType =3D virDomainChrTargetTypeFromString(def->deviceType, @@ -11083,14 +11085,7 @@ virDomainChrDefParseTargetXML(virDomainChrDef *def, return -1; } =20 - child =3D cur->children; - while (child !=3D NULL) { - if (child->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(child, "model")) { - targetModel =3D virXMLPropString(child, "name"); - } - child =3D child->next; - } + targetModel =3D virXPathString("string(./model/@name)", ctxt); =20 if ((def->targetModel =3D virDomainChrTargetModelFromString(def->deviceType, --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128486; cv=none; d=zohomail.com; s=zohoarc; b=mC/LuQi14bKa/Ii8dyLmE2pzy/hWTQXcksT0BSP0t3mobDRKpogDMcgCvXL7KcBzzh5s7QBeX3C9cwxB3a40EhmF5j59wI3wLaVqu8CRtidVpHP0HHp4FFzGyuZDN4jVgguZ8z63yuOrKKVZBZfe8dr1/xWIKHfUXAU4I3Z+sQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128486; h=Content-Type:Content-Transfer-Encoding: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=VHqamxat3eTGQ0NY3a+u9aa41mxnHMZU9ha3OdlhNg0=; b=m+WDN84N5G/w0XzHvQ9DqGgtKtUtWA9zvk/SBQnSWSzkIvvLWTuz/06Jx564KEfjVZcik+JcFxm+NZji9Pw0Seei2emmKYP7B3E/E90Pe3YYuOOo/iZJ4rgby3QVU67jgqrOnAxkNp+rw3jFgNKG8sRfdwAt2nqRNf/NWFlbGSM= 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 1620128486568759.4333753776638; Tue, 4 May 2021 04:41:26 -0700 (PDT) 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-383-lmNIylA5P6KJH8Gk_uFEmw-1; Tue, 04 May 2021 07:41:22 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 844238018A7; Tue, 4 May 2021 11:41:16 +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 5BF1F1037E8B; Tue, 4 May 2021 11:41:16 +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 E7D3755351; Tue, 4 May 2021 11:41:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf5YE000834 for ; Tue, 4 May 2021 07:41:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62CF95D9DD; Tue, 4 May 2021 11:41:05 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAED05D9D5 for ; Tue, 4 May 2021 11:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128485; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=VHqamxat3eTGQ0NY3a+u9aa41mxnHMZU9ha3OdlhNg0=; b=ZMoMYjT338IhzrRyjglehRXpCD+fsTFhgUCV4J44/zdaYoEW2PdXx1bUgN5lkazaWKYoWS 8A9sPD8B6RYTkyILLmjC0zwFl4nBfasifYZ348T1F7mOWsuZMWmm2ssxgisScrc94LDTn5 TqcmO+QxkwKwTmwwj0HjMjqsu4XhUNA= X-MC-Unique: lmNIylA5P6KJH8Gk_uFEmw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 13/19] Refactoring virDomainChrSourceDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:07 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 190 ++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 96 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5ac15fe9e8..c5b13783f3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11350,112 +11350,112 @@ virDomainChrSourceDefParseXML(virDomainChrSourc= eDef *def, virDomainChrDef *chr_def, xmlXPathContextPtr ctxt) { - bool logParsed =3D false; - bool protocolParsed =3D false; - int sourceParsed =3D 0; + xmlNodePtr log =3D NULL; + xmlNodePtr protocol =3D NULL; + g_autofree xmlNodePtr *source =3D NULL; + int n =3D 0; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 - for (; cur; cur =3D cur->next) { - if (cur->type !=3D XML_ELEMENT_NODE) - continue; + ctxt->node =3D cur; =20 - if (virXMLNodeNameEqual(cur, "source")) { - /* Parse only the first source element since only one is used - * for chardev devices, the only exception is UDP type, where - * user can specify two source elements. */ - if (sourceParsed >=3D 1 && def->type !=3D VIR_DOMAIN_CHR_TYPE_= UDP) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only one source element is allowed for " - "character device")); - goto error; - } else if (sourceParsed >=3D 2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only two source elements are allowed for= " - "character device")); - goto error; - } - sourceParsed++; + if ((n =3D virXPathNodeSet("./source", ctxt, &source)) > 0) { + /* Parse only the first source element since only one is used + * for chardev devices, the only exception is UDP type, where + * user can specify two source elements. */ + if (n > 1 && def->type !=3D VIR_DOMAIN_CHR_TYPE_UDP) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only one source element is allowed for " + "character device")); + goto error; + } else if (n > 2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only two source elements are allowed for " + "character device")); + goto error; + } =20 - switch ((virDomainChrType) def->type) { - case VIR_DOMAIN_CHR_TYPE_FILE: - if (virDomainChrSourceDefParseFile(def, cur) < 0) - goto error; - break; + switch ((virDomainChrType) def->type) { + case VIR_DOMAIN_CHR_TYPE_FILE: + if (virDomainChrSourceDefParseFile(def, source[0]) < 0) + goto error; + break; =20 - case VIR_DOMAIN_CHR_TYPE_PTY: - /* PTY path is only parsed from live xml. */ - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - def->data.file.path =3D virXMLPropString(cur, "path"); - break; + case VIR_DOMAIN_CHR_TYPE_PTY: + /* PTY path is only parsed from live xml. */ + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + def->data.file.path =3D virXPathString("string(./source/@p= ath)", ctxt); + break; =20 - case VIR_DOMAIN_CHR_TYPE_DEV: - case VIR_DOMAIN_CHR_TYPE_PIPE: - def->data.file.path =3D virXMLPropString(cur, "path"); - break; + case VIR_DOMAIN_CHR_TYPE_DEV: + case VIR_DOMAIN_CHR_TYPE_PIPE: + def->data.file.path =3D virXPathString("string(./source/@path)= ", ctxt); + break; =20 - case VIR_DOMAIN_CHR_TYPE_UNIX: - if (virDomainChrSourceDefParseUnix(def, cur, ctxt) < 0) - goto error; - break; + case VIR_DOMAIN_CHR_TYPE_UNIX: + if (virDomainChrSourceDefParseUnix(def, source[0], ctxt) < 0) + goto error; + break; =20 - case VIR_DOMAIN_CHR_TYPE_UDP: - if (virDomainChrSourceDefParseUDP(def, cur) < 0) + case VIR_DOMAIN_CHR_TYPE_UDP: + if ((virDomainChrSourceDefParseUDP(def, source[0]) < 0) || + (source[1] && virDomainChrSourceDefParseUDP(def, source[1]= ) < 0)) goto error; - break; + break; =20 - case VIR_DOMAIN_CHR_TYPE_TCP: - if (virDomainChrSourceDefParseTCP(def, cur, ctxt, flags) <= 0) - goto error; - break; + case VIR_DOMAIN_CHR_TYPE_TCP: + if (virDomainChrSourceDefParseTCP(def, source[0], ctxt, flags)= < 0) + goto error; + break; =20 - case VIR_DOMAIN_CHR_TYPE_SPICEPORT: - def->data.spiceport.channel =3D virXMLPropString(cur, "cha= nnel"); - break; + case VIR_DOMAIN_CHR_TYPE_SPICEPORT: + def->data.spiceport.channel =3D virXPathString("string(./sourc= e/@channel)", ctxt); + break; =20 - case VIR_DOMAIN_CHR_TYPE_NMDM: - def->data.nmdm.master =3D virXMLPropString(cur, "master"); - def->data.nmdm.slave =3D virXMLPropString(cur, "slave"); - break; + case VIR_DOMAIN_CHR_TYPE_NMDM: + def->data.nmdm.master =3D virXPathString("string(./source/@mas= ter)", ctxt); + def->data.nmdm.slave =3D virXPathString("string(./source/@slav= e)", ctxt); + break; =20 - case VIR_DOMAIN_CHR_TYPE_LAST: - case VIR_DOMAIN_CHR_TYPE_NULL: - case VIR_DOMAIN_CHR_TYPE_VC: - case VIR_DOMAIN_CHR_TYPE_STDIO: - case VIR_DOMAIN_CHR_TYPE_SPICEVMC: - break; - } + case VIR_DOMAIN_CHR_TYPE_LAST: + case VIR_DOMAIN_CHR_TYPE_NULL: + case VIR_DOMAIN_CHR_TYPE_VC: + case VIR_DOMAIN_CHR_TYPE_STDIO: + case VIR_DOMAIN_CHR_TYPE_SPICEVMC: + break; + } =20 - /* Check for an optional seclabel override in . */ - if (chr_def) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) - ctxt->node =3D cur; - if (virSecurityDeviceLabelDefParseXML(&def->seclabels, - &def->nseclabels, - ctxt, - flags) < 0) { - goto error; - } - } - } else if (virXMLNodeNameEqual(cur, "log")) { - if (logParsed) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only one protocol element is allowed for= " - "character device")); - goto error; - } - logParsed =3D true; - if (virDomainChrSourceDefParseLog(def, cur) < 0) - goto error; - } else if (virXMLNodeNameEqual(cur, "protocol")) { - if (protocolParsed) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only one log element is allowed for " - "character device")); + /* Check for an optional seclabel override in . */ + if (chr_def) { + xmlNodePtr tmp =3D ctxt->node; + ctxt->node =3D source[0]; + if (virSecurityDeviceLabelDefParseXML(&def->seclabels, &def->n= seclabels, + ctxt, flags) < 0) { goto error; } - protocolParsed =3D true; - if (virDomainChrSourceDefParseProtocol(def, cur) < 0) - goto error; + ctxt->node =3D tmp; + } + } + + if ((log =3D virXPathNode("./log", ctxt))) { + if (virXPathBoolean("boolean(count(./log) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only one log element is allowed for " + "character device")); + goto error; + } + if (virDomainChrSourceDefParseLog(def, log) < 0) + goto error; + } + + if ((protocol =3D virXPathNode("./protocol", ctxt))) { + if (virXPathBoolean("boolean(count(./protocol) > 1)", ctxt)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only one protocol element is allowed for " + "character device")); + goto error; } + if (virDomainChrSourceDefParseProtocol(def, protocol) < 0) + goto error; } =20 return 0; @@ -11609,7 +11609,7 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt, ((def->targetType =3D virDomainChrDefaultTargetType(def->deviceTyp= e)) < 0)) goto error; =20 - if (virDomainChrSourceDefParseXML(def->source, node->children, flags, = def, + if (virDomainChrSourceDefParseXML(def->source, node, flags, def, ctxt) < 0) goto error; =20 @@ -11733,7 +11733,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *x= mlopt, } =20 cur =3D node->children; - if (virDomainChrSourceDefParseXML(def->data.passthru, cur, flags, + if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags, NULL, ctxt) < 0) return NULL; =20 @@ -13686,7 +13686,7 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt, } =20 if (virDomainChrSourceDefParseXML(def->source.chardev, - backends[0]->children, flags, + backends[0], flags, NULL, ctxt) < 0) goto error; break; @@ -14693,7 +14693,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOption *xm= lopt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; virDomainRedirdevDef *def; g_autofree char *bus =3D NULL; g_autofree char *type =3D NULL; @@ -14727,10 +14726,9 @@ virDomainRedirdevDefParseXML(virDomainXMLOption *x= mlopt, goto error; } =20 - cur =3D node->children; /* boot gets parsed in virDomainDeviceInfoParseXML * source gets parsed in virDomainChrSourceDefParseXML */ - if (virDomainChrSourceDefParseXML(def->source, cur, flags, + if (virDomainChrSourceDefParseXML(def->source, node, flags, NULL, ctxt) < 0) goto error; =20 --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128481; cv=none; d=zohomail.com; s=zohoarc; b=m1fcAc9v5NBNJ6r9hjj01L3QPRMQJAScADJKqxI29GLUV/QEkp0gN7P2ReaLRUuPYKMnZ88pOLVNNmvI441+hxbe+jjHneyhSLdbmp/z7H+l22JoBYYnMGBtK9PtzmDmblHC02eVIrI3HNegGaobEss6guBIvpC7k9W26z7QQ2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128481; h=Content-Type:Content-Transfer-Encoding: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=E+Fzd8QdCZtVWug6yPNeLRFLaZXy7D9zUrxABfskgpM=; b=MUHr29j6cCiGRtcqwb7laZFwNBvw1al26e1Lidoqu733H3+6jzM9E33S+gUqgMBu0OZGZ5crZiuixpVFe+Fja3nKKSUD2WQcff934QQe2ESbww2D8uDAHYw6YRmJbjvtMRsJRxhHcLvgSJcDFPKr4zFWx7JQ2duD/iCE4SlC9iQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128481151960.090637838286; Tue, 4 May 2021 04:41:21 -0700 (PDT) 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-556-4XfoNmx1Msu2nOUok53pSg-1; Tue, 04 May 2021 07:41:18 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 121691009E37; Tue, 4 May 2021 11:41:13 +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 E5D4060C4A; Tue, 4 May 2021 11:41:12 +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 AD7CE1801266; Tue, 4 May 2021 11:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf6RJ000846 for ; Tue, 4 May 2021 07:41:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA4F35D9DD; Tue, 4 May 2021 11:41:06 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04FB75D9D5 for ; Tue, 4 May 2021 11:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128480; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=E+Fzd8QdCZtVWug6yPNeLRFLaZXy7D9zUrxABfskgpM=; b=FhIwZX1zfl+KUWc2Y74Z+M55Bp0jamulo+LHfSscIxepND4yIIrDbo0p017kgYhDWT/8QD vtRLIDiDEOTpaZK1aab7HD1Zw6KhMOtceYRR81qrqQT17JmuGu0T1pl7dLEWpil/HVBHfP 1Jdwa8m+BLae5/5YHB3yZPv9FiiXvWA= X-MC-Unique: 4XfoNmx1Msu2nOUok53pSg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 14/19] Refactoring virDomainChrDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:08 +0200 Message-Id: <1cf786912d7d2f752ea8d1420f09713deef03c01.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.12 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c5b13783f3..5d7fd6794f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11566,11 +11566,13 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlop= t, xmlNodePtr node, unsigned int flags) { - xmlNodePtr cur; + xmlNodePtr target; const char *nodeName; virDomainChrDef *def; - bool seenTarget =3D false; g_autofree char *type =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D node; =20 if (!(def =3D virDomainChrDefNew(xmlopt))) return NULL; @@ -11593,21 +11595,12 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlop= t, goto error; } =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "target")) { - seenTarget =3D true; - if (virDomainChrDefParseTargetXML(def, cur, ctxt, flags) <= 0) - goto error; - } - } - cur =3D cur->next; - } - - if (!seenTarget && - ((def->targetType =3D virDomainChrDefaultTargetType(def->deviceTyp= e)) < 0)) + if ((target =3D virXPathNode("./target", ctxt))) { + if (virDomainChrDefParseTargetXML(def, target, ctxt, flags) < 0) + goto error; + } else if ((def->targetType =3D virDomainChrDefaultTargetType(def->dev= iceType)) < 0) { goto error; + } =20 if (virDomainChrSourceDefParseXML(def->source, node, flags, def, ctxt) < 0) --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128489; cv=none; d=zohomail.com; s=zohoarc; b=JG+vaRMw0tUt1S9q31WpQLLgfYYGymNplpQjouvsscRP70+6OuTmbSlKn70QyhqTaiU9c412hU4b3E7SClRuZo5nmRXyPN5G0fzx6Zvip3OHcoybYRe71vExPdfynNhzT4QCuC4D3Gplm/xPfZrTPeDibuc4fSdfuOzNX+wS/j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128489; h=Content-Type:Content-Transfer-Encoding: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=hp5tGT9AWSwOnRD/UEVnGzVX/xIAaqtHA98TlMryRA4=; b=WBqJWQEYqJAS8MmOYMd/LrDDDVVGy6HjdA5nKgCyP9cjUAu4t9c1sVmbFr0dg/sBAvcTXIzfp5wrPmjr56aibULwv6HH6Lv1k50eYVnsaUrNzefAeDiCCvZk6wnvHHb59/KebPD35Z7L9053n+CFoU+pUOF7NZkbieZl6IRQaqM= 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 1620128489659782.4947317645767; Tue, 4 May 2021 04:41:29 -0700 (PDT) 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-229-8VLpLh2RMciwrkINQRk5Wg-1; Tue, 04 May 2021 07:41:25 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 830D5195D586; Tue, 4 May 2021 11:41:19 +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 366D560C4A; Tue, 4 May 2021 11:41:19 +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 006A81801266; Tue, 4 May 2021 11:41:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf8sP000875 for ; Tue, 4 May 2021 07:41:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 151FE5D9DD; Tue, 4 May 2021 11:41:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 515C75D9D5 for ; Tue, 4 May 2021 11:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128488; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=hp5tGT9AWSwOnRD/UEVnGzVX/xIAaqtHA98TlMryRA4=; b=faElUcWA6XXUml1ZoSyin2aFCefKt3Zft8BvDEOanZ5SVGVuQ5Zpcbf40kTK2Qzdggue96 XoysdB1yC+wUzP1uKdx5T7uQmyGp/+OT4JFEEEOCXXJPlqRAoVWwaG0RfooxAXJZH38lN8 sMAZ734L657sY3crjGKaQjeLx3SufXQ= X-MC-Unique: 8VLpLh2RMciwrkINQRk5Wg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 15/19] Refactoring virDomainSmartcardDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:09 +0200 Message-Id: <78a767ff9ac7bc9f04b9f67ab14c64530c6d912d.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.12 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 59 ++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d7fd6794f..2511778b15 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11642,12 +11642,14 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; g_autoptr(virDomainSmartcardDef) def =3D NULL; - size_t i; g_autofree char *mode =3D NULL; g_autofree char *type =3D NULL; + g_autofree xmlNodePtr *certificates =3D NULL; + int n =3D 0; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 + ctxt->node =3D node; def =3D g_new0(virDomainSmartcardDef, 1); =20 mode =3D virXMLPropString(node, "mode"); @@ -11668,42 +11670,32 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES: - i =3D 0; - cur =3D node->children; - while (cur) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "certificate")) { - if (i =3D=3D 3) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("host-certificates mode needs " - "exactly three certificates")); - return NULL; - } - if (!(def->data.cert.file[i] =3D virXMLNodeContentString(c= ur))) - return NULL; - - i++; - } else if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "database") && - !def->data.cert.database) { - if (!(def->data.cert.database =3D virXMLNodeContentString(= cur))) - return NULL; - - if (*def->data.cert.database !=3D '/') { - virReportError(VIR_ERR_XML_ERROR, - _("expecting absolute path: %s"), - def->data.cert.database); - return NULL; - } - } - cur =3D cur->next; - } - if (i < 3) { + n =3D virXPathNodeSet("./certificate", ctxt, &certificates); + if (n !=3D VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES) { virReportError(VIR_ERR_XML_ERROR, "%s", _("host-certificates mode needs " "exactly three certificates")); return NULL; } + + if (!(def->data.cert.file[0] =3D virXMLNodeContentString(certifica= tes[0])) || + !(def->data.cert.file[1] =3D virXMLNodeContentString(certifica= tes[1])) || + !(def->data.cert.file[2] =3D virXMLNodeContentString(certifica= tes[2]))) + return NULL; + + if (virXPathNode("./database", ctxt) && + !def->data.cert.database) { + if (!(def->data.cert.database =3D + virXPathString("string(./database/text())", ctxt))) + return NULL; + + if (*def->data.cert.database !=3D '/') { + virReportError(VIR_ERR_XML_ERROR, + _("expecting absolute path: %s"), + def->data.cert.database); + return NULL; + } + } break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: @@ -11725,7 +11717,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *x= mlopt, return NULL; } =20 - cur =3D node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags, NULL, ctxt) < 0) return NULL; --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128656; cv=none; d=zohomail.com; s=zohoarc; b=B4dN5y3TtlFpZMUycbNgqU4ECTXgbFxVh/R1rWgKLBI5DcghAh94Bbst9yP75jBF/L/nvOR4kcIQU+WhRXg+8uAecLnHQI5wEhjDGRPLJqRIYXs0XL7WBQtMFXA0Tmh0ltjmh4ZjaUcJXEcCb8ug6t+DhD9KOAiJewNex2oOFBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128656; h=Content-Type:Content-Transfer-Encoding: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=xL+Ri2o3I9s+eH3ijchx6Ea6T1XxsstufRK0wlWC67E=; b=BmZuGZaWST+rTJlQWpThXW0/I6FuzJ3tua1KOWxoJoKDnMXY5qiFvpALl3PYkiIHtZEHPuQXVsACie+e9XjReDasmqfKlUiVwhOuxY3/Dm7+szzD6ElYZzR0sUXrUdRuVgCuSOTTScZEOK2DYwhVvbXNS4bZTd8bK4F5wGb8G5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 162012865613371.86815524102133; Tue, 4 May 2021 04:44:16 -0700 (PDT) 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-360-8uvwSfUjMWWCbtCLZAk2Lg-1; Tue, 04 May 2021 07:41:20 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43C2A805EF4; Tue, 4 May 2021 11:41:16 +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 A61C610190AA; Tue, 4 May 2021 11:41: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 6CE901801267; Tue, 4 May 2021 11:41:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf9OR000897 for ; Tue, 4 May 2021 07:41:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93DDE5D9F0; Tue, 4 May 2021 11:41:09 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A54A25D9DE for ; Tue, 4 May 2021 11:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128655; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=xL+Ri2o3I9s+eH3ijchx6Ea6T1XxsstufRK0wlWC67E=; b=JuSyDo53i7yQLwRbB9mDCe5+wsK/ZdS+rReuZC1NKRLqch/jhOYan+DBpH0CCdb3JDkrM6 O1qLQSNYySxF0I3K5n8IHYPa30B+2kNnh6q7t9fyALj2LTTYCu5sv/hQRy0o1W7P/ze23n QPvOmHXel9sJcegJUELl3b00ALGB54w= X-MC-Unique: 8uvwSfUjMWWCbtCLZAk2Lg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 16/19] Refactoring virDomainGraphicsDefParseXMLSpice() to use XPath Date: Tue, 4 May 2021 13:40:10 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 303 ++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 189 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2511778b15..206816d76f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12690,12 +12690,29 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDef *def, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; int defaultModeVal; + int nameval; + g_autofree xmlNodePtr *node_list =3D NULL; + int n =3D 0; + size_t i =3D 0; + int value =3D 0; g_autofree char *port =3D virXMLPropString(node, "port"); g_autofree char *tlsPort =3D virXMLPropString(node, "tlsPort"); g_autofree char *autoport =3D virXMLPropString(node, "autoport"); g_autofree char *defaultMode =3D virXMLPropString(node, "defaultMode"); + g_autofree char *compression =3D NULL; + g_autofree char *jpeg_compression =3D NULL; + g_autofree char *zlib_compression =3D NULL; + g_autofree char *playback_compression =3D NULL; + g_autofree char *streaming_mode =3D NULL; + g_autofree char *copypaste =3D NULL; + g_autofree char *filetransfer_enable =3D NULL; + g_autofree char *gl_enable =3D NULL; + g_autofree char *mouse_mode =3D NULL; + g_autofree char *rendernode =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D node; =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; @@ -12751,207 +12768,115 @@ virDomainGraphicsDefParseXMLSpice(virDomainGrap= hicsDef *def, def->type) < 0) return -1; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "channel")) { - int nameval, modeval; - g_autofree char *name =3D NULL; - g_autofree char *mode =3D NULL; - - name =3D virXMLPropString(cur, "name"); - mode =3D virXMLPropString(cur, "mode"); - - if (!name || !mode) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice channel missing name/mode")); - return -1; - } - - if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFrom= String(name)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel name %s"), - name); - return -1; - } - if ((modeval =3D virDomainGraphicsSpiceChannelModeTypeFrom= String(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel mode %s"), - mode); - return -1; - } - - def->data.spice.channels[nameval] =3D modeval; - } else if (virXMLNodeNameEqual(cur, "image")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice image missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceImageCompressionTypeFromString(= compression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice image compression %s"), - compression); - return -1; - } - - def->data.spice.image =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "jpeg")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice jpeg missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceJpegCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice jpeg compression %s"), - compression); - return -1; - } - - def->data.spice.jpeg =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "zlib")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice zlib missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceZlibCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice zlib compression %s"), - compression); - return -1; - } - - def->data.spice.zlib =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "playback")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")= ); - return -1; - } - - if ((compressionVal =3D - virTristateSwitchTypeFromString(compression)) <=3D 0)= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")= ); - return -1; - } - - def->data.spice.playback =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "streaming")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); - - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice streaming missing mode")); - return -1; - } - if ((modeVal =3D - virDomainGraphicsSpiceStreamingModeTypeFromString(mod= e)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice streaming mode")); - return -1; - } - - def->data.spice.streaming =3D modeVal; - } else if (virXMLNodeNameEqual(cur, "clipboard")) { - int copypasteVal; - g_autofree char *copypaste =3D virXMLPropString(cur, "copy= paste"); - - if (!copypaste) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice clipboard missing copypaste")); - return -1; - } + if ((n =3D virXPathNodeSet("./channel", ctxt, &node_list)) < 0) + return -1; =20 - if ((copypasteVal =3D - virTristateBoolTypeFromString(copypaste)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copy= paste); - return -1; - } + for (i =3D 0; i < n; i++) { + g_autofree char *name =3D virXMLPropString(node_list[i], "name"); + g_autofree char *mode =3D virXMLPropString(node_list[i], "mode"); =20 - def->data.spice.copypaste =3D copypasteVal; - } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); + if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFromString(n= ame)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel name %s"), NULLSTR(nam= e)); + return -1; + } + if ((value =3D virDomainGraphicsSpiceChannelModeTypeFromString(mod= e)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel mode %s"), NULLSTR(mod= e)); + return -1; + } + def->data.spice.channels[nameval] =3D value; + } =20 - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); - return -1; - } + if ((compression =3D virXPathString("string(./image/@compression)", ct= xt))) { + if ((value =3D + virDomainGraphicsSpiceImageCompressionTypeFromString(compressi= on)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice image compression %s"), compre= ssion); + return -1; + } + def->data.spice.image =3D value; + } =20 - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } + if ((jpeg_compression =3D virXPathString("string(./jpeg/@compression)"= , ctxt))) { + if ((value =3D + virDomainGraphicsSpiceJpegCompressionTypeFromString(jpeg_comp= ression)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice jpeg compression %s"), + jpeg_compression); + return -1; + } + def->data.spice.jpeg =3D value; + } =20 - def->data.spice.filetransfer =3D enableVal; - } else if (virXMLNodeNameEqual(cur, "gl")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); - g_autofree char *rendernode =3D virXMLPropString(cur, "ren= dernode"); + if ((zlib_compression =3D virXPathString("string(./zlib/@compression)"= , ctxt))) { + if ((value =3D + virDomainGraphicsSpiceZlibCompressionTypeFromString(zlib_comp= ression)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice zlib compression %s"), + zlib_compression); + return -1; + } + def->data.spice.zlib =3D value; + } =20 - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); - return -1; - } + if ((playback_compression =3D virXPathString("string(./playback/@compr= ession)", ctxt))) { + if ((value =3D virTristateSwitchTypeFromString(playback_compressio= n)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice playback compression")); + return -1; + } + def->data.spice.playback =3D value; + } =20 - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } + if ((streaming_mode =3D virXPathString("string(./streaming/@mode)", ct= xt))) { + if ((value =3D + virDomainGraphicsSpiceStreamingModeTypeFromString(streaming_m= ode)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice streaming mode")); + return -1; + } + def->data.spice.streaming =3D value; + } =20 - def->data.spice.gl =3D enableVal; - def->data.spice.rendernode =3D g_steal_pointer(&rendernode= ); + if ((copypaste =3D virXPathString("string(./clipboard/@copypaste)", ct= xt))) { + if ((value =3D virTristateBoolTypeFromString(copypaste)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown copypaste value '%s'"), copypaste); + return -1; + } + def->data.spice.copypaste =3D value; + } =20 - } else if (virXMLNodeNameEqual(cur, "mouse")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); + if ((filetransfer_enable =3D virXPathString("string(./filetransfer/@en= able)", ctxt))) { + if ((value =3D virTristateBoolTypeFromString(filetransfer_enable))= <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), + filetransfer_enable); + return -1; + } + def->data.spice.filetransfer =3D value; + } =20 - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice mouse missing mode")); - return -1; - } + if ((gl_enable =3D virXPathString("string(./gl/@enable)", ctxt))) { + rendernode =3D virXPathString("string(./gl/@rendernode)", ctxt); =20 - if ((modeVal =3D virDomainGraphicsSpiceMouseModeTypeFromSt= ring(mode)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mouse mode value '%s'"), - mode); - return -1; - } + if ((value =3D virTristateBoolTypeFromString(gl_enable)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), gl_enable); + return -1; + } + def->data.spice.gl =3D value; + def->data.spice.rendernode =3D g_steal_pointer(&rendernode); + } =20 - def->data.spice.mousemode =3D modeVal; - } + if ((mouse_mode =3D virXPathString("string(./mouse/@mode)", ctxt))) { + if ((value =3D virDomainGraphicsSpiceMouseModeTypeFromString(mouse= _mode)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown mouse mode value '%s'"), mouse_mode); + return -1; } - cur =3D cur->next; + def->data.spice.mousemode =3D value; } =20 return 0; --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128487; cv=none; d=zohomail.com; s=zohoarc; b=B4jNovj29fP9wboEsITqIp4FkrLnqm6ONSGRs+e2sLfyZnD89OXEa6C8KwKW8WzsM1eFPHrbHbX2WJ8Rr9vn+Nk88xcU01pbEoFPAQ8uynvYjTqr4TpBGoYxKso/GL+CQdH3Ts8cMV2h/y9XlMcXY4SFRN4SlP1StceIemfX7zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128487; h=Content-Type:Content-Transfer-Encoding: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=IcHB1LU2LQGOf4A8qag+3soDSPf7veT0+H/53p12woE=; b=Ke+PeA0cTGjrE/BSDawBkS9Em+3iA37qUFKxlkQkey/oICwD6VgUnv5jtXNyiGR3i41YVaD2ttuWvG0xvojS0TmYXqS8Qv0TjB6KQDWYZTINey4K7xtuNYrWXbv+v7Jaq+gOgOlf88vfHymKEJto0JBjdGMcbX5RtLfeu5YQFpU= 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 1620128487946405.3052166849383; Tue, 4 May 2021 04:41:27 -0700 (PDT) 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-509-CA9RzSWWOKmCiMn57J4X7A-1; Tue, 04 May 2021 07:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD2AF195D576; Tue, 4 May 2021 11:41:18 +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 8C4B760854; Tue, 4 May 2021 11:41:18 +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 52F8155352; Tue, 4 May 2021 11:41:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BfBrn000908 for ; Tue, 4 May 2021 07:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0AEEC5D9F2; Tue, 4 May 2021 11:41:11 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3376E5D9DE for ; Tue, 4 May 2021 11:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128486; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=IcHB1LU2LQGOf4A8qag+3soDSPf7veT0+H/53p12woE=; b=Xl7Gj3j/KYqfEWBrxpiErCWaewR6MseX6iFWCq/xfNOpsVzRxYMhzwqvDUntAPgNWGIEl4 gyoXNEWFuOIo4WHPHhld5sUGkmAzx6mskSXhx1b43SijUS8RqGDidffcUkA4FPXXffouY0 TYHswqFx/QMijQXjakCDnvIYUeW6gZo= X-MC-Unique: CA9RzSWWOKmCiMn57J4X7A-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 17/19] conf: Propagate xmlXPathContextPtr into virDomainVideoDriverDefParseXML() Date: Tue, 4 May 2021 13:40:11 +0200 Message-Id: <760ab4f7340c6aa61471653f8e8abbc00123ce23.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.13 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 206816d76f..97cf940dad 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14348,7 +14348,8 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node) } =20 static virDomainVideoDriverDef * -virDomainVideoDriverDefParseXML(xmlNodePtr node) +virDomainVideoDriverDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED) { xmlNodePtr cur; virDomainVideoDriverDef *def; @@ -14513,7 +14514,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags)= < 0) return NULL; =20 - def->driver =3D virDomainVideoDriverDefParseXML(node); + def->driver =3D virDomainVideoDriverDefParseXML(node, ctxt); =20 return g_steal_pointer(&def); } --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 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=1620128492; cv=none; d=zohomail.com; s=zohoarc; b=fBMGg4WRhK6hjlFYdoVO+Q9DtfCI7WoI7j8skJAdG/4kREltoL6J2KUvwQ6KAhJ+x3kLXv1az2k2ruLPEqOZN1rgqlTpYerHqoQl0vBjT99f/ETofabigQt1QzwB/axy9409zUy9IqIs09Ng0tMk+LHvR+7nNcn4NFdMSyRzVag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128492; h=Content-Type:Content-Transfer-Encoding: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=Oc77HBnLJyUZGjJc59+ggSC9m6BgbRyWLDFNDDJ/vck=; b=SryY1nvaZ2LH6ShzTWnH7uKqV9jP8maITvK6GL98MdA6wOxb/k4WEhy1WhlLTa7y85sNqBp3ynSPF/rmIfAQ6BoplL3+refFoKE/vwnKPXSsYls1A88yMGxzhz3dGHtlqmdgO/5vKfNpGAKG8MVRuhQ5IiLMGf5s9Azpqn109vo= 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 1620128492081724.9110585194578; Tue, 4 May 2021 04:41:32 -0700 (PDT) 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-531-CEXxHql7PHCjZT3hSk0bGg-1; Tue, 04 May 2021 07:41:29 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B5DD79EC0; Tue, 4 May 2021 11:41:22 +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 EC1515C233; Tue, 4 May 2021 11:41:21 +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 B100755354; Tue, 4 May 2021 11:41:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BfCWb000923 for ; Tue, 4 May 2021 07:41:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 175FC5D9F2; Tue, 4 May 2021 11:41:12 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1D7E5D9DE for ; Tue, 4 May 2021 11:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128491; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=Oc77HBnLJyUZGjJc59+ggSC9m6BgbRyWLDFNDDJ/vck=; b=F3W8B8ya2ysEFm1cO5R5AoOCaJ53AHuuYNJkuVbM2EiejY8u9VpHLqutgp4Pt8ttxgReG3 ew5RAO8R8RfI1JcNfert0iNQ8tawhNelCKsioc2R3cVXJ5mNz2sFaDBT39nYxL5XB2fqoS VBGZqq/t2ZQeH1wXKASCsxbapLz5UxA= X-MC-Unique: CEXxHql7PHCjZT3hSk0bGg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 18/19] Refactoring virDomainVideoDriverDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:12 +0200 Message-Id: <9c7daf2dc11925486a1df7bba8c04873bae84596.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.16 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 97cf940dad..f90f720b44 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14349,25 +14349,16 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr no= de) =20 static virDomainVideoDriverDef * virDomainVideoDriverDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED) + xmlXPathContextPtr ctxt) { - xmlNodePtr cur; virDomainVideoDriverDef *def; int val; g_autofree char *vgaconf =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!vgaconf && - virXMLNodeNameEqual(cur, "driver")) { - vgaconf =3D virXMLPropString(cur, "vgaconf"); - } - } - cur =3D cur->next; - } + ctxt->node =3D node; =20 - if (!vgaconf) + if (!(vgaconf =3D virXPathString("string(./driver/@vgaconf)", ctxt))) return NULL; =20 def =3D g_new0(virDomainVideoDriverDef, 1); --=20 2.30.2 From nobody Tue Apr 23 20:20:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620128498; cv=none; d=zohomail.com; s=zohoarc; b=DH07zfaPTRj3zlUBn/pc3UEaf/m78q+CYi9K+Fit9NWiOVbIcaThwV0NnmEaw3DN2UDNScAZ/10FnisjCD7ifhKs5d1MP2rM/X9BJawpcjEs0XkQUuV5TkJlr6WLNCvRJJMFYp0M9Zo4eUDT9B94c0WCd5PvzmHsPDhnYD6Ryqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128498; h=Content-Type:Content-Transfer-Encoding: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=DNnuJZcJpMKAX21f/ARR4JS8sHmzzmXOqUiMEFu3lIs=; b=EB31pA+HjF4QP+dCJnW0kPBFv5r1Nys/11lbjRYt6w/6/w4rZBKIOKmwGrSjakWxSFo+CcRnqIx3RdjVyqvWKRgrEXnfk4p58WKeCvhL8+NB6W+HG6rAtKfi/MEI/GM2dopQ5DuP2jpJlWgGAGvghvivplVUVuXrAOf/oxmZnqY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620128498308880.2856077141469; Tue, 4 May 2021 04:41:38 -0700 (PDT) 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-540-EIguva9wPUCmJmP7U9Cn-A-1; Tue, 04 May 2021 07:41:29 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31EE78042BF; Tue, 4 May 2021 11:41:25 +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 C3E1B1064169; Tue, 4 May 2021 11:41:24 +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 722961801266; Tue, 4 May 2021 11:41:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144BfDUi000933 for ; Tue, 4 May 2021 07:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78D4F5D9FC; Tue, 4 May 2021 11:41:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87A2B5D9F2 for ; Tue, 4 May 2021 11:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128497; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=DNnuJZcJpMKAX21f/ARR4JS8sHmzzmXOqUiMEFu3lIs=; b=QTUV2f/YPAkgDUTj1b4wdTcYPJK5sMNox9fGzVWnN8Z6QFBH1Q6NWcR5X7ovgQNSPPFg1s C02y499kLhnd4GghpwT0oljWtA5TUoi7gU33P4VyI541n2s83TLmlKIuoyVsFSUu5qbJy0 7tWh+MWC+1IF3781b5fE5eCgzuk7SWw= X-MC-Unique: EIguva9wPUCmJmP7U9Cn-A-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 19/19] Refactoring virDomainVideoDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:13 +0200 Message-Id: <20da00e4e297c2f2e5e87ad34da6926244fc7afa.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 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" Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 88 ++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f90f720b44..990c6be309 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14380,7 +14380,9 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, unsigned int flags) { g_autoptr(virDomainVideoDef) def =3D NULL; - xmlNodePtr cur; + xmlNodePtr driver; + xmlNodePtr accel_node; + xmlNodePtr res_node; VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autofree char *type =3D NULL; g_autofree char *driver_name =3D NULL; @@ -14396,62 +14398,28 @@ virDomainVideoDefParseXML(virDomainXMLOption *xml= opt, =20 ctxt->node =3D node; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!type && !vram && !ram && !heads && - virXMLNodeNameEqual(cur, "model")) { - xmlNodePtr child; - type =3D virXMLPropString(cur, "type"); - ram =3D virXMLPropString(cur, "ram"); - vram =3D virXMLPropString(cur, "vram"); - vram64 =3D virXMLPropString(cur, "vram64"); - vgamem =3D virXMLPropString(cur, "vgamem"); - heads =3D virXMLPropString(cur, "heads"); - - if ((primary =3D virXMLPropString(cur, "primary")) !=3D NU= LL) { - ignore_value(virStringParseYesNo(primary, &def->primar= y)); - VIR_FREE(primary); - } + if ((primary =3D virXPathString("string(./model/@primary)", ctxt)) != =3D NULL) + ignore_value(virStringParseYesNo(primary, &def->primary)); =20 - child =3D cur->children; - while (child !=3D NULL) { - if (child->type =3D=3D XML_ELEMENT_NODE) { - if (def->accel =3D=3D NULL && - virXMLNodeNameEqual(child, "acceleration")) { - if ((def->accel =3D virDomainVideoAccelDefPars= eXML(child)) =3D=3D NULL) - return NULL; - } - if (def->res =3D=3D NULL && - virXMLNodeNameEqual(child, "resolution")) { - if ((def->res =3D virDomainVideoResolutionDefP= arseXML(child)) =3D=3D NULL) - return NULL; - } - } - child =3D child->next; - } - } - if (virXMLNodeNameEqual(cur, "driver")) { - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - return NULL; - driver_name =3D virXMLPropString(cur, "name"); - } - } - cur =3D cur->next; - } + if (def->accel =3D=3D NULL && + (accel_node =3D virXPathNode("./model/acceleration", ctxt))) + if ((def->accel =3D virDomainVideoAccelDefParseXML(accel_node)) = =3D=3D NULL) + return NULL; =20 - if (type) { - if ((def->type =3D virDomainVideoTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown video model '%s'"), type); + if (def->res =3D=3D NULL && + (res_node =3D virXPathNode("./model/resolution", ctxt))) + if ((def->res =3D virDomainVideoResolutionDefParseXML(res_node)) = =3D=3D NULL) return NULL; - } - } else { - def->type =3D VIR_DOMAIN_VIDEO_TYPE_DEFAULT; + + if ((driver =3D virXPathNode("./driver", ctxt))) { + if (virDomainVirtioOptionsParseXML(driver, &def->virtio) < 0) + return NULL; + driver_name =3D virXPathString("string(./driver/@name)", ctxt); } =20 if (driver_name) { int backend; + if ((backend =3D virDomainVideoBackendTypeFromString(driver_name))= <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown video driver '%s'"), driver_name); @@ -14462,7 +14430,17 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlo= pt, def->backend =3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT; } =20 - if (ram) { + if ((type =3D virXPathString("string(./model/@type)", ctxt))) { + if ((def->type =3D virDomainVideoTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown video model '%s'"), type); + return NULL; + } + } else { + def->type =3D VIR_DOMAIN_VIDEO_TYPE_DEFAULT; + } + + if ((ram =3D virXPathString("string(./model/@ram)", ctxt))) { if (virStrToLong_uip(ram, NULL, 10, &def->ram) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video ram '%s'"), ram); @@ -14470,7 +14448,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, } } =20 - if (vram) { + if ((vram =3D virXPathString("string(./model/@vram)", ctxt))) { if (virStrToLong_uip(vram, NULL, 10, &def->vram) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vram '%s'"), vram); @@ -14478,7 +14456,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, } } =20 - if (vram64) { + if ((vram64 =3D virXPathString("string(./model/@vram64)", ctxt))) { if (virStrToLong_uip(vram64, NULL, 10, &def->vram64) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vram64 '%s'"), vram64); @@ -14486,7 +14464,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, } } =20 - if (vgamem) { + if ((vgamem =3D virXPathString("string(./model/@vgamem)", ctxt))) { if (virStrToLong_uip(vgamem, NULL, 10, &def->vgamem) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vgamem '%s'"), vgamem); @@ -14494,7 +14472,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, } } =20 - if (heads) { + if ((heads =3D virXPathString("string(./model/@heads)", ctxt))) { if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse video heads '%s'"), heads); --=20 2.30.2