Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virstorageobj.c | 2 +-
src/datatypes.c | 48 ++++++++++++++++++++++--------------
src/datatypes.h | 15 +++++------
src/libvirt-storage.c | 6 ++---
src/libvirt_private.syms | 2 +-
src/qemu/qemu_migration.c | 3 +--
src/rpc/gendispatch.pl | 1 +
src/storage/storage_driver.c | 7 +++---
src/vz/vz_sdk.c | 19 ++++++--------
9 files changed, 54 insertions(+), 49 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 2ee74cae8e..815413418b 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1052,7 +1052,7 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
return data.nvols;
error:
- virObjectListFree(data.vols);
+ virGObjectListFreeCount(data.vols, data.nvols);
return -1;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index e434cc31f5..489c489761 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);
@@ -710,7 +723,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.
*/
@@ -718,18 +731,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);
@@ -741,16 +753,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.
@@ -760,9 +768,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)
@@ -772,6 +780,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 2c8256388c..5492c2ac8a 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()
G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
@@ -73,6 +72,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()
@@ -220,8 +222,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 (_vol == NULL || \
!virObjectIsClass(_vol->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STORAGE, \
VIR_ERR_INVALID_STORAGE_VOL, \
@@ -233,8 +235,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 (_vol == NULL || \
!virObjectIsClass(_vol->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STORAGE, \
VIR_ERR_INVALID_STORAGE_VOL, \
@@ -706,7 +708,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 */
@@ -720,7 +722,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 7548baa3f2..43dcd49786 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1364,6 +1364,7 @@ vir_network_port_get_type;
vir_nw_filter_binding_get_type;
vir_nw_filter_get_type;
vir_storage_pool_get_type;
+vir_storage_vol_get_type;
virConnectClass;
virConnectCloseCallbackDataCall;
virConnectCloseCallbackDataClass;
@@ -1388,7 +1389,6 @@ virGetStream;
virNewConnectCloseCallbackData;
virNodeDeviceClass;
virSecretClass;
-virStorageVolClass;
virStreamClass;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3fd3d570de..f1ad2806e8 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/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 8d19651367..1cfafe3742 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -204,6 +204,7 @@ my %gobject_impl = (
virNWFilter => 1,
virNWFilterBinding => 1,
virStoragePool => 1,
+ virStorageVol => 1,
);
sub use_gobject {
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 7e82c09be5..55c70af104 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.26.2