2019-07-13 19:36:26 +03:00
/*
* virsh - completer - volume . c : virsh completer callbacks related to volumes
*
* Copyright ( C ) 2019 Red Hat , Inc .
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library . If not , see
* < http : //www.gnu.org/licenses/>.
*/
# include <config.h>
# include "virsh-completer-volume.h"
2021-09-26 10:25:41 +03:00
# include "virsh-util.h"
2019-07-13 19:36:26 +03:00
# include "virsh-pool.h"
# include "virsh.h"
2022-03-10 18:22:24 +03:00
# include "virsh-volume.h"
2019-07-13 19:36:26 +03:00
char * *
virshStorageVolNameCompleter ( vshControl * ctl ,
const vshCmd * cmd ,
unsigned int flags )
{
2021-03-11 10:16:13 +03:00
virshControl * priv = ctl - > privData ;
2021-09-26 10:25:41 +03:00
g_autoptr ( virshStoragePool ) pool = NULL ;
2019-07-13 19:36:26 +03:00
virStorageVolPtr * vols = NULL ;
int rc ;
int nvols = 0 ;
size_t i = 0 ;
char * * ret = NULL ;
2020-12-01 11:21:32 +03:00
g_auto ( GStrv ) tmp = NULL ;
2019-07-13 19:36:26 +03:00
virCheckFlags ( 0 , NULL ) ;
if ( ! priv - > conn | | virConnectIsAlive ( priv - > conn ) < = 0 )
return NULL ;
if ( ! ( pool = virshCommandOptPool ( ctl , cmd , " pool " , NULL ) ) )
return NULL ;
if ( ( rc = virStoragePoolListAllVolumes ( pool , & vols , flags ) ) < 0 )
goto cleanup ;
nvols = rc ;
2020-09-14 17:24:44 +03:00
tmp = g_new0 ( char * , nvols + 1 ) ;
2019-07-13 19:36:26 +03:00
for ( i = 0 ; i < nvols ; i + + ) {
const char * name = virStorageVolGetName ( vols [ i ] ) ;
2019-10-20 14:49:46 +03:00
tmp [ i ] = g_strdup ( name ) ;
2019-07-13 19:36:26 +03:00
}
2019-10-16 14:43:36 +03:00
ret = g_steal_pointer ( & tmp ) ;
2019-07-13 19:36:26 +03:00
cleanup :
for ( i = 0 ; i < nvols ; i + + )
2021-09-26 11:28:06 +03:00
virshStorageVolFree ( vols [ i ] ) ;
2020-09-14 17:10:15 +03:00
g_free ( vols ) ;
2019-07-13 19:36:26 +03:00
return ret ;
}
2021-06-16 11:02:51 +03:00
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 + + ;
2021-09-26 11:28:06 +03:00
virshStorageVolFree ( vols [ j ] ) ;
2021-06-16 11:02:51 +03:00
}
g_free ( vols ) ;
}
ret = g_steal_pointer ( & tmp ) ;
cleanup :
virshStoragePoolListFree ( list ) ;
return ret ;
}
2022-03-10 18:22:24 +03:00
char * *
virshStorageVolWipeAlgorithmCompleter ( vshControl * ctl G_GNUC_UNUSED ,
const vshCmd * cmd G_GNUC_UNUSED ,
unsigned int flags )
{
virCheckFlags ( 0 , NULL ) ;
2022-03-12 07:41:56 +03:00
return virshEnumComplete ( VIR_STORAGE_VOL_WIPE_ALG_LAST ,
virshStorageVolWipeAlgorithmTypeToString ) ;
2022-03-10 18:22:24 +03:00
}