Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/bhyve/bhyve_capabilities.c | 3 +-- src/bhyve/bhyve_conf.c | 36 +++++++++++++++++----------------- src/bhyve/bhyve_driver.c | 2 +- src/bhyve/bhyve_utils.h | 11 +++++++++-- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 66442e50ba..00f7613594 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -131,7 +131,7 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn, DIR *dir; struct dirent *entry; size_t firmwares_alloc = 0; - virBhyveDriverConfigPtr cfg = virBhyveDriverGetConfig(conn); + g_autoptr(virBhyveDriverConfig) cfg = virBhyveDriverGetConfig(conn); const char *firmware_dir = cfg->firmwareDir; virDomainCapsStringValuesPtr firmwares = NULL; @@ -167,7 +167,6 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn, cleanup: VIR_FREE(firmwares); VIR_DIR_CLOSE(dir); - virObjectUnref(cfg); return caps; } diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c index f3e2ebf7c7..85f170b1a7 100644 --- a/src/bhyve/bhyve_conf.c +++ b/src/bhyve/bhyve_conf.c @@ -32,29 +32,27 @@ VIR_LOG_INIT("bhyve.bhyve_conf"); -static virClassPtr virBhyveDriverConfigClass; -static void virBhyveDriverConfigDispose(void *obj); +G_DEFINE_TYPE(virBhyveDriverConfig, vir_bhyve_driver_config, G_TYPE_OBJECT); +static void virBhyveDriverConfigFinalize(GObject *obj); -static int virBhyveConfigOnceInit(void) +static void +vir_bhyve_driver_config_init(virBhyveDriverConfig *cfg G_GNUC_UNUSED) { - if (!VIR_CLASS_NEW(virBhyveDriverConfig, virClassForObject())) - return -1; - - return 0; } -VIR_ONCE_GLOBAL_INIT(virBhyveConfig); +static void +vir_bhyve_driver_config_class_init(virBhyveDriverConfigClass *klass) +{ + GObjectClass *obj = G_OBJECT_CLASS(klass); + + obj->finalize = virBhyveDriverConfigFinalize; +} virBhyveDriverConfigPtr virBhyveDriverConfigNew(void) { - virBhyveDriverConfigPtr cfg; - - if (virBhyveConfigInitialize() < 0) - return NULL; - - if (!(cfg = virObjectNew(virBhyveDriverConfigClass))) - return NULL; + virBhyveDriverConfigPtr cfg = + VIR_BHYVE_DRIVER_CONFIG(g_object_new(VIR_TYPE_BHYVE_DRIVER_CONFIG, NULL)); cfg->firmwareDir = g_strdup(DATADIR "/uefi-firmware"); @@ -87,17 +85,19 @@ virBhyveDriverGetConfig(bhyveConnPtr driver) { virBhyveDriverConfigPtr cfg; bhyveDriverLock(driver); - cfg = virObjectRef(driver->config); + cfg = g_object_ref(driver->config); bhyveDriverUnlock(driver); return cfg; } static void -virBhyveDriverConfigDispose(void *obj) +virBhyveDriverConfigFinalize(GObject *obj) { - virBhyveDriverConfigPtr cfg = obj; + virBhyveDriverConfigPtr cfg = VIR_BHYVE_DRIVER_CONFIG(obj); VIR_FREE(cfg->firmwareDir); + + G_OBJECT_CLASS(vir_bhyve_driver_config_parent_class)->finalize(obj); } void diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 6a37c7973b..2bdffe0b63 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1186,7 +1186,7 @@ bhyveStateCleanup(void) virSysinfoDefFree(bhyve_driver->hostsysinfo); virObjectUnref(bhyve_driver->closeCallbacks); virObjectUnref(bhyve_driver->domainEventState); - virObjectUnref(bhyve_driver->config); + g_clear_object(&bhyve_driver->config); virPortAllocatorRangeFree(bhyve_driver->remotePorts); if (bhyve_driver->lockFD != -1) diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index f3e80b6121..675b859098 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -29,16 +29,23 @@ #include "hypervisor/virclosecallbacks.h" #include "virportallocator.h" +#include <glib-object.h> + #define BHYVE_AUTOSTART_DIR SYSCONFDIR "/libvirt/bhyve/autostart" #define BHYVE_CONFIG_DIR SYSCONFDIR "/libvirt/bhyve" #define BHYVE_STATE_DIR RUNSTATEDIR "/libvirt/bhyve" #define BHYVE_LOG_DIR LOCALSTATEDIR "/log/libvirt/bhyve" -typedef struct _virBhyveDriverConfig virBhyveDriverConfig; +#define VIR_TYPE_BHYVE_DRIVER_CONFIG vir_bhyve_driver_config_get_type() +G_DECLARE_FINAL_TYPE(virBhyveDriverConfig, + vir_bhyve_driver_config, + VIR, + BHYVE_DRIVER_CONFIG, + GObject); typedef struct _virBhyveDriverConfig *virBhyveDriverConfigPtr; struct _virBhyveDriverConfig { - virObject parent; + GObject parent; char *firmwareDir; }; -- 2.25.3