Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 133 ++++++++++++++++++++++++++++++++++----------
1 files changed, 103 insertions(+), 30 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index d29a09a..c818368 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -552,7 +552,8 @@ static int parse_block_device(xmlNode *dnode, struct virt_device
**vdevs)
{
struct virt_device *vdev = NULL;
struct disk_device *ddev = NULL;
- xmlNode * child = NULL;
+
+ CU_DEBUG("Enter parse_block_device().");
vdev = calloc(1, sizeof(*vdev));
if (vdev == NULL)
@@ -560,45 +561,117 @@ static int parse_block_device(xmlNode *dnode, struct virt_device
**vdevs)
ddev = &(vdev->dev.disk);
- ddev->type = get_attr_value(dnode, "type");
- if (ddev->type == NULL)
+ ddev->others = parse_data_to_others(dnode, BAD_CAST "devices");
+ if (ddev->others == NULL) {
+ CU_DEBUG("xml file parse failed.");
+ goto err;
+ }
+
+ /* fetch out <disk> tag from others. It will be removed
+ * after others management finished. */
+ fetch_from_others(&ddev->others,
+ "disk",
+ TYPE_NODE,
+ "devices");
+
+ ddev->type = fetch_from_others(&ddev->others,
+ "type",
+ TYPE_PROP,
+ (char *)dnode->name);
+ if (ddev->type == NULL) {
+ CU_DEBUG("no type");
goto err;
+ }
- ddev->device = get_attr_value(dnode, "device");
- if (ddev->device == NULL)
+ ddev->device = fetch_from_others(&ddev->others,
+ "device",
+ TYPE_PROP,
+ (char *)dnode->name);
+ if (ddev->device == NULL) {
+ CU_DEBUG("no device");
goto err;
+ }
- for (child = dnode->children; child != NULL; child = child->next) {
- if (XSTREQ(child->name, "driver")) {
- ddev->driver = get_attr_value(child, "name");
- if (ddev->driver == NULL)
+ if (seek_in_others(&ddev->others,
+ "driver",
+ TYPE_NODE,
+ (char *)dnode->name)) {
+ ddev->driver = fetch_from_others(&ddev->others,
+ "name",
+ TYPE_PROP,
+ "driver");
+
+ if (ddev->driver == NULL) {
+ CU_DEBUG("no driver name");
+ goto err;
+ }
+
+ ddev->driver_type = fetch_from_others(&ddev->others,
+ "type",
+ TYPE_PROP,
+ "driver");
+
+ ddev->cache = fetch_from_others(&ddev->others,
+ "cache",
+ TYPE_PROP,
+ "driver");
+ }
+
+ if (seek_in_others(&ddev->others,
+ "source",
+ TYPE_NODE,
+ (char *)dnode->name)) {
+ ddev->source = fetch_from_others(&ddev->others,
+ "file",
+ TYPE_PROP,
+ "source");
+ if (ddev->source == NULL) {
+ ddev->source = fetch_from_others(&ddev->others,
+ "dev",
+ TYPE_PROP,
+ "source");
+
+ if (ddev->source == NULL) {
+ CU_DEBUG("no source file/dev");
goto err;
- ddev->driver_type = get_attr_value(child, "type");
- ddev->cache = get_attr_value(child, "cache");
- } else if (XSTREQ(child->name, "source")) {
- ddev->source = get_attr_value(child, "file");
- if (ddev->source) {
- ddev->disk_type = DISK_FILE;
- continue;
- }
- ddev->source = get_attr_value(child, "dev");
- if (ddev->source) {
- ddev->disk_type = DISK_PHY;
- continue;
+ } else {
+ ddev->disk_type == DISK_PHY;
}
+ } else {
+ ddev->disk_type = DISK_FILE;
+ }
+ }
+
+ if (seek_in_others(&ddev->others,
+ "target",
+ TYPE_NODE,
+ (char *)dnode->name)) {
+ ddev->virtual_dev = fetch_from_others(&ddev->others,
+ "dev",
+ TYPE_PROP,
+ "target");
+
+ if (ddev->virtual_dev == NULL) {
+ CU_DEBUG("no target dev");
goto err;
- } else if (XSTREQ(child->name, "target")) {
- ddev->virtual_dev = get_attr_value(child, "dev");
- if (ddev->virtual_dev == NULL)
- goto err;
- ddev->bus_type = get_attr_value(child, "bus");
- } else if (XSTREQ(child->name, "readonly")) {
- ddev->readonly = true;
- } else if (XSTREQ(child->name, "shareable")) {
- ddev->shareable = true;
}
+
+ ddev->bus_type = fetch_from_others(&ddev->others,
+ "bus",
+ TYPE_PROP,
+ "target");
}
+ ddev->readonly = seek_in_others(&ddev->others,
+ "readonly",
+ TYPE_NODE,
+ (char *)dnode->name);
+
+ ddev->shareable = seek_in_others(&ddev->others,
+ "shareable",
+ TYPE_NODE,
+ (char *)dnode->name);
+
/* handle the situation that a cdrom device have no disk in it, no ISO file */
if ((XSTREQ(ddev->device, "cdrom")) && (ddev->source ==
NULL)) {
ddev->source = strdup("");
--
1.7.1