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

[libvirt] [libvirt-glib 1/4] gobject: don't try to use pool's volumes before a successful refresh



gvir_storage_pool_refresh must be called and must be successful before
trying to use gvir_storage_pool_get_volume,
gvir_storage_pool_get_volumes and gvir_storage_pool_create_volume.
As the storage pool refresh can fail for reasons external to
libvirt/libvirt-gobject, the library user should check _refresh
errors. This commit outputs runtime warnings when these functions
are called and GVirObjectStoragePool::priv::volumes is NULL.
---
 libvirt-gobject/libvirt-gobject-storage-pool.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index 7f50037..a4316e9 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -523,6 +523,8 @@ GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool)
     if (priv->volumes != NULL) {
         volumes = g_hash_table_get_values(priv->volumes);
         g_list_foreach(volumes, gvir_storage_vol_ref, NULL);
+    } else {
+        g_warn_if_reached();
     }
     g_mutex_unlock(priv->lock);
 
@@ -548,9 +550,14 @@ GVirStorageVol *gvir_storage_pool_get_volume(GVirStoragePool *pool,
 
     priv = pool->priv;
     g_mutex_lock(priv->lock);
-    volume = g_hash_table_lookup(priv->volumes, name);
-    if (volume)
-        g_object_ref(volume);
+    if (priv->volumes != NULL) {
+        volume = g_hash_table_lookup(priv->volumes, name);
+        if (volume)
+            g_object_ref(volume);
+    } else {
+        g_warn_if_reached();
+        volume = NULL;
+    }
     g_mutex_unlock(priv->lock);
 
     return volume;
@@ -604,7 +611,14 @@ GVirStorageVol *gvir_storage_pool_create_volume
     }
 
     g_mutex_lock(priv->lock);
-    g_hash_table_insert(priv->volumes, g_strdup(name), volume);
+    if (priv->volumes != NULL) {
+        g_hash_table_insert(priv->volumes, g_strdup(name), volume);
+    } else {
+        g_warn_if_reached();
+        g_object_unref(G_OBJECT(volume));
+        g_mutex_unlock(priv->lock);
+        return NULL;
+    }
     g_mutex_unlock(priv->lock);
 
     return g_object_ref(volume);
-- 
1.7.12.1


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