[libvirt] [PATCH 1/7] conf: rename network dns host/srv/txt arrays

Laine Stump laine at laine.org
Fri Dec 7 18:56:11 UTC 2012


This shortens the name of the structs for srv and txt, and their
instances in virNetworkDNSDef, to be more compact and uniform with the
naming of the dns host array.
---
 src/conf/network_conf.c     | 102 ++++++++++++++++++++++----------------------
 src/conf/network_conf.h     |  32 +++++++-------
 src/network/bridge_driver.c |  34 +++++++--------
 3 files changed, 85 insertions(+), 83 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index c36bdd3..7caf39f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -136,13 +136,13 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def)
 static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
 {
     if (def) {
-        if (def->txtrecords) {
-            while (def->ntxtrecords--) {
-                VIR_FREE(def->txtrecords[def->ntxtrecords].name);
-                VIR_FREE(def->txtrecords[def->ntxtrecords].value);
+        if (def->txts) {
+            while (def->ntxts--) {
+                VIR_FREE(def->txts[def->ntxts].name);
+                VIR_FREE(def->txts[def->ntxts].value);
             }
         }
-        VIR_FREE(def->txtrecords);
+        VIR_FREE(def->txts);
         if (def->nhosts) {
             while (def->nhosts--) {
                 while (def->hosts[def->nhosts].nnames--)
@@ -151,15 +151,15 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
             }
         }
         VIR_FREE(def->hosts);
-        if (def->nsrvrecords) {
-            while (def->nsrvrecords--) {
-                VIR_FREE(def->srvrecords[def->nsrvrecords].domain);
-                VIR_FREE(def->srvrecords[def->nsrvrecords].service);
-                VIR_FREE(def->srvrecords[def->nsrvrecords].protocol);
-                VIR_FREE(def->srvrecords[def->nsrvrecords].target);
+        if (def->nsrvs) {
+            while (def->nsrvs--) {
+                VIR_FREE(def->srvs[def->nsrvs].domain);
+                VIR_FREE(def->srvs[def->nsrvs].service);
+                VIR_FREE(def->srvs[def->nsrvs].protocol);
+                VIR_FREE(def->srvs[def->nsrvs].target);
             }
         }
-        VIR_FREE(def->srvrecords);
+        VIR_FREE(def->srvs);
         VIR_FREE(def);
     }
 }
@@ -874,18 +874,18 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
         goto error;
     }
 
-    if (VIR_REALLOC_N(def->srvrecords, def->nsrvrecords + 1) < 0) {
+    if (VIR_REALLOC_N(def->srvs, def->nsrvs + 1) < 0) {
         virReportOOMError();
         goto error;
     }
 
-    def->srvrecords[def->nsrvrecords].service = service;
-    def->srvrecords[def->nsrvrecords].protocol = protocol;
-    def->srvrecords[def->nsrvrecords].domain = NULL;
-    def->srvrecords[def->nsrvrecords].target = NULL;
-    def->srvrecords[def->nsrvrecords].port = 0;
-    def->srvrecords[def->nsrvrecords].priority = 0;
-    def->srvrecords[def->nsrvrecords].weight = 0;
+    def->srvs[def->nsrvs].service = service;
+    def->srvs[def->nsrvs].protocol = protocol;
+    def->srvs[def->nsrvs].domain = NULL;
+    def->srvs[def->nsrvs].target = NULL;
+    def->srvs[def->nsrvs].port = 0;
+    def->srvs[def->nsrvs].priority = 0;
+    def->srvs[def->nsrvs].weight = 0;
 
     /* Following attributes are optional but we had to make sure they're NULL above */
     if ((target = virXMLPropString(cur, "target")) && (domain = virXMLPropString(cur, "domain"))) {
@@ -893,23 +893,23 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def,
 
         ctxt->node = cur;
         if (virXPathInt("string(./@port)", ctxt, &port))
-            def->srvrecords[def->nsrvrecords].port = port;
+            def->srvs[def->nsrvs].port = port;
 
         if (virXPathInt("string(./@priority)", ctxt, &priority))
-            def->srvrecords[def->nsrvrecords].priority = priority;
+            def->srvs[def->nsrvs].priority = priority;
 
         if (virXPathInt("string(./@weight)", ctxt, &weight))
-            def->srvrecords[def->nsrvrecords].weight = weight;
+            def->srvs[def->nsrvs].weight = weight;
         ctxt->node = save_ctxt;
 
-        def->srvrecords[def->nsrvrecords].domain = domain;
-        def->srvrecords[def->nsrvrecords].target = target;
-        def->srvrecords[def->nsrvrecords].port = port;
-        def->srvrecords[def->nsrvrecords].priority = priority;
-        def->srvrecords[def->nsrvrecords].weight = weight;
+        def->srvs[def->nsrvs].domain = domain;
+        def->srvs[def->nsrvs].target = target;
+        def->srvs[def->nsrvs].port = port;
+        def->srvs[def->nsrvs].priority = priority;
+        def->srvs[def->nsrvs].weight = weight;
     }
 
-    def->nsrvrecords++;
+    def->nsrvs++;
 
     goto cleanup;
 
@@ -962,14 +962,14 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
                 goto error;
             }
 
-            if (VIR_REALLOC_N(def->txtrecords, def->ntxtrecords + 1) < 0) {
+            if (VIR_REALLOC_N(def->txts, def->ntxts + 1) < 0) {
                 virReportOOMError();
                 goto error;
             }
 
-            def->txtrecords[def->ntxtrecords].name = name;
-            def->txtrecords[def->ntxtrecords].value = value;
-            def->ntxtrecords++;
+            def->txts[def->ntxts].name = name;
+            def->txts[def->ntxts].value = value;
+            def->ntxts++;
             name = NULL;
             value = NULL;
         } else if (cur->type == XML_ELEMENT_NODE &&
@@ -1681,28 +1681,28 @@ virNetworkDNSDefFormat(virBufferPtr buf,
     virBufferAddLit(buf, "<dns>\n");
     virBufferAdjustIndent(buf, 2);
 
-    for (i = 0 ; i < def->ntxtrecords ; i++) {
+    for (i = 0 ; i < def->ntxts ; i++) {
         virBufferAsprintf(buf, "<txt name='%s' value='%s' />\n",
-                              def->txtrecords[i].name,
-                              def->txtrecords[i].value);
+                              def->txts[i].name,
+                              def->txts[i].value);
     }
 
-    for (i = 0 ; i < def->nsrvrecords ; i++) {
-        if (def->srvrecords[i].service && def->srvrecords[i].protocol) {
+    for (i = 0 ; i < def->nsrvs ; i++) {
+        if (def->srvs[i].service && def->srvs[i].protocol) {
             virBufferAsprintf(buf, "<srv service='%s' protocol='%s'",
-                                  def->srvrecords[i].service,
-                                  def->srvrecords[i].protocol);
-
-            if (def->srvrecords[i].domain)
-                virBufferAsprintf(buf, " domain='%s'", def->srvrecords[i].domain);
-            if (def->srvrecords[i].target)
-                virBufferAsprintf(buf, " target='%s'", def->srvrecords[i].target);
-            if (def->srvrecords[i].port)
-                virBufferAsprintf(buf, " port='%d'", def->srvrecords[i].port);
-            if (def->srvrecords[i].priority)
-                virBufferAsprintf(buf, " priority='%d'", def->srvrecords[i].priority);
-            if (def->srvrecords[i].weight)
-                virBufferAsprintf(buf, " weight='%d'", def->srvrecords[i].weight);
+                                  def->srvs[i].service,
+                                  def->srvs[i].protocol);
+
+            if (def->srvs[i].domain)
+                virBufferAsprintf(buf, " domain='%s'", def->srvs[i].domain);
+            if (def->srvs[i].target)
+                virBufferAsprintf(buf, " target='%s'", def->srvs[i].target);
+            if (def->srvs[i].port)
+                virBufferAsprintf(buf, " port='%d'", def->srvs[i].port);
+            if (def->srvs[i].priority)
+                virBufferAsprintf(buf, " priority='%d'", def->srvs[i].priority);
+            if (def->srvs[i].weight)
+                virBufferAsprintf(buf, " weight='%d'", def->srvs[i].weight);
 
             virBufferAsprintf(buf, "/>\n");
         }
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index d4dc214..e78ddae 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -76,16 +76,16 @@ struct _virNetworkDHCPHostDef {
     virSocketAddr ip;
 };
 
-typedef struct _virNetworkDNSTxtRecordsDef virNetworkDNSTxtRecordsDef;
-typedef virNetworkDNSTxtRecordsDef *virNetworkDNSTxtRecordsDefPtr;
-struct _virNetworkDNSTxtRecordsDef {
+typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
+typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr;
+struct _virNetworkDNSTxtDef {
     char *name;
     char *value;
 };
 
-typedef struct _virNetworkDNSSrvRecordsDef virNetworkDNSSrvRecordsDef;
-typedef virNetworkDNSSrvRecordsDef *virNetworkDNSSrvRecordsDefPtr;
-struct _virNetworkDNSSrvRecordsDef {
+typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
+typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
+struct _virNetworkDNSSrvDef {
     char *domain;
     char *service;
     char *protocol;
@@ -95,21 +95,23 @@ struct _virNetworkDNSSrvRecordsDef {
     int weight;
 };
 
-struct _virNetworkDNSHostsDef {
+typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
+typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
+struct _virNetworkDNSHostDef {
     virSocketAddr ip;
     int nnames;
     char **names;
 };
 
-typedef struct _virNetworkDNSHostsDef *virNetworkDNSHostsDefPtr;
-
+typedef struct _virNetworkDNSDef virNetworkDNSDef;
+typedef virNetworkDNSDef *virNetworkDNSDefPtr;
 struct _virNetworkDNSDef {
-    unsigned int ntxtrecords;
-    virNetworkDNSTxtRecordsDefPtr txtrecords;
-    unsigned int nhosts;
-    virNetworkDNSHostsDefPtr hosts;
-    unsigned int nsrvrecords;
-    virNetworkDNSSrvRecordsDefPtr srvrecords;
+    size_t ntxts;
+    virNetworkDNSTxtDefPtr txts;
+    size_t nhosts;
+    virNetworkDNSHostDefPtr hosts;
+    size_t nsrvs;
+    virNetworkDNSSrvDefPtr srvs;
 };
 
 typedef struct _virNetworkDNSDef *virNetworkDNSDefPtr;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 00cffee..453bb63 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -580,7 +580,7 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx,
 
     if (dnsdef) {
         for (i = 0; i < dnsdef->nhosts; i++) {
-            virNetworkDNSHostsDefPtr host = &(dnsdef->hosts[i]);
+            virNetworkDNSHostDefPtr host = &(dnsdef->hosts[i]);
             if (VIR_SOCKET_ADDR_VALID(&host->ip)) {
                 for (j = 0; j < host->nnames; j++)
                     if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0)
@@ -719,38 +719,38 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
         virNetworkDNSDefPtr dns = network->def->dns;
         int i;
 
-        for (i = 0; i < dns->ntxtrecords; i++) {
+        for (i = 0; i < dns->ntxts; i++) {
             virCommandAddArgFormat(cmd, "--txt-record=%s,%s",
-                                   dns->txtrecords[i].name,
-                                   dns->txtrecords[i].value);
+                                   dns->txts[i].name,
+                                   dns->txts[i].value);
         }
 
-        for (i = 0; i < dns->nsrvrecords; i++) {
-            if (dns->srvrecords[i].service && dns->srvrecords[i].protocol) {
-                if (dns->srvrecords[i].port) {
-                    if (virAsprintf(&recordPort, "%d", dns->srvrecords[i].port) < 0) {
+        for (i = 0; i < dns->nsrvs; i++) {
+            if (dns->srvs[i].service && dns->srvs[i].protocol) {
+                if (dns->srvs[i].port) {
+                    if (virAsprintf(&recordPort, "%d", dns->srvs[i].port) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
                 }
-                if (dns->srvrecords[i].priority) {
-                    if (virAsprintf(&recordPriority, "%d", dns->srvrecords[i].priority) < 0) {
+                if (dns->srvs[i].priority) {
+                    if (virAsprintf(&recordPriority, "%d", dns->srvs[i].priority) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
                 }
-                if (dns->srvrecords[i].weight) {
-                    if (virAsprintf(&recordWeight, "%d", dns->srvrecords[i].weight) < 0) {
+                if (dns->srvs[i].weight) {
+                    if (virAsprintf(&recordWeight, "%d", dns->srvs[i].weight) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
                 }
 
                 if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s",
-                                dns->srvrecords[i].service,
-                                dns->srvrecords[i].protocol,
-                                dns->srvrecords[i].domain   ? dns->srvrecords[i].domain : "",
-                                dns->srvrecords[i].target   ? dns->srvrecords[i].target : "",
+                                dns->srvs[i].service,
+                                dns->srvs[i].protocol,
+                                dns->srvs[i].domain   ? dns->srvs[i].domain : "",
+                                dns->srvs[i].target   ? dns->srvs[i].target : "",
                                 recordPort                  ? recordPort                : "",
                                 recordPriority              ? recordPriority            : "",
                                 recordWeight                ? recordWeight              : "") < 0) {
@@ -2764,7 +2764,7 @@ networkValidate(struct network_driver *driver,
             return -1;
         }
         if (def->dns &&
-            (def->dns->ntxtrecords || def->dns->nhosts || def->dns->nsrvrecords)) {
+            (def->dns->ntxts || def->dns->nhosts || def->dns->nsrvs)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("Unsupported <dns> element in network %s "
                              "with forward mode='%s'"),
-- 
1.7.11.7




More information about the libvir-list mailing list