[libvirt PATCH 5/8] lxc: use g_auto for virLXCDriverGetConfig

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/lxc/lxc_driver.c  | 48 +++++++++++++++----------------------------
 src/lxc/lxc_process.c | 22 +++++++-------------
 2 files changed, 23 insertions(+), 47 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 92ae22ef2b..0d438de4a5 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -403,7 +403,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
     virDomainPtr dom = NULL;
     virObjectEvent *event = NULL;
     g_autoptr(virDomainDef) oldDef = NULL;
-    virLXCDriverConfig *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)
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return dom;
 }
 
@@ -475,7 +474,7 @@ static int lxcDomainUndefineFlags(virDomainPtr dom,
     virDomainObj *vm;
     virObjectEvent *event = NULL;
     int ret = -1;
-    virLXCDriverConfig *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;
     virLXCDomainObjPrivate *priv;
     virLXCDriver *driver = dom->conn->privateData;
-    virLXCDriverConfig *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,
     virDomainDef *persistentDef = NULL;
     virDomainObj *vm = NULL;
     virLXCDomainObjPrivate *priv = NULL;
-    virLXCDriverConfig *cfg = NULL;
+    g_autoptr(virLXCDriverConfig) cfg = NULL;
     virLXCDriver *driver = dom->conn->privateData;
     int ret = -1;
 
@@ -804,7 +801,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -975,7 +971,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
     virDomainObj *vm;
     virObjectEvent *event = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, -1);
 
@@ -1022,7 +1018,6 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     virNWFilterUnlockFilterUpdates();
     return ret;
 }
@@ -1078,7 +1073,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
     g_autoptr(virDomainDef) def = NULL;
     virDomainPtr dom = NULL;
     virObjectEvent *event = NULL;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     g_autoptr(virCaps) caps = NULL;
     unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
 
@@ -1147,7 +1142,6 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     virNWFilterUnlockFilterUpdates();
     return dom;
 }
@@ -1592,7 +1586,7 @@ static void lxcNotifyLoadDomain(virDomainObj *vm, int newVM, void *opaque)
 static int
 lxcStateReload(void)
 {
-    virLXCDriverConfig *cfg = NULL;
+    g_autoptr(virLXCDriverConfig) cfg = NULL;
 
     if (!lxc_driver)
         return 0;
@@ -1604,7 +1598,6 @@ lxcStateReload(void)
                                    cfg->autostartDir, false,
                                    lxc_driver->xmlopt,
                                    lxcNotifyLoadDomain, lxc_driver);
-    virObjectUnref(cfg);
     return 0;
 }
 
@@ -1811,7 +1804,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
     int ret = -1;
     int rc;
     virLXCDomainObjPrivate *priv;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -1920,7 +1913,6 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2245,7 +2237,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
     virDomainDef *def = NULL;
     virDomainDef *persistentDef = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = NULL;
+    g_autoptr(virLXCDriverConfig) cfg = NULL;
     virLXCDomainObjPrivate *priv;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -2310,7 +2302,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2470,7 +2461,7 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
     g_autofree char *configFile = NULL;
     g_autofree char *autostartLink = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     if (!(vm = lxcDomObjFromDomain(dom)))
         goto cleanup;
@@ -2534,7 +2525,6 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2622,7 +2612,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
     virDomainObj *vm;
     virObjectEvent *event = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     if (!(vm = lxcDomObjFromDomain(dom)))
         goto cleanup;
@@ -2659,7 +2649,6 @@ static int lxcDomainSuspend(virDomainPtr dom)
  cleanup:
     virObjectEventStateQueue(driver->domainEventState, event);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2671,7 +2660,7 @@ static int lxcDomainResume(virDomainPtr dom)
     int ret = -1;
     int state;
     virLXCDomainObjPrivate *priv;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     if (!(vm = lxcDomObjFromDomain(dom)))
         goto cleanup;
