[PATCH 04/36] rpc: convert virNetClientProgram to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/admin/admin_remote.c        | 10 +++----
 src/locking/lock_driver_lockd.c | 23 ++++++++-------
 src/logging/log_manager.c       | 17 ++++++-----
 src/lxc/lxc_monitor.c           |  3 +-
 src/remote/remote_driver.c      | 52 +++++++++++++++++----------------
 src/rpc/virnetclient.c          |  4 +--
 src/rpc/virnetclientprogram.c   | 29 +++++++++---------
 src/rpc/virnetclientprogram.h   | 10 +++++--
 src/rpc/virnetclientstream.c    |  5 ++--
 9 files changed, 82 insertions(+), 71 deletions(-)

diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
index ca5e0c9fe4..da90939e49 100644
--- a/src/admin/admin_remote.c
+++ b/src/admin/admin_remote.c
@@ -41,7 +41,8 @@ remoteAdminPrivDispose(void *opaque)
 {
     remoteAdminPrivPtr priv = opaque;
 
-    virObjectUnref(priv->program);
+    if (priv->program)
+        g_object_unref(priv->program);
     virObjectUnref(priv->client);
 }
 
@@ -227,10 +228,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..7520545dc0 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,8 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool privileged,
     VIR_FREE(lockdpath);
     virNetClientClose(client);
     virObjectUnref(client);
-    virObjectUnref(*prog);
+    if (*prog)
+        g_object_unref(*prog);
     return NULL;
 }
 
@@ -296,7 +296,8 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path)
     rv = 0;
 
  cleanup:
-    virObjectUnref(program);
+    if (program)
+        g_object_unref(program);
     virNetClientClose(client);
     virObjectUnref(client);
     return rv;
@@ -660,7 +661,8 @@ static int virLockManagerLockDaemonAcquire(virLockManagerPtr lock,
         VIR_FORCE_CLOSE(*fd);
     virNetClientClose(client);
     virObjectUnref(client);
-    virObjectUnref(program);
+    if (program)
+        g_object_unref(program);
 
     return rv;
 }
@@ -713,7 +715,8 @@ static int virLockManagerLockDaemonRelease(virLockManagerPtr lock,
  cleanup:
     virNetClientClose(client);
     virObjectUnref(client);
-    virObjectUnref(program);
+    if (program)
+        g_object_unref(program);
 
     return rv;
 }
diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c
index fd7c2922b3..dee5307e56 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,8 @@ virLogManagerConnect(bool privileged,
     VIR_FREE(logdpath);
     virNetClientClose(client);
     virObjectUnref(client);
-    virObjectUnref(*prog);
+    if (*prog)
+        g_object_unref(*prog);
     return NULL;
 }
 
@@ -135,7 +135,8 @@ virLogManagerFree(virLogManagerPtr mgr)
 
     if (mgr->client)
         virNetClientClose(mgr->client);
-    virObjectUnref(mgr->program);
+    if (mgr->program)
+        g_object_unref(mgr->program);
     virObjectUnref(mgr->client);
 
     VIR_FREE(mgr);
diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 479125374b..923a0a5a2f 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -198,7 +198,8 @@ static void virLXCMonitorDispose(void *opaque)
     VIR_DEBUG("mon=%p", mon);
     if (mon->cb.destroy)
         (mon->cb.destroy)(mon, mon->vm);
-    virObjectUnref(mon->program);
+    if (mon->program)
+        g_object_unref(mon->program);
     virObjectUnref(mon->vm);
 }
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 7bae0c2514..5051c583d7 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,12 @@ doRemoteOpen(virConnectPtr conn,
     return VIR_DRV_OPEN_SUCCESS;
 
  failed:
-    virObjectUnref(priv->remoteProgram);
-    virObjectUnref(priv->lxcProgram);
-    virObjectUnref(priv->qemuProgram);
+    if (priv->remoteProgram)
+        g_object_unref(priv->remoteProgram);
+    if (priv->lxcProgram)
+        g_object_unref(priv->lxcProgram);
+    if (priv->qemuProgram)
+        g_object_unref(priv->qemuProgram);
     virNetClientClose(priv->client);
     virObjectUnref(priv->client);
     priv->client = NULL;
@@ -1532,10 +1532,12 @@ 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;
+    if (priv->remoteProgram)
+        g_clear_object(&priv->remoteProgram);
+    if (priv->lxcProgram)
+        g_clear_object(&priv->lxcProgram);
+    if (priv->qemuProgram)
+        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..f940bed84e 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -685,7 +685,7 @@ void virNetClientDispose(void *obj)
         client->closeFf(client->closeOpaque);
 
     for (i = 0; i < client->nprograms; i++)
-        virObjectUnref(client->programs[i]);
+        g_object_unref(client->programs[i]);
     VIR_FREE(client->programs);
 
     g_main_loop_unref(client->eventLoop);
@@ -1010,7 +1010,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..38625e7ad1 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,19 @@ struct _virNetClientProgram {
     void *eventOpaque;
 };
 
-static virClassPtr virNetClientProgramClass;
-static void virNetClientProgramDispose(void *obj);
+G_DEFINE_TYPE(virNetClientProgram, vir_net_client_program, G_TYPE_OBJECT);
+static void virNetClientProgramFinalize(GObject *obj);
 
-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)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
 
+    obj->finalize = virNetClientProgramFinalize;
+}
 
 virNetClientProgramPtr virNetClientProgramNew(unsigned program,
                                               unsigned version,
@@ -67,13 +67,9 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
                                               size_t nevents,
                                               void *eventOpaque)
 {
-    virNetClientProgramPtr prog;
-
-    if (virNetClientProgramInitialize() < 0)
-        return NULL;
+    virNetClientProgramPtr prog =
+        VIR_NET_CLIENT_PROGRAM(g_object_new(VIR_TYPE_NET_CLIENT_PROGRAM, NULL));
 
-    if (!(prog = virObjectNew(virNetClientProgramClass)))
-        return NULL;
 
     prog->program = program;
     prog->version = version;
@@ -85,8 +81,9 @@ virNetClientProgramPtr virNetClientProgramNew(unsigned program,
 }
 
 
-void virNetClientProgramDispose(void *obj G_GNUC_UNUSED)
+void virNetClientProgramFinalize(GObject *obj)
 {
+    G_OBJECT_CLASS(vir_net_client_program_parent_class)->finalize(obj);
 }
 
 
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..355739892e 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,8 @@ void virNetClientStreamDispose(void *obj)
         virNetMessageQueueServe(&st->rx);
         virNetMessageFree(msg);
     }
-    virObjectUnref(st->prog);
+    if (st->prog)
+        g_object_unref(st->prog);
 }
 
 bool virNetClientStreamMatches(virNetClientStreamPtr st,
-- 
2.25.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux