From nobody Mon Feb 9 01:22:37 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=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 --- 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