From nobody Thu May 15 03:11:17 2025 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.zohomail.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 1516783874345782.166369192372; Wed, 24 Jan 2018 00:51:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D456180B2A; Wed, 24 Jan 2018 08:51:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB6573818A; Wed, 24 Jan 2018 08:51:12 +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 51FBE4ED37; Wed, 24 Jan 2018 08:51:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0O8pB9o003342 for ; Wed, 24 Jan 2018 03:51:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1A58B5EDEB; Wed, 24 Jan 2018 08:51:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57B885D6A8; Wed, 24 Jan 2018 08:51:06 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 24 Jan 2018 09:50:55 +0100 Message-Id: <906b57e62b71efa5dd15d9cc000b0eaf2e92f7b1.1516783466.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/9] virsh: Introduce virshStoragePoolNameCompleter 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 24 Jan 2018 08:51:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- Diff to v1: - Pruned the list of flags accepted in the callback - Pools for vol_* are ACTIVE only - Other small nits raised in the review tools/virsh-completer.c | 48 +++++++++++++++++++++++++++++++++++++++++++++= +++ tools/virsh-completer.h | 4 ++++ tools/virsh-pool.c | 28 ++++++++++++++-------------- tools/virsh-volume.c | 10 +++++++--- tools/virsh.h | 6 ++++-- 5 files changed, 77 insertions(+), 19 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 48dd9fbc2..947c326fc 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -147,3 +147,51 @@ virshDomainInterfaceCompleter(vshControl *ctl, virStringListFree(ret); return NULL; } + + +char ** +virshStoragePoolNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virStoragePoolPtr *pools =3D NULL; + int npools =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE | + VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | + VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((npools =3D virConnectListAllStoragePools(priv->conn, &pools, flag= s)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, npools + 1) < 0) + goto error; + + for (i =3D 0; i < npools; i++) { + const char *name =3D virStoragePoolGetName(pools[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virStoragePoolFree(pools[i]); + } + VIR_FREE(pools); + + return ret; + + error: + for (; i < npools; i++) + virStoragePoolFree(pools[i]); + VIR_FREE(pools); + for (i =3D 0; i < npools; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 1a2dd685f..249e793b9 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -38,4 +38,8 @@ char ** virshDomainInterfaceCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshStoragePoolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 094874b64..56b6cfc73 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -34,8 +34,8 @@ #include "virstring.h" #include "virtime.h" =20 -#define VIRSH_COMMON_OPT_POOL_FULL \ - VIRSH_COMMON_OPT_POOL(N_("pool name or uuid")) +#define VIRSH_COMMON_OPT_POOL_FULL(cflags) \ + VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags) =20 #define VIRSH_COMMON_OPT_POOL_BUILD \ {.name =3D "build", \ @@ -182,7 +182,7 @@ static const vshCmdInfo info_pool_autostart[] =3D { }; =20 static const vshCmdOptDef opts_pool_autostart[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT), =20 {.name =3D "disable", .type =3D VSH_OT_BOOL, @@ -575,7 +575,7 @@ static const vshCmdInfo info_pool_build[] =3D { }; =20 static const vshCmdOptDef opts_pool_build[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), VIRSH_COMMON_OPT_POOL_NO_OVERWRITE, VIRSH_COMMON_OPT_POOL_OVERWRITE, =20 @@ -625,7 +625,7 @@ static const vshCmdInfo info_pool_destroy[] =3D { }; =20 static const vshCmdOptDef opts_pool_destroy[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE), =20 {.name =3D NULL} }; @@ -665,7 +665,7 @@ static const vshCmdInfo info_pool_delete[] =3D { }; =20 static const vshCmdOptDef opts_pool_delete[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE), =20 {.name =3D NULL} }; @@ -705,7 +705,7 @@ static const vshCmdInfo info_pool_refresh[] =3D { }; =20 static const vshCmdOptDef opts_pool_refresh[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D NULL} }; @@ -745,7 +745,7 @@ static const vshCmdInfo info_pool_dumpxml[] =3D { }; =20 static const vshCmdOptDef opts_pool_dumpxml[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D "inactive", .type =3D VSH_OT_BOOL, @@ -1636,7 +1636,7 @@ static const vshCmdInfo info_pool_info[] =3D { }; =20 static const vshCmdOptDef opts_pool_info[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D "bytes", .type =3D VSH_OT_BOOL, @@ -1726,7 +1726,7 @@ static const vshCmdInfo info_pool_name[] =3D { }; =20 static const vshCmdOptDef opts_pool_name[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D NULL} }; @@ -1758,7 +1758,7 @@ static const vshCmdInfo info_pool_start[] =3D { }; =20 static const vshCmdOptDef opts_pool_start[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE), VIRSH_COMMON_OPT_POOL_BUILD, VIRSH_COMMON_OPT_POOL_NO_OVERWRITE, VIRSH_COMMON_OPT_POOL_OVERWRITE, @@ -1819,7 +1819,7 @@ static const vshCmdInfo info_pool_undefine[] =3D { }; =20 static const vshCmdOptDef opts_pool_undefine[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT), =20 {.name =3D NULL} }; @@ -1859,7 +1859,7 @@ static const vshCmdInfo info_pool_uuid[] =3D { }; =20 static const vshCmdOptDef opts_pool_uuid[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D NULL} }; @@ -1896,7 +1896,7 @@ static const vshCmdInfo info_pool_edit[] =3D { }; =20 static const vshCmdOptDef opts_pool_edit[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), =20 {.name =3D NULL} }; diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 8265a3979..bfbb7c7d7 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -44,15 +44,19 @@ #include "virstring.h" =20 #define VIRSH_COMMON_OPT_POOL_FULL \ - VIRSH_COMMON_OPT_POOL(N_("pool name or uuid")) + VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \ + VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE) =20 #define VIRSH_COMMON_OPT_POOL_NAME \ - VIRSH_COMMON_OPT_POOL(N_("pool name")) + VIRSH_COMMON_OPT_POOL(N_("pool name"), \ + VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE) =20 #define VIRSH_COMMON_OPT_POOL_OPTIONAL \ {.name =3D "pool", \ .type =3D VSH_OT_STRING, \ - .help =3D N_("pool name or uuid") \ + .help =3D N_("pool name or uuid"), \ + .completer =3D virshStoragePoolNameCompleter, \ + .completer_flags =3D VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE, \ } =20 #define VIRSH_COMMON_OPT_VOLUME_VOL \ diff --git a/tools/virsh.h b/tools/virsh.h index 528e04558..f2213ebb5 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -64,11 +64,13 @@ /* * Common command options */ -# define VIRSH_COMMON_OPT_POOL(_helpstr) \ +# define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \ {.name =3D "pool", \ .type =3D VSH_OT_DATA, \ .flags =3D VSH_OFLAG_REQ, \ - .help =3D _helpstr \ + .help =3D _helpstr, \ + .completer =3D virshStoragePoolNameCompleter, \ + .completer_flags =3D cflags, \ } =20 # define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list