From nobody Sun Feb 8 15:30:48 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=1618496948; cv=none; d=zohomail.com; s=zohoarc; b=c1MZR0Gr6TP3DdF/dvmhwSXTXYJ+sY0Aet6Rlot6tEV2EeS22uJErdZQOVuE+hX8bexXCiRV7Q5y8z5KdVeB9Yf4YDKjH7yAtv4wnNe3pUoEvWCaUTHr5IGox66wE5FG0hp5bn9LmBeHpFEzkDrWKtD8oPkRwZwm7to0/laT1M0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618496948; 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=sJEWIcyug47d2g4E27dh7F7VlxCqzE7OIGiaNlLKIx0=; b=mvXL3vNHOdB4xdWNfFBz6sxJAQdmpjn+lGC+NGFHmagn+nRvJID3jK3FKjf1ATtZRItkcmX9ndd5jXXKdqYMrYRUD1O4Ec43Uy5vyue+dgXSWuFRcR67BrYBqYtSzeK4HmBPxL9OlCHPwYNlkk/H/RxFiQECy3JNuxyIWA1IciE= 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 1618496948289392.88882871519263; Thu, 15 Apr 2021 07:29:08 -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-384-ip2NzcsgMoWQeJSmgvo9vw-1; Thu, 15 Apr 2021 10:28:04 -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 8A97A8A2A2A; Thu, 15 Apr 2021 14:27:15 +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 65DFE6064B; Thu, 15 Apr 2021 14:27: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 1551A1806D19; Thu, 15 Apr 2021 14:27:15 +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 13FER8K5024217 for ; Thu, 15 Apr 2021 10:27:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id DEC8860917; Thu, 15 Apr 2021 14:27:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.196.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5234C60CCB for ; Thu, 15 Apr 2021 14:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618496947; 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=sJEWIcyug47d2g4E27dh7F7VlxCqzE7OIGiaNlLKIx0=; b=exmwipIlqOL+f4QQAThPt9oR9h/Gj45I4KnhOIXN6svoOY6Uko+eltgguWVs1gpnt477R4 +GXwDmk6ZMeZMYVN6cvjjNKt6wmMFHiEGlUMpjZUbc+s6KZXx9OQnEi6tCoWY7fG9ihxJg j/FWqolasIO8aEn7FE2P7OUDZLq2MwY= X-MC-Unique: ip2NzcsgMoWQeJSmgvo9vw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 04/21] Refactoring virDomainBlkioDeviceParseXML() to use XPath Date: Thu, 15 Apr 2021 16:26:19 +0200 Message-Id: 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.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 --- 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 33cc204507..65d5bb2c2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1698,85 +1698,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