From nobody Wed May 8 02:21:05 2024 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 1491926046573196.34400469065872; Tue, 11 Apr 2017 08:54:06 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 65350C04B955; Tue, 11 Apr 2017 15:54:04 +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 D677A7ED95; Tue, 11 Apr 2017 15:54:03 +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 8080118523C7; Tue, 11 Apr 2017 15:54:03 +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 v3BFs0SC001594 for ; Tue, 11 Apr 2017 11:54:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD1C97ED84; Tue, 11 Apr 2017 15:54:00 +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 9DA497ED83; Tue, 11 Apr 2017 15:53:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 65350C04B955 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 65350C04B955 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:47 +0200 Message-Id: <12bdac314afdd9dffb8e7f2d33c93a6421d74e4b.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 1/9] virsh: Add new file for utility functions and move a few 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.12 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:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Don't accumulate helpers in virsh.c --- tools/Makefile.am | 1 + tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 1 + tools/virsh-util.c | 66 ++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-util.h | 35 +++++++++++++++++++++++ tools/virsh-volume.c | 1 + tools/virsh.c | 41 --------------------------- tools/virsh.h | 4 --- 8 files changed, 105 insertions(+), 45 deletions(-) create mode 100644 tools/virsh-util.c create mode 100644 tools/virsh-util.h diff --git a/tools/Makefile.am b/tools/Makefile.am index bfacaf214..56691c289 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -226,6 +226,7 @@ virsh_SOURCES =3D \ virsh-pool.c virsh-pool.h \ virsh-secret.c virsh-secret.h \ virsh-snapshot.c virsh-snapshot.h \ + virsh-util.c virsh-util.h \ virsh-volume.c virsh-volume.h \ $(NULL) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 901a6ebef..4ade5651c 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -25,6 +25,7 @@ #include #include "virsh-domain-monitor.h" +#include "virsh-util.h" #include #include diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4b6c13ce4..7db74fecf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -25,6 +25,7 @@ #include #include "virsh-domain.h" +#include "virsh-util.h" #include #include diff --git a/tools/virsh-util.c b/tools/virsh-util.c new file mode 100644 index 000000000..98f16ff1a --- /dev/null +++ b/tools/virsh-util.c @@ -0,0 +1,66 @@ +/* + * virsh-util.c: helpers for virsh + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virsh-util.h" + +#include "virfile.h" + +int +virshDomainState(vshControl *ctl, + virDomainPtr dom, + int *reason) +{ + virDomainInfo info; + virshControlPtr priv =3D ctl->privData; + + if (reason) + *reason =3D -1; + + if (!priv->useGetInfo) { + int state; + if (virDomainGetState(dom, &state, reason, 0) < 0) { + virErrorPtr err =3D virGetLastError(); + if (err && err->code =3D=3D VIR_ERR_NO_SUPPORT) + priv->useGetInfo =3D true; + else + return -1; + } else { + return state; + } + } + + /* fall back to virDomainGetInfo if virDomainGetState is not supported= */ + if (virDomainGetInfo(dom, &info) < 0) + return -1; + else + return info.state; +} + + +int +virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED, + const char *bytes, + size_t nbytes, + void *opaque) +{ + int *fd =3D opaque; + + return safewrite(*fd, bytes, nbytes); +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h new file mode 100644 index 000000000..207d57859 --- /dev/null +++ b/tools/virsh-util.h @@ -0,0 +1,35 @@ +/* + * virsh-util.h: helpers for virsh + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef VIRSH_UTIL_H +# define VIRSH_UTIL_H + +# include "virsh.h" + +int +virshDomainState(vshControl *ctl, + virDomainPtr dom, + int *reason); + +int +virshStreamSink(virStreamPtr st, + const char *bytes, + size_t nbytes, + void *opaque); + +#endif /* VIRSH_UTIL_H */ diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 32ffb8149..ddd41d229 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -25,6 +25,7 @@ #include #include "virsh-volume.h" +#include "virsh-util.h" #include diff --git a/tools/virsh.c b/tools/virsh.c index 7eb51ab7d..31e23bd27 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -257,14 +257,6 @@ virshReconnect(vshControl *ctl, const char *name, bool= readonly, bool force) return 0; } -int virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED, - const char *bytes, size_t nbytes, void *opaque) -{ - int *fd =3D opaque; - - return safewrite(*fd, bytes, nbytes); -} - /* --------------- * Command Connect * --------------- @@ -347,39 +339,6 @@ virshConnectionHandler(vshControl *ctl) } -/* --------------- - * Misc utils - * --------------- - */ -int -virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason) -{ - virDomainInfo info; - virshControlPtr priv =3D ctl->privData; - - if (reason) - *reason =3D -1; - - if (!priv->useGetInfo) { - int state; - if (virDomainGetState(dom, &state, reason, 0) < 0) { - virErrorPtr err =3D virGetLastError(); - if (err && err->code =3D=3D VIR_ERR_NO_SUPPORT) - priv->useGetInfo =3D true; - else - return -1; - } else { - return state; - } - } - - /* fall back to virDomainGetInfo if virDomainGetState is not supported= */ - if (virDomainGetInfo(dom, &info) < 0) - return -1; - else - return info.state; -} - /* * Initialize connection. */ diff --git a/tools/virsh.h b/tools/virsh.h index fd552bb3a..9e42ef9bb 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -145,9 +145,5 @@ typedef enum { } virshLookupByFlags; virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly= ); -int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); - -int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes, - void *opaque); #endif /* VIRSH_H */ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 1491926057321600.4425198246964; Tue, 11 Apr 2017 08:54:17 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 5FC84C059747; 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 258CD51C75; 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 B59D85EC60; 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 v3BFs12b001604 for ; Tue, 11 Apr 2017 11:54:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD8067ED84; Tue, 11 Apr 2017 15:54:01 +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 039037ED83; Tue, 11 Apr 2017 15:54:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5FC84C059747 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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 5FC84C059747 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:48 +0200 Message-Id: <56ab435dea9c44649f78384537112632d5bb0dc9.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 2/9] virsh-util: Move domain lookup helpers into virsh-util 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Apr 2017 15:54:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move virshLookupDomainBy, virshCommandOptDomainBy and virshCommandOptDomainBy to the helper file. Additionally turn the virshCommandOptDomainBy macro into a function. --- po/POTFILES.in | 1 + tools/virsh-domain-monitor.c | 1 - tools/virsh-domain.c | 71 ------------------------------------ tools/virsh-domain.h | 12 ------- tools/virsh-host.c | 1 - tools/virsh-snapshot.c | 2 +- tools/virsh-util.c | 86 ++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-util.h | 17 +++++++++ 8 files changed, 105 insertions(+), 86 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 064abd5bb..ccef6f3cf 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -310,6 +310,7 @@ tools/virsh-nwfilter.c tools/virsh-pool.c tools/virsh-secret.c tools/virsh-snapshot.c +tools/virsh-util.c tools/virsh-volume.c tools/virsh.c tools/virt-admin.c diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 4ade5651c..5215ac6f9 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -37,7 +37,6 @@ #include "intprops.h" #include "viralloc.h" #include "virmacaddr.h" -#include "virsh-domain.h" #include "virxml.h" #include "virstring.h" diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7db74fecf..4e4df5b4f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -83,77 +83,6 @@ #define VIRSH_COMMON_OPT_DOMAIN_CURRENT \ VIRSH_COMMON_OPT_CURRENT(N_("affect current domain")) \ -static virDomainPtr -virshLookupDomainInternal(vshControl *ctl, - const char *cmdname, - const char *name, - unsigned int flags) -{ - virDomainPtr dom =3D NULL; - int id; - virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL); - virshControlPtr priv =3D ctl->privData; - - /* try it by ID */ - if (flags & VIRSH_BYID) { - if (virStrToLong_i(name, NULL, 10, &id) =3D=3D 0 && id >=3D 0) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: looks like ID\n", - cmdname); - dom =3D virDomainLookupByID(priv->conn, id); - } - } - - /* try it by UUID */ - if (!dom && (flags & VIRSH_BYUUID) && - strlen(name) =3D=3D VIR_UUID_STRING_BUFLEN-1) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: trying as domain UUID\n= ", - cmdname); - dom =3D virDomainLookupByUUIDString(priv->conn, name); - } - - /* try it by NAME */ - if (!dom && (flags & VIRSH_BYNAME)) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: trying as domain NAME\n= ", - cmdname); - dom =3D virDomainLookupByName(priv->conn, name); - } - - vshResetLibvirtError(); - - if (!dom) - vshError(ctl, _("failed to get domain '%s'"), name); - - return dom; -} - - -virDomainPtr -virshLookupDomainBy(vshControl *ctl, - const char *name, - unsigned int flags) -{ - return virshLookupDomainInternal(ctl, "unknown", name, flags); -} - - -virDomainPtr -virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, unsigned int flags) -{ - const char *n =3D NULL; - const char *optname =3D "domain"; - - if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0) - return NULL; - - vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", - cmd->def->name, optname, n); - - if (name) - *name =3D n; - - return virshLookupDomainInternal(ctl, cmd->def->name, n, flags); -} static virDomainPtr virshDomainDefine(virConnectPtr conn, const char *xml, unsigned int flags) diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index 462f560f9..3f9d12a5f 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -28,18 +28,6 @@ # include "virsh.h" -virDomainPtr virshLookupDomainBy(vshControl *ctl, - const char *name, - unsigned int flags); - -virDomainPtr virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, unsigned int flags= ); - -/* default is lookup by Id, Name and UUID */ -# define virshCommandOptDomain(_ctl, _cmd, _name) \ - virshCommandOptDomainBy(_ctl, _cmd, _name, \ - VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME) - extern const vshCmdDef domManagementCmds[]; #endif /* VIRSH_DOMAIN_H */ diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 3b86c75fa..5509065fd 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -35,7 +35,6 @@ #include "virbitmap.h" #include "virbuffer.h" #include "viralloc.h" -#include "virsh-domain.h" #include "virxml.h" #include "virtypedparam.h" #include "virstring.h" diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 5c844a5ea..46e2cbb24 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -37,7 +37,7 @@ #include "virbuffer.h" #include "viralloc.h" #include "virfile.h" -#include "virsh-domain.h" +#include "virsh-util.h" #include "virstring.h" #include "virxml.h" #include "conf/snapshot_conf.h" diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 98f16ff1a..5c99655fb 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -21,6 +21,92 @@ #include "virsh-util.h" #include "virfile.h" +#include "virstring.h" + +static virDomainPtr +virshLookupDomainInternal(vshControl *ctl, + const char *cmdname, + const char *name, + unsigned int flags) +{ + virDomainPtr dom =3D NULL; + int id; + virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL); + virshControlPtr priv =3D ctl->privData; + + /* try it by ID */ + if (flags & VIRSH_BYID) { + if (virStrToLong_i(name, NULL, 10, &id) =3D=3D 0 && id >=3D 0) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: looks like ID\n", + cmdname); + dom =3D virDomainLookupByID(priv->conn, id); + } + } + + /* try it by UUID */ + if (!dom && (flags & VIRSH_BYUUID) && + strlen(name) =3D=3D VIR_UUID_STRING_BUFLEN-1) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: trying as domain UUID\n= ", + cmdname); + dom =3D virDomainLookupByUUIDString(priv->conn, name); + } + + /* try it by NAME */ + if (!dom && (flags & VIRSH_BYNAME)) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: trying as domain NAME\n= ", + cmdname); + dom =3D virDomainLookupByName(priv->conn, name); + } + + vshResetLibvirtError(); + + if (!dom) + vshError(ctl, _("failed to get domain '%s'"), name); + + return dom; +} + + +virDomainPtr +virshLookupDomainBy(vshControl *ctl, + const char *name, + unsigned int flags) +{ + return virshLookupDomainInternal(ctl, "unknown", name, flags); +} + + +virDomainPtr +virshCommandOptDomainBy(vshControl *ctl, + const vshCmd *cmd, + const char **name, + unsigned int flags) +{ + const char *n =3D NULL; + const char *optname =3D "domain"; + + if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0) + return NULL; + + vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", + cmd->def->name, optname, n); + + if (name) + *name =3D n; + + return virshLookupDomainInternal(ctl, cmd->def->name, n, flags); +} + + +virDomainPtr +virshCommandOptDomain(vshControl *ctl, + const vshCmd *cmd, + const char **name) +{ + return virshCommandOptDomainBy(ctl, cmd, name, + VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAM= E); +} + int virshDomainState(vshControl *ctl, diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 207d57859..132bf0b4b 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -21,6 +21,23 @@ # include "virsh.h" + +virDomainPtr +virshLookupDomainBy(vshControl *ctl, + const char *name, + unsigned int flags); + +virDomainPtr +virshCommandOptDomainBy(vshControl *ctl, + const vshCmd *cmd, + const char **name, + unsigned int flags); + +virDomainPtr +virshCommandOptDomain(vshControl *ctl, + const vshCmd *cmd, + const char **name); + int virshDomainState(vshControl *ctl, virDomainPtr dom, --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 1491926048634199.8745113625805; Tue, 11 Apr 2017 08:54:08 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F338480482; Tue, 11 Apr 2017 15:54:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5C237ED98; Tue, 11 Apr 2017 15:54:06 +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 735964E9BD; Tue, 11 Apr 2017 15:54:06 +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 v3BFs3vG001609 for ; Tue, 11 Apr 2017 11:54:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A6C57ED84; Tue, 11 Apr 2017 15:54:03 +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 6A1C97ED94; Tue, 11 Apr 2017 15:54:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F338480482 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 F338480482 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:49 +0200 Message-Id: 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 3/9] virsh-util: Add wrapper for virDomainFree 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 11 Apr 2017 15:54:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virDomainFree has it's quirks (does not like NULL pointers, resets libvirt errors). Replace it by a virsh helper which will allow us to centrally fix issues with it. The syntax-check rule will prohibit new uses of virDomainFree. --- cfg.mk | 8 ++ tools/virsh-domain-monitor.c | 36 ++++---- tools/virsh-domain.c | 216 ++++++++++++++++++++-------------------= ---- tools/virsh-snapshot.c | 24 ++--- tools/virsh-util.c | 10 ++ tools/virsh-util.h | 3 + 6 files changed, 149 insertions(+), 148 deletions(-) diff --git a/cfg.mk b/cfg.mk index cc174a3cc..1ff87f445 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1014,6 +1014,14 @@ sc_gettext_init: halt=3D'the above files do not call virGettextInitialize' \ $(_sc_search_regexp) +#Ensure that virsh uses the wrappers on top of the object freeing APIs +sc_prohibit_obj_free_apis_in_virsh: + @prohibit=3D'\virDomainFree\b' \ + in_vc_files=3D'\virsh.*\.[ch]$$' \ + exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ + halt=3D'avoid using virDomainFree in virsh, use virsh-prefixed wrappers i= nstead' \ + $(_sc_search_regexp) + # We don't use this feature of maint.mk. prev_version_file =3D /dev/null diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 5215ac6f9..92995ad7d 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -381,7 +381,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -432,7 +432,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -554,7 +554,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); VIR_FREE(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -648,7 +648,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(interfaces); - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(xml); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); @@ -758,7 +758,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xpath); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -811,7 +811,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -997,7 +997,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(params); - virDomainFree(dom); + virshDomainFree(dom); return ret; } #undef DOMBLKSTAT_LEGACY_PRINT @@ -1071,7 +1071,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1132,7 +1132,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(disks); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1241,7 +1241,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(priv->conn, &secmodel) =3D=3D -1) { if (last_error->code !=3D VIR_ERR_NO_SUPPORT) { - virDomainFree(dom); + virshDomainFree(dom); return false; } else { vshResetLibvirtError(); @@ -1254,12 +1254,12 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) /* Security labels are only valid for active domains */ if (VIR_ALLOC(seclabel) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } if (virDomainGetSecurityLabel(dom, seclabel) =3D=3D -1) { - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(seclabel); return false; } else { @@ -1271,7 +1271,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(seclabel); } } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1323,7 +1323,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1427,7 +1427,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1493,7 +1493,7 @@ virshDomainListFree(virshDomainListPtr domlist) if (domlist && domlist->domains) { for (i =3D 0; i < domlist->ndomains; i++) { if (domlist->domains[i]) - virDomainFree(domlist->domains[i]); + virshDomainFree(domlist->domains[i]); } VIR_FREE(domlist->domains); } @@ -1689,7 +1689,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int = flags) remove_entry: /* the domain has to be removed as it failed one of the filters */ - virDomainFree(list->domains[i]); + virshDomainFree(list->domains[i]); list->domains[i] =3D NULL; deleted++; } @@ -2294,7 +2294,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(ifaces); - virDomainFree(dom); + virshDomainFree(dom); return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4e4df5b4f..ba179c89c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -218,7 +218,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -700,8 +700,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } @@ -1011,8 +1010,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } @@ -1056,7 +1054,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Failed to mark domain %s as autostarted"), na= me); else vshError(ctl, _("Failed to unmark domain %s as autostarted"), = name); - virDomainFree(dom); + virshDomainFree(dom); return false; } @@ -1065,7 +1063,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) else vshPrintExtra(ctl, _("Domain %s unmarked as autostarted\n"), name); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -1379,8 +1377,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -1577,7 +1574,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -2086,7 +2083,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2394,7 +2391,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xmlstr); virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2638,8 +2635,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) ret =3D virshBlockJobInfo(ctl, dom, path, raw, bytes); cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -2784,7 +2780,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2848,7 +2844,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) ret =3D true; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -2942,7 +2938,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) ret =3D cmdRunConsole(ctl, dom, name, flags); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } #endif /* WIN32 */ @@ -3123,7 +3119,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(xml_buf); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3314,7 +3310,7 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -3359,7 +3355,7 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3438,7 +3434,7 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3485,7 +3481,7 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3905,7 +3901,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_nodes); xmlFreeDoc(doc); xmlXPathFreeContext(ctxt); - virDomainFree(dom); + virshDomainFree(dom); return ret; error: @@ -4085,7 +4081,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(fds); return ret; } @@ -4183,8 +4179,7 @@ doSave(void *opaque) out: pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(xml); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -4344,7 +4339,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s saved to %s\n"), name, to); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -4607,8 +4602,7 @@ doManagedsave(void *opaque) out: pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -4651,7 +4645,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s state saved by libvirt\n"), name= ); cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return ret; @@ -4708,7 +4702,7 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *c= md) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -4943,7 +4937,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); virTypedParamsFree(updates, nupdates); - virDomainFree(dom); + virshDomainFree(dom); return ret_val; } @@ -5145,7 +5139,7 @@ doDump(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -5191,7 +5185,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s dumped to %s\n"), name, to); cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return ret; @@ -5330,7 +5324,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - virDomainFree(dom); + virshDomainFree(dom); if (st) virStreamFree(st); VIR_FORCE_CLOSE(fd); @@ -5399,7 +5393,7 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } /* @@ -5437,7 +5431,7 @@ cmdResume(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -5520,8 +5514,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virStringListFree(modes); return ret; } @@ -5600,8 +5593,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virStringListFree(modes); return ret; } @@ -5641,7 +5633,7 @@ cmdReset(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -5943,7 +5935,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virTypedParamsFree(params, nparams); return ret; @@ -5982,7 +5974,7 @@ cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) if (virDomainAbortJob(dom) < 0) ret =3D false; - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6183,7 +6175,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6437,7 +6429,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumaps); VIR_FREE(cpuinfo); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6653,7 +6645,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6714,13 +6706,13 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } query =3D !cpulist; if ((maxcpu =3D virshNodeGetCPUCount(priv->conn)) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } @@ -6757,7 +6749,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6853,7 +6845,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6939,7 +6931,7 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7021,7 +7013,7 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7079,7 +7071,7 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7155,7 +7147,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(info); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return niothreads >=3D 0; } @@ -7237,7 +7229,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7302,7 +7294,7 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7367,7 +7359,7 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7758,7 +7750,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; failed_stats: @@ -7854,7 +7846,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (console) cmdRunConsole(ctl, dom, NULL, 0); #endif - virDomainFree(dom); + virshDomainFree(dom); ret =3D true; cleanup: @@ -7913,7 +7905,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (dom !=3D NULL) { vshPrintExtra(ctl, _("Domain %s defined from %s\n"), virDomainGetName(dom), from); - virDomainFree(dom); + virshDomainFree(dom); } else { vshError(ctl, _("Failed to define domain from %s"), from); ret =3D false; @@ -7970,7 +7962,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8137,8 +8129,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) unlink(tmp); VIR_FREE(tmp); } - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8281,7 +8272,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8316,7 +8307,7 @@ cmdInjectNMI(vshControl *ctl, const vshCmd *cmd) if (virDomainInjectNMI(dom, 0) < 0) ret =3D false; - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8412,7 +8403,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8517,7 +8508,7 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *c= md) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8585,7 +8576,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max =3D ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } kibibytes =3D VIR_DIV_UP(bytes, 1024); @@ -8598,7 +8589,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8666,7 +8657,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max =3D ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } kibibytes =3D VIR_DIV_UP(bytes, 1024); @@ -8683,7 +8674,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) } } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8854,7 +8845,7 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -8993,7 +8984,7 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9126,7 +9117,7 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -9220,7 +9211,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *= cmd) VIR_FREE(result); VIR_FREE(monitor_cmd); virJSONValueFree(pretty); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9384,8 +9375,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cm= d) if (eventId >=3D 0 && virConnectDomainQemuMonitorEventDeregister(priv->conn, eventId) < = 0) ret =3D false; - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9431,7 +9421,7 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain %s attached to pid %u\n"), virDomainGetName(dom), pid_value); - virDomainFree(dom); + virshDomainFree(dom); ret =3D true; cleanup: @@ -9555,8 +9545,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cm= d) cleanup: VIR_FREE(result); VIR_FREE(guest_agent_cmd); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9697,8 +9686,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *c= md) cleanup: VIR_FREE(seclabel); VIR_FREE(secmodel); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(cmdargv); return ret; } @@ -9769,7 +9757,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9915,7 +9903,7 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd) return false; vshPrint(ctl, "%s\n", virDomainGetName(dom)); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -9962,7 +9950,7 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9999,7 +9987,7 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", "-"); else vshPrint(ctl, "%d\n", id); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -10036,7 +10024,7 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, "%s", _("failed to get domain UUID")); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -10466,7 +10454,7 @@ doMigrate(void *opaque) virDomainPtr ddom =3D NULL; if ((ddom =3D virDomainMigrate3(dom, dconn, params, nparams, flags= ))) { - virDomainFree(ddom); + virshDomainFree(ddom); ret =3D '0'; } } @@ -10475,8 +10463,7 @@ doMigrate(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: virTypedParamsFree(params, nparams); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); return; @@ -10632,7 +10619,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) virConnectClose(data.dconn); if (iterEvent !=3D -1) virConnectDomainEventDeregisterAny(priv->conn, iterEvent); - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return functionReturn; @@ -10684,7 +10671,7 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vsh= Cmd *cmd) ret =3D true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10741,7 +10728,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *= cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10788,7 +10775,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd= *cmd) ret =3D true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10828,7 +10815,7 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd= *cmd) ret =3D true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10870,7 +10857,7 @@ cmdMigratePostCopy(vshControl *ctl, const vshCmd *c= md) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11127,7 +11114,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(output); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11208,7 +11195,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11264,7 +11251,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeObject(obj); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11307,7 +11294,7 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) error: VIR_FREE(hostname); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11504,7 +11491,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return funcRet; } @@ -11586,7 +11573,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11772,7 +11759,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *c= md) } VIR_FREE(doc_live); VIR_FREE(doc_config); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -12129,7 +12116,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) xmlFreeNode(disk_node); VIR_FREE(disk_xml); VIR_FREE(doc); - virDomainFree(dom); + virshDomainFree(dom); return functionReturn; } @@ -12196,10 +12183,8 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - if (dom) - virDomainFree(dom); - if (dom_edited) - virDomainFree(dom_edited); + virshDomainFree(dom); + virshDomainFree(dom_edited); return ret; } @@ -13087,8 +13072,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(data); } - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13253,7 +13237,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) VIR_FREE(doc); xmlFreeNode(disk_node); VIR_FREE(disk_xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13306,7 +13290,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13359,7 +13343,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virDomainFree(dom); + virshDomainFree(dom); return ret >=3D 0; } @@ -13412,7 +13396,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virDomainFree(dom); + virshDomainFree(dom); return ret >=3D 0; } @@ -13472,7 +13456,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret >=3D 0; } diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 46e2cbb24..5af9a7d7a 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -210,8 +210,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -454,7 +453,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) cleanup: virBufferFreeAndReset(&buf); VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -606,7 +605,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) virDomainSnapshotFree(edited); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -720,7 +719,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1008,7 +1007,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(parent); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1647,7 +1646,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(doc); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1711,7 +1710,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1771,8 +1770,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) VIR_FREE(parent); if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1857,8 +1855,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd= *cmd) cleanup: if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1940,8 +1937,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) cleanup: if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 5c99655fb..5fdb40855 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -150,3 +150,13 @@ virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED, return safewrite(*fd, bytes, nbytes); } + + +void +virshDomainFree(virDomainPtr dom) +{ + if (!dom) + return; + + virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 132bf0b4b..78f7a0ea9 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -38,6 +38,9 @@ virshCommandOptDomain(vshControl *ctl, const vshCmd *cmd, const char **name); +void +virshDomainFree(virDomainPtr dom); + int virshDomainState(vshControl *ctl, virDomainPtr dom, --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 1491926061059110.41800072725187; Tue, 11 Apr 2017 08:54:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id BE8D63DBCA; Tue, 11 Apr 2017 15:54:19 +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 91EE27ED84; Tue, 11 Apr 2017 15:54:19 +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 4647B18523D2; Tue, 11 Apr 2017 15:54:19 +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 v3BFs4FM001623 for ; Tue, 11 Apr 2017 11:54:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 836587ED83; Tue, 11 Apr 2017 15:54:04 +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 D83C57ED98; Tue, 11 Apr 2017 15:54:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE8D63DBCA Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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 BE8D63DBCA From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:50 +0200 Message-Id: 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 4/9] virsh: Add wrapper for virDomainSnapshotFree 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Apr 2017 15:54:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. --- tools/virsh-snapshot.c | 48 ++++++++++++++++++----------------------------= -- tools/virsh-util.c | 10 ++++++++++ tools/virsh-util.h | 3 +++ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 5af9a7d7a..24cd4abd9 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -106,8 +106,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, = const char *buffer, cleanup: xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); VIR_FREE(doc); return ret; } @@ -601,10 +600,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) cleanup: if (!ret && name) vshError(ctl, _("Failed to update %s"), name); - if (edited) - virDomainSnapshotFree(edited); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(edited); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; } @@ -681,7 +678,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!(snapshot2 =3D virDomainSnapshotCreateXML(dom, xml, flags))) goto cleanup; - virDomainSnapshotFree(snapshot2); + virshDomainSnapshotFree(snapshot2); vshPrintExtra(ctl, _("Snapshot %s set as current"), snapshotname); ret =3D true; goto cleanup; @@ -717,8 +714,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!ret) vshReportError(ctl); VIR_FREE(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -777,8 +773,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapsh= otPtr snapshot, } else { vshResetLibvirtError(); } - if (parent) - virDomainSnapshotFree(parent); + virshDomainSnapshotFree(parent); xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); VIR_FREE(xml); @@ -906,7 +901,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) if (other) { if (STREQ(name, virDomainSnapshotGetName(other))) current =3D 1; - virDomainSnapshotFree(other); + virshDomainSnapshotFree(other); } } vshPrint(ctl, "%-15s %s\n", _("Current:"), @@ -1005,8 +1000,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) xmlFreeDoc(xmldoc); VIR_FREE(doc); VIR_FREE(parent); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; } @@ -1031,8 +1025,7 @@ virshSnapshotListFree(virshSnapshotListPtr snaplist) return; if (snaplist->snaps) { for (i =3D 0; i < snaplist->nsnaps; i++) { - if (snaplist->snaps[i].snap) - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); VIR_FREE(snaplist->snaps[i].parent); } VIR_FREE(snaplist->snaps); @@ -1270,7 +1263,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, STRNEQ_NULLABLE(fromname, snaplist->snaps[i].parent)))) || (roots && snaplist->snaps[i].parent)) { - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1298,7 +1291,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, for (i =3D 0; i < count; i++) { if (i =3D=3D start_index || !snaplist->snaps[i].parent) { VIR_FREE(names[i]); - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1336,7 +1329,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, if (!found_parent) { changed =3D true; VIR_FREE(names[i]); - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1359,7 +1352,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, case 1: break; case 0: - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1641,8 +1634,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) virshSnapshotListFree(snaplist); VIR_FREE(parent_snap); VIR_FREE(state); - if (start) - virDomainSnapshotFree(start); + virshDomainSnapshotFree(start); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(doc); @@ -1708,8 +1700,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1768,8 +1759,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(parent); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1853,8 +1843,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd= *cmd) ret =3D true; cleanup: - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1935,8 +1924,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 5fdb40855..e225d3332 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -160,3 +160,13 @@ virshDomainFree(virDomainPtr dom) virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ } + + +void +virshDomainSnapshotFree(virDomainSnapshotPtr snap) +{ + if (!snap) + return; + + virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 78f7a0ea9..2b5aedfba 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl, void virshDomainFree(virDomainPtr dom); +void +virshDomainSnapshotFree(virDomainSnapshotPtr snap); + int virshDomainState(vshControl *ctl, virDomainPtr dom, --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 1491926056748516.5616679075597; Tue, 11 Apr 2017 08:54:16 -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 73EA83DBC4; Tue, 11 Apr 2017 15:54: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 4783D7B52A; 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 E522418523CE; 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 v3BFs5bp001630 for ; Tue, 11 Apr 2017 11:54:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77C917ED84; Tue, 11 Apr 2017 15:54:05 +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 CD1FA7ED83; Tue, 11 Apr 2017 15:54:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 73EA83DBC4 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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 73EA83DBC4 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:51 +0200 Message-Id: <396ca0a42d524a2e1cae55415c8f96f7a6035cf6.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 5/9] vsh: Add helper for safe remembering of libvirt errors 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.30]); Tue, 11 Apr 2017 15:54:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Avoid the annoying issue where the public object freeing APIs overwrite the error set by helper functions, since they don't invoke the callback. The new helper remembers the error only if no previous error was set. --- tools/virsh-util.c | 2 ++ tools/vsh.c | 15 +++++++++++++++ tools/vsh.h | 1 + 3 files changed, 18 insertions(+) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index e225d3332..79a38bb23 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -158,6 +158,7 @@ virshDomainFree(virDomainPtr dom) if (!dom) return; + vshSaveLibvirtHelperError(); virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ } @@ -168,5 +169,6 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) if (!snap) return; + vshSaveLibvirtHelperError(); virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ } diff --git a/tools/vsh.c b/tools/vsh.c index d2024be91..10a65c39f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -258,6 +258,21 @@ vshSaveLibvirtError(void) last_error =3D virSaveLastError(); } + +/* Store libvirt error from helper API but don't overwrite existing errors= */ +void +vshSaveLibvirtHelperError(void) +{ + if (last_error) + return; + + if (!virGetLastError()) + return; + + vshSaveLibvirtError(); +} + + /* * Reset libvirt error on graceful fallback paths */ diff --git a/tools/vsh.h b/tools/vsh.h index 8f5d1a69f..2f686eba6 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -341,6 +341,7 @@ void vshErrorHandler(void *opaque, virErrorPtr error); void vshReportError(vshControl *ctl); void vshResetLibvirtError(void); void vshSaveLibvirtError(void); +void vshSaveLibvirtHelperError(void); /* file handling */ char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 149192606050565.21145838926498; Tue, 11 Apr 2017 08:54:20 -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 04A70804F0; Tue, 11 Apr 2017 15:54:19 +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 C582D7B552; Tue, 11 Apr 2017 15:54:18 +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 7B96918523D1; Tue, 11 Apr 2017 15:54:18 +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 v3BFs682001638 for ; Tue, 11 Apr 2017 11:54:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id C87027ED9B; Tue, 11 Apr 2017 15:54:06 +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 C27A87ED83; Tue, 11 Apr 2017 15:54:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 04A70804F0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 04A70804F0 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:52 +0200 Message-Id: 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 6/9] virsh: add helpers for getting domain XML for XPath purposes 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.27]); Tue, 11 Apr 2017 15:54:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In virsh we quite often get the domain XML just to initialize the XPath parser so that we can extract information. Add helpers which will simplify this by wrapping the getting of the XML and parsing it along with error reporting. Additionally a second helper also gets the domain object from the parameters and releases it so that functions which need the XML as only source of data can be simplified further. --- tools/virsh-util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh-util.h | 20 ++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 79a38bb23..4b86e29cb 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -22,6 +22,7 @@ #include "virfile.h" #include "virstring.h" +#include "viralloc.h" static virDomainPtr virshLookupDomainInternal(vshControl *ctl, @@ -172,3 +173,50 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) vshSaveLibvirtHelperError(); virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ } + + +int +virshDomainGetXMLFromDom(vshControl *ctl, + virDomainPtr dom, + unsigned int flags, + xmlDocPtr *xml, + xmlXPathContextPtr *ctxt) +{ + char *desc =3D NULL; + + if (!(desc =3D virDomainGetXMLDesc(dom, flags))) { + vshError(ctl, _("Failed to get domain description xml")); + return -1; + } + + *xml =3D virXMLParseStringCtxt(desc, _("(domain_definition)"), ctxt); + VIR_FREE(desc); + + if (!(*xml)) { + vshError(ctl, _("Failed to parse domain description xml")); + return -1; + } + + return 0; +} + + +int +virshDomainGetXML(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags, + xmlDocPtr *xml, + xmlXPathContextPtr *ctxt) +{ + virDomainPtr dom; + int ret; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return -1; + + ret =3D virshDomainGetXMLFromDom(ctl, dom, flags, xml, ctxt); + + virshDomainFree(dom); + + return ret; +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 2b5aedfba..64cef23c0 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -21,6 +21,8 @@ # include "virsh.h" +# include +# include virDomainPtr virshLookupDomainBy(vshControl *ctl, @@ -55,4 +57,22 @@ virshStreamSink(virStreamPtr st, size_t nbytes, void *opaque); +int +virshDomainGetXMLFromDom(vshControl *ctl, + virDomainPtr dom, + unsigned int flags, + xmlDocPtr *xml, + xmlXPathContextPtr *ctxt) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4) + ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK; + +int +virshDomainGetXML(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags, + xmlDocPtr *xml, + xmlXPathContextPtr *ctxt) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4) + ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK; + #endif /* VIRSH_UTIL_H */ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:21:05 2024 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 From nobody Wed May 8 02:21:05 2024 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 From nobody Wed May 8 02:21:05 2024 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 1491926074321360.7803938120709; Tue, 11 Apr 2017 08:54:34 -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 04B008FCEE; Tue, 11 Apr 2017 15:54:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF96B18ED9; Tue, 11 Apr 2017 15:54:32 +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 5F6965EC6B; Tue, 11 Apr 2017 15:54:26 +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 v3BFsAXx001682 for ; Tue, 11 Apr 2017 11:54:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id A65C37ED8A; Tue, 11 Apr 2017 15:54:10 +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 454917ED8E; Tue, 11 Apr 2017 15:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 04B008FCEE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 04B008FCEE From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:53:55 +0200 Message-Id: <615a25f076b1523934775c59c5029f741791d33b.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 9/9] virsh-domain: Refactor cmdTTYConsole 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.26]); Tue, 11 Apr 2017 15:54:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the new XML helpers and use virXPathString rather than hand-rolling the code. --- tools/virsh-domain.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d64a2dca0..d6f33b1ee 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11183,37 +11183,23 @@ static bool cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml =3D NULL; - xmlXPathObjectPtr obj =3D NULL; xmlXPathContextPtr ctxt =3D NULL; - virDomainPtr dom; bool ret =3D false; - char *doc; + char *tty =3D NULL; - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; - doc =3D virDomainGetXMLDesc(dom, 0); - if (!doc) + if (!(tty =3D virXPathString("string(/domain/devices/console/@tty)", c= txt))) goto cleanup; - xml =3D virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt); - VIR_FREE(doc); - if (!xml) - goto cleanup; - - obj =3D xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", = ctxt); - if (obj =3D=3D NULL || obj->type !=3D XPATH_STRING || - obj->stringval =3D=3D NULL || obj->stringval[0] =3D=3D 0) { - goto cleanup; - } - vshPrint(ctl, "%s\n", (const char *)obj->stringval); + vshPrint(ctl, "%s\n", tty); ret =3D true; cleanup: - xmlXPathFreeObject(obj); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); + VIR_FREE(tty); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list