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

[libvirt] [PATCH v6 3/5] Network: Move dnsmasqContext creation to networkSaveDnsmasqHostsfile()



This patch moves the dnsmasqContext creation to the
networkSaveDnsmasqHostsfile() function.

Signed-off-by: Michal Novotny <minovotn redhat com>
---
 src/network/bridge_driver.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 9c0423a..e3a1225 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -433,13 +433,20 @@ networkShutdown(void) {
 }
 
 
-static int
+static dnsmasqContext*
 networkSaveDnsmasqHostsfile(virNetworkIpDefPtr ipdef,
-                            dnsmasqContext *dctx,
+                            char *name,
                             bool force)
 {
     unsigned int i;
 
+    dnsmasqContext *dctx = dnsmasqContextNew(name,
+                                             DNSMASQ_STATE_DIR);
+    if (dctx == NULL) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
     if (! force && virFileExists(dctx->hostsfile->path))
         return 0;
 
@@ -450,9 +457,14 @@ networkSaveDnsmasqHostsfile(virNetworkIpDefPtr ipdef,
     }
 
     if (dnsmasqSave(dctx) < 0)
-        return -1;
+        goto cleanup;
 
-    return 0;
+    return dctx;
+
+cleanup:
+    dnsmasqContextFree(dctx);
+
+    return NULL;
 }
 
 
@@ -465,6 +477,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
     int nbleases = 0;
     int ii;
     virNetworkIpDefPtr tmpipdef;
+    dnsmasqContext *dctx = NULL;
 
     /*
      * NB, be careful about syntax for dnsmasq options in long format.
@@ -591,19 +604,11 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         if (ipdef->nranges || ipdef->nhosts)
             virCommandAddArg(cmd, "--dhcp-no-override");
 
-        if (ipdef->nhosts > 0) {
-            dnsmasqContext *dctx = dnsmasqContextNew(network->def->name,
-                                                     DNSMASQ_STATE_DIR);
-            if (dctx == NULL) {
-                virReportOOMError();
-                goto cleanup;
-            }
-
-            if (networkSaveDnsmasqHostsfile(ipdef, dctx, false) == 0) {
+            if ((dctx = networkSaveDnsmasqHostsfile(ipdef, network->def->name, false))) {
                 if (dctx->hostsfile->nhosts)
                     virCommandAddArgPair(cmd, "--dhcp-hostsfile",
                                          dctx->hostsfile->path);
-            }
+
             dnsmasqContextFree(dctx);
         }
 
@@ -2231,11 +2236,9 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
         }
     }
     if (ipv4def) {
-        dnsmasqContext *dctx = dnsmasqContextNew(network->def->name, DNSMASQ_STATE_DIR);
+        dnsmasqContext* dctx = networkSaveDnsmasqHostsfile(ipv4def, network->def->name, true);
         if (dctx == NULL)
             goto cleanup;
-
-        networkSaveDnsmasqHostsfile(ipv4def, dctx, true);
         dnsmasqContextFree(dctx);
     }
 
-- 
1.7.3.2


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