virsh-volume: Introduce virshStorageVolKeyCompleter

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Lin Ma 2021-06-16 16:02:51 +08:00 committed by Michal Privoznik
parent 64787c80fc
commit 254504adc3
2 changed files with 52 additions and 0 deletions

View File

@ -69,3 +69,50 @@ virshStorageVolNameCompleter(vshControl *ctl,
g_free(vols);
return ret;
}
char **
virshStorageVolKeyCompleter(vshControl *ctl,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int flags)
{
virshControl *priv = ctl->privData;
struct virshStoragePoolList *list = NULL;
virStorageVolPtr *vols = NULL;
int rc;
int nvols = 0;
size_t i = 0, j = 0;
char **ret = NULL;
g_auto(GStrv) tmp = NULL;
virCheckFlags(0, NULL);
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
return NULL;
list = virshStoragePoolListCollect(ctl, VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE);
if (!list)
goto cleanup;
for (i = 0; i < list->npools; i++) {
if ((rc = virStoragePoolListAllVolumes(list->pools[i], &vols, 0)) < 0)
goto cleanup;
tmp = g_renew(char *, tmp, nvols + rc + 1);
memset(&tmp[nvols], 0, sizeof(*tmp) * (rc + 1));
for (j = 0; j < rc; j++) {
const char *key = virStorageVolGetKey(vols[j]);
tmp[nvols] = g_strdup(key);
nvols++;
virStorageVolFree(vols[j]);
}
g_free(vols);
}
ret = g_steal_pointer(&tmp);
cleanup:
virshStoragePoolListFree(list);
return ret;
}

View File

@ -26,3 +26,8 @@
char ** virshStorageVolNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshStorageVolKeyCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);