Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/xmlgen.c | 185 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 149 insertions(+), 36 deletions(-)
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 74b4a0d..097a5c8 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -1250,8 +1250,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];
@@ -1260,40 +1260,118 @@ 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,
+ 0,
+ "interface",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "type",
+ net->type,
+ TYPE_PROP,
+ 0,
+ "interface");
if (net->mac != NULL) {
- tmp = xmlNewChild(nic, NULL, BAD_CAST "mac", NULL);
- if (tmp == NULL)
+ net->others = add_node_to_others(net->others,
+ 0,
+ "mac",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "address",
+ net->mac,
+ TYPE_PROP,
+ 0,
+ "mac");
}
if (net->device != NULL) {
- tmp = xmlNewChild(nic, NULL, BAD_CAST "target", NULL);
- if (tmp == NULL)
+ net->others = add_node_to_others(net->others,
+ 0,
+ "target",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "dev",
+ net->device,
+ TYPE_PROP,
+ 0,
+ "target");
}
if (net->model != NULL) {
- tmp = xmlNewChild(nic, NULL, BAD_CAST "model", NULL);
- if (tmp == NULL)
+ net->others = add_node_to_others(net->others,
+ 0,
+ "model",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "type",
+ net->model,
+ TYPE_PROP,
+ 0,
+ "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,
+ 0,
+ "filterref",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "filter",
+ net->filter_ref,
+ TYPE_PROP,
+ 0,
+ "filterref");
}
#if LIBVIR_VERSION_NUMBER >= 9000
@@ -1302,24 +1380,47 @@ 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,
+ 0,
+ "bandwidth",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "inbound",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "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,
+ 0,
+ "average",
+ string,
+ TYPE_PROP,
+ 0,
+ "inbound");
+
free(string);
}
@@ -1328,28 +1429,40 @@ 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,
+ 0,
+ "peak",
+ string,
+ TYPE_PROP,
+ 0,
+ "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, 0,
"devices");
+ if (check_others_active(net->others)) {
+ return "xml generation failed.";
+ }
}
return msg;
--
1.7.1