qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qiaonuohan@cn.fujitsu.com
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	qemu-devel@nongnu.org, lcapitulino@redhat.com,
	zhangxh@cn.fujitsu.com, kumagai-atsushi@mxc.nes.nec.co.jp,
	anderson@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 2/9] dump: Add API to manipulate cache_data
Date: Wed, 19 Jun 2013 14:29:21 +0200	[thread overview]
Message-ID: <51C1A421.4030004@suse.de> (raw)
In-Reply-To: <1369709437-24969-3-git-send-email-qiaonuohan@cn.fujitsu.com>

Am 28.05.2013 04:50, schrieb qiaonuohan@cn.fujitsu.com:
> From: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
> 
> Struct cache_data is associated with a tmp file which is used to store page
> desc and page data in kdump-compressed format temporarily.

CacheData please - but I do find the English term "cache data"
irritating as it sounds like data about a cache when instead it is about
cached data. DataCache? CachedData? Maybe a native English speaker can
advise?

> The following patch
> will use these function to gather data of page and cache them in tmp files.
> 
> Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
> Reviewed-by: Zhang Xiaohe <zhangxh@cn.fujitsu.com>
> ---
>  Makefile.target      |    2 +-
>  cache_data.c         |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/cache_data.h |   56 +++++++++++++++++++++++
>  3 files changed, 178 insertions(+), 1 deletions(-)
>  create mode 100644 cache_data.c
>  create mode 100644 include/cache_data.h
> 
> diff --git a/Makefile.target b/Makefile.target
> index 8e557f9..298ec84 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -110,7 +110,7 @@ obj-y += qtest.o
>  obj-y += hw/
>  obj-$(CONFIG_FDT) += device_tree.o
>  obj-$(CONFIG_KVM) += kvm-all.o
> -obj-y += dump_bitmap.o
> +obj-y += dump_bitmap.o cache_data.o

Same comment as for dump_bitmap.o: Can we build this only once, please?

>  obj-y += memory.o savevm.o cputlb.o
>  obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
>  obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o
> diff --git a/cache_data.c b/cache_data.c
> new file mode 100644
> index 0000000..6e91538
> --- /dev/null
> +++ b/cache_data.c
> @@ -0,0 +1,121 @@
> +/*
> + * QEMU cache data
> + *
> + * Copyright (C) 2013 FUJITSU LIMITED
> + *
> + * Authors:
> + *     Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "qemu-common.h"
> +#include "cache_data.h"
> +
> +int init_cache_data(struct cache_data *cd, const char *filename)
> +{
> +    int fd;
> +    char *tmpname;
> +
> +    /* init the tmp file */
> +    tmpname = getenv("TMPDIR");
> +    if (!tmpname) {
> +        tmpname = (char *)P_tmpdir;

P_tmpdir is marked obsolescent in Open Group spec 7. Maybe Erik can
comment some more? Did you verify it builds with mingw32/64?
(I stumbled over it because I found the variable name odd and didn't see
it defined anywhere.)

> +    }
> +
> +    cd->file_name = (char *)g_strdup_printf("%s/%s", tmpname, filename);
> +
> +    fd = mkstemp(cd->file_name);
> +    if (fd < 0) {
> +        return -1;

Error **errp? Same below.

> +    }
> +
> +    cd->fd = fd;
> +    unlink(cd->file_name);
> +
> +    /* init buf */
> +    cd->buf_size = BUFSIZE_CACHE_DATA;
> +    cd->cache_size = 0;
> +    cd->buf = g_malloc0(BUFSIZE_CACHE_DATA);
> +
> +    cd->offset = 0;
> +
> +    return 0;
> +}

I wonder if it makes sense to introduce this interface instead of going
through the block layer, which would offer a number of different
backends at least. CC'ing the experts.

