Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/conf/storage_event.c | 15 ++++------ src/conf/virstorageobj.c | 8 ++++- src/datatypes.c | 46 ++++++++++++++++++----------- src/datatypes.h | 15 +++++----- src/libvirt-storage.c | 6 ++-- src/libvirt_private.syms | 1 - src/qemu/qemu_migration.c | 3 +- src/remote/remote_daemon_dispatch.c | 2 +- src/remote/remote_driver.c | 4 +-- src/vz/vz_sdk.c | 3 +- 10 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c index de36ec3af9..e18069f718 100644 --- a/src/conf/storage_event.c +++ b/src/conf/storage_event.c @@ -110,10 +110,10 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn, virConnectObjectEventGenericCallback cb, void *cbopaque) { - virStoragePoolPtr pool = virGetStoragePool(conn, - event->meta.name, - event->meta.uuid, - NULL, NULL); + g_autoptr(virStoragePool) pool = virGetStoragePool(conn, + event->meta.name, + event->meta.uuid, + NULL, NULL); if (!pool) return; @@ -127,23 +127,20 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn, storagePoolLifecycleEvent->type, storagePoolLifecycleEvent->detail, cbopaque); - goto cleanup; + return; } case VIR_STORAGE_POOL_EVENT_ID_REFRESH: { ((virConnectStoragePoolEventGenericCallback)cb)(conn, pool, cbopaque); - goto cleanup; + return; } case VIR_STORAGE_POOL_EVENT_ID_LAST: break; } VIR_WARN("Unexpected event ID %d", event->eventID); - - cleanup: - virObjectUnref(pool); } diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 5cbd30f93c..bff6eb6ae1 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -2095,6 +2095,12 @@ virStoragePoolObjListExport(virConnectPtr conn, return data.nPools; error: - virObjectListFree(data.pools); + if (data.pools) { + while (data.nPools--) { + if (data.pools[data.nPools]) + g_object_unref(data.pools[data.nPools]); + } + } + VIR_FREE(data.pools); return -1; } diff --git a/src/datatypes.c b/src/datatypes.c index f1bcca44f1..e434c31785 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -40,7 +40,6 @@ virClassPtr virNodeDeviceClass; virClassPtr virSecretClass; virClassPtr virStreamClass; virClassPtr virStorageVolClass; -virClassPtr virStoragePoolClass; static void virConnectDispose(void *obj); static void virConnectCloseCallbackDataDispose(void *obj); @@ -49,7 +48,6 @@ static void virNodeDeviceDispose(void *obj); static void virSecretDispose(void *obj); static void virStreamDispose(void *obj); static void virStorageVolDispose(void *obj); -static void virStoragePoolDispose(void *obj); G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT); static void virDomainCheckpointFinalize(GObject *obj); @@ -163,6 +161,22 @@ vir_nw_filter_binding_class_init(virNWFilterBindingClass *klass) obj->finalize = virNWFilterBindingFinalize; } +G_DEFINE_TYPE(virStoragePool, vir_storage_pool, G_TYPE_OBJECT); +static void virStoragePoolFinalize(GObject *obj); + +static void +vir_storage_pool_init(virStoragePool *pool G_GNUC_UNUSED) +{ +} + +static void +vir_storage_pool_class_init(virStoragePoolClass *klass) +{ + GObjectClass *obj = G_OBJECT_CLASS(klass); + + obj->finalize = virStoragePoolFinalize; +} + virClassPtr virAdmConnectClass; virClassPtr virAdmConnectCloseCallbackDataClass; @@ -219,7 +233,6 @@ virDataTypesOnceInit(void) DECLARE_CLASS(virSecret); DECLARE_CLASS(virStream); DECLARE_CLASS(virStorageVol); - DECLARE_CLASS(virStoragePool); DECLARE_CLASS_LOCKABLE(virAdmConnect); DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData); @@ -628,7 +641,7 @@ virInterfaceFinalize(GObject *obj) * @freeFunc: private data cleanup function pointer specific to driver * * Allocates a new storage pool 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 pool object, or NULL on error. */ @@ -637,17 +650,16 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid, void *privateData, virFreeCallback freeFunc) { - virStoragePoolPtr ret = NULL; + g_autoptr(virStoragePool) ret = NULL; if (virDataTypesInitialize() < 0) return NULL; - virCheckConnectGoto(conn, error); - virCheckNonNullArgGoto(name, error); - virCheckNonNullArgGoto(uuid, error); + virCheckConnectReturn(conn, NULL); + virCheckNonNullArgReturn(name, NULL); + virCheckNonNullArgReturn(uuid, NULL); - if (!(ret = virObjectNew(virStoragePoolClass))) - goto error; + ret = VIR_STORAGE_POOL(g_object_new(VIR_TYPE_STORAGE_POOL, NULL)); ret->name = g_strdup(name); @@ -658,16 +670,12 @@ virGetStoragePool(virConnectPtr conn, const char *name, ret->privateData = privateData; ret->privateDataFreeFunc = freeFunc; - return ret; - - error: - virObjectUnref(ret); - return NULL; + return g_steal_pointer(&ret); } /** - * virStoragePoolDispose: + * virStoragePoolFinalize: * @obj: the storage pool to release * * Unconditionally release all memory associated with a pool. @@ -677,9 +685,9 @@ virGetStoragePool(virConnectPtr conn, const char *name, * which may also be released if its ref count hits zero. */ static void -virStoragePoolDispose(void *obj) +virStoragePoolFinalize(GObject *obj) { - virStoragePoolPtr pool = obj; + virStoragePoolPtr pool = VIR_STORAGE_POOL(obj); char uuidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(pool->uuid, uuidstr); @@ -690,6 +698,8 @@ virStoragePoolDispose(void *obj) VIR_FREE(pool->name); virObjectUnref(pool->conn); + + G_OBJECT_CLASS(vir_storage_pool_parent_class)->finalize(obj); } diff --git a/src/datatypes.h b/src/datatypes.h index c68a0e9265..a630472f6e 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -36,7 +36,6 @@ extern virClassPtr virNodeDeviceClass; extern virClassPtr virSecretClass; extern virClassPtr virStreamClass; extern virClassPtr virStorageVolClass; -extern virClassPtr virStoragePoolClass; #define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type() @@ -72,6 +71,9 @@ G_DECLARE_FINAL_TYPE(virNWFilterBinding, NW_FILTER_BINDING, GObject); +#define VIR_TYPE_STORAGE_POOL vir_storage_pool_get_type() +G_DECLARE_FINAL_TYPE(virStoragePool, vir_storage_pool, VIR, STORAGE_POOL, GObject); + extern virClassPtr virAdmConnectClass; #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type() @@ -192,8 +194,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject); #define virCheckStoragePoolReturn(obj, retval) \ do { \ - virStoragePoolPtr _pool = (obj); \ - if (!virObjectIsClass(_pool, virStoragePoolClass) || \ + virStoragePoolPtr _pool = VIR_STORAGE_POOL(obj); \ + if (!G_IS_OBJECT(_pool) || !(G_OBJECT_TYPE(_pool) == VIR_TYPE_STORAGE_POOL) || \ !virObjectIsClass(_pool->conn, virConnectClass)) { \ virReportErrorHelper(VIR_FROM_STORAGE, \ VIR_ERR_INVALID_STORAGE_POOL, \ @@ -206,8 +208,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject); #define virCheckStoragePoolGoto(obj, label) \ do { \ - virStoragePoolPtr _pool= (obj); \ - if (!virObjectIsClass(_pool, virStoragePoolClass) || \ + virStoragePoolPtr _pool= VIR_STORAGE_POOL(obj); \ + if (!G_IS_OBJECT(_pool) || !(G_OBJECT_TYPE(_pool) == VIR_TYPE_STORAGE_POOL) || \ !virObjectIsClass(_pool->conn, virConnectClass)) { \ virReportErrorHelper(VIR_FROM_STORAGE, \ VIR_ERR_INVALID_STORAGE_POOL, \ @@ -684,7 +686,7 @@ struct _virInterface { * Internal structure associated to a storage pool */ struct _virStoragePool { - virObject parent; + GObject parent; virConnectPtr conn; /* pointer back to the connection */ char *name; /* the storage pool external name */ unsigned char uuid[VIR_UUID_BUFLEN]; /* the storage pool unique identifier */ @@ -697,7 +699,6 @@ struct _virStoragePool { virFreeCallback privateDataFreeFunc; }; -G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virObjectUnref); /** diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c index 0406fe84d3..b88b2162de 100644 --- a/src/libvirt-storage.c +++ b/src/libvirt-storage.c @@ -846,7 +846,7 @@ virStoragePoolFree(virStoragePoolPtr pool) virCheckStoragePoolReturn(pool, -1); - virObjectUnref(pool); + g_object_unref(pool); return 0; } @@ -872,13 +872,13 @@ virStoragePoolFree(virStoragePoolPtr pool) int virStoragePoolRef(virStoragePoolPtr pool) { - VIR_DEBUG("pool=%p refs=%d", pool, pool ? pool->parent.u.s.refs : 0); + VIR_DEBUG("pool=%p", pool); virResetLastError(); virCheckStoragePoolReturn(pool, -1); - virObjectRef(pool); + g_object_ref(pool); return 0; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a5e4b00a0e..f48ed05684 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1367,7 +1367,6 @@ virGetStream; virNewConnectCloseCallbackData; virNodeDeviceClass; virSecretClass; -virStoragePoolClass; virStorageVolClass; virStreamClass; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index bc280e856a..de65c730f7 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -174,7 +174,7 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, unsigned long long capacity) { int ret = -1; - virStoragePoolPtr pool = NULL; + g_autoptr(virStoragePool) pool = NULL; virStorageVolPtr vol = NULL; char *volName = NULL, *basePath = NULL; char *volStr = NULL; @@ -269,7 +269,6 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, VIR_FREE(basePath); VIR_FREE(volStr); virObjectUnref(vol); - virObjectUnref(pool); return ret; } diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index 9f5aee07cd..9f367bc515 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -6196,7 +6196,7 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server G_GNUC_U remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); - virObjectUnref(pool); + g_object_unref(pool); return rv; } diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index f19061200c..f5d7842104 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5493,7 +5493,7 @@ remoteStoragePoolBuildEventLifecycle(virNetClientProgramPtr prog G_GNUC_UNUSED, event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, msg->event, msg->detail); - virObjectUnref(pool); + g_object_unref(pool); virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID); } @@ -5514,7 +5514,7 @@ remoteStoragePoolBuildEventRefresh(virNetClientProgramPtr prog G_GNUC_UNUSED, return; event = virStoragePoolEventRefreshNew(pool->name, pool->uuid); - virObjectUnref(pool); + g_object_unref(pool); virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID); } diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 9cee6f1fde..ed3d5ee2c0 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4081,7 +4081,7 @@ prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def) static int virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src) { - virStoragePoolPtr pool = NULL; + g_autoptr(virStoragePool) pool = NULL; virStorageVolPtr vol = NULL; virStorageVolInfo info; int ret = -1; @@ -4115,7 +4115,6 @@ virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src) ret = 0; cleanup: - virObjectUnref(pool); virObjectUnref(vol); return ret; } -- 2.25.1