From nobody Mon Dec 15 03:26:45 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 1515767959595508.35659816862915; Fri, 12 Jan 2018 06:39:19 -0800 (PST) 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 63745C049D56; Fri, 12 Jan 2018 14:39:02 +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 A3A6B65609; Fri, 12 Jan 2018 14:39:00 +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 465B118033DC; Fri, 12 Jan 2018 14:38:57 +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 w0CEbsS9025291 for ; Fri, 12 Jan 2018 09:37:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4753D5D6A6; Fri, 12 Jan 2018 14:37:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFF906B43D for ; Fri, 12 Jan 2018 14:37:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 15:37:36 +0100 Message-Id: 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 2/8] virsh: Introduce virshStorageVolNameCompleter 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.31]); Fri, 12 Jan 2018 14:39:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This one is a bit simpler since virStoragePoolListAllVolumes() has no flags yet. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- tools/virsh-completer.c | 52 +++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-completer.h | 4 ++++ tools/virsh-volume.c | 3 ++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 8ca2fffd9..d6ac0ccb8 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -24,6 +24,7 @@ =20 #include "virsh-completer.h" #include "virsh.h" +#include "virsh-pool.h" #include "virsh-util.h" #include "internal.h" #include "viralloc.h" @@ -198,3 +199,54 @@ virshStoragePoolNameCompleter(vshControl *ctl, VIR_FREE(ret); return NULL; } + + +char ** +virshStorageVolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virStoragePoolPtr pool =3D NULL; + virStorageVolPtr *vols =3D NULL; + int nvols =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) + return false; + + if ((nvols =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) + goto error; + + if (VIR_ALLOC_N(ret, nvols + 1) < 0) + goto error; + + for (i =3D 0; i < nvols; i++) { + const char *name =3D virStorageVolGetName(vols[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virStorageVolFree(vols[i]); + } + VIR_FREE(vols); + virStoragePoolFree(pool); + + return ret; + + error: + for (; i < nvols; i++) + virStorageVolFree(vols[i]); + VIR_FREE(vols); + for (i =3D 0; i < nvols; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + virStoragePoolFree(pool); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 249e793b9..1e4ce5932 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -42,4 +42,8 @@ char ** virshStoragePoolNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshStorageVolNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b96e205f7..c1f36d9b9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -61,7 +61,8 @@ {.name =3D "vol", \ .type =3D VSH_OT_DATA, \ .flags =3D VSH_OFLAG_REQ, \ - .help =3D N_("vol name, key or path") \ + .help =3D N_("vol name, key or path"), \ + .completer =3D virshStorageVolNameCompleter, \ } =20 virStorageVolPtr --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list