[PATCH v2 35/40] libxl: convert libxlMigrationDstArgs to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/libxl/libxl_migration.c | 76 ++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 27 deletions(-)

diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 50225855ae..8530b172ec 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -60,7 +60,7 @@ struct _libxlMigrationCookie {
 };
 
 typedef struct _libxlMigrationDstArgs {
-    virObject parent;
+    GObject parent;
 
     int recvfd;
     virConnectPtr conn;
@@ -73,7 +73,30 @@ typedef struct _libxlMigrationDstArgs {
     size_t nsocks;
 } libxlMigrationDstArgs;
 
-static virClassPtr libxlMigrationDstArgsClass;
+G_DEFINE_TYPE(libxlMigrationDstArgs, libxl_migration_dst_args, G_TYPE_OBJECT);
+#define LIBXL_TYPE_MIGRATION_DST_ARGS libxl_migration_dst_args_get_type()
+G_DECLARE_FINAL_TYPE(libxlMigrationDstArgs,
+                     libxl_migration_dst_args,
+                     LIBXL,
+                     MIGRATION_DST_ARGS,
+                     GObject);
+
+static void libxlMigrationDstArgsDispose(GObject *obj);
+static void libxlMigrationDstArgsFinalize(GObject *obj);
+
+static void
+libxl_migration_dst_args_init(lixlMigrationDstArgs *args G_GNUC_UNUSED)
+{
+}
+
+static void
+libxl_migration_dst_args_class_init(lixlMigrationDstArgsClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->dispose = libxlMigrationDstArgsDispose;
+    obj->finalize = libxlMigrationDstArgsFinalize;
+}
 
 
 static void
@@ -226,31 +249,34 @@ libxlMigrationEatCookie(const char *cookiein,
 }
 
 static void
-libxlMigrationDstArgsDispose(void *obj)
+libxlMigrationDstArgsDispose(GObject *obj)
 {
-    libxlMigrationDstArgs *args = obj;
+    libxlMigrationDstArgs *args = LIBXL_MIGRATION_DST_ARGS(obj);
 
-    libxlMigrationCookieFree(args->migcookie);
-    VIR_FREE(args->socks);
     virObjectUnref(args->conn);
+    args->conn = NULL;
     virObjectUnref(args->vm);
+    args->vm = NULL;
+
+    G_OBJECT_CLASS(libxl_migration_dst_args_parent_class)->dispose(obj);
 }
 
-static int
-libxlMigrationDstArgsOnceInit(void)
+static void
+libxlMigrationDstArgsFinalize(GObject *obj)
 {
-    if (!VIR_CLASS_NEW(libxlMigrationDstArgs, virClassForObject()))
-        return -1;
+    libxlMigrationDstArgs *args = LIBXL_MIGRATION_DST_ARGS(obj);
 
-    return 0;
+    libxlMigrationCookieFree(args->migcookie);
+    VIR_FREE(args->socks);
+
+    G_OBJECT_CLASS(libxl_migration_dst_args_parent_class)->finalize(obj);
 }
 
-VIR_ONCE_GLOBAL_INIT(libxlMigrationDstArgs);
 
 static void
 libxlDoMigrateDstReceive(void *opaque)
 {
-    libxlMigrationDstArgs *args = opaque;
+    g_autoptr(libxlMigrationDstArgs) args = LIBXL_MIGRATION_DST_ARGS(opaque);
     virDomainObjPtr vm = args->vm;
     virNetSocketPtr *socks = args->socks;
     size_t nsocks = args->nsocks;
@@ -277,7 +303,6 @@ libxlDoMigrateDstReceive(void *opaque)
     }
     args->nsocks = 0;
     VIR_FORCE_CLOSE(recvfd);
-    virObjectUnref(args);
     virDomainObjEndAPI(&vm);
 }
 
