mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-06 20:00:05 +00:00
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:
parent
64787c80fc
commit
254504adc3
@ -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;
|
||||
}
|
||||
|
@ -26,3 +26,8 @@
|
||||
char ** virshStorageVolNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
|
||||
char ** virshStorageVolKeyCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
Loading…
x
Reference in New Issue
Block a user