From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W824g-0004ji-DR for qemu-devel@nongnu.org; Tue, 28 Jan 2014 01:23:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W824Y-0003xl-JV for qemu-devel@nongnu.org; Tue, 28 Jan 2014 01:23:06 -0500 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:39475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W824Y-0003xS-3s for qemu-devel@nongnu.org; Tue, 28 Jan 2014 01:22:58 -0500 Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 1140D3EE1E2 for ; Tue, 28 Jan 2014 15:22:57 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id F260E45DD77 for ; Tue, 28 Jan 2014 15:22:56 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.nic.fujitsu.com [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id CDB2145DE53 for ; Tue, 28 Jan 2014 15:22:56 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id C21671DB8040 for ; Tue, 28 Jan 2014 15:22:56 +0900 (JST) Received: from s01.gw.fujitsu.co.jp (s01.gw.nic.fujitsu.com [133.161.11.16]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 5FD6E1DB803B for ; Tue, 28 Jan 2014 15:22:56 +0900 (JST) Received: from s01.gw.fujitsu.co.jp (yt-mxio2.gw.nic.fujitsu.com [10.134.25.142]) by s01.gw.fujitsu.co.jp (Postfix) with ESMTP id 016D9D80CF for ; Tue, 28 Jan 2014 15:22:55 +0900 (JST) Received: from G08FNSTD100518.localdomain (unknown [10.167.226.68]) by s01.gw.fujitsu.co.jp (Postfix) with ESMTP id 7E0588A015 for ; Tue, 28 Jan 2014 15:22:54 +0900 (JST) From: qiaonuohan Date: Tue, 28 Jan 2014 14:22:03 +0800 Message-Id: <1390890126-17377-11-git-send-email-qiaonuohan@cn.fujitsu.com> In-Reply-To: <1390890126-17377-1-git-send-email-qiaonuohan@cn.fujitsu.com> References: <1390890126-17377-1-git-send-email-qiaonuohan@cn.fujitsu.com> Subject: [Qemu-devel] [PATCH v8 10/13] dump: add APIs to operate DataCache List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: lersek@redhat.com, stefanha@gmail.com, lcapitulino@redhat.com, afaerber@suse.de, eblake@redhat.com Cc: kumagai-atsushi@mxc.nes.nec.co.jp, qiaonuohan , anderson@redhat.com, qemu-devel@nongnu.org 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 Reviewed-by: Laszlo Ersek --- dump.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/dump.h | 9 +++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/dump.c b/dump.c index 5755534..a7a85d3 100644 --- a/dump.c +++ b/dump.c @@ -1165,6 +1165,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; + } + + 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); -- 1.7.1