Re: [libvirt-glib] Add gvir_storage_vol_resize()

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

 



On Wed, Feb 01, 2012 at 02:27:28AM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> Add wrapper for virStorageVolResize().
> ---
>  libvirt-gobject/libvirt-gobject-storage-vol.c |   45 +++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-storage-vol.h |   20 +++++++++++
>  libvirt-gobject/libvirt-gobject.sym           |    1 +
>  3 files changed, 66 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
> index 491e2e6..f6f0c50 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
> @@ -299,3 +299,48 @@ gboolean gvir_storage_vol_delete(GVirStorageVol *vol,
>  
>      return TRUE;
>  }
> +
> +/**
> + * gvir_storage_vol_resize:
> + * @vol: the storage volume to resize
> + * @capacity: the new capacity of the volume
> + * @flags: the flags
> + * @err: Return location for errors, or NULL
> + *
> + * Changes the capacity of the storage volume @vol to @capacity.
> + *
> + * Returns: the new capacity of the volume on success, 0 otherwise
> + */
> +gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
> +                                 guint64 capacity,
> +                                 GVirStorageVolResizeFlags flags,

We're probably already doing that in other places, I may have already
mentioned it, but I'm a bit uncomfortable with using the enum type for
bitfields. If I'm not mistaken, if we use GVirStorageVolResizeFlags,
passing a value which is not one of the enum values (such as DELTA |
SHRINK) is undefined behaviour in the C spec. I'm fine with us deciding
it's not important, but it's still worth mentioning :)


> +                                 GError **err)
> +{
> +    GVirStoragePoolInfo* pool_info = NULL;
> +    GVirStorageVolInfo* volume_info = NULL;
> +    gboolean ret = FALSE;
> +
> +    pool_info = gvir_storage_pool_get_info (vol->priv->pool, err);
> +    if (err != NULL && *err != NULL)
> +        goto cleanup;
> +    volume_info = gvir_storage_vol_get_info (vol, err);
> +    if (err != NULL && *err != NULL)
> +        goto cleanup;

What are pool_info and volume_info used for?

Rest of the patch is straightforward, so ACK once libvirt 0.9.10 (11?) is
released. Don't forget to update the libvirt requirement in configure.ac
if you're the first one to commit something depending on this new release.

Thanks,

Christophe



> +
> +    if (virStorageVolResize(vol->priv->handle, capacity, flags) < 0) {
> +        gvir_set_error_literal(err,
> +                               GVIR_STORAGE_VOL_ERROR,
> +                               0,
> +                               "Unable to resize volume storage");
> +        goto cleanup;
> +    }
> +
> +    ret = TRUE;
> +
> +cleanup:
> +    if (pool_info)
> +        g_boxed_free(GVIR_TYPE_STORAGE_POOL_INFO, pool_info);
> +    if (volume_info)
> +        gvir_storage_vol_info_free(volume_info);
> +    return ret;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h
> index 25f683a..459a2ac 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.h
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
> @@ -23,6 +23,7 @@
>  #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
>  #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
>  #endif
> +#include <libvirt/libvirt.h>
>  
>  #ifndef __LIBVIRT_GOBJECT_STORAGE_VOL_H__
>  #define __LIBVIRT_GOBJECT_STORAGE_VOL_H__
> @@ -65,6 +66,21 @@ typedef enum {
>      GVIR_STORAGE_VOL_STATE_DIR   = 2, /* Directory-passthrough based volume */
>  } GVirStorageVolType;
>  
> +/**
> + * GVirStorageVolResizeFlags:
> + * @GVIR_STORAGE_VOL_RESIZE_NONE: No flags
> + * @GVIR_STORAGE_VOL_RESIZE_ALLOCATE: force allocation of new size
> + * @GVIR_STORAGE_VOL_RESIZE_DELTA: size is relative to current
> + * @GVIR_STORAGE_VOL_RESIZE_SHRINK: allow decrease in capacity. This combined
> + * with #GVIR_STORAGE_VOL_RESIZE_DELTA, implies a negative delta.
> + */
> +typedef enum {
> +    GVIR_STORAGE_VOL_RESIZE_NONE     = 0,
> +    GVIR_STORAGE_VOL_RESIZE_ALLOCATE = VIR_STORAGE_VOL_RESIZE_ALLOCATE,
> +    GVIR_STORAGE_VOL_RESIZE_DELTA    = VIR_STORAGE_VOL_RESIZE_DELTA,
> +    GVIR_STORAGE_VOL_RESIZE_SHRINK   = VIR_STORAGE_VOL_RESIZE_SHRINK,
> +} GVirStorageVolResizeFlags;
> +
>  typedef struct _GVirStorageVolInfo GVirStorageVolInfo;
>  struct _GVirStorageVolInfo
>  {
> @@ -89,6 +105,10 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
>                                                    GError **err);
>  GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol,
>                                                GError **err);
> +gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
> +                                 guint64 capacity,
> +                                 GVirStorageVolResizeFlags flags,
> +                                 GError **err);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index a4f03f7..468bf65 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -126,6 +126,7 @@ LIBVIRT_GOBJECT_0.0.4 {
>  	gvir_storage_vol_get_config;
>  	gvir_storage_vol_get_info;
>  	gvir_storage_vol_delete;
> +	gvir_storage_vol_resize;
>  
>  	gvir_connection_handle_get_type;
>  
> -- 
> 1.7.7.6
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpgscUA_I8R0.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]