From nobody Wed May 14 23:25:39 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 1515767891091280.26216991552667; Fri, 12 Jan 2018 06:38:11 -0800 (PST) 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 2A7A3C056781; Fri, 12 Jan 2018 14:38:03 +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 263985D962; Fri, 12 Jan 2018 14:38:01 +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 EB90D410B3; Fri, 12 Jan 2018 14:37:54 +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 w0CEbr5P025285 for ; Fri, 12 Jan 2018 09:37:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6E96965609; Fri, 12 Jan 2018 14:37:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id C168565626 for ; Fri, 12 Jan 2018 14:37:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:35 +0100 Message-Id: <651d0b3af7aa97c0ccd4844dea199c16fc6aaf1d.1515767806.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 12 Jan 2018 14:38:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 51 +++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-completer.h | 4 ++++ tools/virsh-pool.c | 28 +++++++++++++-------------- tools/virsh-volume.c | 42 +++++++++++++++++++++------------------- tools/virsh.h | 6 ++++-- 5 files changed, 95 insertions(+), 36 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 48dd9fbc2..8ca2fffd9 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -147,3 +147,54 @@ 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 | + VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT | + VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART | + VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART, + 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..cea4cfc12 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(0), =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(0), =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..b96e205f7 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -43,16 +43,18 @@ #include "virxml.h" #include "virstring.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_NAME \ - VIRSH_COMMON_OPT_POOL(N_("pool name")) +#define VIRSH_COMMON_OPT_POOL_NAME(cflags) \ + VIRSH_COMMON_OPT_POOL(N_("pool name"), cflags) =20 -#define VIRSH_COMMON_OPT_POOL_OPTIONAL \ +#define VIRSH_COMMON_OPT_POOL_OPTIONAL(cflags) \ {.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 cflags, \ } =20 #define VIRSH_COMMON_OPT_VOLUME_VOL \ @@ -165,7 +167,7 @@ static const vshCmdInfo info_vol_create_as[] =3D { }; =20 static const vshCmdOptDef opts_vol_create_as[] =3D { - VIRSH_COMMON_OPT_POOL_NAME, + VIRSH_COMMON_OPT_POOL_NAME(0), {.name =3D "name", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -378,7 +380,7 @@ static const vshCmdInfo info_vol_create[] =3D { }; =20 static const vshCmdOptDef opts_vol_create[] =3D { - VIRSH_COMMON_OPT_POOL_NAME, + VIRSH_COMMON_OPT_POOL_NAME(0), VIRSH_COMMON_OPT_FILE(N_("file containing an XML vol description")), {.name =3D "prealloc-metadata", .type =3D VSH_OT_BOOL, @@ -440,7 +442,7 @@ static const vshCmdInfo info_vol_create_from[] =3D { }; =20 static const vshCmdOptDef opts_vol_create_from[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), VIRSH_COMMON_OPT_FILE(N_("file containing an XML vol description")), VIRSH_COMMON_OPT_VOLUME_VOL, {.name =3D "inputpool", @@ -559,7 +561,7 @@ static const vshCmdOptDef opts_vol_clone[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("clone name") }, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "prealloc-metadata", .type =3D VSH_OT_BOOL, .help =3D N_("preallocate metadata (for qcow2 instead of full allocat= ion)") @@ -651,7 +653,7 @@ static const vshCmdInfo info_vol_upload[] =3D { static const vshCmdOptDef opts_vol_upload[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, VIRSH_COMMON_OPT_FILE(N_("file")), - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "offset", .type =3D VSH_OT_INT, .help =3D N_("volume offset to upload to") @@ -766,7 +768,7 @@ static const vshCmdInfo info_vol_download[] =3D { static const vshCmdOptDef opts_vol_download[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, VIRSH_COMMON_OPT_FILE(N_("file")), - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "offset", .type =3D VSH_OT_INT, .help =3D N_("volume offset to download from") @@ -875,7 +877,7 @@ static const vshCmdInfo info_vol_delete[] =3D { =20 static const vshCmdOptDef opts_vol_delete[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "delete-snapshots", .type =3D VSH_OT_BOOL, .help =3D N_("delete snapshots associated with volume (must be " @@ -925,7 +927,7 @@ static const vshCmdInfo info_vol_wipe[] =3D { =20 static const vshCmdOptDef opts_vol_wipe[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "algorithm", .type =3D VSH_OT_STRING, .help =3D N_("perform selected wiping algorithm") @@ -1012,7 +1014,7 @@ static const vshCmdInfo info_vol_info[] =3D { =20 static const vshCmdOptDef opts_vol_info[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "bytes", .type =3D VSH_OT_BOOL, .help =3D N_("sizes are represented in bytes rather than pretty units= ") @@ -1107,7 +1109,7 @@ static const vshCmdOptDef opts_vol_resize[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("new capacity for the vol, as scaled integer (default by= tes)") }, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D "allocate", .type =3D VSH_OT_BOOL, .help =3D N_("allocate the new capacity, rather than leaving it spars= e") @@ -1199,7 +1201,7 @@ static const vshCmdInfo info_vol_dumpxml[] =3D { =20 static const vshCmdOptDef opts_vol_dumpxml[] =3D { VIRSH_COMMON_OPT_VOLUME_VOL, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D NULL} }; =20 @@ -1363,7 +1365,7 @@ static const vshCmdInfo info_vol_list[] =3D { }; =20 static const vshCmdOptDef opts_vol_list[] =3D { - VIRSH_COMMON_OPT_POOL_FULL, + VIRSH_COMMON_OPT_POOL_FULL(0), {.name =3D "details", .type =3D VSH_OT_BOOL, .help =3D N_("display extended details for volumes") @@ -1705,7 +1707,7 @@ static const vshCmdOptDef opts_vol_key[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("volume name or path") }, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D NULL} }; =20 @@ -1741,7 +1743,7 @@ static const vshCmdOptDef opts_vol_path[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("volume name or key") }, - VIRSH_COMMON_OPT_POOL_OPTIONAL, + VIRSH_COMMON_OPT_POOL_OPTIONAL(0), {.name =3D NULL} }; =20 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