[libvirt] [libvirt-glib 1/2] Wrap storage pool info API
Christophe Fergeau
cfergeau at redhat.com
Thu Dec 1 11:02:48 UTC 2011
On Wed, Nov 30, 2011 at 08:11:30PM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
>
> ---
> libvirt-gobject/libvirt-gobject-storage-pool.c | 44 ++++++++++++++++++++++++
> libvirt-gobject/libvirt-gobject-storage-pool.h | 21 +++++++++++
> libvirt-gobject/libvirt-gobject.sym | 2 +
> 3 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
> index da8ada5..3c30a3d 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
> @@ -189,6 +189,21 @@ gvir_storage_pool_handle_free(GVirStoragePoolHandle *src)
> G_DEFINE_BOXED_TYPE(GVirStoragePoolHandle, gvir_storage_pool_handle,
> gvir_storage_pool_handle_copy, gvir_storage_pool_handle_free)
>
> +static GVirStoragePoolInfo *
> +gvir_storage_pool_info_copy(GVirStoragePoolInfo *info)
> +{
> + return g_slice_dup(GVirStoragePoolInfo, info);
> +}
> +
> +static void
> +gvir_storage_pool_info_free(GVirStoragePoolInfo *info)
> +{
> + g_slice_free(GVirStoragePoolInfo, info);
> +}
> +
> +G_DEFINE_BOXED_TYPE(GVirStoragePoolInfo, gvir_storage_pool_info,
> + gvir_storage_pool_info_copy, gvir_storage_pool_info_free)
> +
> const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool)
> {
> GVirStoragePoolPrivate *priv = pool->priv;
> @@ -237,6 +252,35 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
> return conf;
> }
>
> +/**
> + * gvir_storage_pool_get_info:
> + * @pool: the storage_pool
> + * Returns: (transfer full): the info
> + */
> +GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool,
> + GError **err)
> +{
> + GVirStoragePoolPrivate *priv = pool->priv;
> + virStoragePoolInfo info;
> + GVirStoragePoolInfo *ret;
> +
> + if (virStoragePoolGetInfo(priv->handle, &info) < 0) {
> + if (err)
> + *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
> + 0,
> + "Unable to get storage pool info");
> + return NULL;
> + }
> +
> + ret = g_slice_new(GVirStoragePoolInfo);
> + ret->state = info.state;
> + ret->capacity = info.capacity;
> + ret->allocation = info.allocation;
> + ret->available = info.available;
> +
> + return ret;
> +}
> +
Any idea if this is always non blocking, or if it can take time if the
storage is remote ?
> typedef gint (* CountFunction) (virStoragePoolPtr vpool);
> typedef gint (* ListFunction) (virStoragePoolPtr vpool, gchar **lst, gint max);
>
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h
> index d95bb19..436238b 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.h
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h
> @@ -36,6 +36,7 @@ G_BEGIN_DECLS
> #define GVIR_IS_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STORAGE_POOL))
> #define GVIR_STORAGE_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolClass))
>
> +#define GVIR_TYPE_STORAGE_POOL_INFO (gvir_storage_pool_info_get_type())
> #define GVIR_TYPE_STORAGE_POOL_HANDLE (gvir_storage_pool_handle_get_type())
>
> typedef struct _GVirStoragePool GVirStoragePool;
> @@ -58,8 +59,25 @@ struct _GVirStoragePoolClass
> gpointer padding[20];
> };
>
> +typedef enum {
> + GVIR_STORAGE_POOL_STATE_INACTIVE = 0, /* Not running */
> + GVIR_STORAGE_POOL_STATE_BUILDING = 1, /* Initializing pool, not available */
> + GVIR_STORAGE_POOL_STATE_RUNNING = 2, /* Running normally */
> + GVIR_STORAGE_POOL_STATE_DEGRADED = 3, /* Running degraded */
> + GVIR_STORAGE_POOL_STATE_INACCESSIBLE = 4, /* Running, but not accessible */
> +} GVirStoragePoolState;
> +
> +typedef struct _GVirStoragePoolInfo GVirStoragePoolInfo;
> +struct _GVirStoragePoolInfo
> +{
> + GVirStoragePoolState state; /* the state */
> + guint64 capacity; /* Logical size bytes */
> + guint64 allocation; /* Current allocation bytes */
> + guint16 available; /* Remaining free space bytes */
guint64 available;
Do we want enum in public struct like this? (GVirDomainInfo has one too).
The size of the int used to store the enum value is very vaguely defined in
the C standard and can easily change. I don't know if we want to be extra
careful here or if we're fine with living with the nicer code.
> +};
>
> GType gvir_storage_pool_get_type(void);
> +GType gvir_storage_pool_info_get_type(void);
> GType gvir_storage_pool_handle_get_type(void);
>
> const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool);
> @@ -69,6 +87,9 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
> guint flags,
> GError **err);
>
> +GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool,
> + GError **err);
> +
> gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
> GCancellable *cancellable,
> GError **err);
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 61a3a31..55c515b 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -91,10 +91,12 @@ LIBVIRT_GOBJECT_0.0.1 {
> gvir_secret_get_config;
>
> gvir_storage_pool_get_type;
> + gvir_storage_pool_info_get_type;
> gvir_storage_pool_handle_get_type;
> gvir_storage_pool_get_name;
> gvir_storage_pool_get_uuid;
> gvir_storage_pool_get_config;
> + gvir_storage_pool_get_info;
> gvir_storage_pool_refresh;
> gvir_storage_pool_refresh_async;
> gvir_storage_pool_refresh_finish;
> --
> 1.7.7.3
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111201/eef27fbb/attachment-0001.sig>
More information about the libvir-list
mailing list