From: Xu Wang <cngesaint(a)gmail.com>
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
libxkutil/device_parsing.h | 7 +++++
src/svpc_types.h | 1 +
3 files changed, 83 insertions(+)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 5a012bc..a6a6cfe 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -101,6 +101,15 @@ static void cleanup_others(struct others *others)
}
}
+static void cleanup_unknown_device(struct unknown_device *dev)
+{
+ if (dev == NULL)
+ return;
+
+ free(dev->name);
+ cleanup_others(dev->others);
+}
+
static void cleanup_disk_device(struct disk_device *dev)
{
if (dev == NULL)
@@ -371,6 +380,8 @@ void cleanup_virt_device(struct virt_device *dev)
cleanup_input_device(&dev->dev.input);
else if (dev->type == CIM_RES_TYPE_CONSOLE)
cleanup_console_device(&dev->dev.console);
+ else if (dev->type == CIM_RES_TYPE_UNKDEV)
+ cleanup_unknown_device(&dev->dev.unknown);
free(dev->id);
@@ -2152,6 +2163,70 @@ static int parse_input_device(xmlNode *node, struct virt_device
**vdevs)
return 0;
}
+static int parse_unknown_device(xmlNode *node, struct virt_device **vdevs)
+{
+ struct virt_device *vdev = NULL;
+ struct unknown_device *udev = NULL;
+ xmlNode *child = NULL;
+
+ CU_DEBUG("Enter parse_unknown_device().");
+
+ vdev = calloc(1, sizeof(*vdev));
+ if (vdev == NULL) {
+ CU_DEBUG("calloc failed.");
+ goto err;
+ }
+
+ udev = &(vdev->dev.unknown);
+
+ for (child = node->children; child != NULL; child = child->next) {
+ /* Skip all items parsed in other parse_*() functions.
+ * Everything here is just to be compatible with old versions.
+ * Here may need some improvement in the future.
+ */
+ if (XSTREQ(child->name, "disk") ||
+ XSTREQ(child->name, "filesystem") ||
+ XSTREQ(child->name, "interface") ||
+ XSTREQ(child->name, "emulator") ||
+ XSTREQ(child->name, "graphics") ||
+ XSTREQ(child->name, "console") ||
+ XSTREQ(child->name, "serial") ||
+ XSTREQ(child->name, "input")) {
+ /* Just skip them and do nothing */
+ } else {
+ udev->others = parse_data_to_others(udev->others,
+ child,
+ 0,
+ BAD_CAST
"devices");
+ }
+ }
+
+ if (udev->others == NULL) {
+ CU_DEBUG("no others.");
+ /* Should this really be an error? or success that
+ * we didn't find something unknown?!!
+ */
+ goto err;
+ }
+
+ vdev->type = CIM_RES_TYPE_UNKDEV;
+
+ udev->name = strdup("unknown");
+ if (udev->name == NULL) {
+ CU_DEBUG("Failed to strdup unknown name");
+ goto err;
+ }
+
+ *vdevs = vdev;
+
+ return 1;
+err:
+ cleanup_unknown_device(udev);
+ free(vdev);
+
+ return 0;
+}
+
static bool resize_devlist(struct virt_device **list, int newsize)
{
struct virt_device *_list;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 275d91f..a4e60ee 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -60,6 +60,12 @@ struct others {
} status;
};
+/* The structure for saving unknown device */
+struct unknown_device {
+ char *name;
+ struct others *others;
+};
+
struct vsi_device {
char *vsi_type;
char *manager_id;
@@ -201,6 +207,7 @@ struct virt_device {
struct graphics_device graphics;
struct console_device console;
struct input_device input;
+ struct unknown_device unknown;
} dev;
char *id;
};
diff --git a/src/svpc_types.h b/src/svpc_types.h
index 404e428..4928742 100644
--- a/src/svpc_types.h
+++ b/src/svpc_types.h
@@ -33,6 +33,7 @@
#define CIM_RES_TYPE_GRAPHICS 24
#define CIM_RES_TYPE_INPUT 13
#define CIM_RES_TYPE_UNKNOWN 1000
+#define CIM_RES_TYPE_UNKDEV 1001
#define CIM_RES_TYPE_IMAGE 32768
#define CIM_RES_TYPE_CONSOLE 32769
#define CIM_RES_TYPE_EMU 32770
--
1.8.3.1