Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/admin/admin_remote.c | 9 +++----
src/locking/lock_driver_lockd.c | 19 +++++++-------
src/logging/log_manager.c | 15 +++++------
src/lxc/lxc_monitor.c | 2 +-
src/remote/remote_driver.c | 46 +++++++++++++++------------------
src/rpc/virnetclient.c | 7 ++---
src/rpc/virnetclientprogram.c | 29 ++++++---------------
src/rpc/virnetclientprogram.h | 10 +++++--
src/rpc/virnetclientstream.c | 4 +--
9 files changed, 62 insertions(+), 79 deletions(-)
diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
index ca5e0c9fe4..c732379695 100644
--- a/src/admin/admin_remote.c
+++ b/src/admin/admin_remote.c
@@ -41,7 +41,7 @@ remoteAdminPrivDispose(void *opaque)
{
remoteAdminPrivPtr priv = opaque;
- virObjectUnref(priv->program);
+ g_clear_object(&priv->program);
virObjectUnref(priv->client);
}
@@ -227,10 +227,9 @@ remoteAdminPrivNew(const char *sock_path)
if (!(priv->client = virNetClientNewUNIX(sock_path, false, NULL)))
goto error;
- if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
- ADMIN_PROTOCOL_VERSION,
- NULL, 0, NULL)))
- goto error;
+ priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
+ ADMIN_PROTOCOL_VERSION,
+ NULL, 0, NULL);
if (virNetClientAddProgram(priv->client, priv->program) < 0)
goto error;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index bec98dd05f..3101454a1d 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -213,12 +213,11 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool
privileged,
daemonPath)))
goto error;
- if (!(*prog = virNetClientProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
- VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
- NULL,
- 0,
- NULL)))
- goto error;
+ *prog = virNetClientProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
+ VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
+ NULL,
+ 0,
+ NULL);
if (virNetClientAddProgram(client, *prog) < 0)
goto error;
@@ -233,7 +232,7 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool
privileged,
VIR_FREE(lockdpath);
virNetClientClose(client);
virObjectUnref(client);
- virObjectUnref(*prog);
+ g_clear_object(prog);
return NULL;
}
@@ -296,7 +295,7 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path)
rv = 0;
cleanup:
- virObjectUnref(program);
+ g_clear_object(&program);
virNetClientClose(client);
virObjectUnref(client);
return rv;
@@ -660,7 +659,7 @@ static int virLockManagerLockDaemonAcquire(virLockManagerPtr lock,
VIR_FORCE_CLOSE(*fd);
virNetClientClose(client);
virObjectUnref(client);
- virObjectUnref(program);
+ g_clear_object(&program);
return rv;
}
@@ -713,7 +712,7 @@ static int virLockManagerLockDaemonRelease(virLockManagerPtr lock,
cleanup:
virNetClientClose(client);
virObjectUnref(client);
- virObjectUnref(program);
+ g_clear_object(&program);
return rv;
}
diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c
index fd7c2922b3..0428ea4728 100644
--- a/src/logging/log_manager.c
+++ b/src/logging/log_manager.c
@@ -83,12 +83,11 @@ virLogManagerConnect(bool privileged,
daemonPath)))
goto error;
- if (!(*prog = virNetClientProgramNew(VIR_LOG_MANAGER_PROTOCOL_PROGRAM,
- VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION,
- NULL,
- 0,
- NULL)))
- goto error;
+ *prog = virNetClientProgramNew(VIR_LOG_MANAGER_PROTOCOL_PROGRAM,
+ VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION,
+ NULL,
+ 0,
+ NULL);
if (virNetClientAddProgram(client, *prog) < 0)
goto error;
@@ -103,7 +102,7 @@ virLogManagerConnect(bool privileged,
VIR_FREE(logdpath);
virNetClientClose(client);
virObjectUnref(client);
- virObjectUnref(*prog);
+ g_clear_object(prog);
return NULL;
}
@@ -135,7 +134,7 @@ virLogManagerFree(virLogManagerPtr mgr)
if (mgr->client)
virNetClientClose(mgr->client);
- virObjectUnref(mgr->program);
+ g_clear_object(&mgr->program);
virObjectUnref(mgr->client);
VIR_FREE(mgr);
diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 479125374b..b3d6da6b98 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -198,7 +198,7 @@ static void virLXCMonitorDispose(void *opaque)
VIR_DEBUG("mon=%p", mon);
if (mon->cb.destroy)
(mon->cb.destroy)(mon, mon->vm);
- virObjectUnref(mon->program);
+ g_clear_object(&mon->program);
virObjectUnref(mon->vm);
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 7bae0c2514..09e3e8c51b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1280,24 +1280,21 @@ doRemoteOpen(virConnectPtr conn,
remoteClientCloseFunc,
priv->closeCallback, virObjectFreeCallback);
- if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM,
- REMOTE_PROTOCOL_VERSION,
- remoteEvents,
- G_N_ELEMENTS(remoteEvents),
- conn)))
- goto failed;
- if (!(priv->lxcProgram = virNetClientProgramNew(LXC_PROGRAM,
- LXC_PROTOCOL_VERSION,
- NULL,
- 0,
- NULL)))
- goto failed;
- if (!(priv->qemuProgram = virNetClientProgramNew(QEMU_PROGRAM,
- QEMU_PROTOCOL_VERSION,
- qemuEvents,
- G_N_ELEMENTS(qemuEvents),
- conn)))
- goto failed;
+ priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM,
+ REMOTE_PROTOCOL_VERSION,
+ remoteEvents,
+ G_N_ELEMENTS(remoteEvents),
+ conn);
+ priv->lxcProgram = virNetClientProgramNew(LXC_PROGRAM,
+ LXC_PROTOCOL_VERSION,
+ NULL,
+ 0,
+ NULL);
+ priv->qemuProgram = virNetClientProgramNew(QEMU_PROGRAM,
+ QEMU_PROTOCOL_VERSION,
+ qemuEvents,
+ G_N_ELEMENTS(qemuEvents),
+ conn);
if (virNetClientAddProgram(priv->client, priv->remoteProgram) < 0 ||
virNetClientAddProgram(priv->client, priv->lxcProgram) < 0 ||
@@ -1369,9 +1366,9 @@ doRemoteOpen(virConnectPtr conn,
return VIR_DRV_OPEN_SUCCESS;
failed:
- virObjectUnref(priv->remoteProgram);
- virObjectUnref(priv->lxcProgram);
- virObjectUnref(priv->qemuProgram);
+ g_clear_object(&priv->remoteProgram);
+ g_clear_object(&priv->lxcProgram);
+ g_clear_object(&priv->qemuProgram);
virNetClientClose(priv->client);
virObjectUnref(priv->client);
priv->client = NULL;
@@ -1532,10 +1529,9 @@ doRemoteClose(virConnectPtr conn, struct private_data *priv)
priv->client = NULL;
virObjectUnref(priv->closeCallback);
priv->closeCallback = NULL;
- virObjectUnref(priv->remoteProgram);
- virObjectUnref(priv->lxcProgram);
- virObjectUnref(priv->qemuProgram);
- priv->remoteProgram = priv->qemuProgram = priv->lxcProgram = NULL;
+ g_clear_object(&priv->remoteProgram);
+ g_clear_object(&priv->lxcProgram);
+ g_clear_object(&priv->qemuProgram);
/* Free hostname copy */
VIR_FREE(priv->hostname);
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1c5bef86a1..9bec5235b9 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -676,7 +676,6 @@ bool virNetClientHasPassFD(virNetClientPtr client)
void virNetClientDispose(void *obj)
{
virNetClientPtr client = obj;
- size_t i;
PROBE(RPC_CLIENT_DISPOSE,
"client=%p", client);
@@ -684,9 +683,7 @@ void virNetClientDispose(void *obj)
if (client->closeFf)
client->closeFf(client->closeOpaque);
- for (i = 0; i < client->nprograms; i++)
- virObjectUnref(client->programs[i]);
- VIR_FREE(client->programs);
+ virGObjectListFreeCount(client->programs, client->nprograms);
g_main_loop_unref(client->eventLoop);
g_main_context_unref(client->eventCtx);
@@ -1010,7 +1007,7 @@ int virNetClientAddProgram(virNetClientPtr client,
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
goto error;
- client->programs[client->nprograms-1] = virObjectRef(prog);
+ client->programs[client->nprograms-1] = g_object_ref(prog);
virObjectUnlock(client);
return 0;
diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c
index 4d1a2bc28b..d76f3eaea7 100644
--- a/src/rpc/virnetclientprogram.c
+++ b/src/rpc/virnetclientprogram.c
@@ -38,7 +38,7 @@
VIR_LOG_INIT("rpc.netclientprogram");
struct _virNetClientProgram {
- virObject parent;
+ GObject parent;
unsigned program;
unsigned version;
@@ -47,19 +47,15 @@ struct _virNetClientProgram {
void *eventOpaque;
};
-static virClassPtr virNetClientProgramClass;
-static void virNetClientProgramDispose(void *obj);
+G_DEFINE_TYPE(virNetClientProgram, vir_net_client_program, G_TYPE_OBJECT);
-static int virNetClientProgramOnceInit(void)
+static void vir_net_client_program_init(virNetClientProgram *prg G_GNUC_UNUSED)
{
- if (!VIR_CLASS_NEW(virNetClientProgram, virClassForObject()))
- return -1;
-
- return 0;
}
-VIR_ONCE_GLOBAL_INIT(virNetClientProgram);
-
+static void vir_net_client_program_class_init(virNetClientProgramClass *klass
G_GNUC_UNUSED)
+{
+}
virNetClientProgramPtr virNetClientProgramNew(unsigned program,
unsigned version,
@@ -67,13 +63,9 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
size_t nevents,
void *eventOpaque)
{
- virNetClientProgramPtr prog;
+ virNetClientProgramPtr prog =
+ VIR_NET_CLIENT_PROGRAM(g_object_new(VIR_TYPE_NET_CLIENT_PROGRAM, NULL));
- if (virNetClientProgramInitialize() < 0)
- return NULL;
-
- if (!(prog = virObjectNew(virNetClientProgramClass)))
- return NULL;
prog->program = program;
prog->version = version;
@@ -85,11 +77,6 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
}
-void virNetClientProgramDispose(void *obj G_GNUC_UNUSED)
-{
-}
-
-
unsigned virNetClientProgramGetProgram(virNetClientProgramPtr prog)
{
return prog->program;
diff --git a/src/rpc/virnetclientprogram.h b/src/rpc/virnetclientprogram.h
index 1ac0f30023..1f7006d462 100644
--- a/src/rpc/virnetclientprogram.h
+++ b/src/rpc/virnetclientprogram.h
@@ -24,12 +24,18 @@
#include <rpc/xdr.h>
#include "virnetmessage.h"
-#include "virobject.h"
+#include "internal.h"
+#include <glib-object.h>
typedef struct _virNetClient virNetClient;
typedef virNetClient *virNetClientPtr;
-typedef struct _virNetClientProgram virNetClientProgram;
+#define VIR_TYPE_NET_CLIENT_PROGRAM vir_net_client_program_get_type()
+G_DECLARE_FINAL_TYPE(virNetClientProgram,
+ vir_net_client_program,
+ VIR,
+ NET_CLIENT_PROGRAM,
+ GObject);
typedef virNetClientProgram *virNetClientProgramPtr;
typedef struct _virNetClientProgramEvent virNetClientProgramEvent;
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index f904eaba31..183eddd98b 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -145,7 +145,7 @@ virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr
prog,
if (!(st = virObjectLockableNew(virNetClientStreamClass)))
return NULL;
- st->prog = virObjectRef(prog);
+ st->prog = g_object_ref(prog);
st->proc = proc;
st->serial = serial;
st->allowSkip = allowSkip;
@@ -163,7 +163,7 @@ void virNetClientStreamDispose(void *obj)
virNetMessageQueueServe(&st->rx);
virNetMessageFree(msg);
}
- virObjectUnref(st->prog);
+ g_clear_object(&st->prog);
}
bool virNetClientStreamMatches(virNetClientStreamPtr st,
--
2.25.3