From nobody Mon Feb 9 09:08:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1618496937; cv=none; d=zohomail.com; s=zohoarc; b=mdsGoDIA/xctaF9BXJ8kkOiEJ4fk8DoJ+zLWXPyAsbb9hpQoKWBHvELs/ko1V10OdKbq5hMmxGeOvr0w9zaF7x6xzo+qh3rUFMMt432bh8hl39V6ilyzdKkptTVSxFP8j+avjA6ejdkOmeZgRhzoWkg0IdRWqRuWdq9lIjpbbq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618496937; 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=3rLuj7CzV7kxavhNgcoSy/jJwjbzTgHMCJlJSc0je3k=; b=bYzE10dgbB0wrjRLNskGjtZBCr5V+VeUJhjNw6Il1l7+ZZ1bBz/TsAdlv3+2eYxXtU1NPSezvTYsNFsk0R1h6B0mXNguJAT4w/tAQ4R2st268HC5np+UVLO+s/NaSVDCaGzetr6tka18ZAcKPKGKGOsNy6K+IhZfiBNBhkp/6R8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1618496937667614.5796922191612; Thu, 15 Apr 2021 07:28:57 -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-558-pBdaP33dP7awkMbzI1lLHQ-1; Thu, 15 Apr 2021 10:28:54 -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 CBD038D6FD4; Thu, 15 Apr 2021 14:27:39 +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 7FBC653B1C; Thu, 15 Apr 2021 14:27:39 +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 168BF44A5B; Thu, 15 Apr 2021 14:27:39 +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 13FERb46024307 for ; Thu, 15 Apr 2021 10:27:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62B826BF74; Thu, 15 Apr 2021 14:27:37 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.196.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7292712A8 for ; Thu, 15 Apr 2021 14:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618496936; 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=3rLuj7CzV7kxavhNgcoSy/jJwjbzTgHMCJlJSc0je3k=; b=DgiuqNpyD3mO9TVp42LKRUPC3chQat7o+mzeuQrXdygtm+WWUFioji90AARgHXXbdjJold 78P3PNLUreWyepniQdpyrAiwljp+kvPM+zaa+w53/7PY+8Ji1N7NtHO+bjOFbXhiB+bebN lks/PyVkRupH7li4hZZw2apEuNq0Yy8= X-MC-Unique: pBdaP33dP7awkMbzI1lLHQ-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 08/21] Refactoring virDomainLeaseDefParseXML() to use XPath Date: Thu, 15 Apr 2021 16:26:23 +0200 Message-Id: <66a20924a642ead23dec0ee718fdadc964eac114.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.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 --- src/conf/domain_conf.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6a03727f2c..808169883f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8122,48 +8122,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); --=20 2.30.2