From: Xu Wang <cngesaint(a)gmail.com>
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 180 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 149 insertions(+), 31 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 20b35e1..dac2ea1 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -925,7 +925,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)
@@ -933,47 +934,164 @@ 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(ddev->others,
+ dnode,
+ 0,
+ 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,
+ -1,
+ "disk",
+ TYPE_NODE,
+ -1,
+ "devices");
- ddev->device = get_attr_value(dnode, "device");
- if (ddev->device == NULL)
+ ddev->type = fetch_from_others(&ddev->others,
+ -1,
+ "type",
+ TYPE_PROP,
+ -1,
+ (char *)dnode->name);
+ if (ddev->type == NULL) {
+ CU_DEBUG("no type");
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)
+ ddev->device = fetch_from_others(&ddev->others,
+ -1,
+ "device",
+ TYPE_PROP,
+ -1,
+ (char *)dnode->name);
+ if (ddev->device == NULL) {
+ CU_DEBUG("no device");
+ goto err;
+ }
+
+ if (seek_in_others(&ddev->others,
+ -1,
+ "driver",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name)) {
+ ddev->driver = fetch_from_others(&ddev->others,
+ -1,
+ "name",
+ TYPE_PROP,
+ -1,
+ "driver");
+
+ if (ddev->driver == NULL) {
+ CU_DEBUG("no driver name");
+ goto err;
+ }
+
+ ddev->driver_type = fetch_from_others(&ddev->others,
+ -1,
+ "type",
+ TYPE_PROP,
+ -1,
+ "driver");
+
+ ddev->cache = fetch_from_others(&ddev->others,
+ -1,
+ "cache",
+ TYPE_PROP,
+ -1,
+ "driver");
+ }
+
+ if (seek_in_others(&ddev->others,
+ -1,
+ "source",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name)) {
+ ddev->source = fetch_from_others(&ddev->others,
+ -1,
+ "file",
+ TYPE_PROP,
+ -1,
+ "source");
+ if (ddev->source == NULL) {
+ ddev->source = fetch_from_others(&ddev->others,
+ -1,
+ "dev",
+ TYPE_PROP,
+ -1,
+ "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) {
+ } else {
ddev->disk_type = DISK_PHY;
- continue;
}
+ } else {
+ ddev->disk_type = DISK_FILE;
+ }
+ }
+
+ if (seek_in_others(&ddev->others,
+ -1,
+ "target",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name)) {
+ ddev->virtual_dev = fetch_from_others(&ddev->others,
+ -1,
+ "dev",
+ TYPE_PROP,
+ -1,
+ "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;
- } else if (XSTREQ(child->name, "address")) {
- parse_device_address(child, &ddev->address);
}
+
+ ddev->bus_type = fetch_from_others(&ddev->others,
+ -1,
+ "bus",
+ TYPE_PROP,
+ -1,
+ "target");
}
+ ddev->readonly = seek_in_others(&ddev->others,
+ -1,
+ "readonly",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name);
+
+ ddev->shareable = seek_in_others(&ddev->others,
+ -1,
+ "shareable",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name);
+
+ if (seek_in_others(&ddev->others,
+ -1,
+ "address",
+ TYPE_NODE,
+ -1,
+ (char *)dnode->name)) {
+ if (!fetch_device_address_from_others(&ddev->others,
+ &ddev->address)) {
+ CU_DEBUG("error fetching device address");
+ goto err;
+ }
+ }
+
+
/* 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.8.3.1