Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/xmlgen.c | 334 ++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 261 insertions(+), 73 deletions(-)
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index d1e1c94..f5fe4a4 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -276,8 +276,9 @@ static const char *check_others_active(struct others *others)
static const char *console_xml(xmlNodePtr root, struct domain *dominfo)
{
int i;
- xmlNodePtr console;
- xmlNodePtr tmp;
+ int mode_id;
+
+ CU_DEBUG("Enter disk_block_xml()");
for (i = 0; i < dominfo->dev_console_ct; i++) {
struct virt_device *_dev = &dominfo->dev_console[i];
@@ -286,108 +287,279 @@ static const char *console_xml(xmlNodePtr root, struct domain
*dominfo)
struct console_device *cdev = &_dev->dev.console;
- console = xmlNewChild(root, NULL, BAD_CAST "console", NULL);
- if (console == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "console",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "devices");
+
+ if (cdev->others == NULL) {
+ CU_DEBUG("Add tag <disk> failed.");
return XML_ERROR;
+ }
- xmlNewProp(console, BAD_CAST "type",
- BAD_CAST
- chardev_source_type_IDToStr(cdev->source_type));
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "type",
+ chardev_source_type_IDToStr(
+ cdev->source_type),
+ TYPE_PROP,
+ 0,
+ "console");
switch (cdev->source_type) {
case CIM_CHARDEV_SOURCE_TYPE_PTY:
/* The path property is not mandatory */
if (cdev->source_dev.pty.path) {
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "path",
- BAD_CAST cdev->source_dev.pty.path);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "path",
+
cdev->source_dev.pty.path,
+ TYPE_PROP,
+ 0,
+ "source");
}
break;
case CIM_CHARDEV_SOURCE_TYPE_DEV:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "path",
- BAD_CAST cdev->source_dev.dev.path);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "path",
+ cdev->source_dev.dev.path,
+ TYPE_PROP,
+ 0,
+ "source");
break;
case CIM_CHARDEV_SOURCE_TYPE_FILE:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "path",
- BAD_CAST cdev->source_dev.file.path);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "path",
+ cdev->source_dev.file.path,
+ TYPE_PROP,
+ 0,
+ "source");
break;
case CIM_CHARDEV_SOURCE_TYPE_PIPE:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "path",
- BAD_CAST cdev->source_dev.pipe.path);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "path",
+ cdev->source_dev.pipe.path,
+ TYPE_PROP,
+ 0,
+ "source");
break;
case CIM_CHARDEV_SOURCE_TYPE_UNIXSOCK:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "mode",
- BAD_CAST cdev->source_dev.unixsock.mode);
- xmlNewProp(tmp, BAD_CAST "path",
- BAD_CAST cdev->source_dev.unixsock.path);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "mode",
+
cdev->source_dev.unixsock.mode,
+ TYPE_PROP,
+ 0,
+ "source");
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "path",
+
cdev->source_dev.unixsock.path,
+ TYPE_PROP,
+ 0,
+ "source");
break;
case CIM_CHARDEV_SOURCE_TYPE_UDP:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ mode_id = get_id_of_others(cdev->others,
+ "mode",
+ "bind",
+ TYPE_PROP,
+ 0,
+ "source");
+ if (mode_id == -1) {
+ CU_DEBUG("get id of mode failed");
+ return NULL;
+ }
+
+ cdev->others = add_node_to_others(cdev->others,
+ mode_id,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "mode", BAD_CAST
"bind");
- xmlNewProp(tmp, BAD_CAST "host",
- BAD_CAST cdev->source_dev.udp.bind_host);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "mode",
+ "bind",
+ TYPE_PROP,
+ mode_id,
+ "source");
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "host",
+
cdev->source_dev.udp.bind_host,
+ TYPE_PROP,
+ mode_id,
+ "source");
+
/* The service property is not mandatory */
if (cdev->source_dev.udp.bind_service)
- xmlNewProp(tmp, BAD_CAST "service",
- BAD_CAST
- cdev->source_dev.udp.bind_service);
-
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others =
+ add_node_to_others(cdev->others,
+ 0,
+ "service",
+
cdev->source_dev.udp.bind_service,
+ TYPE_PROP,
+ mode_id,
+ "source");
+
+ cdev->others = add_node_to_others(cdev->others,
+ 1 - mode_id,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "mode", BAD_CAST
"connect");
- xmlNewProp(tmp, BAD_CAST "host",
- BAD_CAST cdev->source_dev.udp.connect_host);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "mode",
+ "connect",
+ TYPE_PROP,
+ 1 - mode_id,
+ "source");
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "host",
+
cdev->source_dev.udp.connect_host,
+ TYPE_PROP,
+ 1 - mode_id,
+ "source");
+
/* The service property is not mandatory */
if (cdev->source_dev.udp.connect_service)
- xmlNewProp(tmp, BAD_CAST "service",
- BAD_CAST
- cdev->source_dev.udp.connect_service);
+ cdev->others =
+ add_node_to_others(cdev->others,
+ 0,
+ "service",
+
cdev->source_dev.udp.connect_service,
+ TYPE_PROP,
+ 1 - mode_id,
+ "source");
break;
case CIM_CHARDEV_SOURCE_TYPE_TCP:
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "source", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "mode",
- BAD_CAST cdev->source_dev.tcp.mode);
- xmlNewProp(tmp, BAD_CAST "host",
- BAD_CAST cdev->source_dev.tcp.host);
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "mode",
+ cdev->source_dev.tcp.mode,
+ TYPE_PROP,
+ 0,
+ "source");
+
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "host",
+ cdev->source_dev.tcp.host,
+ TYPE_PROP,
+ 0,
+ "source");
+
if (cdev->source_dev.tcp.service)
- xmlNewProp(tmp, BAD_CAST "service",
- BAD_CAST
- cdev->source_dev.tcp.service);
+ cdev->others =
+ add_node_to_others(cdev->others,
+ 0,
+ "service",
+
cdev->source_dev.tcp.service,
+ TYPE_PROP,
+ 0,
+ "source");
+
if (cdev->source_dev.tcp.protocol) {
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "protocol", NULL);
- if (tmp == NULL)
+ cdev->others =
+ add_node_to_others(cdev->others,
+ 0,
+ "protocol",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "type",
- BAD_CAST cdev->source_dev.tcp.protocol);
+ cdev->others =
+ add_node_to_others(cdev->others,
+ 0,
+ "type",
+
cdev->source_dev.tcp.protocol,
+ TYPE_PROP,
+ 0,
+ "protocol");
}
break;
default:
@@ -401,14 +573,30 @@ static const char *console_xml(xmlNodePtr root, struct domain
*dominfo)
}
if (cdev->target_type) {
- tmp = xmlNewChild(console, NULL,
- BAD_CAST "target", NULL);
- if (tmp == NULL)
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "target",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "console");
+ if (cdev->others == NULL)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "type",
- BAD_CAST cdev->target_type);
+ cdev->others = add_node_to_others(cdev->others,
+ 0,
+ "type",
+ cdev->target_type,
+ TYPE_PROP,
+ 0,
+ "target");
+ }
+
+ cdev->others = others_to_xml(root, cdev->others, 0,
"devices");
+ if (check_others_active(cdev->others)) {
+ return "xml generation failed.";
}
}
+
return NULL;
}
--
1.7.1