Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/libvirt_private.syms | 1 +
src/network/bridge_driver.c | 22 ++++++---------
src/util/virdnsmasq.c | 56 +++++++++++++++++--------------------
src/util/virdnsmasq.h | 6 ++--
tests/networkxml2conftest.c | 10 ++-----
5 files changed, 42 insertions(+), 53 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1e2b9af689..4a927a26bf 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1948,6 +1948,7 @@ virDevMapperGetTargets;
# util/virdnsmasq.h
+dnsmasq_caps_get_type;
dnsmasqAddDhcpHost;
dnsmasqAddHost;
dnsmasqCapsGet;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 47d5d95678..3c110a53fc 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -115,9 +115,10 @@ networkDriverUnlock(virNetworkDriverStatePtr driver)
static dnsmasqCapsPtr
networkGetDnsmasqCaps(virNetworkDriverStatePtr driver)
{
- dnsmasqCapsPtr ret;
+ dnsmasqCapsPtr ret = NULL;
networkDriverLock(driver);
- ret = virObjectRef(driver->dnsmasqCaps);
+ if (driver->dnsmasqCaps)
+ ret = g_object_ref(driver->dnsmasqCaps);
networkDriverUnlock(driver);
return ret;
}
@@ -132,7 +133,7 @@ networkDnsmasqCapsRefresh(virNetworkDriverStatePtr driver)
return -1;
networkDriverLock(driver);
- virObjectUnref(driver->dnsmasqCaps);
+ g_clear_object(&driver->dnsmasqCaps);
driver->dnsmasqCaps = caps;
networkDriverUnlock(driver);
return 0;
@@ -545,7 +546,7 @@ networkUpdateState(virNetworkObjPtr obj,
{
virNetworkDefPtr def;
virNetworkDriverStatePtr driver = opaque;
- dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
+ g_autoptr(dnsmasqCaps) dnsmasq_caps = networkGetDnsmasqCaps(driver);
virMacMapPtr macmap;
char *macMapFile = NULL;
int ret = -1;
@@ -631,7 +632,6 @@ networkUpdateState(virNetworkObjPtr obj,
ret = 0;
cleanup:
virObjectUnlock(obj);
- virObjectUnref(dnsmasq_caps);
VIR_FREE(macMapFile);
return ret;
}
@@ -907,7 +907,7 @@ networkStateCleanup(void)
VIR_FREE(network_driver->dnsmasqStateDir);
VIR_FREE(network_driver->radvdStateDir);
- virObjectUnref(network_driver->dnsmasqCaps);
+ g_clear_object(&network_driver->dnsmasqCaps);
virMutexDestroy(&network_driver->lock);
@@ -1581,7 +1581,7 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverStatePtr driver,
dnsmasqContext *dctx)
{
virNetworkDefPtr def = virNetworkObjGetDef(obj);
- dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
+ g_autoptr(dnsmasqCaps) dnsmasq_caps = networkGetDnsmasqCaps(driver);
virCommandPtr cmd = NULL;
int ret = -1;
char *configfile = NULL;
@@ -1625,7 +1625,6 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverStatePtr driver,
*cmdout = cmd;
ret = 0;
cleanup:
- virObjectUnref(dnsmasq_caps);
VIR_FREE(configfile);
VIR_FREE(configstr);
VIR_FREE(leaseshelper_path);
@@ -1949,7 +1948,7 @@ networkStartRadvd(virNetworkDriverStatePtr driver,
virNetworkObjPtr obj)
{
virNetworkDefPtr def = virNetworkObjGetDef(obj);
- dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
+ g_autoptr(dnsmasqCaps) dnsmasq_caps = networkGetDnsmasqCaps(driver);
pid_t radvdPid;
char *pidfile = NULL;
char *radvdpidbase = NULL;
@@ -2027,7 +2026,6 @@ networkStartRadvd(virNetworkDriverStatePtr driver,
ret = 0;
cleanup:
- virObjectUnref(dnsmasq_caps);
virCommandFree(cmd);
VIR_FREE(configfile);
VIR_FREE(radvdpidbase);
@@ -2041,14 +2039,13 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver,
virNetworkObjPtr obj)
{
virNetworkDefPtr def = virNetworkObjGetDef(obj);
- dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
+ g_autoptr(dnsmasqCaps) dnsmasq_caps = networkGetDnsmasqCaps(driver);
g_autofree char *radvdpidbase = NULL;
g_autofree char *pidfile = NULL;
pid_t radvdPid;
/* Is dnsmasq handling RA? */
if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) {
- virObjectUnref(dnsmasq_caps);
if ((radvdpidbase = networkRadvdPidfileBasename(def->name)) &&
(pidfile = virPidFileBuildPath(driver->pidDir, radvdpidbase))) {
/* radvd should not be running but in case it is */
@@ -2057,7 +2054,6 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver,
}
return 0;
}
- virObjectUnref(dnsmasq_caps);
/* if there's no running radvd, just start it */
radvdPid = virNetworkObjGetRadvdPid(obj);
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 818219fbeb..4d62680f3a 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -598,7 +598,7 @@ dnsmasqReload(pid_t pid G_GNUC_UNUSED)
*
*/
struct _dnsmasqCaps {
- virObject parent;
+ GObject parent;
char *binaryPath;
bool noRefresh;
time_t mtime;
@@ -606,26 +606,31 @@ struct _dnsmasqCaps {
unsigned long version;
};
-static virClassPtr dnsmasqCapsClass;
+G_DEFINE_TYPE(dnsmasqCaps, dnsmasq_caps, G_TYPE_OBJECT);
static void
-dnsmasqCapsDispose(void *obj)
+dnsmasqCapsFinalize(GObject *obj)
{
- dnsmasqCapsPtr caps = obj;
+ dnsmasqCapsPtr caps = DNSMASQ_CAPS(obj);
virBitmapFree(caps->flags);
VIR_FREE(caps->binaryPath);
+
+ G_OBJECT_CLASS(dnsmasq_caps_parent_class)->finalize(obj);
}
-static int dnsmasqCapsOnceInit(void)
+static void
+dnsmasq_caps_init(dnsmasqCaps *caps G_GNUC_UNUSED)
{
- if (!VIR_CLASS_NEW(dnsmasqCaps, virClassForObject()))
- return -1;
-
- return 0;
}
-VIR_ONCE_GLOBAL_INIT(dnsmasqCaps);
+static void
+dnsmasq_caps_class_init(dnsmasqCapsClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = dnsmasqCapsFinalize;
+}
static void
dnsmasqCapsSet(dnsmasqCapsPtr caps,
@@ -764,65 +769,54 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force)
static dnsmasqCapsPtr
dnsmasqCapsNewEmpty(const char *binaryPath)
{
- dnsmasqCapsPtr caps;
-
- if (dnsmasqCapsInitialize() < 0)
- return NULL;
- if (!(caps = virObjectNew(dnsmasqCapsClass)))
- return NULL;
+ g_autoptr(dnsmasqCaps) caps =
+ DNSMASQ_CAPS(g_object_new(DNSMASQ_TYPE_CAPS, NULL));
if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
- goto error;
+ return NULL;
caps->binaryPath = g_strdup(binaryPath ? binaryPath : DNSMASQ);
- return caps;
-
- error:
- virObjectUnref(caps);
- return NULL;
+ return g_steal_pointer(&caps);
}
dnsmasqCapsPtr
dnsmasqCapsNewFromBuffer(const char *buf, const char *binaryPath)
{
- dnsmasqCapsPtr caps = dnsmasqCapsNewEmpty(binaryPath);
+ g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty(binaryPath);
if (!caps)
return NULL;
if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) {
- virObjectUnref(caps);
return NULL;
}
- return caps;
+ return g_steal_pointer(&caps);
}
dnsmasqCapsPtr
dnsmasqCapsNewFromFile(const char *dataPath, const char *binaryPath)
{
- dnsmasqCapsPtr caps = dnsmasqCapsNewEmpty(binaryPath);
+ g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty(binaryPath);
if (!caps)
return NULL;
if (dnsmasqCapsSetFromFile(caps, dataPath) < 0) {
- virObjectUnref(caps);
return NULL;
}
- return caps;
+ return g_steal_pointer(&caps);
}
dnsmasqCapsPtr
dnsmasqCapsNewFromBinary(const char *binaryPath)
{
- dnsmasqCapsPtr caps = dnsmasqCapsNewEmpty(binaryPath);
+ g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty(binaryPath);
if (!caps)
return NULL;
if (dnsmasqCapsRefreshInternal(caps, true) < 0) {
- virObjectUnref(caps);
return NULL;
}
- return caps;
+ return g_steal_pointer(&caps);
}
/** dnsmasqCapsRefresh:
diff --git a/src/util/virdnsmasq.h b/src/util/virdnsmasq.h
index 4c14bc6ca7..d5de44c5ba 100644
--- a/src/util/virdnsmasq.h
+++ b/src/util/virdnsmasq.h
@@ -23,7 +23,8 @@
#pragma once
-#include "virobject.h"
+#include "internal.h"
+#include <glib-object.h>
#include "virsocketaddr.h"
typedef struct
@@ -75,7 +76,8 @@ typedef enum {
DNSMASQ_CAPS_LAST, /* this must always be the last item */
} dnsmasqCapsFlags;
-typedef struct _dnsmasqCaps dnsmasqCaps;
+#define DNSMASQ_TYPE_CAPS dnsmasq_caps_get_type()
+G_DECLARE_FINAL_TYPE(dnsmasqCaps, dnsmasq_caps, DNSMASQ, CAPS, GObject);
typedef dnsmasqCaps *dnsmasqCapsPtr;
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index b35de50f0b..a5902bacc9 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -122,11 +122,11 @@ static int
mymain(void)
{
int ret = 0;
- dnsmasqCapsPtr restricted
+ g_autoptr(dnsmasqCaps) restricted
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.48", DNSMASQ);
- dnsmasqCapsPtr full
+ g_autoptr(dnsmasqCaps) full
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.63\n--bind-dynamic",
DNSMASQ);
- dnsmasqCapsPtr dhcpv6
+ g_autoptr(dnsmasqCaps) dhcpv6
= dnsmasqCapsNewFromBuffer("Dnsmasq version 2.64\n--bind-dynamic",
DNSMASQ);
#define DO_TEST(xname, xcaps) \
@@ -168,10 +168,6 @@ mymain(void)
DO_TEST("leasetime-hours", full);
DO_TEST("leasetime-infinite", full);
- virObjectUnref(dhcpv6);
- virObjectUnref(full);
- virObjectUnref(restricted);
-
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
2.26.2