Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/libxl/libxl_migration.c | 57 +++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index a105a03b47..15724bb262 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,28 @@ 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 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->finalize = libxlMigrationDstArgsFinalize; +} static void @@ -226,26 +247,18 @@ libxlMigrationEatCookie(const char *cookiein, } static void -libxlMigrationDstArgsDispose(void *obj) +libxlMigrationDstArgsFinalize(GObject *obj) { - libxlMigrationDstArgs *args = obj; + libxlMigrationDstArgs *args = LIBXL_MIGRATION_DST_ARGS(obj); libxlMigrationCookieFree(args->migcookie); VIR_FREE(args->socks); virObjectUnref(args->conn); virObjectUnref(args->vm); -} -static int -libxlMigrationDstArgsOnceInit(void) -{ - if (!VIR_CLASS_NEW(libxlMigrationDstArgs, virClassForObject())) - return -1; - - return 0; + G_OBJECT_CLASS(libxl_migration_dst_args_parent_class)->finalize(obj); } -VIR_ONCE_GLOBAL_INIT(libxlMigrationDstArgs); static void libxlDoMigrateDstReceive(void *opaque) @@ -277,7 +290,7 @@ libxlDoMigrateDstReceive(void *opaque) } args->nsocks = 0; VIR_FORCE_CLOSE(recvfd); - virObjectUnref(args); + g_object_unref(args); virDomainObjEndAPI(&vm); } @@ -339,7 +352,7 @@ libxlMigrateDstReceive(virNetSocketPtr sock, } args->nsocks = 0; VIR_FORCE_CLOSE(recvfd); - virObjectUnref(args); + g_object_unref(args); } static int @@ -600,8 +613,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); @@ -634,7 +647,8 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn, libxlMigrationCookieFree(mig); VIR_FORCE_CLOSE(dataFD[1]); VIR_FORCE_CLOSE(dataFD[0]); - virObjectUnref(args); + if (args) + g_object_unref(args); /* Remove virDomainObj from domain list */ if (vm) virDomainObjListRemove(driver->domains, vm); @@ -765,8 +779,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); @@ -823,7 +837,8 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, VIR_FREE(hostname); else virURIFree(uri); - virObjectUnref(args); + if (args) + g_object_unref(args); virDomainObjEndAPI(&vm); return ret; } -- 2.25.1