@@ -2716,7 +2705,6 @@ static int lxcDomainResume(virDomainPtr dom)
  cleanup:
     virObjectEventStateQueue(driver->domainEventState, event);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4286,7 +4274,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
     virDomainDeviceDef *dev = NULL;
     virDomainDeviceDef *dev_copy = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4370,7 +4358,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
         virDomainDeviceDefFree(dev_copy);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4392,7 +4379,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
     g_autoptr(virDomainDef) vmdef = NULL;
     virDomainDeviceDef *dev = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4440,7 +4427,6 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
  cleanup:
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4456,7 +4442,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
     virDomainDeviceDef *dev = NULL;
     virDomainDeviceDef *dev_copy = NULL;
     int ret = -1;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4534,7 +4520,6 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
         virDomainDeviceDefFree(dev_copy);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4807,7 +4792,7 @@ lxcDomainSetMetadata(virDomainPtr dom,
 {
     virLXCDriver *driver = dom->conn->privateData;
     virDomainObj *vm;
-    virLXCDriverConfig *cfg = NULL;
+    g_autoptr(virLXCDriverConfig) cfg = NULL;
     int ret = -1;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -4838,7 +4823,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 501f418557..9cae025517 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -170,7 +170,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
     size_t i;
     virLXCDomainObjPrivate *priv = vm->privateData;
     const virNetDevVPortProfile *vport = NULL;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     g_autoptr(virConnect) conn = NULL;
 
     VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d flags=0x%x",
@@ -278,8 +278,6 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
 
     if (flags & VIR_LXC_PROCESS_CLEANUP_REMOVE_TRANSIENT)
         virDomainObjRemoveTransientDef(vm);
-
-    virObjectUnref(cfg);
 }
 
 
@@ -367,7 +365,7 @@ virLXCProcessSetupInterfaceDirect(virLXCDriver *driver,
     char *res_ifname = NULL;
     const virNetDevBandwidth *bw;
     const virNetDevVPortProfile *prof;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     const char *linkdev = virDomainNetGetActualDirectDev(net);
     unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_IFUP;
 
@@ -414,7 +412,6 @@ virLXCProcessSetupInterfaceDirect(virLXCDriver *driver,
     ret = res_ifname;
 
  cleanup:
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -801,7 +798,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitor *mon G_GNUC_UNUSED,
 {
     virLXCDriver *driver = lxc_driver;
     virLXCDomainObjPrivate *priv;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     ino_t inode = 0;
 
     virObjectLock(vm);
@@ -821,7 +818,6 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitor *mon G_GNUC_UNUSED,
         VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name);
 
     virObjectUnlock(vm);
-    virObjectUnref(cfg);
 }
 
 static virLXCMonitorCallbacks monitorCallbacks = {
@@ -835,7 +831,7 @@ static virLXCMonitor *virLXCProcessConnectMonitor(virLXCDriver *driver,
                                                     virDomainObj *vm)
 {
     virLXCMonitor *monitor = NULL;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     if (virSecurityManagerSetSocketLabel(driver->securityManager, vm->def) < 0)
         goto cleanup;
@@ -859,7 +855,6 @@ static virLXCMonitor *virLXCProcessConnectMonitor(virLXCDriver *driver,
     }
 
  cleanup:
-    virObjectUnref(cfg);
     return monitor;
 }
 
@@ -948,7 +943,7 @@ virLXCProcessBuildControllerCmd(virLXCDriver *driver,
     g_autofree char *filterstr = NULL;
     g_autofree char *outputstr = NULL;
     virCommand *cmd;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
 
     cmd = virCommandNew(vm->def->emulator);
 
@@ -1020,7 +1015,6 @@ virLXCProcessBuildControllerCmd(virLXCDriver *driver,
     virCommandRequireHandshake(cmd);
 
  cleanup:
-    virObjectUnref(cfg);
     return cmd;
  error:
     virCommandFree(cmd);
@@ -1209,7 +1203,7 @@ int virLXCProcessStart(virConnectPtr conn,
     virLXCDomainObjPrivate *priv = vm->privateData;
     g_autoptr(virCaps) caps = NULL;
     virErrorPtr err = NULL;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     g_autoptr(virCgroup) selfcgroup = NULL;
     int status;
     g_autofree char *pidfile = NULL;
@@ -1578,7 +1572,6 @@ int virLXCProcessStart(virConnectPtr conn,
         VIR_FORCE_CLOSE(ttyFDs[i]);
     for (i = 0; i < G_N_ELEMENTS(handshakefds); i++)
         VIR_FORCE_CLOSE(handshakefds[i]);
-    virObjectUnref(cfg);
 
     virErrorRestore(&err);
 
@@ -1689,7 +1682,7 @@ virLXCProcessReconnectDomain(virDomainObj *vm,
 {
     virLXCDriver *driver = opaque;
     virLXCDomainObjPrivate *priv;
-    virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
+    g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     int ret = -1;
 
     virObjectLock(vm);
@@ -1752,7 +1745,6 @@ virLXCProcessReconnectDomain(virDomainObj *vm,
 
     ret = 0;
  cleanup:
-    virObjectUnref(cfg);
     virObjectUnlock(vm);
     return ret;
 
-- 
2.31.1




[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