From: Xu Wang <cngesaint(a)gmail.com>
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 164 +++++++++++++++++++++++++++++++++++++--------
libxkutil/device_parsing.h | 2 +
2 files changed, 139 insertions(+), 27 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 99f6eda..b244d8a 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -2736,10 +2736,8 @@ static int parse_features(struct domain *dominfo, xmlNode
*features)
return 1;
}
-static void set_action(uint16_t *val, xmlNode *child)
+static void set_action(uint16_t *val, const char *action)
{
- char *action = (char *)xmlNodeGetContent(child);
-
if (action == NULL)
*val = CIM_VSSD_RECOVERY_NONE;
else if (STREQ(action, "destroy"))
@@ -2750,38 +2748,148 @@ static void set_action(uint16_t *val, xmlNode *child)
*val = CIM_VSSD_RECOVERY_RESTART;
else
*val = CIM_VSSD_RECOVERY_NONE;
-
- xmlFree(action);
}
static int parse_domain(xmlNodeSet *nsv, struct domain *dominfo)
{
xmlNode **nodes = nsv->nodeTab;
xmlNode *child;
+ xmlAttrPtr xmlAttr = NULL;
+ char *action = NULL;
+
+ CU_DEBUG("Enter parse_domain()");
+
+ /* parsing attributions of domain into others */
+ xmlAttr = nodes[0]->properties;
+ while(xmlAttr) {
+ dominfo->others = add_others(dominfo->others,
+ nodes[0],
+ xmlAttr->name,
+ TYPE_PROP,
+ 0,
+ nodes[0]->name);
+ xmlAttr = xmlAttr->next;
+ }
+
+ dominfo->typestr = fetch_from_others(&dominfo->others,
+ -1,
+ "type",
+ TYPE_PROP,
+ -1,
+ (char *)nodes[0]->name);
+
+ /* parse every item in the field of domain and skip some will be parsed
+ * in other functions. The white list contains:
+ * <memory> (parsed in parse_mem_device())
+ * <currentMemory> (parsed in parse_mem_device())
+ * <vcpu> (parsed in parse_vcpu_device())
+ * <devices> (parsed in other parse_*_device())
+ */
+ for (child = nodes[0]->children; child != NULL; child = child->next) {
+ if (XSTREQ(child->name, "memory") ||
+ XSTREQ(child->name, "currentMemory") ||
+ XSTREQ(child->name, "vcpu") ||
+ XSTREQ(child->name, "devices")) {
+ continue;
+ } else {
+ dominfo->others = parse_data_to_others(dominfo->others,
+ child,
+ 0,
+ nodes[0]->name);
+ }
+ }
- dominfo->typestr = get_attr_value(nodes[0], "type");
+ dominfo->name = fetch_from_others(&dominfo->others,
+ -1,
+ "name",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
- for (child = nodes[0]->children; child != NULL; child = child->next) {
- if (XSTREQ(child->name, "name"))
- STRPROP(dominfo, name, child);
- else if (XSTREQ(child->name, "uuid"))
- STRPROP(dominfo, uuid, child);
- else if (XSTREQ(child->name, "bootloader"))
- STRPROP(dominfo, bootloader, child);
- else if (XSTREQ(child->name, "bootloader_args"))
- STRPROP(dominfo, bootloader_args, child);
- else if (XSTREQ(child->name, "os"))
- parse_os(dominfo, child);
- else if (XSTREQ(child->name, "on_poweroff"))
- set_action(&dominfo->on_poweroff, child);
- else if (XSTREQ(child->name, "on_reboot"))
- set_action(&dominfo->on_reboot, child);
- else if (XSTREQ(child->name, "on_crash"))
- set_action(&dominfo->on_crash, child);
- else if (XSTREQ(child->name, "clock"))
- dominfo->clock = get_attr_value(child, "offset");
- else if (XSTREQ(child->name, "features"))
- parse_features(dominfo, child);
+ dominfo->uuid = fetch_from_others(&dominfo->others,
+ -1,
+ "uuid",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader = fetch_from_others(&dominfo->others,
+ -1,
+ "bootloader",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader_args = fetch_from_others(&dominfo->others,
+ -1,
+ "bootloader_args",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "os",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ /* parse_os(); */
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_poweroff",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_poweroff, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_reboot",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_reboot, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_crash",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_crash, action);
+ free(action);
+ }
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "clock",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ dominfo->clock = fetch_from_others(&dominfo->others,
+ -1,
+ "offset",
+ TYPE_PROP,
+ -1,
+ "clock");
+ }
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "features",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ /* parse_features(); */
}
return 1;
@@ -2945,6 +3053,8 @@ void cleanup_dominfo(struct domain **dominfo)
cleanup_virt_devices(&dom->dev_console, dom->dev_console_ct);
cleanup_virt_devices(&dom->dev_unknown, dom->dev_unknown_ct);
+ cleanup_others(dom->others);
+
free(dom);
*dominfo = NULL;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index fa8aa17..35011ae 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -286,6 +286,8 @@ struct domain {
struct virt_device *dev_unknown;
int dev_unknown_ct;
+
+ struct others *others;
};
struct virt_device *virt_device_dup(struct virt_device *dev);
--
1.8.3.1