mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
list: Define new API virStorageListAllStoragePools
This introduces a new API to list the storage pool objects, 4 groups of flags are provided to filter the returned pools: * Active or not * Autostarting or not * Persistent or not * And the pool type. include/libvirt/libvirt.h.in: New enum virConnectListAllStoragePoolFlags; Declare the API. python/generator.py: Skip the generating src/driver.h: (virDrvConnectListAllStoragePools) src/libvirt.c: Implementation for the API. src/libvirt_public.syms: Export the symbol.
This commit is contained in:
parent
9e0ba44faf
commit
075c754af0
@ -2553,6 +2553,39 @@ int virConnectListDefinedStoragePools(virConnectPtr conn,
|
||||
char **const names,
|
||||
int maxnames);
|
||||
|
||||
/*
|
||||
* virConnectListAllStoragePoolsFlags:
|
||||
*
|
||||
* Flags used to tune pools returned by virConnectListAllStoragePools().
|
||||
* Note that these flags come in groups; if all bits from a group are 0,
|
||||
* then that group is not used to filter results.
|
||||
*/
|
||||
typedef enum {
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE = 1 << 0,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE = 1 << 1,
|
||||
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT = 1 << 2,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT = 1 << 3,
|
||||
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART = 1 << 4,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART = 1 << 5,
|
||||
|
||||
/* List pools by type */
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_DIR = 1 << 6,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_FS = 1 << 7,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_NETFS = 1 << 8,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL = 1 << 9,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_DISK = 1 << 10,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI = 1 << 11,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_SCSI = 1 << 12,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_MPATH = 1 << 13,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_RBD = 1 << 14,
|
||||
VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG = 1 << 15,
|
||||
} virConnectListAllStoragePoolsFlags;
|
||||
|
||||
int virConnectListAllStoragePools(virConnectPtr conn,
|
||||
virStoragePoolPtr **pools,
|
||||
unsigned int flags);
|
||||
/*
|
||||
* Query a host for storage pools of a particular type
|
||||
*/
|
||||
|
@ -337,7 +337,7 @@ foreign_encoding_args = (
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
# Class methods which are written by hand in libvir.c but the Python-level
|
||||
# Class methods which are written by hand in libvirt.c but the Python-level
|
||||
# code is still automatically generated (so they are not in skip_function()).
|
||||
skip_impl = (
|
||||
'virConnectGetVersion',
|
||||
@ -457,9 +457,10 @@ skip_function = (
|
||||
'virConnectDomainEventDeregisterAny', # overridden in virConnect.py
|
||||
'virSaveLastError', # We have our own python error wrapper
|
||||
'virFreeError', # Only needed if we use virSaveLastError
|
||||
'virConnectListAllDomains', #overridden in virConnect.py
|
||||
'virConnectListAllDomains', # overridden in virConnect.py
|
||||
'virDomainListAllSnapshots', # overridden in virDomain.py
|
||||
'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
|
||||
'virConnectListAllStoragePools', # overridden in virConnect.py
|
||||
|
||||
'virStreamRecvAll', # Pure python libvirt-override-virStream.py
|
||||
'virStreamSendAll', # Pure python libvirt-override-virStream.py
|
||||
|
@ -1252,6 +1252,10 @@ typedef int
|
||||
(*virDrvConnectListDefinedStoragePools) (virConnectPtr conn,
|
||||
char **const names,
|
||||
int maxnames);
|
||||
typedef int
|
||||
(*virDrvConnectListAllStoragePools) (virConnectPtr conn,
|
||||
virStoragePoolPtr **pools,
|
||||
unsigned int flags);
|
||||
typedef char *
|
||||
(*virDrvConnectFindStoragePoolSources) (virConnectPtr conn,
|
||||
const char *type,
|
||||
@ -1396,6 +1400,7 @@ struct _virStorageDriver {
|
||||
virDrvConnectListStoragePools listPools;
|
||||
virDrvConnectNumOfDefinedStoragePools numOfDefinedPools;
|
||||
virDrvConnectListDefinedStoragePools listDefinedPools;
|
||||
virDrvConnectListAllStoragePools listAllPools;
|
||||
virDrvConnectFindStoragePoolSources findPoolSources;
|
||||
virDrvStoragePoolLookupByName poolLookupByName;
|
||||
virDrvStoragePoolLookupByUUID poolLookupByUUID;
|
||||
|
112
src/libvirt.c
112
src/libvirt.c
@ -11415,6 +11415,90 @@ virStoragePoolGetConnect (virStoragePoolPtr pool)
|
||||
return pool->conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* virConnectListAllStoragePools:
|
||||
* @conn: Pointer to the hypervisor connection.
|
||||
* @pools: Pointer to a variable to store the array containing storage pool
|
||||
* objects or NULL if the list is not required (just returns number
|
||||
* of pools).
|
||||
* @flags: bitwise-OR of virConnectListAllStoragePoolsFlags.
|
||||
*
|
||||
* Collect the list of storage pools, and allocate an array to store those
|
||||
* objects. This API solves the race inherent between
|
||||
* virConnectListStoragePools and virConnectListDefinedStoragePools.
|
||||
*
|
||||
* Normally, all storage pools are returned; however, @flags can be used to
|
||||
* filter the results for a smaller list of targeted pools. The valid
|
||||
* flags are divided into groups, where each group contains bits that
|
||||
* describe mutually exclusive attributes of a pool, and where all bits
|
||||
* within a group describe all possible pools.
|
||||
*
|
||||
* The first group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE (online)
|
||||
* and VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE (offline) to filter the pools
|
||||
* by state.
|
||||
*
|
||||
* The second group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_PERSITENT
|
||||
* (defined) and VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT (running but not
|
||||
* defined), to filter the pools by whether they have persistent config or not.
|
||||
*
|
||||
* The third group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART
|
||||
* and VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART, to filter the pools by
|
||||
* whether they are marked as autostart or not.
|
||||
*
|
||||
* The last group of @flags is provided to filter the pools by the types,
|
||||
* the flags include:
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_DIR
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_FS
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_NETFS
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_DISK
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_SCSI
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_MPATH
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_RBD
|
||||
* VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG
|
||||
*
|
||||
* Returns the number of storage pools found or -1 and sets @pools to
|
||||
* NULL in case of error. On success, the array stored into @pools is
|
||||
* guaranteed to have an extra allocated element set to NULL but not included
|
||||
* in the return count, to make iteration easier. The caller is responsible
|
||||
* for calling virStoragePoolFree() on each array element, then calling
|
||||
* free() on @pools.
|
||||
*/
|
||||
int
|
||||
virConnectListAllStoragePools(virConnectPtr conn,
|
||||
virStoragePoolPtr **pools,
|
||||
unsigned int flags)
|
||||
{
|
||||
VIR_DEBUG("conn=%p, pools=%p, flags=%x", conn, pools, flags);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
if (pools)
|
||||
*pools = NULL;
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (conn->storageDriver &&
|
||||
conn->storageDriver->listAllPools) {
|
||||
int ret;
|
||||
ret = conn->storageDriver->listAllPools(conn, pools, flags);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
return ret;
|
||||
}
|
||||
|
||||
virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||
|
||||
error:
|
||||
virDispatchError(conn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virConnectNumOfStoragePools:
|
||||
* @conn: pointer to hypervisor connection
|
||||
@ -11457,11 +11541,17 @@ error:
|
||||
* @names: array of char * to fill with pool names (allocated by caller)
|
||||
* @maxnames: size of the names array
|
||||
*
|
||||
* Provides the list of names of active storage pools
|
||||
* upto maxnames. If there are more than maxnames, the
|
||||
* remaining names will be silently ignored.
|
||||
* Provides the list of names of active storage pools up to maxnames.
|
||||
* If there are more than maxnames, the remaining names will be silently
|
||||
* ignored.
|
||||
*
|
||||
* Returns 0 on success, -1 on error
|
||||
* For more control over the results, see virConnectListAllStoragePools().
|
||||
*
|
||||
* Returns the number of pools found or -1 in case of error. Note that
|
||||
* this command is inherently racy; a pool can be started between a call to
|
||||
* virConnectNumOfStoragePools() and this call; you are only guaranteed
|
||||
* that all currently active pools were listed if the return is less than
|
||||
* @maxnames.
|
||||
*/
|
||||
int
|
||||
virConnectListStoragePools(virConnectPtr conn,
|
||||
@ -11540,11 +11630,17 @@ error:
|
||||
* @names: array of char * to fill with pool names (allocated by caller)
|
||||
* @maxnames: size of the names array
|
||||
*
|
||||
* Provides the list of names of inactive storage pools
|
||||
* upto maxnames. If there are more than maxnames, the
|
||||
* remaining names will be silently ignored.
|
||||
* Provides the list of names of inactive storage pools up to maxnames.
|
||||
* If there are more than maxnames, the remaining names will be silently
|
||||
* ignored.
|
||||
*
|
||||
* Returns 0 on success, -1 on error
|
||||
* For more control over the results, see virConnectListAllStoragePools().
|
||||
*
|
||||
* Returns the number of names provided in the array or -1 in case of error.
|
||||
* Note that this command is inherently racy; a pool can be defined between
|
||||
* a call to virConnectNumOfDefinedStoragePools() and this call; you are only
|
||||
* guaranteed that all currently defined pools were listed if the return
|
||||
* is less than @maxnames. The client must call free() on each returned name.
|
||||
*/
|
||||
int
|
||||
virConnectListDefinedStoragePools(virConnectPtr conn,
|
||||
|
@ -554,4 +554,9 @@ LIBVIRT_0.10.0 {
|
||||
virDomainGetEmulatorPinInfo;
|
||||
} LIBVIRT_0.9.13;
|
||||
|
||||
LIBVIRT_0.10.2 {
|
||||
global:
|
||||
virConnectListAllStoragePools;
|
||||
} LIBVIRT_0.10.0;
|
||||
|
||||
# .... define new API here using predicted next version number ....
|
||||
|
Loading…
Reference in New Issue
Block a user