[libvirt] [glib PATCH V2] Add bindings for virStorageVolDownload() and virStorageVolUpload()
Daniel P. Berrange
berrange at redhat.com
Wed Jul 11 15:51:15 UTC 2012
On Wed, Jul 11, 2012 at 03:50:29PM +0200, Jovanka Gulicoska wrote:
> ---
> libvirt-gobject/libvirt-gobject-storage-vol.c | 75 +++++++++++++++++++++++++
> libvirt-gobject/libvirt-gobject-storage-vol.h | 14 +++++
> libvirt-gobject/libvirt-gobject.h | 1 +
> libvirt-gobject/libvirt-gobject.sym | 2 +
> 4 files changed, 92 insertions(+)
>
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
> index 6f60fcd..7f9aeb7 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
> @@ -349,3 +349,78 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
>
> return TRUE;
> }
> +
> +/**
> + * gvir_storage_vol_download:
> + * @vol: the storage volume to download from
> + * @stream: stream to use as output
> + * @offset: position in @vol to start reading from
> + * @length: limit on amount of data to download
> + * @flags: extra flags, not used yet, pass 0
> + *
> + * Returns: #TRUE of success, #FALSE otherwise
> + */
> +gboolean gvir_storage_vol_download(GVirStorageVol *vol,
> + GVirStream *stream,
> + unsigned long long offset,
> + unsigned long long length,
> + guint flags,
> + GError **err)
> +{
> + virStreamPtr st = NULL;
> +
> + g_object_get(stream, "handle", &st, NULL);
IIRC, g_object_get() will acquire a reference on the objects it
returns, so I think you might need a virStreamFree() call at
the end when you're done.
> +
> + g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
> + g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
> + g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> + if(virStorageVolDownload(vol->priv->handle, st, offset, length, 0) < 0) {
s/if(foo)/if (foo)/
> + gvir_set_error_literal(err,
> + GVIR_STORAGE_VOL_ERROR,
> + 0,
> + "Unable to downlaod volume storage");
> +
> + return FALSE;
> + }
> +
> + return TRUE;
> +}
> +
> +/**
> + * gvir_storage_vol_upload:
> + * @vol: the storage volume to upload
> + * @stream: stream to use as input
> + * @offset: position in @vol to start to write to
> + * @length: limit on amount of data to upload
> + * @flags: the flags, not set yet, pass 0
> + *
> + * Returns: #TRUE of success, #FALSE otherwise
> + */
> +gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
> + GVirStream *stream,
> + unsigned long long offset,
> + unsigned long long length,
> + guint flags,
> + GError **err)
> +{
> + virStreamPtr st = NULL;
> +
> + g_object_get(stream, "handle", &st, NULL);
> +
> + g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
> + g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
> + g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> + if(virStorageVolUpload(vol->priv->handle, st, offset, length, 0) < 0) {
> + gvir_set_error_literal(err,
> + GVIR_STORAGE_VOL_ERROR,
> + 0,
> + "Unable to upload to stream");
> +
> + return FALSE;
> + }
Same comments as above.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list