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, + 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; + + 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