From nobody Mon Feb 9 05:19:36 2026 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=1618496945; cv=none; d=zohomail.com; s=zohoarc; b=CRq2LsfTghMBAcdhrg+DYcMzeVtbRR83JDAIlPrIctvwPUjFENSKS71l4DlQniOkv0vmFh+eEi4BgGA7U75hWluTdLX2W+Dvv3FZQ72A4dwCmbYNyJ+JJKnuj3BgnNA6TNlJjb/kLvvcAHhXGvZE3iO+bCTdfvyfkXQTk3t1lKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618496945; 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=B7hN04et+3i/zsdATZV2CYZtrerD30ENveHgU1nAPvc=; b=JZv0XRPMT/nE2TNafFiyYDad2WZXMWq/wmSN6MDVBVq+jMwr+ZQw/C/nU+0HR+GrXYHP/mKcUIL/htBqJ+BalMPPTkascMX1LTn7M/U2+96wOm7AdKn+Rjc1VmGBV1L8WnnH8XE4lQj2IQ/EoNPqNd4yexIzjVGT3qdKZYP1+5U= 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 1618496945580647.4567533266141; Thu, 15 Apr 2021 07:29:05 -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-279-oz18_JLeMYiHhnr9eDlSOQ-1; Thu, 15 Apr 2021 10:29:01 -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 C688CA0CAC; Thu, 15 Apr 2021 14:28:01 +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 A18C05C701; Thu, 15 Apr 2021 14:28:01 +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 644FE1806D1D; Thu, 15 Apr 2021 14:28:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13FES0AX024527 for ; Thu, 15 Apr 2021 10:28:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C8E66A97C; Thu, 15 Apr 2021 14:28:00 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.196.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B1DE60917 for ; Thu, 15 Apr 2021 14:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618496944; 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=B7hN04et+3i/zsdATZV2CYZtrerD30ENveHgU1nAPvc=; b=Id95/GQaKiyqRHdp+pvheDSUfZF5jhGt6PHZlv0O8xvR+MMrvXYaS4Zfl71Ot+4EO3CgXN 5QCqhM/9xLunYCT48+fs/SqgVVjJD/rtE92OebtvqZFW7p9iN+DUout53K8fi8JFSNuILN 7CPI9mpXojzSxYeBCesi8EJ+5nvgCaw= X-MC-Unique: oz18_JLeMYiHhnr9eDlSOQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 21/21] Refactoring virDomainVideoDefParseXML() to use XPath Date: Thu, 15 Apr 2021 16:26:36 +0200 Message-Id: <8af3085ba9a4e3512614a253784768e8834cbaa1.1618495577.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 --- 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 a5dce8a8af..54348c8c23 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15080,7 +15080,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; @@ -15096,62 +15098,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); @@ -15162,7 +15130,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); @@ -15170,7 +15148,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); @@ -15178,7 +15156,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); @@ -15186,7 +15164,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); @@ -15194,7 +15172,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