Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/virchrdev.c | 4 ++--
src/datatypes.c | 32 +++++++++++++++++++++--------
src/datatypes.h | 14 +++++++------
src/libvirt-stream.c | 7 +++----
src/libvirt_private.syms | 2 +-
src/libxl/libxl_migration.c | 3 +--
src/qemu/qemu_migration.c | 6 ++----
src/remote/remote_daemon_dispatch.c | 4 ++--
src/remote/remote_daemon_stream.c | 2 +-
src/remote/remote_driver.c | 2 +-
src/rpc/gendispatch.pl | 3 ++-
src/util/virfdstream.c | 4 ++--
12 files changed, 48 insertions(+), 35 deletions(-)
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 800e82869e..8a60ac4dad 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -205,7 +205,7 @@ static void virChrdevHashEntryFree(void *data)
return;
/* free stream reference */
- virObjectUnref(ent->st);
+ g_clear_object(&ent->st);
/* delete lock file */
virChrdevLockFileRemove(ent->dev);
@@ -435,7 +435,7 @@ int virChrdevOpen(virChrdevsPtr devs,
if (added)
virHashRemoveEntry(devs->hash, path);
else
- virObjectUnref(st);
+ g_clear_object(&st);
if (cbdata)
VIR_FREE(cbdata->path);
diff --git a/src/datatypes.c b/src/datatypes.c
index b98db8721f..1c8eff9685 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);
@@ -930,7 +943,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.
*/
@@ -942,8 +955,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);
@@ -951,7 +963,7 @@ virGetStream(virConnectPtr conn)
}
/**
- * virStreamDispose:
+ * virStreamFinalize:
* @obj: the stream to release
*
* Unconditionally release all memory associated with a stream.
@@ -961,14 +973,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 2f97268691..e96654cac1 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +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,
@@ -79,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()
@@ -307,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 (_st == NULL || \
!virObjectIsClass(_st->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STREAMS, \
VIR_ERR_INVALID_STREAM, \
@@ -320,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 (_st == NULL || \
!virObjectIsClass(_st->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_STREAMS, \
VIR_ERR_INVALID_STREAM, \
@@ -763,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 41b9cc1445..d1e2fde3b4 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;
}
@@ -1265,6 +1264,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 7a1e7b60dc..fc3fe83b14 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1367,6 +1367,7 @@ vir_nw_filter_get_type;
vir_secret_get_type;
vir_storage_pool_get_type;
vir_storage_vol_get_type;
+vir_stream_get_type;
virConnectClass;
virConnectCloseCallbackDataCall;
virConnectCloseCallbackDataClass;
@@ -1389,7 +1390,6 @@ virGetStoragePool;
virGetStorageVol;
virGetStream;
virNewConnectCloseCallbackData;
-virStreamClass;
# driver.h
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index defdda5ed6..50804ca8b8 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -999,7 +999,7 @@ libxlDoMigrateSrcP2P(libxlDriverPrivatePtr driver,
virErrorPtr orig_err = NULL;
int ret = -1;
/* For tunnel migration */
- virStreamPtr st = NULL;
+ g_autoptr(virStream) st = NULL;
struct libxlTunnelControl *tc = NULL;
if (dname &&
@@ -1110,7 +1110,6 @@ libxlDoMigrateSrcP2P(libxlDriverPrivatePtr driver,
cleanup:
if (flags & VIR_MIGRATE_TUNNELLED) {
libxlMigrationSrcStopTunnel(tc);
- virObjectUnref(st);
}
if (ddomain) {
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f1ad2806e8..1f5afbe0a4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3998,7 +3998,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, "
@@ -4107,7 +4107,6 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
ret = -1;
}
- virObjectUnref(st);
virErrorRestore(&orig_err);
VIR_FREE(uri_out);
@@ -4151,7 +4150,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;
@@ -4444,7 +4443,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 427cede17e..70c1dd3cbb 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -5641,7 +5641,7 @@ remoteDispatchDomainMigratePrepareTunnel3Params(virNetServerPtr
server G_GNUC_UN
char *cookieout = NULL;
int cookieoutlen = 0;
int rv = -1;
- virStreamPtr st = NULL;
+ g_autoptr(virStream) st = NULL;
daemonClientStreamPtr stream = NULL;
virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -5688,7 +5688,7 @@ remoteDispatchDomainMigratePrepareTunnel3Params(virNetServerPtr
server G_GNUC_UN
virStreamAbort(st);
daemonFreeClientStream(client, stream);
} else {
- virObjectUnref(st);
+ g_clear_object(&st);
}
}
return rv;
diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c
index 62bc9e0f5b..6e1dba3bc0 100644
--- a/src/remote/remote_daemon_stream.c
+++ b/src/remote/remote_daemon_stream.c
@@ -419,7 +419,7 @@ int daemonFreeClientStream(virNetServerClientPtr client,
msg = tmp;
}
- virObjectUnref(stream->st);
+ g_clear_object(&stream->st);
VIR_FREE(stream);
return ret;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index c108b56c34..b9337967af 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5823,7 +5823,7 @@ static void remoteStreamCallbackFree(void *opaque)
if (!cbdata->cb && cbdata->ff)
(cbdata->ff)(cbdata->opaque);
- virObjectUnref(cbdata->st);
+ g_clear_object(&cbdata->st);
VIR_FREE(opaque);
}
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 902ff091a5..29b3feb17c 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -207,6 +207,7 @@ my %gobject_impl = (
virSecret => 1,
virStoragePool => 1,
virStorageVol => 1,
+ virStream => 1,
);
sub use_gobject {
@@ -1068,7 +1069,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_clear_object(&st);");
push(@free_list_on_error, "}");
}
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 111e451f8c..e6271b860c 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -407,7 +407,7 @@ virFDStreamThreadDataFree(virFDStreamThreadDataPtr data)
if (!data)
return;
- virObjectUnref(data->st);
+ g_clear_object(&data->st);
VIR_FREE(data->fdinname);
VIR_FREE(data->fdoutname);
VIR_FREE(data);
@@ -1282,7 +1282,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.26.2