> +
> +int write_cache(struct cache_data *cd, void *buf, size_t size)
> +{
> +    /*
> +     * check if the space is enough to cache data, if not write cached
> +     * data to the tmp file
> +     */
> +    if (cd->cache_size + size > cd->buf_size) {
> +        if (lseek(cd->fd, cd->offset, SEEK_SET) < 0) {
> +            return -1;
> +        }
> +
> +        if (write(cd->fd, cd->buf, cd->cache_size) != cd->cache_size) {
> +            return -1;
> +        }
> +
> +        cd->offset += cd->cache_size;
> +        cd->cache_size = 0;
> +    }
> +
> +    memcpy(cd->buf + cd->cache_size, buf, size);
> +    cd->cache_size += size;
> +
> +    return 0;
> +}
> +
> +int sync_cache(struct cache_data *cd)
> +{
> +    /* no data is cached in cache_data */
> +    if (cd->cache_size == 0) {
> +        return 0;
> +    }
> +
> +    if (lseek(cd->fd, cd->offset, SEEK_SET) < 0) {
> +        return -1;
> +    }
> +
> +    if (write(cd->fd, cd->buf, cd->cache_size) != cd->cache_size) {
> +        return -1;
> +    }
> +
> +    cd->offset += cd->cache_size;
> +
> +    return 0;
> +}
> +
> +int read_cache(struct cache_data *cd)
> +{
> +    if (lseek(cd->fd, cd->offset, SEEK_SET) < 0) {
> +        return -1;
> +    }
> +
> +    if (read(cd->fd, cd->buf, cd->cache_size) != cd->cache_size) {
> +        return -1;
> +    }
> +
> +    cd->offset += cd->cache_size;
> +
> +    return 0;
> +}
> +
> +void free_cache_data(struct cache_data *cd)
> +{
> +    if (cd) {
> +        if (cd->file_name) {
> +            g_free(cd->file_name);
> +        }
> +
> +        if (cd->buf) {
> +            g_free(cd->buf);
> +        }
> +
> +        g_free(cd);
> +    }
> +}
> diff --git a/include/cache_data.h b/include/cache_data.h
> new file mode 100644
> index 0000000..18e8680
> --- /dev/null
> +++ b/include/cache_data.h
> @@ -0,0 +1,56 @@
> +/*
> + * QEMU cache data
> + *
> + * Copyright (C) 2013 FUJITSU LIMITED
> + *
> + * Authors:
> + *     Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#ifndef CACHE_DATA_H
> +#define CACHE_DATA_H
> +
> +#define BUFSIZE_CACHE_DATA          (4096 * 4)
> +
> +struct cache_data {
> +    int fd;             /* fd of the tmp file used to store cache data */
> +    char *file_name;    /* name of the tmp file */
> +    char *buf;          /* used to cache data */
> +    size_t buf_size;    /* size of the buf */
> +    size_t cache_size;  /* size of cached data in buf */
> +    off_t offset;       /* offset of the tmp file */
> +};

CamelCase and typedef please.

Regards,
Andreas

> +
> +/*
> + * create a tmp file used to store cache data, then init the buf
> + */
> +int init_cache_data(struct cache_data *cd, const char *filename);
> +
> +/*
> + * write data to the tmp file, the data may first be cached in the buf of
> + * cache_data
> + */
> +int write_cache(struct cache_data *cd, void *buf, size_t size);
> +
> +/*
> + * when cache_data is caching data in the buf, sync_cache is needed to write the
> + * data back to tmp file
> + */
> +int sync_cache(struct cache_data *cd);
> +
> +/*  read data from the tmp file to the buf of 'cd', the start place is set by
> + *  cd->offset, and the size is set by cd->cache_size. cd->offset is changed
> + *  automaticlly according to the size of data read this time.
> + */
> +int read_cache(struct cache_data *cd);
> +
> +/*
> + * free the space used by cache_data
> + */
> +void free_cache_data(struct cache_data *cd);
> +
> +#endif
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2013-06-19 12:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28  2:50 [Qemu-devel] [PATCH v4 0/9] Make 'dump-guest-memory' dump in kdump-compressed format qiaonuohan
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 1/9] dump: Add API to manipulate dump_bitmap qiaonuohan
2013-06-19 11:42   ` Andreas Färber
2013-06-19 12:00   ` Andreas Färber
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 2/9] dump: Add API to manipulate cache_data qiaonuohan
2013-06-19 12:29   ` Andreas Färber [this message]
2013-06-21 11:00     ` Eric Blake
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 3/9] dump: Move struct definition into dump_memroy.h qiaonuohan
2013-06-19 13:08   ` Andreas Färber
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 4/9] dump: Add API to create header of vmcore qiaonuohan
2013-06-19 13:23   ` Andreas Färber
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 5/9] dump: Add API to create data of dump bitmap qiaonuohan
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 6/9] dump: Add API to create page qiaonuohan
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 7/9] dump: Add API to free memory used by creating header, bitmap and page qiaonuohan
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 8/9] dump: Add API to write header, bitmap and page into vmcore qiaonuohan
2013-05-28  2:50 ` [Qemu-devel] [PATCH v4 9/9] dump: Make kdump-compressed format available for 'dump-guest-memory' qiaonuohan
2013-06-19 13:10   ` Stefan Hajnoczi
2013-06-05  1:29 ` [Qemu-devel] [PATCH v4 0/9] Make 'dump-guest-memory' dump in kdump-compressed format Qiao Nuohan
2013-06-05  2:12   ` Luiz Capitulino
2013-06-05  2:15   ` Luiz Capitulino
2013-06-05 11:44     ` Amos Kong
2013-06-10  2:15     ` Qiao Nuohan
2013-06-10 12:54       ` Luiz Capitulino
2013-06-11  1:48         ` Qiao Nuohan
2013-06-13 18:12           ` Luiz Capitulino
2013-06-19 10:07             ` Qiao Nuohan
2013-06-19 13:49 ` Stefan Hajnoczi
2013-06-20  2:18   ` Qiao Nuohan
2013-06-20  8:57     ` Stefan Hajnoczi
2013-06-27  7:11       ` Qiao Nuohan
2013-06-27  8:54         ` Stefan Hajnoczi
2013-06-28  2:57           ` Qiao Nuohan
2013-07-01 11:45             ` Stefan Hajnoczi
2013-07-03  7:39               ` Qiao Nuohan
2013-07-04  8:26                 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51C1A421.4030004@suse.de \
    --to=afaerber@suse.de \
    --cc=anderson@redhat.com \
    --cc=kumagai-atsushi@mxc.nes.nec.co.jp \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.com \
    --cc=stefanha@gmail.com \
    --cc=zhangxh@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).