Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/locking/lock_daemon.c | 28 ++++++----------
src/logging/log_daemon.c | 28 ++++++----------
src/lxc/lxc_controller.c | 11 +++---
src/remote/remote_daemon.c | 52 ++++++++++-------------------
src/remote/remote_daemon_dispatch.c | 18 +++++-----
src/remote/remote_daemon_stream.c | 4 +--
src/rpc/virnetserver.c | 14 ++++----
src/rpc/virnetserverprogram.c | 30 +++++------------
src/rpc/virnetserverprogram.h | 10 ++++--
9 files changed, 77 insertions(+), 118 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index b0cd89375b..c4faf3349d 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -859,8 +859,8 @@ virLockDaemonUsage(const char *argv0, bool privileged)
int main(int argc, char **argv) {
virNetServerPtr lockSrv = NULL;
virNetServerPtr adminSrv = NULL;
- virNetServerProgramPtr lockProgram = NULL;
- virNetServerProgramPtr adminProgram = NULL;
+ g_autoptr(virNetServerProgram) lockProgram = NULL;
+ g_autoptr(virNetServerProgram) adminProgram = NULL;
char *remote_config_file = NULL;
int statuswrite = -1;
int ret = 1;
@@ -1133,13 +1133,10 @@ int main(int argc, char **argv) {
goto cleanup;
}
- if (!(lockProgram = virNetServerProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
- VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
- virLockSpaceProtocolProcs,
- virLockSpaceProtocolNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ lockProgram = virNetServerProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
+ VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
+ virLockSpaceProtocolProcs,
+ virLockSpaceProtocolNProcs);
if (virNetServerAddProgram(lockSrv, lockProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
@@ -1147,13 +1144,10 @@ int main(int argc, char **argv) {
}
if (adminSrv != NULL) {
- if (!(adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
- ADMIN_PROTOCOL_VERSION,
- adminProcs,
- adminNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
+ ADMIN_PROTOCOL_VERSION,
+ adminProcs,
+ adminNProcs);
if (virNetServerAddProgram(adminSrv, adminProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
@@ -1190,8 +1184,6 @@ int main(int argc, char **argv) {
ret = 0;
cleanup:
- virObjectUnref(lockProgram);
- virObjectUnref(adminProgram);
virObjectUnref(lockSrv);
virObjectUnref(adminSrv);
virLockDaemonFree(lockDaemon);
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 7017db2dcc..40cfae9ae8 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -640,8 +640,8 @@ virLogDaemonUsage(const char *argv0, bool privileged)
int main(int argc, char **argv) {
virNetServerPtr logSrv = NULL;
virNetServerPtr adminSrv = NULL;
- virNetServerProgramPtr logProgram = NULL;
- virNetServerProgramPtr adminProgram = NULL;
+ g_autoptr(virNetServerProgram) logProgram = NULL;
+ g_autoptr(virNetServerProgram) adminProgram = NULL;
char *remote_config_file = NULL;
int statuswrite = -1;
int ret = 1;
@@ -915,26 +915,20 @@ int main(int argc, char **argv) {
goto cleanup;
}
- if (!(logProgram = virNetServerProgramNew(VIR_LOG_MANAGER_PROTOCOL_PROGRAM,
- VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION,
- virLogManagerProtocolProcs,
- virLogManagerProtocolNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ logProgram = virNetServerProgramNew(VIR_LOG_MANAGER_PROTOCOL_PROGRAM,
+ VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION,
+ virLogManagerProtocolProcs,
+ virLogManagerProtocolNProcs);
if (virNetServerAddProgram(logSrv, logProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
if (adminSrv != NULL) {
- if (!(adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
- ADMIN_PROTOCOL_VERSION,
- adminProcs,
- adminNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
+ ADMIN_PROTOCOL_VERSION,
+ adminProcs,
+ adminNProcs);
if (virNetServerAddProgram(adminSrv, adminProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
@@ -970,8 +964,6 @@ int main(int argc, char **argv) {
ret = 0;
cleanup:
- virObjectUnref(logProgram);
- virObjectUnref(adminProgram);
virObjectUnref(logSrv);
virObjectUnref(adminSrv);
virLogDaemonFree(logDaemon);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 43f75d639a..f078c1c425 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -316,6 +316,7 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
VIR_FREE(ctrl->nsFDs);
virCgroupFree(&ctrl->cgroup);
+ g_clear_object(&ctrl->prog);
/* This must always be the last thing to be closed */
VIR_FORCE_CLOSE(ctrl->handshakeFd);
VIR_FREE(ctrl);
@@ -991,11 +992,10 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
virObjectUnref(svc);
svc = NULL;
- if (!(ctrl->prog = virNetServerProgramNew(VIR_LXC_MONITOR_PROGRAM,
- VIR_LXC_MONITOR_PROGRAM_VERSION,
- virLXCMonitorProcs,
- virLXCMonitorNProcs)))
- goto error;
+ ctrl->prog = virNetServerProgramNew(VIR_LXC_MONITOR_PROGRAM,
+ VIR_LXC_MONITOR_PROGRAM_VERSION,
+ virLXCMonitorProcs,
+ virLXCMonitorNProcs);
if (!(ctrl->daemon = virNetDaemonNew()) ||
virNetDaemonAddServer(ctrl->daemon, srv) < 0)
@@ -1007,6 +1007,7 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
error:
VIR_FREE(sockpath);
+ g_clear_object(&ctrl->prog);
virObjectUnref(srv);
virObjectUnref(ctrl->daemon);
ctrl->daemon = NULL;
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 1aa9bfc0d2..e015034333 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -760,8 +760,8 @@ int main(int argc, char **argv) {
virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL;
virNetServerPtr srvAdm = NULL;
- virNetServerProgramPtr adminProgram = NULL;
- virNetServerProgramPtr lxcProgram = NULL;
+ g_autoptr(virNetServerProgram) adminProgram = NULL;
+ g_autoptr(virNetServerProgram) lxcProgram = NULL;
char *remote_config_file = NULL;
int statuswrite = -1;
int ret = 1;
@@ -1038,37 +1038,28 @@ int main(int argc, char **argv) {
remoteProcs[REMOTE_PROC_AUTH_SASL_STEP].needAuth = false;
remoteProcs[REMOTE_PROC_AUTH_SASL_START].needAuth = false;
remoteProcs[REMOTE_PROC_AUTH_POLKIT].needAuth = false;
- if (!(remoteProgram = virNetServerProgramNew(REMOTE_PROGRAM,
- REMOTE_PROTOCOL_VERSION,
- remoteProcs,
- remoteNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ remoteProgram = virNetServerProgramNew(REMOTE_PROGRAM,
+ REMOTE_PROTOCOL_VERSION,
+ remoteProcs,
+ remoteNProcs);
if (virNetServerAddProgram(srv, remoteProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (!(lxcProgram = virNetServerProgramNew(LXC_PROGRAM,
- LXC_PROTOCOL_VERSION,
- lxcProcs,
- lxcNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ lxcProgram = virNetServerProgramNew(LXC_PROGRAM,
+ LXC_PROTOCOL_VERSION,
+ lxcProcs,
+ lxcNProcs);
if (virNetServerAddProgram(srv, lxcProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
- if (!(qemuProgram = virNetServerProgramNew(QEMU_PROGRAM,
- QEMU_PROTOCOL_VERSION,
- qemuProcs,
- qemuNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ qemuProgram = virNetServerProgramNew(QEMU_PROGRAM,
+ QEMU_PROTOCOL_VERSION,
+ qemuProcs,
+ qemuNProcs);
if (virNetServerAddProgram(srv, qemuProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
@@ -1095,13 +1086,10 @@ int main(int argc, char **argv) {
goto cleanup;
}
- if (!(adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
- ADMIN_PROTOCOL_VERSION,
- adminProcs,
- adminNProcs))) {
- ret = VIR_DAEMON_ERR_INIT;
- goto cleanup;
- }
+ adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
+ ADMIN_PROTOCOL_VERSION,
+ adminProcs,
+ adminNProcs);
if (virNetServerAddProgram(srvAdm, adminProgram) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
@@ -1213,11 +1201,7 @@ int main(int argc, char **argv) {
virStateCleanup();
}
- virObjectUnref(adminProgram);
virObjectUnref(srvAdm);
- virObjectUnref(qemuProgram);
- virObjectUnref(lxcProgram);
- virObjectUnref(remoteProgram);
virObjectUnref(srv);
virObjectUnref(dmn);
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index 6f67d2fb30..3b016636e0 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -150,7 +150,7 @@ remoteEventCallbackFree(void *opaque)
daemonClientEventCallbackPtr callback = opaque;
if (!callback)
return;
- virObjectUnref(callback->program);
+ g_clear_object(&callback->program);
virObjectUnref(callback->client);
VIR_FREE(callback);
}
@@ -4255,7 +4255,7 @@ remoteDispatchConnectDomainEventRegister(virNetServerPtr server
G_GNUC_UNUSED,
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
callback->callbackID = -1;
callback->legacy = true;
@@ -4484,7 +4484,7 @@ remoteDispatchConnectDomainEventRegisterAny(virNetServerPtr server
G_GNUC_UNUSED
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
callback->legacy = true;
@@ -4560,7 +4560,7 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr
server G_GNU
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
ref = callback;
@@ -6043,7 +6043,7 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server
G_GNUC_UNUSE
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
ref = callback;
@@ -6164,7 +6164,7 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr
server G_GNUC_U
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
ref = callback;
@@ -6284,7 +6284,7 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(virNetServerPtr
server G_GNUC_UN
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
ref = callback;
@@ -6404,7 +6404,7 @@ remoteDispatchConnectSecretEventRegisterAny(virNetServerPtr server
G_GNUC_UNUSED
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(remoteProgram);
+ callback->program = g_object_ref(remoteProgram);
callback->eventID = args->eventID;
callback->callbackID = -1;
ref = callback;
@@ -6519,7 +6519,7 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server
G_GNUC_UNUS
if (VIR_ALLOC(callback) < 0)
goto cleanup;
callback->client = virObjectRef(client);
- callback->program = virObjectRef(qemuProgram);
+ callback->program = g_object_ref(qemuProgram);
callback->eventID = -1;
callback->callbackID = -1;
ref = callback;
diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c
index 73e4d7befb..62bc9e0f5b 100644
--- a/src/remote/remote_daemon_stream.c
+++ b/src/remote/remote_daemon_stream.c
@@ -367,7 +367,7 @@ daemonCreateClientStream(virNetServerClientPtr client,
stream->refs = 1;
stream->priv = priv;
- stream->prog = virObjectRef(prog);
+ stream->prog = g_object_ref(prog);
stream->procedure = header->proc;
stream->serial = header->serial;
stream->filterID = -1;
@@ -399,7 +399,7 @@ int daemonFreeClientStream(virNetServerClientPtr client,
VIR_DEBUG("client=%p, proc=%d, serial=%u",
client, stream->procedure, stream->serial);
- virObjectUnref(stream->prog);
+ g_clear_object(&stream->prog);
msg = stream->rx;
while (msg) {
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index e0a23867f6..15be0275e6 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -154,13 +154,13 @@ static void virNetServerHandleJob(void *jobOpaque, void *opaque)
if (virNetServerProcessMsg(srv, job->client, job->prog, job->msg) < 0)
goto error;
- virObjectUnref(job->prog);
+ g_clear_object(&job->prog);
virObjectUnref(job->client);
VIR_FREE(job);
return;
error:
- virObjectUnref(job->prog);
+ g_clear_object(&job->prog);
virNetMessageFree(job->msg);
virNetServerClientClose(job->client);
virObjectUnref(job->client);
@@ -218,14 +218,14 @@ virNetServerDispatchNewMessage(virNetServerClientPtr client,
job->msg = msg;
if (prog) {
- job->prog = virObjectRef(prog);
+ job->prog = g_object_ref(prog);
priority = virNetServerProgramGetPriority(prog, msg->header.proc);
}
if (virThreadPoolSendJob(srv->workers, priority, job) < 0) {
virObjectUnref(client);
VIR_FREE(job);
- virObjectUnref(prog);
+ g_clear_object(&prog);
goto error;
}
} else {
@@ -826,7 +826,7 @@ int virNetServerAddProgram(virNetServerPtr srv,
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
goto error;
- srv->programs[srv->nprograms-1] = virObjectRef(prog);
+ srv->programs[srv->nprograms-1] = g_object_ref(prog);
virObjectUnlock(srv);
return 0;
@@ -918,9 +918,7 @@ void virNetServerDispose(void *obj)
virObjectUnref(srv->services[i]);
VIR_FREE(srv->services);
- for (i = 0; i < srv->nprograms; i++)
- virObjectUnref(srv->programs[i]);
- VIR_FREE(srv->programs);
+ virGObjectListFreeCount(srv->programs, srv->nprograms);
for (i = 0; i < srv->nclients; i++)
virObjectUnref(srv->clients[i]);
diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c
index 8df92fb8df..119c9d01c1 100644
--- a/src/rpc/virnetserverprogram.c
+++ b/src/rpc/virnetserverprogram.c
@@ -35,7 +35,7 @@
VIR_LOG_INIT("rpc.netserverprogram");
struct _virNetServerProgram {
- virObject parent;
+ GObject parent;
unsigned program;
unsigned version;
@@ -44,32 +44,23 @@ struct _virNetServerProgram {
};
-static virClassPtr virNetServerProgramClass;
-static void virNetServerProgramDispose(void *obj);
+G_DEFINE_TYPE(virNetServerProgram, vir_net_server_program, G_TYPE_OBJECT);
-static int virNetServerProgramOnceInit(void)
+static void vir_net_server_program_init(virNetServerProgram *prog G_GNUC_UNUSED)
{
- if (!VIR_CLASS_NEW(virNetServerProgram, virClassForObject()))
- return -1;
-
- return 0;
}
-VIR_ONCE_GLOBAL_INIT(virNetServerProgram);
-
+static void vir_net_server_program_class_init(virNetServerProgramClass *klass
G_GNUC_UNUSED)
+{
+}
virNetServerProgramPtr virNetServerProgramNew(unsigned program,
unsigned version,
virNetServerProgramProcPtr procs,
size_t nprocs)
{
- virNetServerProgramPtr prog;
-
- if (virNetServerProgramInitialize() < 0)
- return NULL;
-
- if (!(prog = virObjectNew(virNetServerProgramClass)))
- return NULL;
+ virNetServerProgramPtr prog =
+ VIR_NET_SERVER_PROGRAM(g_object_new(VIR_TYPE_NET_SERVER_PROGRAM, NULL));
prog->program = program;
prog->version = version;
@@ -567,8 +558,3 @@ int virNetServerProgramSendStreamHole(virNetServerProgramPtr prog,
return virNetServerClientSendMessage(client, msg);
}
-
-
-void virNetServerProgramDispose(void *obj G_GNUC_UNUSED)
-{
-}
diff --git a/src/rpc/virnetserverprogram.h b/src/rpc/virnetserverprogram.h
index 851bbf0183..bcc10809d4 100644
--- a/src/rpc/virnetserverprogram.h
+++ b/src/rpc/virnetserverprogram.h
@@ -23,7 +23,8 @@
#include "virnetmessage.h"
#include "virnetserverclient.h"
-#include "virobject.h"
+#include "internal.h"
+#include <glib-object.h>
typedef struct _virNetDaemon virNetDaemon;
typedef virNetDaemon *virNetDaemonPtr;
@@ -31,7 +32,12 @@ typedef virNetDaemon *virNetDaemonPtr;
typedef struct _virNetServerService virNetServerService;
typedef virNetServerService *virNetServerServicePtr;
-typedef struct _virNetServerProgram virNetServerProgram;
+#define VIR_TYPE_NET_SERVER_PROGRAM vir_net_server_program_get_type()
+G_DECLARE_FINAL_TYPE(virNetServerProgram,
+ vir_net_server_program,
+ VIR,
+ NET_SERVER_PROGRAM,
+ GObject);
typedef virNetServerProgram *virNetServerProgramPtr;
typedef struct _virNetServerProgramProc virNetServerProgramProc;
--
2.26.2