[Libvirt-cim] [PATCH V2] Add dumpCore tag support to memory

Xu Wang gesaint at linux.vnet.ibm.com
Thu Aug 15 06:40:24 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/device_parsing.c |   26 +++++++++++++++++++++++++-
 libxkutil/device_parsing.h |    1 +
 libxkutil/xmlgen.c         |    4 ++++
 3 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 7900e06..23fa6d4 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -141,6 +141,15 @@ static void cleanup_input_device(struct input_device *dev)
         free(dev->bus);
 }
 
+static void cleanup_mem_device(struct mem_device *dev)
+{
+        if (dev == NULL)
+                return;
+
+        if (dev->dumpCore)
+                free(dev->dumpCore);
+}
+
 void cleanup_virt_device(struct virt_device *dev)
 {
         if (dev == NULL)
@@ -156,6 +165,8 @@ void cleanup_virt_device(struct virt_device *dev)
                 cleanup_graphics_device(&dev->dev.graphics);
         else if (dev->type == CIM_RES_TYPE_INPUT)
                 cleanup_input_device(&dev->dev.input);
+        else if (dev->type == CIM_RES_TYPE_MEM)
+                cleanup_mem_device(&dev->dev.mem);
 
         free(dev->id);
 
@@ -605,8 +616,10 @@ static int parse_mem_device(xmlNode *node, struct virt_device **vdevs)
 
         if (XSTREQ(node->name, "currentMemory"))
                 sscanf(content, "%" PRIu64, &mdev->size);
-        else if (XSTREQ(node->name, "memory"))
+        else if (XSTREQ(node->name, "memory")) {
                 sscanf(content, "%" PRIu64, &mdev->maxsize);
+                mdev->dumpCore = get_attr_value(node, "dumpCore");
+        }
 
         free(content);
 
@@ -987,10 +1000,21 @@ static int _get_mem_device(const char *xml, struct virt_device **list)
                                          mdevs[1].dev.mem.size);
                 mdev->dev.mem.maxsize = MAX(mdevs[0].dev.mem.maxsize,
                                             mdevs[1].dev.mem.maxsize);
+                /* If both of them have dumpCore field, the first one
+                 * will be saved. If one of them has that field, it will
+                 * be saved too. If none of them has that field, the
+                 * value will be left null.
+                 */
+                if (mdevs[0].dev.mem.dumpCore) {
+                        mdev->dev.mem.dumpCore = strdup(mdevs[0].dev.mem.dumpCore);
+                } else if (mdevs[1].dev.mem.dumpCore) {
+                        mdev->dev.mem.dumpCore = strdup(mdevs[1].dev.mem.dumpCore);
+                }
         } else {
                 mdev->dev.mem.size = MAX(mdevs[0].dev.mem.size,
                                          mdevs[0].dev.mem.maxsize);
                 mdev->dev.mem.maxsize = mdev->dev.mem.size;
+                mdev->dev.mem.dumpCore = strdup(mdevs[0].dev.mem.dumpCore);
         }
 
         mdev->type = CIM_RES_TYPE_MEM;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 2b6d3d1..73810c9 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -75,6 +75,7 @@ struct net_device {
 struct mem_device {
         uint64_t size;
         uint64_t maxsize;
+        char *dumpCore;
 };
 
 struct vcpu_device {
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 4287d42..7c16657 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -498,6 +498,10 @@ static const char *mem_xml(xmlNodePtr root, struct domain *dominfo)
                           BAD_CAST string);
 
         free(string);
+
+        if (tmp == NULL)
+                return XML_ERROR;
+        xmlNewProp(tmp, BAD_CAST "dumpCore", BAD_CAST mem->dumpCore);
  out:
         if (tmp == NULL)
                 return XML_ERROR;
-- 
1.7.1




More information about the Libvirt-cim mailing list