From nobody Sun Feb 8 21:41:43 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 1491926057194791.862021928154; Tue, 11 Apr 2017 08:54:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 563B8C04BD24; Tue, 11 Apr 2017 15:54:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2612C18EE8; Tue, 11 Apr 2017 15:54: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 C5E0B5EC65; Tue, 11 Apr 2017 15:54:14 +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 v3BFs8OZ001651 for ; Tue, 11 Apr 2017 11:54:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 043EB7ED96; 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 1EA207ED94; Tue, 11 Apr 2017 15:54:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 563B8C04BD24 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 563B8C04BD24 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:53 +0200 Message-Id: <9b368d8902d9878ae0f65e38c12e8679a95aeafd.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 7/9] virsh-domain-monitor: 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 11 Apr 2017 15:54:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Reuse virshDomainGetXML and virshDomainGetXMLFromDom. --- tools/virsh-domain-monitor.c | 57 ++++------------------------------------= ---- 1 file changed, 5 insertions(+), 52 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 92995ad7d..3db4795d2 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -63,7 +63,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, unsigned int flags) { char *desc =3D NULL; - char *domxml =3D NULL; virErrorPtr err =3D NULL; xmlDocPtr doc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; @@ -90,16 +89,9 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr = dom, bool title, } /* fall back to xml */ - /* get domain's xml description and extract the title/description */ - if (!(domxml =3D virDomainGetXMLDesc(dom, flags))) { - vshError(ctl, "%s", _("Failed to retrieve domain XML")); + if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0) goto cleanup; - } - doc =3D virXMLParseStringCtxt(domxml, _("(domain_definition)"), &ctxt); - if (!doc) { - vshError(ctl, "%s", _("Couldn't parse domain XML")); - goto cleanup; - } + if (title) desc =3D virXPathString("string(./title[1])", ctxt); else @@ -109,7 +101,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr= dom, bool title, desc =3D vshStrdup(ctl, ""); cleanup: - VIR_FREE(domxml); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); @@ -465,10 +456,8 @@ static const vshCmdOptDef opts_domblklist[] =3D { static bool cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; bool ret =3D false; unsigned int flags =3D 0; - char *xml =3D NULL; xmlDocPtr xmldoc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; int ndisks; @@ -485,15 +474,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) details =3D vshCommandOptBool(cmd, "details"); - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return false; - - xml =3D virDomainGetXMLDesc(dom, flags); - if (!xml) - goto cleanup; - - xmldoc =3D virXMLParseStringCtxt(xml, _("(domain_definition)"), &ctxt); - if (!xmldoc) + if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) goto cleanup; ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); @@ -553,8 +534,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) VIR_FREE(disks); xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); - VIR_FREE(xml); - virshDomainFree(dom); return ret; } @@ -579,10 +558,8 @@ static const vshCmdOptDef opts_domiflist[] =3D { static bool cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; bool ret =3D false; unsigned int flags =3D 0; - char *xml =3D NULL; xmlDocPtr xmldoc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; int ninterfaces; @@ -592,15 +569,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "inactive")) flags |=3D VIR_DOMAIN_XML_INACTIVE; - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return false; - - xml =3D virDomainGetXMLDesc(dom, flags); - if (!xml) - goto cleanup; - - xmldoc =3D virXMLParseStringCtxt(xml, _("(domain_definition)"), &ctxt); - if (!xmldoc) + if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) goto cleanup; ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); @@ -648,8 +617,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(interfaces); - virshDomainFree(dom); - VIR_FREE(xml); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); return ret; @@ -686,13 +653,11 @@ static const vshCmdOptDef opts_domif_getlink[] =3D { static bool cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; const char *iface =3D NULL; char *state =3D NULL; char *xpath =3D NULL; virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; - char *desc =3D NULL; xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; xmlNodePtr *interfaces =3D NULL; @@ -703,21 +668,11 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) return false; - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return false; - if (vshCommandOptBool(cmd, "config")) flags =3D VIR_DOMAIN_XML_INACTIVE; - if (!(desc =3D virDomainGetXMLDesc(dom, flags))) { - vshError(ctl, _("Failed to get domain description xml")); + if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) goto cleanup; - } - - if (!(xml =3D virXMLParseStringCtxt(desc, _("(domain_definition)"), &c= txt))) { - vshError(ctl, _("Failed to parse domain description xml")); - goto cleanup; - } /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) =3D=3D 0) @@ -752,13 +707,11 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - VIR_FREE(desc); VIR_FREE(state); VIR_FREE(interfaces); VIR_FREE(xpath); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list