[Libvirt-cim] [PATCH 27/47] Fix xml generation algorithm in net_xml()

Xu Wang gesaint at linux.vnet.ibm.com
Tue Oct 8 06:14:01 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/xmlgen.c |  157 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 121 insertions(+), 36 deletions(-)

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 592e67d..4d5ff28 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -730,8 +730,8 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo)
 {
         int i;
         const char *msg = NULL;
-        xmlNodePtr nic;
-        xmlNodePtr tmp;
+
+        CU_DEBUG("Enter net_xml()");
 
         for (i = 0; (i < dominfo->dev_net_ct) && (msg == NULL); i++) {
                 struct virt_device *dev = &dominfo->dev_net[i];
@@ -740,40 +740,98 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo)
 
                 struct net_device *net = &dev->dev.net;
 
-                nic = xmlNewChild(root, NULL, BAD_CAST "interface", NULL);
-                if (nic == NULL)
+                net->others = add_node_to_others(net->others,
+                                                 "interface",
+                                                 NULL,
+                                                 TYPE_NODE,
+                                                 "devices");
+
+                if (net->others == NULL) {
+                        CU_DEBUG("add node <interface> failed.");
                         return XML_ERROR;
-                xmlNewProp(nic, BAD_CAST "type", BAD_CAST net->type);
+                }
+
+                net->others = add_node_to_others(net->others,
+                                                 "type",
+                                                 net->type,
+                                                 TYPE_PROP,
+                                                 "interface");
 
                 if (net->mac != NULL) {
-                        tmp = xmlNewChild(nic, NULL, BAD_CAST "mac", NULL);
-                        if (tmp == NULL)
+                        net->others = add_node_to_others(net->others,
+                                                         "mac",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "interface");
+
+                        if (net->others == NULL) {
+                                CU_DEBUG("add node <mac> failed.");
                                 return XML_ERROR;
-                        xmlNewProp(tmp, BAD_CAST "address", BAD_CAST net->mac);
+                        }
+
+                        net->others = add_node_to_others(net->others,
+                                                         "address",
+                                                         net->mac,
+                                                         TYPE_PROP,
+                                                         "mac");
                 }
 
                 if (net->device != NULL) {
-                        tmp = xmlNewChild(nic, NULL, BAD_CAST "target", NULL);
-                        if (tmp == NULL)
+                        net->others = add_node_to_others(net->others,
+                                                         "target",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "interface");
+
+                        if (net->others == NULL) {
+                                CU_DEBUG("add node <target> failed.");
                                 return XML_ERROR;
-                        xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST net->device);
+                        }
+
+                        net->others = add_node_to_others(net->others,
+                                                         "dev",
+                                                         net->device,
+                                                         TYPE_PROP,
+                                                         "target");
                 }
 
 
                 if (net->model != NULL) {
-                        tmp = xmlNewChild(nic, NULL, BAD_CAST "model", NULL);
-                        if (tmp == NULL)
+                        net->others = add_node_to_others(net->others,
+                                                         "model",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "interface");
+
+                        if (net->others == NULL) {
+                                CU_DEBUG("add node <model> failed.");
                                 return XML_ERROR;
-                        xmlNewProp(tmp, BAD_CAST "type", BAD_CAST net->model);
+                        }
+
+                        net->others = add_node_to_others(net->others,
+                                                         "type",
+                                                         net->model,
+                                                         TYPE_PROP,
+                                                         "model");
                 }
 
                 if (net->filter_ref != NULL) {
-                        tmp = xmlNewChild(nic, NULL,
-                                BAD_CAST "filterref", NULL);
-                        if (tmp == NULL)
+                        net->others = add_node_to_others(net->others,
+                                                         "filterref",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "interface");
+
+                        if (net->others == NULL) {
+                                CU_DEBUG("add node <filterref> failed.");
                                 return XML_ERROR;
-                        xmlNewProp(tmp, BAD_CAST "filter",
-                                BAD_CAST net->filter_ref);
+                        }
+
+                        net->others = add_node_to_others(net->others,
+                                                         "filter",
+                                                         net->filter_ref,
+                                                         TYPE_PROP,
+                                                         "filterref");
                 }
 
 #if LIBVIR_VERSION_NUMBER >= 9000
@@ -782,24 +840,41 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo)
                         int ret;
                         char *string = NULL;
 
-                        tmp = xmlNewChild(nic, NULL,
-                                          BAD_CAST "bandwidth", NULL);
-                        if (tmp == NULL)
-                                return XML_ERROR;
+                        net->others = add_node_to_others(net->others,
+                                                         "bandwidth",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "interface");
+
+                        if (net->others == NULL) {
+                                 CU_DEBUG("add node <bandwidth> failed.");
+                                 return XML_ERROR;
+                        }
 
                         /* Set inbound bandwidth from Reservation & Limit */
-                        tmp = xmlNewChild(tmp, NULL,
-                                          BAD_CAST "inbound", NULL);
-                        if (tmp == NULL)
-                                return XML_ERROR;
+                        net->others = add_node_to_others(net->others,
+                                                         "inbound",
+                                                         NULL,
+                                                         TYPE_NODE,
+                                                         "bandwidth");
+
+                        if (net->others == NULL) {
+                                 CU_DEBUG("add node <inbound> failed.");
+                                 return XML_ERROR;
+                        }
 
                         if (net->reservation) {
                                 ret = asprintf(&string, "%" PRIu64,
                                                net->reservation);
                                 if (ret == -1)
                                         return XML_ERROR;
-                                xmlNewProp(tmp, BAD_CAST "average",
-                                           BAD_CAST string);
+
+                                net->others = add_node_to_others(net->others,
+                                                                 "average",
+                                                                 string,
+                                                                 TYPE_PROP,
+                                                                 "inbound");
+
                                 free(string);
                         }
 
@@ -808,28 +883,38 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo)
                                                net->limit);
                                 if (ret == -1)
                                         return XML_ERROR;
-                                xmlNewProp(tmp, BAD_CAST "peak",
-                                           BAD_CAST string);
+
+                                net->others = add_node_to_others(net->others,
+                                                                 "peak",
+                                                                 string,
+                                                                 TYPE_PROP,
+                                                                 "inbound");
+
                                 free(string);
                         }
                 }
 #endif
 
                 if (STREQ(dev->dev.net.type, "network")) {
-                        msg = set_net_source(nic, net, "network");
+                        msg = set_net_source("interface", net, "network", &net->others);
                 } else if (STREQ(dev->dev.net.type, "bridge")) {
-                        msg = bridge_net_to_xml(nic, net, dominfo->type);
+                        msg = bridge_net_to_xml("interface", net, dominfo->type, &net->others);
                 } else if (STREQ(dev->dev.net.type, "user")) {
-                        continue;
+                        /* do nothing */
                 } else if (STREQ(dev->dev.net.type, "direct")) {
-                        msg = set_net_source(nic, net, "direct");
+                        msg = set_net_source("interface", net, "direct", &net->others);
                         if (net->vsi.vsi_type != NULL) {
                                 struct vsi_device *vsi = &dev->dev.net.vsi;
-                                msg = set_net_vsi(nic, vsi);
+                                msg = set_net_vsi("interface", vsi, &net->others);
                         }
                 }
                 else
                         msg = "Unknown interface type";
+
+                net->others = others_to_xml(root, net->others, "devices");
+                if (net->others) {
+                        CU_DEBUG("others_to_xml failed.");
+                }
         }
 
         return msg;
-- 
1.7.1




More information about the Libvirt-cim mailing list