[libvirt] [libvirt-glib] gobject: Also delete storage volume from its pool's list

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Nov 20 18:51:23 UTC 2012


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Without this patch, storage pool still lists the volume even after it is
deleted.

Related Boxes bug: https://bugzilla.gnome.org/show_bug.cgi?id=688724
---
 libvirt-gobject/libvirt-gobject-storage-pool.c | 23 +++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-storage-vol.c  |  4 ++++
 2 files changed, 27 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index 8f579a1..df7e77c 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -29,6 +29,7 @@
 #include "libvirt-glib/libvirt-glib.h"
 #include "libvirt-gobject/libvirt-gobject.h"
 #include "libvirt-gobject-compat.h"
+#include "libvirt-gobject-storage-pool-private.h"
 
 #define GVIR_STORAGE_POOL_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolPrivate))
@@ -1129,3 +1130,25 @@ gboolean gvir_storage_pool_delete_finish(GVirStoragePool *pool,
 
     return TRUE;
 }
+
+G_GNUC_INTERNAL gboolean gvir_storage_pool_delete_vol(GVirStoragePool *pool,
+                                                      GVirStorageVol *volume)
+{
+    GVirStoragePoolPrivate *priv;
+    gboolean ret = FALSE;
+
+    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
+    g_return_val_if_fail(GVIR_IS_STORAGE_VOL(volume), FALSE);
+
+    priv = pool->priv;
+    g_mutex_lock(priv->lock);
+    if (priv->volumes != NULL) {
+        const gchar *name = gvir_storage_vol_get_name(volume);
+        ret = g_hash_table_remove(priv->volumes, name);
+    } else {
+        g_warn_if_reached();
+    }
+    g_mutex_unlock(priv->lock);
+
+    return ret;
+}
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c
index c7ebb45..4352d30 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -29,6 +29,7 @@
 #include "libvirt-glib/libvirt-glib.h"
 #include "libvirt-gobject/libvirt-gobject.h"
 #include "libvirt-gobject-compat.h"
+#include "libvirt-gobject-storage-pool-private.h"
 
 #define GVIR_STORAGE_VOL_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_STORAGE_VOL, GVirStorageVolPrivate))
@@ -309,6 +310,9 @@ gboolean gvir_storage_vol_delete(GVirStorageVol *vol,
     g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
     g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
 
+    if (!gvir_storage_pool_delete_vol(vol->priv->pool, vol))
+        return FALSE;
+
     if (virStorageVolDelete(vol->priv->handle, flags) < 0) {
         gvir_set_error_literal(err,
                                GVIR_STORAGE_VOL_ERROR,
-- 
1.8.0




More information about the libvir-list mailing list