Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/conf/virchrdev.c | 5 +++-- src/datatypes.c | 32 +++++++++++++++++++++-------- src/datatypes.h | 15 +++++++------- src/libvirt-stream.c | 7 +++---- src/libvirt_private.syms | 1 - src/libxl/libxl_migration.c | 2 +- src/qemu/qemu_migration.c | 6 ++---- src/remote/remote_daemon_dispatch.c | 2 +- src/remote/remote_daemon_stream.c | 3 ++- src/remote/remote_driver.c | 3 ++- src/rpc/gendispatch.pl | 2 +- src/util/virfdstream.c | 5 +++-- 12 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 800e82869e..2338d40c39 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -205,7 +205,8 @@ static void virChrdevHashEntryFree(void *data) return; /* free stream reference */ - virObjectUnref(ent->st); + if (ent->st) + g_object_unref(ent->st); /* delete lock file */ virChrdevLockFileRemove(ent->dev); @@ -435,7 +436,7 @@ int virChrdevOpen(virChrdevsPtr devs, if (added) virHashRemoveEntry(devs->hash, path); else - virObjectUnref(st); + g_object_unref(st); if (cbdata) VIR_FREE(cbdata->path); diff --git a/src/datatypes.c b/src/datatypes.c index 4f2bca6e6d..8cf9e0c51b 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -36,12 +36,10 @@ VIR_LOG_INIT("datatypes"); virClassPtr virConnectClass; virClassPtr virConnectCloseCallbackDataClass; virClassPtr virDomainClass; -virClassPtr virStreamClass; static void virConnectDispose(void *obj); static void virConnectCloseCallbackDataDispose(void *obj); static void virDomainDispose(void *obj); -static void virStreamDispose(void *obj); G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT); static void virDomainCheckpointFinalize(GObject *obj); @@ -219,6 +217,22 @@ vir_storage_vol_class_init(virStorageVolClass *klass) obj->finalize = virStorageVolFinalize; } +G_DEFINE_TYPE(virStream, vir_stream, G_TYPE_OBJECT); +static void virStreamFinalize(GObject *obj); + +static void +vir_stream_init(virStream *strm G_GNUC_UNUSED) +{ +} + +static void +vir_stream_class_init(virStreamClass *klass) +{ + GObjectClass *obj = G_OBJECT_CLASS(klass); + + obj->finalize = virStreamFinalize; +} + virClassPtr virAdmConnectClass; virClassPtr virAdmConnectCloseCallbackDataClass; @@ -271,7 +285,6 @@ virDataTypesOnceInit(void) DECLARE_CLASS_LOCKABLE(virConnect); DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData); DECLARE_CLASS(virDomain); - DECLARE_CLASS(virStream); DECLARE_CLASS_LOCKABLE(virAdmConnect); DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData); @@ -933,7 +946,7 @@ virSecretFinalize(GObject *obj) * @conn: the hypervisor connection * * Allocates a new stream 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 stream object, or NULL on error. */ @@ -945,8 +958,7 @@ virGetStream(virConnectPtr conn) if (virDataTypesInitialize() < 0) return NULL; - if (!(ret = virObjectNew(virStreamClass))) - return NULL; + ret = VIR_STREAM(g_object_new(VIR_TYPE_STREAM, NULL)); ret->conn = virObjectRef(conn); @@ -954,7 +966,7 @@ virGetStream(virConnectPtr conn) } /** - * virStreamDispose: + * virStreamFinalize: * @obj: the stream to release * * Unconditionally release all memory associated with a stream. @@ -964,14 +976,16 @@ virGetStream(virConnectPtr conn) * which may also be released if its ref count hits zero. */ static void -virStreamDispose(void *obj) +virStreamFinalize(GObject *obj) { - virStreamPtr st = obj; + virStreamPtr st = VIR_STREAM(obj); VIR_DEBUG("release dev %p", st); if (st->ff) st->ff(st->privateData); virObjectUnref(st->conn); + + G_OBJECT_CLASS(vir_stream_parent_class)->finalize(obj); } diff --git a/src/datatypes.h b/src/datatypes.h index 4b0747f728..759e5487c3 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -32,8 +32,6 @@ extern virClassPtr virConnectClass; extern virClassPtr virDomainClass; -extern virClassPtr virStreamClass; - #define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type() G_DECLARE_FINAL_TYPE(virDomainCheckpoint, @@ -80,6 +78,9 @@ G_DECLARE_FINAL_TYPE(virStoragePool, vir_storage_pool, VIR, STORAGE_POOL, GObjec #define VIR_TYPE_STORAGE_VOL vir_storage_vol_get_type() G_DECLARE_FINAL_TYPE(virStorageVol, vir_storage_vol, VIR, STORAGE_VOL, GObject); +#define VIR_TYPE_STREAM vir_stream_get_type() +G_DECLARE_FINAL_TYPE(virStream, vir_stream, VIR, STREAM, GObject); + extern virClassPtr virAdmConnectClass; #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type() @@ -308,8 +309,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject); #define virCheckStreamReturn(obj, retval) \ do { \ - virStreamPtr _st = (obj); \ - if (!virObjectIsClass(_st, virStreamClass) || \ + virStreamPtr _st = VIR_STREAM(obj); \ + if (!G_IS_OBJECT(_st) || !(G_OBJECT_TYPE(_st) == VIR_TYPE_STREAM) || \ !virObjectIsClass(_st->conn, virConnectClass)) { \ virReportErrorHelper(VIR_FROM_STREAMS, \ VIR_ERR_INVALID_STREAM, \ @@ -321,8 +322,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject); } while (0) #define virCheckStreamGoto(obj, label) \ do { \ - virStreamPtr _st = (obj); \ - if (!virObjectIsClass(_st, virStreamClass) || \ + virStreamPtr _st = VIR_STREAM(obj); \ + if (!G_IS_OBJECT(_st) || !(G_OBJECT_TYPE(_st) == VIR_TYPE_STREAM) || \ !virObjectIsClass(_st->conn, virConnectClass)) { \ virReportErrorHelper(VIR_FROM_STREAMS, \ VIR_ERR_INVALID_STREAM, \ @@ -764,7 +765,7 @@ typedef int (*virStreamFinishFunc)(virStreamPtr, void *opaque); * Internal structure associated with an input stream */ struct _virStream { - virObject parent; + GObject parent; virConnectPtr conn; unsigned int flags; diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c index 6f6bb5df0b..95d975b61b 100644 --- a/src/libvirt-stream.c +++ b/src/libvirt-stream.c @@ -85,14 +85,13 @@ virStreamNew(virConnectPtr conn, int virStreamRef(virStreamPtr stream) { - VIR_DEBUG("stream=%p refs=%d", stream, - stream ? stream->parent.u.s.refs : 0); + VIR_DEBUG("stream=%p", stream); virResetLastError(); virCheckStreamReturn(stream, -1); - virObjectRef(stream); + g_object_ref(stream); return 0; } @@ -1273,6 +1272,6 @@ virStreamFree(virStreamPtr stream) /* XXX Enforce shutdown before free'ing resources ? */ - virObjectUnref(stream); + g_object_unref(stream); return 0; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b66c3623f6..86331a97bc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1365,7 +1365,6 @@ virGetStoragePool; virGetStorageVol; virGetStream; virNewConnectCloseCallbackData; -virStreamClass; # driver.h diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index defdda5ed6..ac462aaf3f 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -1110,7 +1110,7 @@ libxlDoMigrateSrcP2P(libxlDriverPrivatePtr driver, cleanup: if (flags & VIR_MIGRATE_TUNNELLED) { libxlMigrationSrcStopTunnel(tc); - virObjectUnref(st); + g_object_unref(st); } if (ddomain) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 07e137e2c9..13ff06f5c7 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4000,7 +4000,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver, int cookielen = 0, ret; virErrorPtr orig_err = NULL; bool cancelled; - virStreamPtr st = NULL; + g_autoptr(virStream) st = NULL; unsigned long destflags; VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, dconnuri=%s, " @@ -4109,7 +4109,6 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver, ret = -1; } - virObjectUnref(st); virErrorRestore(&orig_err); VIR_FREE(uri_out); @@ -4153,7 +4152,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver, int ret = -1; virErrorPtr orig_err = NULL; bool cancelled = true; - virStreamPtr st = NULL; + g_autoptr(virStream) st = NULL; unsigned long destflags; virTypedParameterPtr params = NULL; int nparams = 0; @@ -4446,7 +4445,6 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver, ret = -1; } - virObjectUnref(st); virErrorRestore(&orig_err); VIR_FREE(uri_out); diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index a2dd0415b3..f3bbfbea32 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -5690,7 +5690,7 @@ remoteDispatchDomainMigratePrepareTunnel3Params(virNetServerPtr server G_GNUC_UN virStreamAbort(st); daemonFreeClientStream(client, stream); } else { - virObjectUnref(st); + g_object_unref(st); } } return rv; diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c index ec9667fe56..cc11f88688 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -420,7 +420,8 @@ int daemonFreeClientStream(virNetServerClientPtr client, msg = tmp; } - virObjectUnref(stream->st); + if (stream->st) + g_object_unref(stream->st); VIR_FREE(stream); return ret; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 65c2b92f1e..bb04db9aa7 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5836,7 +5836,8 @@ static void remoteStreamCallbackFree(void *opaque) if (!cbdata->cb && cbdata->ff) (cbdata->ff)(cbdata->opaque); - virObjectUnref(cbdata->st); + if (cbdata->st) + g_object_unref(cbdata->st); VIR_FREE(opaque); } diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 3187a0b798..0d0cce551a 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1026,7 +1026,7 @@ elsif ($mode eq "server") { push(@free_list_on_error, " virStreamAbort(st);"); push(@free_list_on_error, " daemonFreeClientStream(client, stream);"); push(@free_list_on_error, "} else {"); - push(@free_list_on_error, " virObjectUnref(st);"); + push(@free_list_on_error, " g_object_unref(st);"); push(@free_list_on_error, "}"); } diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 111e451f8c..013b6dd1f5 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -407,7 +407,8 @@ virFDStreamThreadDataFree(virFDStreamThreadDataPtr data) if (!data) return; - virObjectUnref(data->st); + if (data->st) + g_object_unref(data->st); VIR_FREE(data->fdinname); VIR_FREE(data->fdoutname); VIR_FREE(data); @@ -1282,7 +1283,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, if (VIR_ALLOC(threadData) < 0) goto error; - threadData->st = virObjectRef(st); + threadData->st = g_object_ref(st); threadData->length = length; threadData->sparse = sparse; -- 2.25.1