[libvirt] [PATCH 1/7] fspool: introduce filesystem pools API

Olga Krishtal okrishtal at virtuozzo.com
Thu Aug 25 10:53:45 UTC 2016


On 25/08/16 04:00, Daniel P. Berrange wrote:
> On Fri, Aug 19, 2016 at 06:03:29PM +0300, Olga Krishtal wrote:
>> API follows the API of storage pools closely in parts which
>> do not differ for filesystems.
>>
>> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
>> ---
>>   include/libvirt/libvirt-fs.h | 273 +++++++++++++++++++++++++++++++++++++++++++
>>   include/libvirt/libvirt.h    |   1 +
>>   2 files changed, 274 insertions(+)
>>   create mode 100644 include/libvirt/libvirt-fs.h
>>
>> diff --git a/include/libvirt/libvirt-fs.h b/include/libvirt/libvirt-fs.h
>> new file mode 100644
>> index 0000000..4385220
>> --- /dev/null
>> +++ b/include/libvirt/libvirt-fs.h
>
>> +typedef enum {
>> +    VIR_FS_POOL_CREATE_NORMAL = 0,
>> +
>> +    /* Create the fspool and perform fspool build without any flags */
>> +    VIR_FS_POOL_CREATE_WITH_BUILD = 1 << 0,
>> +
>> +    /* Create the fspool and perform fspool build using the
>> +     * exclusive to VIR_FS_POOL_CREATE_WITH_BUILD_NO_OVERWRITE */
>> +    VIR_FS_POOL_CREATE_WITH_BUILD_OVERWRITE = 1 << 1,
>> +
>> +    /* Create the pool and perform pool build using the
>> +     * VIR_FS_POOL_BUILD_NO_OVERWRITE flag. This is mutually
>> +     * exclusive to VIR_FS_POOL_CREATE_WITH_BUILD_OVERWRITE */
>> +    VIR_FS_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = 1 << 2,
>> +} virFsPoolCreateFlags;
>
> nitpick, I suggest we use  virFSPool, not virFsPool, since 'fs'
> is an abbreviation and thus normal to capitalize both parts.
>
>> +
>> +typedef enum {
>> +    VIR_FS_POOL_BUILD_NEW  = 0,   /* Regular build from scratch */
>> +    VIR_FS_POOL_BUILD_NO_OVERWRITE = (1 << 2),  /* Do not overwrite existing pool */
>> +    VIR_FS_POOL_BUILD_OVERWRITE = (1 << 3),  /* Overwrite data */
>> +} virFsPoolBuildFlags;
>> +
>> +/**
>> + * virFsPool:
>> + *
>> + * a virFsPool is a private structure representing a fspool
>> + */
>> +typedef struct _virFsPool virFsPool;
>> +
>> +/**
>> + * virFsPoolPtr:
>> + *
>> + * a virFSPoolPtr is pointer to a virFsPool private structure, this is the
>> + * type used to reference a fspool in the API.
>> + */
>> +typedef virFsPool *virFsPoolPtr;
>> +
>> +typedef enum {
>> +    VIR_FS_POOL_INACTIVE = 0,
>> +    VIR_FS_POOL_BUILDING = 1,
>> +    VIR_FS_POOL_RUNNING = 2,
>> +
>> +# ifdef VIR_ENUM_SENTINELS
>> +    VIR_FS_POOL_STATE_LAST
>> +# endif
>> +} virFsPoolState;
>> +
>> +typedef struct _virFsPoolInfo virFsPoolInfo;
>> +
>> +struct _virFsPoolInfo {
>> +    int state;                     /* virFsPoolState flags */
>> +    unsigned long long capacity;   /* Logical size bytes */
>> +    unsigned long long allocation; /* Current allocation bytes */
>> +    unsigned long long available;  /* Remaining free space bytes */
>> +};
>> +
>> +typedef virFsPoolInfo *virFsPoolInfoPtr;
>> +
>> +/**
>> + * virFsItem:
>> + *
>> + * a virFsItem is a private structure representing a fspool item
>> + */
>> +typedef struct _virFsItem virFsItem;
>> +
>> +/**
>> + * virFsItemPtr:
>> + *
>> + * a virFsItemPtr is pointer to a virFsItem private structure, this is the
>> + * type used to reference a fspool item in the API.
>> + */
>> +typedef virFsItem *virFsItemPtr;
>> +
>> +typedef struct _virFsItemInfo virFsItemInfo;
>> +
>> +typedef enum {
>> +    VIR_FS_ITEM_DIR = 0,
>> +    VIR_FS_ITEM_LAST
>> +} virFsItemType;
>> +
>> +struct _virFsItemInfo {
>> +    int type;                      /* virFsItemType flags */
>> +    unsigned long long capacity;   /* Logical size bytes */
>> +    unsigned long long allocation; /* Current allocation bytes */
>> +};
>> +
>> +typedef virFsItemInfo *virFsItemInfoPtr;
>> +/*
>> + * Get connection from fspool.
>> + */
>> +virConnectPtr           virFsPoolGetConnect        (virFsPoolPtr fsool);
> No need to copy the crazy whitespace we have in other headers - a single
> ' ' between return value and function name, is fine and no space at all
> between function name and '('
>
>> +
>> +/*
>> + * List active fspools
>> + */
>> +int                     virConnectNumOfFsPools     (virConnectPtr conn);
>> +int                     virConnectListFsPools      (virConnectPtr conn,
>> +                                                    char **const names,
>> +                                                    int maxnames);
>> +
>> +/*
>> + * List inactive fspools
>> + */
>> +int                     virConnectNumOfDefinedFsPools(virConnectPtr conn);
>> +int                     virConnectListDefinedFsPools(virConnectPtr conn,
>> +                                                     char **const names,
>> +                                                     int maxnames);
> The 4 apis follow our old model for listing objects which we discourage
> apps from using since they require O(N) API calls and have a designed
> in race condition.
>
> So, I suggest just skip these 4 APis and exclusively rely on
> the virConnectListAllFsPools API, as we have no need for back
> compat with old apps for this new stuff.
>
>
>> +
>> +/*
>> + * virConnectListAllFsPoolsFlags:
>> + *
>> + * Flags used to tune fspools returned by virConnectListAllFsPools().
>> + * 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_FS_POOLS_INACTIVE      = 1 << 0,
>> +    VIR_CONNECT_LIST_FS_POOLS_ACTIVE        = 1 << 1,
>> +
>> +    VIR_CONNECT_LIST_FS_POOLS_PERSISTENT    = 1 << 2,
>> +    VIR_CONNECT_LIST_FS_POOLS_TRANSIENT     = 1 << 3,
>> +
>> +    VIR_CONNECT_LIST_FS_POOLS_AUTOSTART     = 1 << 4,
>> +    VIR_CONNECT_LIST_FS_POOLS_NO_AUTOSTART  = 1 << 5,
>> +
>> +    /* List fspools by type */
>> +    VIR_CONNECT_LIST_FS_POOLS_DIR                = 1 << 6,
>> +} virConnectListAllFsPoolsFlags;
>> +
>> +typedef enum {
>> +    VIR_FS_XML_INACTIVE    = (1 << 0), /* dump inactive fspool/item information */
>> +} virFsXMLFlags;
>> +
>> +
>> +int                     virConnectListAllFsPools(virConnectPtr conn,
>> +                                                 virFsPoolPtr **fspools,
>> +                                                 unsigned int flags);
>> +
>> +/*
>> + * Lookup fspool by name or uuid
>> + */
>> +virFsPoolPtr       virFsPoolLookupByName       (virConnectPtr conn,
>> +                                                const char *name);
>> +virFsPoolPtr       virFsPoolLookupByUUID       (virConnectPtr conn,
>> +                                                const unsigned char *uuid);
>> +virFsPoolPtr       virFsPoolLookupByUUIDString (virConnectPtr conn,
>> +                                                const char *uuid);
>> +virFsPoolPtr       virFsPoolLookupByItem       (virFsItemPtr item);
>> +
>> +
>> +/*
>> + * Creating/destroying fspools
>> + */
>> +virFsPoolPtr       virFsPoolCreateXML         (virConnectPtr conn,
>> +                                               const char *xmlDesc,
>> +                                               unsigned int flags);
>> +virFsPoolPtr       virFsPoolDefineXML         (virConnectPtr conn,
>> +                                               const char *xmlDesc,
>> +                                               unsigned int flags);
>> +int                     virFsPoolBuild        (virFsPoolPtr fsool,
>> +                                               unsigned int flags);
>> +int                     virFsPoolRefresh      (virFsPoolPtr fsool,
>> +                                               unsigned int flags);
>> +int                     virFsPoolUndefine     (virFsPoolPtr fsool);
>> +int                     virFsPoolCreate       (virFsPoolPtr pool,
>> +                                               unsigned int flags);
>> +int                     virFsPoolDestroy      (virFsPoolPtr fsool);
>> +int                     virFsPoolDelete       (virFsPoolPtr fsool,
>> +                                               unsigned int flags);
>> +int                     virFsPoolRefresh      (virFsPoolPtr fsool,
>> +                                               unsigned int flags);
>> +int                     virFsPoolRef          (virFsPoolPtr fspool);
>> +int                     virFsPoolFree         (virFsPoolPtr fspool);
>> +
>> +/*
>> + * FsPool information
>> + */
>> +const char*             virFsPoolGetName           (virFsPoolPtr fsool);
>> +int                     virFsPoolGetUUID           (virFsPoolPtr fsool,
>> +                                                    unsigned char *uuid);
>> +int                     virFsPoolGetUUIDString     (virFsPoolPtr fsool,
>> +                                                    char *buf);
>> +
>> +int                     virFsPoolGetInfo           (virFsPoolPtr item,
>> +                                                    virFsPoolInfoPtr info);
>> +
>> +char *                  virFsPoolGetXMLDesc        (virFsPoolPtr fsool,
>> +                                                    unsigned int flags);
>> +int                     virFsPoolGetAutostart      (virFsPoolPtr pool,
>> +                                                    int *autostart);
>> +int                     virFsPoolSetAutostart      (virFsPoolPtr pool,
>> +                                                    int autostart);
>> +
>> +
>> +/*
>> + * List/lookup fs items within a fsool
>> + */
>> +int                     virFsPoolNumOfItems      (virFsPoolPtr fsool);
>> +int                     virFsPoolListItems       (virFsPoolPtr fsool,
>> +                                                  char **const names,
>> +                                                  int maxnames);
>> +int                     virFsPoolListAllItems    (virFsPoolPtr fsool,
>> +                                                  virFsItemPtr **items,
>> +                                                  unsigned int flags);
>> +
>> +virConnectPtr           virFsItemGetConnect       (virFsItemPtr item);
>> +
>> +/*
>> + * Lookup itemumes based on various attributes
>> + */
>> +virFsItemPtr        virFsItemLookupByName       (virFsPoolPtr fsool,
>> +                                                 const char *name);
>> +virFsItemPtr        virFsItemLookupByKey        (virConnectPtr conn,
>> +                                                 const char *key);
>> +virFsItemPtr        virFsItemLookupByPath       (virConnectPtr conn,
>> +                                                 const char *path);
>> +
>> +
>> +const char*             virFsItemGetName            (virFsItemPtr item);
>> +const char*             virFsItemGetKey             (virFsItemPtr item);
>> +
>> +virFsItemPtr        virFsItemCreateXML          (virFsPoolPtr fsool,
>> +                                                 const char *xmldesc,
>> +                                                 unsigned int flags);
>> +virFsItemPtr        virFsItemCreateXMLFrom      (virFsPoolPtr fsool,
>> +                                                 const char *xmldesc,
>> +                                                 virFsItemPtr cloneitem,
>> +                                                 unsigned int flags);
>> +
>> +int                     virFsItemDelete             (virFsItemPtr item,
>> +                                                     unsigned int flags);
>> +int                     virFsItemRef                (virFsItemPtr item);
>> +int                     virFsItemFree               (virFsItemPtr item);
>> +
>> +int                     virFsItemGetInfo            (virFsItemPtr item,
>> +                                                     virFsItemInfoPtr info);
>> +char *                  virFsItemGetXMLDesc         (virFsItemPtr item,
>> +                                                     unsigned int flags);
>> +
>> +char *                  virFsItemGetPath            (virFsItemPtr item);
>> +
>> +int virFsPoolIsActive(virFsPoolPtr fspool);
>> +int virFsPoolIsPersistent(virFsPoolPtr fspool);
>
> All this looks fine to me.
>
>
> Regards,
> Daniel

OK




More information about the libvir-list mailing list