
From: Xu Wang <cngesaint@gmail.com> Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- libxkutil/device_parsing.c | 52 +++++++++++++++++++++++++++++++++++++++++----- libxkutil/device_parsing.h | 1 + 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index 5fdf28e..0a74ff3 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -159,6 +159,14 @@ static void cleanup_vcpu_device(struct vcpu_device *dev) cleanup_others(dev->others); } +static void cleanup_mem_device(struct mem_device *dev) +{ + if (dev == NULL) + return; + + cleanup_others(dev->others); +} + static void cleanup_emu_device(struct emu_device *dev) { if (dev == NULL) @@ -350,6 +358,8 @@ void cleanup_virt_device(struct virt_device *dev) cleanup_net_device(&dev->dev.net); else if (dev->type == CIM_RES_TYPE_PROC) cleanup_vcpu_device(&dev->dev.vcpu); + else if (dev->type == CIM_RES_TYPE_MEM) + cleanup_mem_device(&dev->dev.mem); else if (dev->type == CIM_RES_TYPE_EMU) cleanup_emu_device(&dev->dev.emu); else if (dev->type == CIM_RES_TYPE_GRAPHICS) @@ -1553,20 +1563,50 @@ static int parse_mem_device(xmlNode *node, struct virt_device **vdevs) char *content = NULL; char *tmpval = NULL; int ret = 0; + struct others *new_others = NULL; + + CU_DEBUG("Enter parse_mem_device()."); vdev = calloc(1, sizeof(*vdev)); - if (vdev == NULL) + if (vdev == NULL) { + CU_DEBUG("calloc failed."); goto err; + } mdev = &(vdev->dev.mem); - content = get_node_content(node); + new_others = parse_data_to_others(new_others, + node, + 0, + BAD_CAST "domain"); + mdev->others = combine_others(mdev->others, new_others); + + if (XSTREQ(node->name, "currentMemory")) { + content = fetch_from_others(&mdev->others, + -1, + "currentMemory", + TYPE_NODE, + -1, + "domain"); - if (XSTREQ(node->name, "currentMemory")) sscanf(content, "%" PRIu64, &mdev->size); - else if (XSTREQ(node->name, "memory")) { + } else if (XSTREQ(node->name, "memory")) { + content = fetch_from_others(&mdev->others, + -1, + "memory", + TYPE_NODE, + -1, + "domain"); + sscanf(content, "%" PRIu64, &mdev->maxsize); - tmpval = get_attr_value(node, "dumpCore"); + + tmpval = fetch_from_others(&mdev->others, + -1, + "dumpCore", + TYPE_PROP, + -1, + "memory"); + if (tmpval && XSTREQ(tmpval, "on")) { mdev->dumpCore = MEM_DUMP_CORE_ON; } else if (tmpval && XSTREQ(content, "off")) { @@ -1574,6 +1614,8 @@ static int parse_mem_device(xmlNode *node, struct virt_device **vdevs) } else { mdev->dumpCore = MEM_DUMP_CORE_NOT_SET; } + } else { + /* do nothing */ } *vdevs = vdev; diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h index c5517e3..0855166 100644 --- a/libxkutil/device_parsing.h +++ b/libxkutil/device_parsing.h @@ -109,6 +109,7 @@ struct mem_device { enum { MEM_DUMP_CORE_NOT_SET, MEM_DUMP_CORE_ON, MEM_DUMP_CORE_OFF } dumpCore; + struct others *others; }; struct vcpu_device { -- 1.8.3.1