Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/lxc/lxc_conf.c | 31 +++++++++++++-------------
src/lxc/lxc_conf.h | 10 +++++++--
src/lxc/lxc_driver.c | 51 +++++++++++++++----------------------------
src/lxc/lxc_process.c | 33 +++++++++-------------------
4 files changed, 51 insertions(+), 74 deletions(-)
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index cfb80eaf22..243020f9f1 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -42,19 +42,20 @@
VIR_LOG_INIT("lxc.lxc_conf");
-static virClassPtr virLXCDriverConfigClass;
-static void virLXCDriverConfigDispose(void *obj);
+G_DEFINE_TYPE(virLXCDriverConfig, vir_lxc_driver_config, G_TYPE_OBJECT);
-static int virLXCConfigOnceInit(void)
-{
- if (!VIR_CLASS_NEW(virLXCDriverConfig, virClassForObject()))
- return -1;
+static void virLXCDriverConfigFinalize(GObject *obj);
- return 0;
+static void vir_lxc_driver_config_init(virLXCDriverConfig *cfg G_GNUC_UNUSED)
+{
}
-VIR_ONCE_GLOBAL_INIT(virLXCConfig);
+static void vir_lxc_driver_config_class_init(virLXCDriverConfigClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+ obj->finalize = virLXCDriverConfigFinalize;
+}
/* Functions */
virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
@@ -227,11 +228,7 @@ virLXCDriverConfigNew(void)
{
virLXCDriverConfigPtr cfg;
- if (virLXCConfigInitialize() < 0)
- return NULL;
-
- if (!(cfg = virObjectNew(virLXCDriverConfigClass)))
- return NULL;
+ cfg = VIR_LXC_DRIVER_CONFIG(g_object_new(VIR_TYPE_LXC_DRIVER_CONFIG, NULL));
cfg->securityDefaultConfined = false;
cfg->securityRequireConfined = false;
@@ -278,19 +275,21 @@ virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)
{
virLXCDriverConfigPtr cfg;
lxcDriverLock(driver);
- cfg = virObjectRef(driver->config);
+ cfg = g_object_ref(driver->config);
lxcDriverUnlock(driver);
return cfg;
}
static void
-virLXCDriverConfigDispose(void *obj)
+virLXCDriverConfigFinalize(GObject *obj)
{
- virLXCDriverConfigPtr cfg = obj;
+ virLXCDriverConfigPtr cfg = VIR_LXC_DRIVER_CONFIG(obj);
VIR_FREE(cfg->configDir);
VIR_FREE(cfg->autostartDir);
VIR_FREE(cfg->stateDir);
VIR_FREE(cfg->logDir);
VIR_FREE(cfg->securityDriverName);
+
+ G_OBJECT_CLASS(vir_lxc_driver_config_parent_class)->finalize(obj);
}
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index f2f0e0a570..5ed84f79c7 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -34,6 +34,7 @@
#include "virusb.h"
#include "virclosecallbacks.h"
#include "virhostdev.h"
+#include <glib-object.h>
#define LXC_DRIVER_NAME "LXC"
@@ -45,11 +46,16 @@
typedef struct _virLXCDriver virLXCDriver;
typedef virLXCDriver *virLXCDriverPtr;
-typedef struct _virLXCDriverConfig virLXCDriverConfig;
+#define VIR_TYPE_LXC_DRIVER_CONFIG vir_lxc_driver_config_get_type()
+G_DECLARE_FINAL_TYPE(virLXCDriverConfig,
+ vir_lxc_driver_config,
+ VIR,
+ LXC_DRIVER_CONFIG,
+ GObject);
typedef virLXCDriverConfig *virLXCDriverConfigPtr;
struct _virLXCDriverConfig {
- virObject parent;
+ GObject parent;
char *configDir;
char *autostartDir;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 5da9ec7c58..07bc7219f1 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -400,7 +400,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
virDomainDefPtr oldDef = NULL;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
g_autoptr(virCaps) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -458,7 +458,6 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
virDomainDefFree(oldDef);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return dom;
}
@@ -475,7 +474,7 @@ static int lxcDomainUndefineFlags(virDomainPtr dom,
virDomainObjPtr vm;
virObjectEventPtr event = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(0, -1);
@@ -510,7 +509,6 @@ static int lxcDomainUndefineFlags(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
return ret;
}
@@ -638,7 +636,7 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long
newmem,
int ret = -1;
virLXCDomainObjPrivatePtr priv;
virLXCDriverPtr driver = dom->conn->privateData;
- virLXCDriverConfigPtr cfg = NULL;
+ g_autoptr(virLXCDriverConfig) cfg = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG |
@@ -719,7 +717,6 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long
newmem,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -743,7 +740,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
virDomainDefPtr persistentDef = NULL;
virDomainObjPtr vm = NULL;
virLXCDomainObjPrivatePtr priv = NULL;
- virLXCDriverConfigPtr cfg = NULL;
+ g_autoptr(virLXCDriverConfig) cfg = NULL;
virLXCDriverPtr driver = dom->conn->privateData;
int ret = -1;
@@ -804,7 +801,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -976,7 +972,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
virDomainObjPtr vm;
virObjectEventPtr event = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
@@ -1023,7 +1019,6 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates();
return ret;
}
@@ -1079,7 +1074,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
virDomainDefPtr def = NULL;
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
g_autoptr(virCaps) caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -1150,7 +1145,6 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
- virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates();
return dom;
}
@@ -1582,7 +1576,7 @@ static void lxcNotifyLoadDomain(virDomainObjPtr vm, int newVM, void
*opaque)
static int
lxcStateReload(void)
{
- virLXCDriverConfigPtr cfg = NULL;
+ g_autoptr(virLXCDriverConfig) cfg = NULL;
if (!lxc_driver)
return 0;
@@ -1594,7 +1588,6 @@ lxcStateReload(void)
cfg->autostartDir, false,
lxc_driver->xmlopt,
lxcNotifyLoadDomain, lxc_driver);
- virObjectUnref(cfg);
return 0;
}
@@ -1620,7 +1613,8 @@ static int lxcStateCleanup(void)
if (lxc_driver->lockFD != -1)
virPidFileRelease(lxc_driver->config->stateDir, "driver",
lxc_driver->lockFD);
- virObjectUnref(lxc_driver->config);
+ if (lxc_driver->config)
+ g_object_unref(lxc_driver->config);
virMutexDestroy(&lxc_driver->lock);
VIR_FREE(lxc_driver);
@@ -1801,7 +1795,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
int ret = -1;
int rc;
virLXCDomainObjPrivatePtr priv;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -1914,7 +1908,6 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
cleanup:
virDomainDefFree(persistentDefCopy);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -2239,7 +2232,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
virDomainDefPtr def = NULL;
virDomainDefPtr persistentDef = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = NULL;
+ g_autoptr(virLXCDriverConfig) cfg = NULL;
virLXCDomainObjPrivatePtr priv;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -2304,7 +2297,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -2463,7 +2455,7 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
virDomainObjPtr vm;
char *configFile = NULL, *autostartLink = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (!(vm = lxcDomObjFromDomain(dom)))
goto cleanup;
@@ -2529,7 +2521,6 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
VIR_FREE(configFile);
VIR_FREE(autostartLink);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -2625,7 +2616,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
virDomainObjPtr vm;
virObjectEventPtr event = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (!(vm = lxcDomObjFromDomain(dom)))
goto cleanup;
@@ -2662,7 +2653,6 @@ static int lxcDomainSuspend(virDomainPtr dom)
cleanup:
virObjectEventStateQueue(driver->domainEventState, event);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -2674,7 +2664,7 @@ static int lxcDomainResume(virDomainPtr dom)
int ret = -1;
int state;
virLXCDomainObjPrivatePtr priv;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (!(vm = lxcDomObjFromDomain(dom)))
goto cleanup;
@@ -2719,7 +2709,6 @@ static int lxcDomainResume(virDomainPtr dom)
cleanup:
virObjectEventStateQueue(driver->domainEventState, event);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -4297,7 +4286,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4384,7 +4373,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -4406,7 +4394,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4456,7 +4444,6 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
virDomainDefFree(vmdef);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -4471,7 +4458,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4552,7 +4539,6 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
@@ -4825,7 +4811,7 @@ lxcDomainSetMetadata(virDomainPtr dom,
{
virLXCDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- virLXCDriverConfigPtr cfg = NULL;
+ g_autoptr(virLXCDriverConfig) cfg = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -4856,7 +4842,6 @@ lxcDomainSetMetadata(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- virObjectUnref(cfg);
return ret;
}
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 699accc633..cacfa14094 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -162,7 +162,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
size_t i;
virLXCDomainObjPrivatePtr priv = vm->privateData;
const virNetDevVPortProfile *vport = NULL;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virConnectPtr conn = NULL;
VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d",
@@ -257,7 +257,6 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
}
virDomainObjRemoveTransientDef(vm);
- virObjectUnref(cfg);
virObjectUnref(conn);
}
@@ -340,11 +339,10 @@ virLXCProcessSetupInterfaceDirect(virLXCDriverPtr driver,
virDomainDefPtr def,
virDomainNetDefPtr net)
{
- char *ret = NULL;
char *res_ifname = NULL;
const virNetDevBandwidth *bw;
const virNetDevVPortProfile *prof;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
const char *linkdev = virDomainNetGetActualDirectDev(net);
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_IFUP;
@@ -386,13 +384,9 @@ virLXCProcessSetupInterfaceDirect(virLXCDriverPtr driver,
cfg->stateDir,
NULL, 0,
macvlan_create_flags) < 0)
- goto cleanup;
-
- ret = res_ifname;
+ return NULL;
- cleanup:
- virObjectUnref(cfg);
- return ret;
+ return res_ifname;
}
static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
@@ -786,7 +780,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon
G_GNUC_UNUSED,
{
virLXCDriverPtr driver = lxc_driver;
virLXCDomainObjPrivatePtr priv;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
ino_t inode = 0;
virObjectLock(vm);
@@ -806,7 +800,6 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon
G_GNUC_UNUSED,
VIR_WARN("Cannot update XML with PID for LXC %s",
vm->def->name);
virObjectUnlock(vm);
- virObjectUnref(cfg);
}
static virLXCMonitorCallbacks monitorCallbacks = {
@@ -820,10 +813,10 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr
driver,
virDomainObjPtr vm)
{
virLXCMonitorPtr monitor = NULL;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0)
- goto cleanup;
+ return NULL;
/* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active. This will be unreffed
@@ -840,11 +833,8 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr
driver,
virObjectUnref(monitor);
monitor = NULL;
}
- goto cleanup;
}
- cleanup:
- virObjectUnref(cfg);
return monitor;
}
@@ -932,7 +922,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
char *filterstr;
char *outputstr;
virCommandPtr cmd;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
cmd = virCommandNew(vm->def->emulator);
@@ -1013,7 +1003,6 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
virCommandRequireHandshake(cmd);
cleanup:
- virObjectUnref(cfg);
return cmd;
error:
virCommandFree(cmd);
@@ -1202,7 +1191,7 @@ int virLXCProcessStart(virConnectPtr conn,
virLXCDomainObjPrivatePtr priv = vm->privateData;
virCapsPtr caps = NULL;
virErrorPtr err = NULL;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
virCgroupPtr selfcgroup;
int status;
char *pidfile = NULL;
@@ -1564,7 +1553,6 @@ int virLXCProcessStart(virConnectPtr conn,
VIR_FORCE_CLOSE(handshakefds[1]);
VIR_FREE(pidfile);
VIR_FREE(logfile);
- virObjectUnref(cfg);
if (caps)
g_object_unref(caps);
@@ -1663,7 +1651,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
{
virLXCDriverPtr driver = opaque;
virLXCDomainObjPrivatePtr priv;
- virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
int ret = -1;
virObjectLock(vm);
@@ -1729,7 +1717,6 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
ret = 0;
cleanup:
- virObjectUnref(cfg);
virObjectUnlock(vm);
return ret;
--
2.25.1