qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qiaonuohan <qiaonuohan@cn.fujitsu.com>
Cc: stefanha@gmail.com, qemu-devel@nongnu.org,
	lcapitulino@redhat.com, anderson@redhat.com,
	kumagai-atsushi@mxc.nes.nec.co.jp, afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH 10/13 v7] dump: add APIs to operate DataCache
Date: Thu, 23 Jan 2014 15:50:42 +0100	[thread overview]
Message-ID: <52E12C42.2020107@redhat.com> (raw)
In-Reply-To: <1389944779-31899-11-git-send-email-qiaonuohan@cn.fujitsu.com>

one comment below

On 01/17/14 08:46, qiaonuohan wrote:
> DataCache is used to store data temporarily, then the data will be written to
> vmcore. These functions will be called later when writing data of page to
> vmcore.
> 
> Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  dump.c                |   47 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/sysemu/dump.h |    9 +++++++++
>  2 files changed, 56 insertions(+), 0 deletions(-)
> 
> diff --git a/dump.c b/dump.c
> index 26a1756..fa183cb 100644
> --- a/dump.c
> +++ b/dump.c
> @@ -1173,6 +1173,53 @@ out:
>      return ret;
>  }
>  
> +static void prepare_data_cache(DataCache *data_cache, DumpState *s,
> +                               off_t offset)
> +{
> +    data_cache->fd = s->fd;
> +    data_cache->data_size = 0;
> +    data_cache->buf_size = BUFSIZE_DATA_CACHE;
> +    data_cache->buf = g_malloc0(BUFSIZE_DATA_CACHE);
> +    data_cache->offset = offset;
> +}
> +
> +static int write_cache(DataCache *dc, const void *buf, size_t size,
> +                       bool flag_sync)
> +{
> +    /*
> +     * dc->buf_size should not be less than size, otherwise dc will never be
> +     * enough
> +     */
> +    assert(size <= dc->buf_size);
> +
> +    /*
> +     * if flag_sync is set, synchronize data in dc->buf into vmcore.
> +     * otherwise check if the space is enough for caching data in buf, if not,
> +     * write the data in dc->buf to dc->fd and reset dc->buf
> +     */
> +    if ((!flag_sync && dc->data_size + size > dc->buf_size) ||
> +        (flag_sync && dc->data_size > 0)) {
> +        if (write_buffer(dc->fd, dc->offset, dc->buf, dc->data_size) < 0) {
> +            return -1;
> +        }
> +
> +        dc->offset += dc->data_size;
> +        dc->data_size = 0;
> +    }
> +
> +    if (!flag_sync) {
> +        memcpy(dc->buf + dc->data_size, buf, size);
> +        dc->data_size += size;
> +    }

You don't need to make this block conditional on !flag_sync. By removing
that restriction, the function would become more general.

But I assume you don't need that -- I believe you feed all data to this
function with flag_sync==false, then call it one last time with
(flag_sync==false && size==0).

Thanks for adding the assert() and for the type change on "buf".

My R-b stands.

Laszlo

> +
> +    return 0;
> +}
> +
> +static void free_data_cache(DataCache *data_cache)
> +{
> +    g_free(data_cache->buf);
> +}
> +
>  static ram_addr_t get_start_block(DumpState *s)
>  {
>      GuestPhysBlock *block;
> diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
> index 6d4d0bc..92a95e4 100644
> --- a/include/sysemu/dump.h
> +++ b/include/sysemu/dump.h
> @@ -41,6 +41,7 @@
>  #define DISKDUMP_HEADER_BLOCKS      (1)
>  #define BUFSIZE_BITMAP              (TARGET_PAGE_SIZE)
>  #define PFN_BUFBITMAP               (CHAR_BIT * BUFSIZE_BITMAP)
> +#define BUFSIZE_DATA_CACHE          (TARGET_PAGE_SIZE * 4)
>  
>  typedef struct ArchDumpInfo {
>      int d_machine;  /* Architecture */
> @@ -142,6 +143,14 @@ typedef struct QEMU_PACKED KdumpSubHeader64 {
>      uint64_t max_mapnr_64;          /* header_version 6 and later */
>  } KdumpSubHeader64;
>  
> +typedef struct DataCache {
> +    int fd;             /* fd of the file where to write the cached data */
> +    uint8_t *buf;       /* buffer for cached data */
> +    size_t buf_size;    /* size of the buf */
> +    size_t data_size;   /* size of cached data in buf */
> +    off_t offset;       /* offset of the file */
> +} DataCache;
> +
>  struct GuestPhysBlockList; /* memory_mapping.h */
>  int cpu_get_dump_info(ArchDumpInfo *info,
>                        const struct GuestPhysBlockList *guest_phys_blocks);
> 

  reply	other threads:[~2014-01-23 14:51 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17  7:46 [Qemu-devel] [PATCH 00/13 v7] Make 'dump-guest-memory' dump in kdump-compressed format qiaonuohan
2014-01-17  7:46 ` [Qemu-devel] [PATCH 01/13 v7] dump: const-qualify the buf of WriteCoreDumpFunction qiaonuohan
2014-01-22 15:48   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 02/13 v7] dump: add argument to write_elfxx_notes qiaonuohan
2014-01-22 15:56   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 03/13 v7] dump: add API to write header of flatten format qiaonuohan
2014-01-22 16:03   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 04/13 v7] dump: add API to write vmcore qiaonuohan
2014-01-22 16:06   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 05/13 v7] dump: add API to write elf notes to buffer qiaonuohan
2014-01-22 16:09   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 06/13 v7] dump: add support for lzo/snappy qiaonuohan
2014-01-22 16:12   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 07/13 v7] dump: add members to DumpState and init some of them qiaonuohan
2014-01-22 17:04   ` Laszlo Ersek
2014-01-24  1:52     ` Qiao Nuohan
2014-01-24 10:00       ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 08/13 v7] dump: add API to write dump header qiaonuohan
2014-01-22 18:07   ` Laszlo Ersek
2014-01-23 14:29   ` Ekaterina Tumanova
2014-01-17  7:46 ` [Qemu-devel] [PATCH 09/13 v7] dump: add API to write dump_bitmap qiaonuohan
2014-01-23 13:56   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 10/13 v7] dump: add APIs to operate DataCache qiaonuohan
2014-01-23 14:50   ` Laszlo Ersek [this message]
2014-01-17  7:46 ` [Qemu-devel] [PATCH 11/13 v7] dump: add API to write dump pages qiaonuohan
2014-01-23 15:32   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 12/13 v7] dump: make kdump-compressed format available for 'dump-guest-memory' qiaonuohan
2014-01-23 15:17   ` Ekaterina Tumanova
2014-01-24 11:27     ` Laszlo Ersek
2014-01-24 12:06   ` Laszlo Ersek
2014-01-17  7:46 ` [Qemu-devel] [PATCH 13/13 v7] dump: add 'query-dump-guest-memory-capability' command qiaonuohan
2014-01-24 12:31   ` Laszlo Ersek
2014-01-17  8:50 ` [Qemu-devel] [PATCH 00/13 v7] Make 'dump-guest-memory' dump in kdump-compressed format Christian Borntraeger
2014-01-17  9:04   ` Qiao Nuohan
2014-01-21  9:56 ` Qiao Nuohan
2014-01-21 10:14   ` Laszlo Ersek
2014-01-22  1:27     ` Qiao Nuohan

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=52E12C42.2020107@redhat.com \
    --to=lersek@redhat.com \
    --cc=afaerber@suse.de \
    --cc=anderson@redhat.com \
    --cc=kumagai-atsushi@mxc.nes.nec.co.jp \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.com \
    --cc=stefanha@gmail.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).