Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virstorageobj.c | 8 +++++-
src/datatypes.c | 48 ++++++++++++++++++++++--------------
src/datatypes.h | 15 +++++------
src/libvirt-storage.c | 6 ++---
src/libvirt_private.syms | 1 -
src/qemu/qemu_migration.c | 3 +--
src/storage/storage_driver.c | 7 +++---
src/vz/vz_sdk.c | 19 ++++++--------
8 files changed, 58 insertions(+), 49 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index bff6eb6ae1..698fc25c5f 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1052,7 +1052,13 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
return data.nvols;
error:
- virObjectListFree(data.vols);
+ if (data.vols) {
+ while (data.nvols--) {
+ if (data.vols[data.nvols])
+ g_object_unref(data.vols[data.nvols]);
+ }
+ VIR_FREE(data.vols);
+ }
return -1;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index e434c31785..1f811e5f5e 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -39,7 +39,6 @@ virClassPtr virDomainClass;
virClassPtr virNodeDeviceClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
-virClassPtr virStorageVolClass;
static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
@@ -47,7 +46,6 @@ static void virDomainDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
-static void virStorageVolDispose(void *obj);
G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT);
static void virDomainCheckpointFinalize(GObject *obj);
@@ -177,6 +175,22 @@ vir_storage_pool_class_init(virStoragePoolClass *klass)
obj->finalize = virStoragePoolFinalize;
}
+G_DEFINE_TYPE(virStorageVol, vir_storage_vol, G_TYPE_OBJECT);
+static void virStorageVolFinalize(GObject *obj);
+
+static void
+vir_storage_vol_init(virStorageVol *vol G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_storage_vol_class_init(virStorageVolClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virStorageVolFinalize;
+}
+
virClassPtr virAdmConnectClass;
virClassPtr virAdmConnectCloseCallbackDataClass;
@@ -232,7 +246,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS(virNodeDevice);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
- DECLARE_CLASS(virStorageVol);
DECLARE_CLASS_LOCKABLE(virAdmConnect);
DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
@@ -713,7 +726,7 @@ virStoragePoolFinalize(GObject *obj)
* @freeFunc: private data cleanup function pointer specific to driver
*
* Allocates a new storage volume object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
*
* Returns a pointer to the storage volume object, or NULL on error.
*/
@@ -721,18 +734,17 @@ virStorageVolPtr
virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
const char *key, void *privateData, virFreeCallback freeFunc)
{
- virStorageVolPtr ret = NULL;
+ g_autoptr(virStorageVol) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckConnectGoto(conn, error);
- virCheckNonNullArgGoto(pool, error);
- virCheckNonNullArgGoto(name, error);
- virCheckNonNullArgGoto(key, error);
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgReturn(pool, NULL);
+ virCheckNonNullArgReturn(name, NULL);
+ virCheckNonNullArgReturn(key, NULL);
- if (!(ret = virObjectNew(virStorageVolClass)))
- goto error;
+ ret = VIR_STORAGE_VOL(g_object_new(VIR_TYPE_STORAGE_VOL, NULL));
ret->pool = g_strdup(pool);
ret->name = g_strdup(name);
@@ -744,16 +756,12 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char
*name,
ret->privateData = privateData;
ret->privateDataFreeFunc = freeFunc;
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virStorageVolDispose:
+ * virStorageVolFinalize:
* @obj: the storage volume to release
*
* Unconditionally release all memory associated with a volume.
@@ -763,9 +771,9 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char
*name,
* which may also be released if its ref count hits zero.
*/
static void
-virStorageVolDispose(void *obj)
+virStorageVolFinalize(GObject *obj)
{
- virStorageVolPtr vol = obj;
+ virStorageVolPtr vol = VIR_STORAGE_VOL(obj);
VIR_DEBUG("release vol %p %s", vol, vol->name);
if (vol->privateDataFreeFunc)
@@ -775,6 +783,8 @@ virStorageVolDispose(void *obj)
VIR_FREE(vol->name);
VIR_FREE(vol->pool);
virObjectUnref(vol->conn);
+
+ G_OBJECT_CLASS(vir_storage_vol_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index a630472f6e..7fab565a7c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -35,7 +35,6 @@ extern virClassPtr virDomainClass;
extern virClassPtr virNodeDeviceClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
-extern virClassPtr virStorageVolClass;
#define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type()
@@ -74,6 +73,9 @@ G_DECLARE_FINAL_TYPE(virNWFilterBinding,
#define VIR_TYPE_STORAGE_POOL vir_storage_pool_get_type()
G_DECLARE_FINAL_TYPE(virStoragePool, vir_storage_pool, VIR, STORAGE_POOL, GObject);
+#define VIR_TYPE_STORAGE_VOL vir_storage_vol_get_type()
+G_DECLARE_FINAL_TYPE(virStorageVol, vir_storage_vol, VIR, STORAGE_VOL, GObject);
+
extern virClassPtr virAdmConnectClass;
#define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -221,8 +223,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckStorageVolReturn(obj, retval) \
do { \
- virStorageVolPtr _vol = (obj); \
- if (!virObjectIsClass(_vol, virStorageVolClass) || \
+ virStorageVolPtr _vol = VIR_STORAGE_VOL(obj); \
+ if (!G_IS_OBJECT(_vol) || !(G_OBJECT_TYPE(_vol) == VIR_TYPE_STORAGE_VOL) || \
!virObjectIsClass(_vol->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STORAGE, \
VIR_ERR_INVALID_STORAGE_VOL, \
@@ -234,8 +236,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
} while (0)
#define virCheckStorageVolGoto(obj, label) \
do { \
- virStorageVolPtr _vol = (obj); \
- if (!virObjectIsClass(_vol, virStorageVolClass) || \
+ virStorageVolPtr _vol = VIR_STORAGE_VOL(obj); \
+ if (!G_IS_OBJECT(_vol) || !(G_OBJECT_TYPE(_vol) == VIR_TYPE_STORAGE_VOL) || \
!virObjectIsClass(_vol->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STORAGE, \
VIR_ERR_INVALID_STORAGE_VOL, \
@@ -707,7 +709,7 @@ struct _virStoragePool {
* Internal structure associated to a storage volume
*/
struct _virStorageVol {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *pool; /* Pool name of owner */
char *name; /* the storage vol external name */
@@ -721,7 +723,6 @@ struct _virStorageVol {
virFreeCallback privateDataFreeFunc;
};
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virObjectUnref);
/**
diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c
index b88b2162de..53ad9eeec6 100644
--- a/src/libvirt-storage.c
+++ b/src/libvirt-storage.c
@@ -1884,7 +1884,7 @@ virStorageVolFree(virStorageVolPtr vol)
virCheckStorageVolReturn(vol, -1);
- virObjectUnref(vol);
+ g_object_unref(vol);
return 0;
}
@@ -1909,13 +1909,13 @@ virStorageVolFree(virStorageVolPtr vol)
int
virStorageVolRef(virStorageVolPtr vol)
{
- VIR_DEBUG("vol=%p refs=%d", vol, vol ? vol->parent.u.s.refs : 0);
+ VIR_DEBUG("vol=%p", vol);
virResetLastError();
virCheckStorageVolReturn(vol, -1);
- virObjectRef(vol);
+ g_object_ref(vol);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f48ed05684..7bee97f2dc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1367,7 +1367,6 @@ virGetStream;
virNewConnectCloseCallbackData;
virNodeDeviceClass;
virSecretClass;
-virStorageVolClass;
virStreamClass;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index de65c730f7..07e137e2c9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -175,7 +175,7 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
{
int ret = -1;
g_autoptr(virStoragePool) pool = NULL;
- virStorageVolPtr vol = NULL;
+ g_autoptr(virStorageVol) vol = NULL;
char *volName = NULL, *basePath = NULL;
char *volStr = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -268,7 +268,6 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
cleanup:
VIR_FREE(basePath);
VIR_FREE(volStr);
- virObjectUnref(vol);
return ret;
}
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 2db763caa5..8c0f7eae44 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1892,7 +1892,8 @@ storageVolCreateXML(virStoragePoolPtr pool,
virStoragePoolObjPtr obj;
virStoragePoolDefPtr def;
virStorageBackendPtr backend;
- virStorageVolPtr vol = NULL, newvol = NULL;
+ virStorageVolPtr vol = NULL;
+ g_autoptr(virStorageVol) newvol = NULL;
g_autoptr(virStorageVolDef) voldef = NULL;
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
@@ -2012,7 +2013,6 @@ storageVolCreateXML(virStoragePoolPtr pool,
voldef = NULL;
cleanup:
- virObjectUnref(newvol);
virStoragePoolObjEndAPI(&obj);
return vol;
}
@@ -2029,7 +2029,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
virStorageBackendPtr backend;
virStorageVolDefPtr voldefsrc = NULL;
virStorageVolDefPtr shadowvol = NULL;
- virStorageVolPtr newvol = NULL;
+ g_autoptr(virStorageVol) newvol = NULL;
virStorageVolPtr vol = NULL;
int buildret;
g_autoptr(virStorageVolDef) voldef = NULL;
@@ -2204,7 +2204,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
voldef = NULL;
cleanup:
- virObjectUnref(newvol);
VIR_FREE(shadowvol);
virStoragePoolObjEndAPI(&obj);
virStoragePoolObjEndAPI(&objsrc);
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index ed3d5ee2c0..17d8f9d94b 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -4082,9 +4082,8 @@ static int
virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src)
{
g_autoptr(virStoragePool) pool = NULL;
- virStorageVolPtr vol = NULL;
+ g_autoptr(virStorageVol) vol = NULL;
virStorageVolInfo info;
- int ret = -1;
if (!(pool = virStoragePoolLookupByName(conn, src->srcpool->pool)))
return -1;
@@ -4093,30 +4092,26 @@ virStorageTranslatePoolLocal(virConnectPtr conn,
virStorageSourcePtr src)
_("storage pool '%s' containing volume '%s'
"
"is not active"), src->srcpool->pool,
src->srcpool->volume);
- goto cleanup;
+ return -1;
}
if (!(vol = virStorageVolLookupByName(pool, src->srcpool->volume)))
- goto cleanup;
+ return -1;
if (virStorageVolGetInfo(vol, &info) < 0)
- goto cleanup;
+ return -1;
if (info.type != VIR_STORAGE_VOL_PLOOP) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported volume format '%s'"),
virStorageVolTypeToString(info.type));
- goto cleanup;
+ return -1;
}
if (!(src->path = virStorageVolGetPath(vol)))
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(vol);
- return ret;
+ return 0;
}
--
2.25.1