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

Michal Privoznik mprivozn at redhat.com
Wed Nov 21 08:30:02 UTC 2012


On 20.11.2012 19:51, Zeeshan Ali (Khattak) wrote:
> 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);

The latter one has been already checked as can be seen in context of the
last chunk. The first one should not fail since it is us who inserted
the value into volume->priv->vol; But assuming this function
may be used somewhere else in the future these checks are actually
correct - maybe my assumptions won't last then. Moreover, it doesn't
hurt to check when playing around, right?

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

ACK

Michal




More information about the libvir-list mailing list