Re: [libvirt-glib 2/2] Wrap storage volume info API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Same concerns as with the previous patch actually :) (enum use in public
struct and can virStorageVolGetInfo be slow)

Christophe

On Wed, Nov 30, 2011 at 08:11:31PM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> ---
>  libvirt-gobject/libvirt-gobject-storage-vol.c |   43 +++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-storage-vol.h |   18 ++++++++++
>  libvirt-gobject/libvirt-gobject.sym           |    2 +
>  3 files changed, 63 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
> index 6340ad7..19f17d3 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
> @@ -159,6 +159,21 @@ gvir_storage_vol_handle_free(GVirStorageVolHandle *src)
>  G_DEFINE_BOXED_TYPE(GVirStorageVolHandle, gvir_storage_vol_handle,
>                      gvir_storage_vol_handle_copy, gvir_storage_vol_handle_free)
>  
> +static GVirStorageVolInfo *
> +gvir_storage_vol_info_copy(GVirStorageVolInfo *info)
> +{
> +    return g_slice_dup(GVirStorageVolInfo, info);
> +}
> +
> +static void
> +gvir_storage_vol_info_free(GVirStorageVolInfo *info)
> +{
> +    g_slice_free(GVirStorageVolInfo, info);
> +}
> +
> +G_DEFINE_BOXED_TYPE(GVirStorageVolInfo, gvir_storage_vol_info,
> +                    gvir_storage_vol_info_copy, gvir_storage_vol_info_free)
> +
>  const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol)
>  {
>      GVirStorageVolPrivate *priv = vol->priv;
> @@ -209,3 +224,31 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
>      free(xml);
>      return conf;
>  }
> +
> +/**
> + * gvir_storage_vol_get_info:
> + * @vol: the storage_vol
> + * Returns: (transfer full): the info
> + */
> +GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol,
> +                                              GError **err)
> +{
> +    GVirStorageVolPrivate *priv = vol->priv;
> +    virStorageVolInfo info;
> +    GVirStorageVolInfo *ret;
> +
> +    if (virStorageVolGetInfo(priv->handle, &info) < 0) {
> +        if (err)
> +            *err = gvir_error_new_literal(GVIR_STORAGE_VOL_ERROR,
> +                                          0,
> +                                          "Unable to get storage vol info");
> +        return NULL;
> +    }
> +
> +    ret = g_slice_new(GVirStorageVolInfo);
> +    ret->type = info.type;
> +    ret->capacity = info.capacity;
> +    ret->allocation = info.allocation;
> +
> +    return ret;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h
> index 8acdcf9..65bb495 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.h
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
> @@ -36,6 +36,7 @@ G_BEGIN_DECLS
>  #define GVIR_IS_STORAGE_VOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STORAGE_VOL))
>  #define GVIR_STORAGE_VOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STORAGE_VOL, GVirStorageVolClass))
>  
> +#define GVIR_TYPE_STORAGE_VOL_INFO       (gvir_storage_vol_info_get_type())
>  #define GVIR_TYPE_STORAGE_VOL_HANDLE     (gvir_storage_vol_handle_get_type())
>  
>  typedef struct _GVirStorageVol GVirStorageVol;
> @@ -58,7 +59,22 @@ struct _GVirStorageVolClass
>      gpointer padding[20];
>  };
>  
> +typedef enum {
> +    GVIR_STORAGE_VOL_STATE_FILE  = 0, /* Regular file based volume */
> +    GVIR_STORAGE_VOL_STATE_BLOCK = 1, /* Block based volume */
> +    GVIR_STORAGE_VOL_STATE_DIR   = 2, /* Directory-passthrough based volume */
> +} GVirStorageVolType;
> +
> +typedef struct _GVirStorageVolInfo GVirStorageVolInfo;
> +struct _GVirStorageVolInfo
> +{
> +    GVirStorageVolType type; /* Type flags */
> +    guint64 capacity;        /* Logical size bytes */
> +    guint64 allocation;      /* Current allocation bytes */
> +};
> +
>  GType gvir_storage_vol_get_type(void);
> +GType gvir_storage_vol_info_get_type(void);
>  GType gvir_storage_vol_handle_get_type(void);
>  
>  const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol);
> @@ -67,6 +83,8 @@ const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
>  GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
>                                                    guint flags,
>                                                    GError **err);
> +GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol,
> +                                              GError **err);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 55c515b..c0d2e19 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -111,10 +111,12 @@ LIBVIRT_GOBJECT_0.0.1 {
>  	gvir_storage_pool_start_finish;
>  
>  	gvir_storage_vol_get_type;
> +	gvir_storage_vol_info_get_type;
>  	gvir_storage_vol_handle_get_type;
>  	gvir_storage_vol_get_name;
>  	gvir_storage_vol_get_path;
>  	gvir_storage_vol_get_config;
> +	gvir_storage_vol_get_info;
>  
>  	gvir_connection_handle_get_type;
>  
> -- 
> 1.7.7.3
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpvlTdnnGhdp.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]