From: Xu Wang <cngesaint(a)gmail.com>
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 120 ++++++++++++++++++++++++++++++++-------------
1 file changed, 87 insertions(+), 33 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index b244d8a..56c9d3d 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -2617,9 +2617,8 @@ static void cleanup_bootlist(char **blist, unsigned blist_ct)
free(blist);
}
-static int parse_os(struct domain *dominfo, xmlNode *os)
+static int parse_os(struct domain *dominfo)
{
- xmlNode *child;
char **blist = NULL;
unsigned bl_size = 0;
char *arch = NULL;
@@ -2631,39 +2630,93 @@ static int parse_os(struct domain *dominfo, xmlNode *os)
char *boot = NULL;
char *init = NULL;
- for (child = os->children; child != NULL; child = child->next) {
- if (XSTREQ(child->name, "type")) {
- STRPROP(dominfo, os_info.pv.type, child);
- arch = get_attr_value(child, "arch");
- machine = get_attr_value(child, "machine");
- } else if (XSTREQ(child->name, "kernel"))
- kernel = get_node_content(child);
- else if (XSTREQ(child->name, "initrd"))
- initrd = get_node_content(child);
- else if (XSTREQ(child->name, "cmdline"))
- cmdline = get_node_content(child);
- else if (XSTREQ(child->name, "loader"))
- loader = get_node_content(child);
- else if (XSTREQ(child->name, "boot")) {
- char **tmp_list = NULL;
-
- tmp_list = (char **)realloc(blist,
- (bl_size + 1) *
- sizeof(char *));
- if (tmp_list == NULL) {
- // Nothing you can do. Just go on.
- CU_DEBUG("Could not alloc space for "
- "boot device");
- continue;
- }
- blist = tmp_list;
+ CU_DEBUG("Enter parse_os()");
+
+ dominfo->os_info.pv.type = fetch_from_others(&dominfo->others,
+ 0,
+ "type",
+ TYPE_NODE,
+ 0,
+ "os");
+ if (dominfo->os_info.pv.type) {
+ arch = fetch_from_others(&dominfo->others,
+ -1,
+ "arch",
+ TYPE_PROP,
+ -1,
+ "type");
+
+ machine = fetch_from_others(&dominfo->others,
+ -1,
+ "machine",
+ TYPE_PROP,
+ -1,
+ "type");
+ }
+
+ dominfo->os_info.pv.kernel = fetch_from_others(&dominfo->others,
+ -1,
+ "kernel",
+ TYPE_NODE,
+ -1,
+ "os");
+
+ dominfo->os_info.pv.initrd = fetch_from_others(&dominfo->others,
+ -1,
+ "initrd",
+ TYPE_NODE,
+ -1,
+ "os");
+
+ dominfo->os_info.pv.cmdline = fetch_from_others(&dominfo->others,
+ -1,
+ "cmdline",
+ TYPE_NODE,
+ -1,
+ "os");
+
+ dominfo->os_info.fv.loader = fetch_from_others(&dominfo->others,
+ -1,
+ "loader",
+ TYPE_NODE,
+ -1,
+ "os");
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "boot",
+ TYPE_NODE,
+ -1,
+ "os")) {
+ char **tmp_list = NULL;
+
+ tmp_list = (char **)realloc(blist,
+ (bl_size + 1) * sizeof(char *));
+
+ if (tmp_list == NULL) {
+ /* Nothing you can do. Just go on. */
+ CU_DEBUG("Could not alloc space for "
+ "boot device");
+ } else {
+ blist = tmp_list;
- blist[bl_size] = get_attr_value(child, "dev");
+ blist[bl_size] = fetch_from_others(&dominfo->others,
+ -1,
+ "dev",
+ TYPE_PROP,
+ -1,
+ "boot");
bl_size++;
- } else if (XSTREQ(child->name, "init"))
- init = get_node_content(child);
+ }
}
+ dominfo->os_info.lxc.init = fetch_from_others(&dominfo->others,
+ -1,
+ "init",
+ TYPE_NODE,
+ -1,
+ "os");
+
if ((STREQC(dominfo->os_info.fv.type, "hvm")) &&
(STREQC(dominfo->typestr, "xen")))
dominfo->type = DOMAIN_XENFV;
@@ -2673,7 +2726,8 @@ static int parse_os(struct domain *dominfo, xmlNode *os)
dominfo->type = DOMAIN_QEMU;
else if (STREQC(dominfo->typestr, "lxc"))
dominfo->type = DOMAIN_LXC;
- else if (STREQC(dominfo->os_info.pv.type, "linux"))
+ else if (dominfo->os_info.pv.type &&
+ STREQC(dominfo->os_info.pv.type, "linux"))
dominfo->type = DOMAIN_XENPV;
else
dominfo->type = -1;
@@ -2833,7 +2887,7 @@ static int parse_domain(xmlNodeSet *nsv, struct domain *dominfo)
TYPE_NODE,
-1,
(char *)nodes[0]->name)) {
- /* parse_os(); */
+ parse_os(dominfo);
}
action = fetch_from_others(&dominfo->others,
--
1.8.3.1