[libvirt] [libvirt-glib] Add wrapper for volume deletion API

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gobject/libvirt-gobject-storage-vol.c | 25 +++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-storage-vol.h | 4 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 30 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index 15ae404..e7a7581 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -252,3 +252,28 @@ GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol, return ret; } + +/** + * gvir_storage_vol_delete: + * @vol: the storage volume to delete + * @flags: the flags + * @err: Return location for errors, or NULL + * + * Deletes the storage volume @vol. + * + * Returns: %TRUE on success, %FALSE otherwise + */ +gboolean gvir_storage_vol_delete(GVirStorageVol *vol, + guint flags, + GError **err) +{ + if (virStorageVolDelete(vol->priv->handle, flags) < 0) { + g_set_error (err, + GVIR_STORAGE_VOL_ERROR, + 0, + "Unable to delete storage volume"); + return FALSE; + } + + return TRUE; +} diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h index 717ef4a..db63865 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.h +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h @@ -80,6 +80,10 @@ GType gvir_storage_vol_handle_get_type(void); const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol); const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol); +gboolean gvir_storage_vol_delete(GVirStorageVol *vol, + guint flags, + GError **err); + GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, guint flags, GError **err); diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index c0d2e19..3727fb7 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -117,6 +117,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_storage_vol_get_path; gvir_storage_vol_get_config; gvir_storage_vol_get_info; + gvir_storage_vol_delete; gvir_connection_handle_get_type; -- 1.7.7.3

On Fri, Dec 02, 2011 at 05:34:15PM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gobject/libvirt-gobject-storage-vol.c | 25 +++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-storage-vol.h | 4 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index 15ae404..e7a7581 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -252,3 +252,28 @@ GVirStorageVolInfo *gvir_storage_vol_get_info(GVirStorageVol *vol,
return ret; } + +/** + * gvir_storage_vol_delete: + * @vol: the storage volume to delete + * @flags: the flags + * @err: Return location for errors, or NULL + * + * Deletes the storage volume @vol. + * + * Returns: %TRUE on success, %FALSE otherwise + */ +gboolean gvir_storage_vol_delete(GVirStorageVol *vol, + guint flags, + GError **err) +{ + if (virStorageVolDelete(vol->priv->handle, flags) < 0) { + g_set_error (err, + GVIR_STORAGE_VOL_ERROR, + 0, + "Unable to delete storage volume");
I think gvir_error_new_literal should be used here ACK otherwise
+ return FALSE; + } + + return TRUE; +} diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h index 717ef4a..db63865 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.h +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h @@ -80,6 +80,10 @@ GType gvir_storage_vol_handle_get_type(void); const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol); const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
+gboolean gvir_storage_vol_delete(GVirStorageVol *vol, + guint flags, + GError **err); + GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, guint flags, GError **err); diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index c0d2e19..3727fb7 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -117,6 +117,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_storage_vol_get_path; gvir_storage_vol_get_config; gvir_storage_vol_get_info; + gvir_storage_vol_delete;
gvir_connection_handle_get_type;
-- 1.7.7.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Fri, Dec 2, 2011 at 6:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Fri, Dec 02, 2011 at 05:34:15PM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
+ if (virStorageVolDelete(vol->priv->handle, flags) < 0) { + g_set_error (err, + GVIR_STORAGE_VOL_ERROR, + 0, + "Unable to delete storage volume");
I think gvir_error_new_literal should be used here
g_set_error() checks if error is NULL and doesn't set the error if so. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Sat, Dec 03, 2011 at 12:11:04AM +0200, Zeeshan Ali (Khattak) wrote:
On Fri, Dec 2, 2011 at 6:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Fri, Dec 02, 2011 at 05:34:15PM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
+ if (virStorageVolDelete(vol->priv->handle, flags) < 0) { + g_set_error (err, + GVIR_STORAGE_VOL_ERROR, + 0, + "Unable to delete storage volume");
I think gvir_error_new_literal should be used here
g_set_error() checks if error is NULL and doesn't set the error if so.
I know, but gvir_error_new_literal automatically appends the error message from libvirt so this should be used here. But yeah for now you have to check for NULL errors by yourself. Or you can wait until the gvir_set_error_literal patches go in. Christophe

On Sat, Dec 03, 2011 at 12:11:04AM +0200, Zeeshan Ali (Khattak) wrote:
On Fri, Dec 2, 2011 at 6:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Fri, Dec 02, 2011 at 05:34:15PM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
+ if (virStorageVolDelete(vol->priv->handle, flags) < 0) { + g_set_error (err, + GVIR_STORAGE_VOL_ERROR, + 0, + "Unable to delete storage volume");
I think gvir_error_new_literal should be used here
g_set_error() checks if error is NULL and doesn't set the error if so.
You actually want gvir_set_error_literal(), to avoid potential format string vulnerabilities from bogus translations. Regards, 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 :|
participants (3)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Zeeshan Ali (Khattak)