@@ -287,7 +312,7 @@ libxlMigrateDstReceive(virNetSocketPtr sock,
                        int events G_GNUC_UNUSED,
                        void *opaque)
 {
-    libxlMigrationDstArgs *args = opaque;
+    g_autoptr(libxlMigrationDstArgs) args = LIBXL_MIGRATION_DST_ARGS(opaque);
     virNetSocketPtr *socks = args->socks;
     size_t nsocks = args->nsocks;
     libxlDomainObjPrivatePtr priv = args->vm->privateData;
@@ -321,7 +346,7 @@ libxlMigrateDstReceive(virNetSocketPtr sock,
                             libxlDoMigrateDstReceive,
                             name,
                             false,
-                            args) < 0) {
+                            g_object_ref(args)) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
         goto fail;
@@ -339,7 +364,6 @@ libxlMigrateDstReceive(virNetSocketPtr sock,
     }
     args->nsocks = 0;
     VIR_FORCE_CLOSE(recvfd);
-    virObjectUnref(args);
 }
 
 static int
@@ -551,7 +575,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     libxlMigrationCookiePtr mig = NULL;
     libxlDriverPrivatePtr driver = dconn->privateData;
     virDomainObjPtr vm = NULL;
-    libxlMigrationDstArgs *args = NULL;
+    g_autoptr(libxlMigrationDstArgs) args = NULL;
     bool taint_hook = false;
     libxlDomainObjPrivatePtr priv = NULL;
     char *xmlout = NULL;
@@ -600,8 +624,8 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     if (libxlMigrationDstArgsInitialize() < 0)
         goto endjob;
 
-    if (!(args = virObjectNew(libxlMigrationDstArgsClass)))
-        goto endjob;
+    args = LIBXL_MIGRATION_DST_ARGS(
+            g_object_new(LIBXL_TYPE_MIGRATION_DST_ARGS, NULL));
 
     args->conn = virObjectRef(dconn);
     args->vm = virObjectRef(vm);
@@ -618,7 +642,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     name = g_strdup_printf("mig-%s", args->vm->def->name);
     if (virThreadCreateFull(priv->migrationDstReceiveThr, true,
                             libxlDoMigrateDstReceive,
-                            name, false, args) < 0) {
+                            name, false, g_object_ref(args)) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
         goto endjob;
@@ -634,7 +658,6 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     libxlMigrationCookieFree(mig);
     VIR_FORCE_CLOSE(dataFD[1]);
     VIR_FORCE_CLOSE(dataFD[0]);
-    virObjectUnref(args);
     /* Remove virDomainObj from domain list */
     if (vm)
         virDomainObjListRemove(driver->domains, vm);
@@ -665,7 +688,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
     virNetSocketPtr *socks = NULL;
     size_t nsocks = 0;
     int nsocks_listen = 0;
-    libxlMigrationDstArgs *args = NULL;
+    g_autoptr(libxlMigrationDstArgs) args = NULL;
     bool taint_hook = false;
     libxlDomainObjPrivatePtr priv = NULL;
     size_t i;
@@ -765,8 +788,8 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
     if (libxlMigrationDstArgsInitialize() < 0)
         goto endjob;
 
-    if (!(args = virObjectNew(libxlMigrationDstArgsClass)))
-        goto endjob;
+    args = LIBXL_MIGRATION_DST_ARGS(
+            g_object_new(LIBXL_TYPE_MIGRATION_DST_ARGS, NULL));
 
     args->conn = virObjectRef(dconn);
     args->vm = virObjectRef(vm);
@@ -786,7 +809,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
         if (virNetSocketAddIOCallback(socks[i],
                                       VIR_EVENT_HANDLE_READABLE,
                                       libxlMigrateDstReceive,
-                                      virObjectRef(args),
+                                      g_object_ref(args),
                                       NULL) < 0)
             continue;
 
@@ -823,7 +846,6 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
         VIR_FREE(hostname);
     else
         virURIFree(uri);
-    virObjectUnref(args);
     virDomainObjEndAPI(&vm);
     return ret;
 }
-- 
2.25.3






[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