>From 3ff1d49644124b72f9ab0c08df51d2879f2bb1bd Mon Sep 17 00:00:00 2001
From: John Ferlan <jferlan@redhat.com>
Date: Thu, 13 Mar 2014 09:40:26 -0400
Subject: [PATCH] Adjustments to patch 1/3

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 libxkutil/device_parsing.c | 42 +++++++++++++++++++++++++++++++++++-------
 libxkutil/device_parsing.h |  6 ++++++
 libxkutil/xmlgen.c         | 26 ++++++++++++++++++++++----
 src/svpc_types.h           |  2 +-
 4 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 12c52dc..2d5556a 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -313,7 +313,13 @@ static void cleanup_controller_device(struct controller_device *dev)
                 return;
 
         free(dev->type);
+        free(dev->index);
         free(dev->model);
+        free(dev->queues);
+        free(dev->ports);
+        free(dev->vectors);
+        cleanup_device_address(&dev->address);
+        cleanup_device_address(&dev->master);
 }
 
 void cleanup_virt_device(struct virt_device *dev)
@@ -1113,10 +1119,11 @@ static int parse_input_device(xmlNode *node, struct virt_device **vdevs)
         return 0;
 }
 
-static int parse_controller_device(xmlNode *node, struct virt_device **vdevs)
+static int parse_controller_device(xmlNode *cnode, struct virt_device **vdevs)
 {
         struct virt_device *vdev = NULL;
         struct controller_device *cdev = NULL;
+        xmlNode *child = NULL;
         int ret;
 
         vdev = calloc(1, sizeof(*vdev));
@@ -1125,15 +1132,36 @@ static int parse_controller_device(xmlNode *node, struct virt_device **vdevs)
 
         cdev = &(vdev->dev.controller);
 
-        cdev->type = get_attr_value(node, "type");
-        cdev->model = get_attr_value(node, "model");
-
-        if (cdev->type == NULL)
+        cdev->type = get_attr_value(cnode, "type");
+        if (cdev->type == NULL) {
+                CU_DEBUG("No type");
                 goto err;
-
+        }
+        cdev->type = get_attr_value(cnode, "index");
+        if (cdev->type == NULL) {
+                CU_DEBUG("No index");
+                goto err;
+        }
+        cdev->model = get_attr_value(cnode, "model");
+        cdev->ports = get_attr_value(cnode, "ports");
+        cdev->vectors = get_attr_value(cnode, "vectors");
+
+        for (child = cnode->children; child != NULL; child = child->next) {
+                if (XSTREQ(child->name, "address")) {
+                        parse_device_address(child, &cdev->address);
+                } else if (XSTREQ(child->name, "master")) {
+                        /* Although technically not an address it is similar
+                         * insomuch as it's a paired list of attributes that
+                         * we're just going to save and write out later
+                         */
+                        parse_device_address(child, &cdev->master);
+                } else if (XSTREQ(child->name, "driver")) {
+                        cdev->queues = get_attr_value(child, "queues");
+                }
+        }
         vdev->type = CIM_RES_TYPE_CONTROLLER;
 
-        ret = asprintf(&vdev->id, "%s", cdev->type);
+        ret = asprintf(&vdev->id, "%s:%s", cdev->type, cdev->index);
         if (ret == -1) {
                 CU_DEBUG("Failed to create controller id string");
                 goto err;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 556b9f2..2ec7b09 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -163,7 +163,13 @@ struct input_device {
 
 struct controller_device {
         char *type;
+        char *index;
         char *model;
+        char *queues;
+        char *ports;
+        char *vectors;
+        struct device_address address;
+        struct device_address master;
 };
 
 struct virt_device {
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 96e1c28..153db60 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -799,6 +799,7 @@ static const char *controller_xml(xmlNodePtr root, struct domain *dominfo)
         int i;
 
         for (i = 0; i < dominfo->dev_controller_ct; i++) {
+                xmlNodePtr ctlr;
                 xmlNodePtr tmp;
                 struct virt_device *_dev = &dominfo->dev_controller[i];
                 if (_dev->type == CIM_RES_TYPE_UNKNOWN)
@@ -806,12 +807,29 @@ static const char *controller_xml(xmlNodePtr root, struct domain *dominfo)
 
                 struct controller_device *dev = &_dev->dev.controller;
 
-                tmp = xmlNewChild(root, NULL, BAD_CAST "controller", NULL);
-                if (tmp == NULL)
+                ctlr = xmlNewChild(root, NULL, BAD_CAST "controller", NULL);
+                if (ctlr == NULL)
                         return XML_ERROR;
 
-                xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->type);
-                xmlNewProp(tmp, BAD_CAST "model", BAD_CAST dev->model);
+                /* Required */
+                xmlNewProp(ctlr, BAD_CAST "type", BAD_CAST dev->type);
+                xmlNewProp(ctlr, BAD_CAST "index", BAD_CAST dev->index);
+
+                /* Optional */
+                if (dev->model)
+                    xmlNewProp(ctlr, BAD_CAST "model", BAD_CAST dev->model);
+                if (dev->ports)
+                    xmlNewProp(ctlr, BAD_CAST "ports", BAD_CAST dev->ports);
+                if (dev->vectors)
+                    xmlNewProp(ctlr, BAD_CAST "vectors", BAD_CAST dev->vectors);
+                if (dev->queues) {
+                    tmp = xmlNewChild(ctlr, NULL, BAD_CAST "driver", NULL);
+                    xmlNewProp(tmp, BAD_CAST "queueus", BAD_CAST dev->queues);
+                }
+                if (dev->master.ct > 0)
+                    return device_address_xml(ctlr, &dev->master);
+                if (dev->address.ct > 0)
+                    return device_address_xml(ctlr, &dev->address);
         }
 
         return NULL;
diff --git a/src/svpc_types.h b/src/svpc_types.h
index d76097c..7a2b653 100644
--- a/src/svpc_types.h
+++ b/src/svpc_types.h
@@ -32,11 +32,11 @@
 #define CIM_RES_TYPE_DISK       17
 #define CIM_RES_TYPE_GRAPHICS   24
 #define CIM_RES_TYPE_INPUT      13 
-#define CIM_RES_TYPE_CONTROLLER 33
 #define CIM_RES_TYPE_UNKNOWN    1000
 #define CIM_RES_TYPE_IMAGE      32768 
 #define CIM_RES_TYPE_CONSOLE    32769
 #define CIM_RES_TYPE_EMU        32770
+#define CIM_RES_TYPE_CONTROLLER 32771
 
 #define CIM_RES_TYPE_COUNT 8
 const static int cim_res_types[CIM_RES_TYPE_COUNT] = 
-- 
1.8.5.3

