From nobody Mon Feb 9 16:53:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1491926064663938.7728876035169; Tue, 11 Apr 2017 08:54:24 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6003134076A; Tue, 11 Apr 2017 15:54:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 372FA7B55B; Tue, 11 Apr 2017 15:54:23 +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 E8EA25EC67; Tue, 11 Apr 2017 15:54:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3BFs9na001663 for ; Tue, 11 Apr 2017 11:54:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id F389A7ED8E; Tue, 11 Apr 2017 15:54:08 +0000 (UTC) Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FA7E7ED99; Tue, 11 Apr 2017 15:54:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6003134076A Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6003134076A From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:54 +0200 Message-Id: <81cfc0814783c13694f39d1335717f621ee78293.1491925946.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 8/9] virsh-domain: Use the virsh wrappers for getting XML to simplify code 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 11 Apr 2017 15:54:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Reuse virshDomainGetXML and virshDomainGetXMLFromDom. --- tools/virsh-domain.c | 62 ++++++++++--------------------------------------= ---- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ba179c89c..d64a2dca0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2983,13 +2983,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) const char *iface; const char *state; char *value; - char *desc; virMacAddr macaddr; const char *element; const char *attr; bool config; bool ret =3D false; unsigned int flags =3D 0; + unsigned int xmlflags =3D 0; size_t i; xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; @@ -3011,28 +3011,18 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - /* get persistent or live description of network device */ - desc =3D virDomainGetXMLDesc(dom, config ? VIR_DOMAIN_XML_INACTIVE : 0= ); - if (desc =3D=3D NULL) { - vshError(ctl, _("Failed to get domain description xml")); - goto cleanup; - } - - if (config) + if (config) { flags =3D VIR_DOMAIN_AFFECT_CONFIG; - else + xmlflags |=3D VIR_DOMAIN_XML_INACTIVE; + } else { flags =3D VIR_DOMAIN_AFFECT_LIVE; + } if (virDomainIsActive(dom) =3D=3D 0) flags =3D VIR_DOMAIN_AFFECT_CONFIG; - /* extract current network device description */ - xml =3D virXMLParseStringCtxt(desc, _("(domain_definition)"), &ctxt); - VIR_FREE(desc); - if (!xml) { - vshError(ctl, _("Failed to parse domain description xml")); + if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0) goto cleanup; - } obj =3D xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt); if (obj =3D=3D NULL || obj->type !=3D XPATH_NODESET || @@ -3575,7 +3565,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) int nvol_list =3D 0; virshUndefineVolume *vols =3D NULL; /* info about the volumes to delet= e*/ size_t nvols =3D 0; - char *def =3D NULL; /* domain def */ xmlDocPtr doc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; xmlNodePtr *vol_nodes =3D NULL; /* XML nodes of volumes of the guest= */ @@ -3685,14 +3674,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (!(def =3D virDomainGetXMLDesc(dom, 0))) { - vshError(ctl, _("Could not retrieve domain XML description")); + if (virshDomainGetXMLFromDom(ctl, dom, 0, &doc, &ctxt) < 0) goto cleanup; - } - - if (!(doc =3D virXMLParseStringCtxt(def, _("(domain_definition)"), - &ctxt))) - goto error; /* tokenize the string from user and save its parts into an array = */ if (vol_string && @@ -3897,7 +3880,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_list[i]); VIR_FREE(vol_list); - VIR_FREE(def); VIR_FREE(vol_nodes); xmlFreeDoc(doc); xmlXPathFreeContext(ctxt); @@ -6029,7 +6011,6 @@ virshCPUCountCollect(vshControl *ctl, int ret =3D -2; virDomainInfo info; int count; - char *def =3D NULL; xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; @@ -6071,10 +6052,8 @@ virshCPUCountCollect(vshControl *ctl, count =3D info.nrVirtCpu; } } else { - if (!(def =3D virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE))) - goto cleanup; - - if (!(xml =3D virXMLParseStringCtxt(def, _("(domain_definition)"),= &ctxt))) + if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, + &xml, &ctxt) < 0) goto cleanup; if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { @@ -6092,7 +6071,6 @@ virshCPUCountCollect(vshControl *ctl, ret =3D count; cleanup: - VIR_FREE(def); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); @@ -6237,7 +6215,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, bool inactive) { unsigned int flags =3D 0; - char *def =3D NULL; virBitmapPtr ret =3D NULL; xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; @@ -6253,10 +6230,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (inactive) flags |=3D VIR_DOMAIN_XML_INACTIVE; - if (!(def =3D virDomainGetXMLDesc(dom, flags))) - goto cleanup; - - if (!(xml =3D virXMLParseStringCtxt(def, _("(domain_definition)"), &ct= xt))) + if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) goto cleanup; if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) { @@ -6308,7 +6282,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, VIR_FREE(nodes); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - VIR_FREE(def); return ret; } @@ -10901,7 +10874,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; virBuffer buf =3D VIR_BUFFER_INITIALIZER; bool ret =3D false; - char *doc =3D NULL; char *xpath =3D NULL; char *listen_addr =3D NULL; int port, tls_port =3D 0; @@ -10931,10 +10903,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) goto cleanup; - if (!(doc =3D virDomainGetXMLDesc(dom, flags))) - goto cleanup; - - if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ct= xt))) + if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) goto cleanup; /* Attempt to grab our display info */ @@ -11107,14 +11076,12 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(doc); VIR_FREE(xpath); VIR_FREE(passwd); VIR_FREE(listen_addr); VIR_FREE(output); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); return ret; } @@ -11144,7 +11111,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; bool ret =3D false; int port =3D 0; - char *doc =3D NULL; char *listen_addr =3D NULL; if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) @@ -11156,10 +11122,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (!(doc =3D virDomainGetXMLDesc(dom, 0))) - goto cleanup; - - if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ct= xt))) + if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0) goto cleanup; /* Get the VNC port */ @@ -11191,7 +11154,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - VIR_FREE(doc); VIR_FREE(listen_addr); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list