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

Wenchao Xia xiawenc at linux.vnet.ibm.com
Tue Aug 20 01:56:11 UTC 2013


于 2013-8-19 17:11, Xu Wang 写道:
> dumpCore tag in the <memory> is not supported by libvirt-cim and
> it will be dropped during updating any element in the xml definition
> of a domain. This patch keep the tag all the time.
>
> Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
> ---
>   libxkutil/device_parsing.c |   28 +++++++++++++++++++++++++++-
>   libxkutil/device_parsing.h |    3 +++
>   libxkutil/xmlgen.c         |    9 +++++++++
>   3 files changed, 39 insertions(+), 1 deletions(-)
>
> diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
> index 7900e06..96db532 100644
> --- a/libxkutil/device_parsing.c
> +++ b/libxkutil/device_parsing.c
> @@ -605,8 +605,17 @@ 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);
> +                content = get_attr_value(node, "dumpCore");
> +                if (XSTREQ(content, "on")) {
> +                    mdev->dumpCore = MEM_DUMP_CORE_ON;
> +                } else if (XSTREQ(content, "off")) {
> +                    mdev->dumpCore = MEM_DUMP_CORE_OFF;
> +                } else {
> +                    mdev->dumpCore = MEM_DUMP_CORE_NOT_SET;
> +                }
> +        }
>
>           free(content);
>
> @@ -968,6 +977,7 @@ static int _get_mem_device(const char *xml, struct virt_device **list)
>           struct virt_device *mdevs = NULL;
>           struct virt_device *mdev = NULL;
>           int ret;
> +        bool mem_dump_core_set = false;
>
>           ret = parse_devices(xml, &mdevs, CIM_RES_TYPE_MEM);
>           if (ret <= 0)
> @@ -987,10 +997,26 @@ 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);
> +                /* libvirt dumpCore tag always belong to memory xml node, but
> +                 * here we may have two mdev for memory node and currentMemory
> +                 * node. So pick up one value.
> +                 */
> +                if (mdevs[0].dev.mem.dumpCore != MEM_DUMP_CORE_NOT_SET) {
> +                        mdev->dev.mem.dumpCore = mdevs[0].dev.mem.dumpCore;
> +                        mem_dump_core_set = true;
> +                } else if (mdevs[1].dev.mem.dumpCore !=
> +                           MEM_DUMP_CORE_NOT_SET) {
> +                        if (mem_dump_core_set) {
> +                                CU_DEBUG("WARN: libvirt set memory core dump in"
> +                                         "two nodes!");
> +                        }
> +                        mdev->dev.mem.dumpCore = 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 = 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..979b792 100644
> --- a/libxkutil/device_parsing.h
> +++ b/libxkutil/device_parsing.h
> @@ -75,6 +75,9 @@ struct net_device {
>   struct mem_device {
>           uint64_t size;
>           uint64_t maxsize;
> +        enum { MEM_DUMP_CORE_NOT_SET,
> +               MEM_DUMP_CORE_ON,
> +               MEM_DUMP_CORE_OFF } dumpCore;
>   };
>
>   struct vcpu_device {
> diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
> index 4287d42..30e9a5e 100644
> --- a/libxkutil/xmlgen.c
> +++ b/libxkutil/xmlgen.c
> @@ -498,6 +498,15 @@ static const char *mem_xml(xmlNodePtr root, struct domain *dominfo)
>                             BAD_CAST string);
>
>           free(string);
> +
> +        if (tmp == NULL)
> +                return XML_ERROR;
   No checking with tmp is a bugfix, so better to fix it in another
patch. And also, better to add documents in commit message that:
"This patch just add mapping between libvirt xml and struct mem_device,
it make sure this tag will not be changed in cim call".
About the code, no other issues found.

Reviewed-by: Wenchao Xia <xiawenc at linux.vnet.ibm.com>

> +        if (mem->dumpCore == MEM_DUMP_CORE_ON) {
> +                xmlNewProp(tmp, BAD_CAST "dumpCore", BAD_CAST "on");
> +        } else if (mem->dumpCore == MEM_DUMP_CORE_OFF) {
> +                xmlNewProp(tmp, BAD_CAST "dumpCore", BAD_CAST "off");
> +        }
> +
>    out:
>           if (tmp == NULL)
>                   return XML_ERROR;
>


-- 
Best Regards

Wenchao Xia




More information about the Libvirt-cim mailing list