From nobody Mon Feb 9 01:17:04 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 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