# HG changeset patch
# User Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
# Date 1243891182 10800
# Node ID 6107c1026ed44acaf24ce9430a0e6dd2fa97f252
# Parent db7956e2e1028b553e9e722751eff3b8bea6ee38
XML generation and parsing for the BootDevices property
#2:
- Code style changes
#3:
- Removed commented code sections
Signed-off-by: Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
diff -r db7956e2e102 -r 6107c1026ed4 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Mon Jun 01 18:19:43 2009 -0300
+++ b/libxkutil/device_parsing.c Mon Jun 01 18:19:42 2009 -0300
@@ -810,6 +810,8 @@
static int parse_os(struct domain *dominfo, xmlNode *os)
{
xmlNode *child;
+ char **blist = NULL;
+ unsigned bl_size = 0;
for (child = os->children; child != NULL; child = child->next) {
if (XSTREQ(child->name, "type"))
@@ -822,10 +824,23 @@
STRPROP(dominfo, os_info.pv.cmdline, child);
else if (XSTREQ(child->name, "loader"))
STRPROP(dominfo, os_info.fv.loader, child);
- else if (XSTREQ(child->name, "boot"))
- dominfo->os_info.fv.boot = get_attr_value(child,
- "dev");
- else if (XSTREQ(child->name, "init"))
+ 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;
+
+ blist[bl_size] = get_attr_value(child, "dev");
+ bl_size++;
+ } else if (XSTREQ(child->name, "init"))
STRPROP(dominfo, os_info.lxc.init, child);
}
@@ -843,6 +858,9 @@
else
dominfo->type = -1;
+ dominfo->os_info.fv.bootlist = blist;
+ dominfo->os_info.fv.bootlist_ct = bl_size;
+
return 1;
}
@@ -1001,9 +1019,15 @@
free(dom->os_info.pv.cmdline);
} else if ((dom->type == DOMAIN_XENFV) ||
(dom->type == DOMAIN_KVM) || (dom->type == DOMAIN_QEMU)) {
+ int i;
+
free(dom->os_info.fv.type);
free(dom->os_info.fv.loader);
- free(dom->os_info.fv.boot);
+
+ for (i = 0; i < dom->os_info.fv.bootlist_ct; i++) {
+ free(dom->os_info.fv.bootlist[i]);
+ }
+ free(dom->os_info.fv.bootlist);
} else if (dom->type == DOMAIN_LXC) {
free(dom->os_info.lxc.type);
free(dom->os_info.lxc.init);
diff -r db7956e2e102 -r 6107c1026ed4 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Mon Jun 01 18:19:43 2009 -0300
+++ b/libxkutil/device_parsing.h Mon Jun 01 18:19:42 2009 -0300
@@ -99,7 +99,8 @@
struct fv_os_info {
char *type; /* Should always be 'hvm' */
char *loader;
- char *boot;
+ unsigned bootlist_ct;
+ char **bootlist;
};
struct lxc_os_info {
diff -r db7956e2e102 -r 6107c1026ed4 libxkutil/xml_parse_test.c
--- a/libxkutil/xml_parse_test.c Mon Jun 01 18:19:43 2009 -0300
+++ b/libxkutil/xml_parse_test.c Mon Jun 01 18:19:42 2009 -0300
@@ -28,6 +28,7 @@
static void print_os(struct domain *dom,
FILE *d)
{
+ int i;
if (dom->type == DOMAIN_XENPV) {
print_value(d, "Domain Type", "Xen PV");
@@ -39,13 +40,18 @@
print_value(d, "Domain Type", "Xen FV");
print_value(d, "Type", dom->os_info.fv.type);
print_value(d, "Loader", dom->os_info.fv.loader);
- print_value(d, "Boot", dom->os_info.fv.boot);
+ for (i = 0; i < dom->os_info.fv.bootlist_ct; i++) {
+ print_value(d, "Boot",
dom->os_info.fv.bootlist[i]);
+ }
} else if ((dom->type == DOMAIN_KVM) || (dom->type == DOMAIN_QEMU)) {
print_value(d, "Domain Type", "KVM/QEMU");
print_value(d, "Type", dom->os_info.fv.type);
print_value(d, "Loader", dom->os_info.fv.loader);
- print_value(d, "Boot", dom->os_info.fv.boot);
+
+ for (i = 0; i < dom->os_info.fv.bootlist_ct; i++) {
+ print_value(d, "Boot",
dom->os_info.fv.bootlist[i]);
+ }
} else if (dom->type == DOMAIN_LXC) {
print_value(d, "Init", dom->os_info.lxc.init);
} else {
diff -r db7956e2e102 -r 6107c1026ed4 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c Mon Jun 01 18:19:43 2009 -0300
+++ b/libxkutil/xmlgen.c Mon Jun 01 18:19:42 2009 -0300
@@ -435,10 +435,27 @@
return NULL;
}
+static int _fv_bootlist_xml(xmlNodePtr root, struct fv_os_info *os)
+{
+ unsigned i;
+ xmlNodePtr tmp;
+
+ for (i = 0; i < os->bootlist_ct; i++) {
+ tmp = xmlNewChild(root, NULL, BAD_CAST "boot", NULL);
+ if (tmp == NULL)
+ return 0;
+
+ xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST os->bootlist[i]);
+ }
+
+ return 1;
+}
+
static char *_xenfv_os_xml(xmlNodePtr root, struct domain *domain)
{
struct fv_os_info *os = &domain->os_info.fv;
xmlNodePtr tmp;
+ unsigned ret;
if (os->type == NULL)
os->type = strdup("hvm");
@@ -446,8 +463,11 @@
if (os->loader == NULL)
os->loader = strdup("/usr/lib/xen/boot/hvmloader");
- if (os->boot == NULL)
- os->boot = strdup("hd");
+ if (os->bootlist_ct == 0) {
+ os->bootlist_ct = 1;
+ os->bootlist = (char **)calloc(1, sizeof(char *));
+ os->bootlist[0] = strdup("hd");
+ }
tmp = xmlNewChild(root, NULL, BAD_CAST "type", BAD_CAST os->type);
if (tmp == NULL)
@@ -457,12 +477,10 @@
if (tmp == NULL)
return XML_ERROR;
- tmp = xmlNewChild(root, NULL, BAD_CAST "boot", NULL);
- if (tmp == NULL)
+ ret = _fv_bootlist_xml(root, os);
+ if (ret == 0)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST os->boot);
-
tmp = xmlNewChild(root, NULL, BAD_CAST "features", NULL);
xmlNewChild(tmp, NULL, BAD_CAST "pae", NULL);
xmlNewChild(tmp, NULL, BAD_CAST "acpi", NULL);
@@ -475,21 +493,24 @@
{
struct fv_os_info *os = &domain->os_info.fv;
xmlNodePtr tmp;
+ unsigned ret;
if (os->type == NULL)
os->type = strdup("hvm");
- if (os->boot == NULL)
- os->boot = strdup("hd");
+ if (os->bootlist_ct == 0) {
+ os->bootlist_ct = 1;
+ os->bootlist = (char **)calloc(1, sizeof(char *));
+ os->bootlist[0] = strdup("hd");
+ }
tmp = xmlNewChild(root, NULL, BAD_CAST "type", BAD_CAST os->type);
if (tmp == NULL)
return XML_ERROR;
-
- tmp = xmlNewChild(root, NULL, BAD_CAST "boot", NULL);
- if (tmp == NULL)
+
+ ret = _fv_bootlist_xml(root, os);
+ if (ret == 0)
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST os->boot);
return NULL;
}