From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdBIZ-0005z4-LW for qemu-devel@nongnu.org; Thu, 16 May 2013 23:25:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdBIM-000723-9l for qemu-devel@nongnu.org; Thu, 16 May 2013 23:25:39 -0400 Received: from [222.73.24.84] (port=15821 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdBIL-0006vY-KZ for qemu-devel@nongnu.org; Thu, 16 May 2013 23:25:26 -0400 From: Qiao Nuohan Date: Fri, 17 May 2013 11:25:00 +0800 Message-Id: <1368761104-20105-6-git-send-email-qiaonuohan@cn.fujitsu.com> In-Reply-To: <1368761104-20105-1-git-send-email-qiaonuohan@cn.fujitsu.com> References: <1368761104-20105-1-git-send-email-qiaonuohan@cn.fujitsu.com> Subject: [Qemu-devel] [PATCH 5/9 v3] Add API to create data of dump bitmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Qiao Nuohan , d.hatayama@jp.fujitsu.com, zhangxh@cn.fujitsu.com, kumagai-atsushi@mxc.nes.nec.co.jp, anderson@redhat.com, afaerber@suse.de Functions in this patch are used to gather data of 1st and 2nd dump bitmap in kdump-compressed format. The following patch will use these functions to gather data of dump bitmap, then cache them into tmp files. Signed-off-by: Qiao Nuohan Reviewed-by: Zhang Xiaohe --- dump.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/dump.h | 10 +++++ 2 files changed, 108 insertions(+), 0 deletions(-) diff --git a/dump.c b/dump.c index bdebb33..998d71e 100644 --- a/dump.c +++ b/dump.c @@ -779,6 +779,104 @@ static int create_header(DumpState *s) return create_header64(s); } +/* + * create two tmpfile and save 1st and 2nd bitmap separately + */ +static int prepare_dump_bitmap(DumpState *s) +{ + int ret; + struct dump_bitmap *db1; + struct dump_bitmap *db2; + + db1 = g_malloc0(sizeof(struct dump_bitmap)); + + db2 = g_malloc0(sizeof(struct dump_bitmap)); + + ret = init_dump_bitmap(db1, FILENAME_BITMAP1); + if (ret < 0) { + dump_error(s, "dump: failed to init db1."); + return -1; + } + s->dump_bitmap1 = db1; + + ret = init_dump_bitmap(db2, FILENAME_BITMAP2); + if (ret < 0) { + dump_error(s, "dump: failed to init db1."); + return -1; + } + s->dump_bitmap2 = db2; + + return 0; +} + +static int create_dump_bitmap(DumpState *s) +{ + int ret; + unsigned long long num_dumpable; + MemoryMapping *memory_mapping; + unsigned long long pfn_start, pfn_end, pfn; + + ret = prepare_dump_bitmap(s); + if (ret < 0) { + dump_error(s, "dump: failed to prepare dump_bitmap.\n"); + return -1; + } + + ret = clear_dump_bitmap(s->dump_bitmap1, s->len_dump_bitmap / 2); + if (ret < 0) { + dump_error(s, "dump: failed to clear dump_bitmap1.\n"); + return -1; + } + + ret = clear_dump_bitmap(s->dump_bitmap2, s->len_dump_bitmap / 2); + if (ret < 0) { + dump_error(s, "dump: failed to clear dump_bitmap2.\n"); + return -1; + } + + /* write dump bitmap to tmp files */ + num_dumpable = 0; + + QTAILQ_FOREACH(memory_mapping, &s->list.head, next) { + pfn_start = paddr_to_pfn(memory_mapping->phys_addr, s->page_shift); + pfn_end = paddr_to_pfn(memory_mapping->phys_addr + + memory_mapping->length, s->page_shift); + + for (pfn = pfn_start; pfn < pfn_end; pfn++) { + ret = set_dump_bitmap(s->dump_bitmap1, pfn, 1); + if (ret < 0) { + dump_error(s, "dump: failed to set dump_bitmap1.\n"); + return -1; + } + /* set dump_bitmap2, same as dump_bitmap1 */ + ret = set_dump_bitmap(s->dump_bitmap2, pfn, 1); + if (ret < 0) { + dump_error(s, "dump: failed to set dump_bitmap2.\n"); + return -1; + } + num_dumpable++; + } + } + + /* write cached data to tmp files */ + ret = sync_dump_bitmap(s->dump_bitmap1); + if (ret < 0) { + dump_error(s, "dump: failed to sync dump_bitmap1.\n"); + return -1; + } + + ret = sync_dump_bitmap(s->dump_bitmap2); + if (ret < 0) { + dump_error(s, "dump: failed to sync dump_bitmap2.\n"); + return -1; + } + + /* get the number of dumpable page */ + s->num_dumpable = num_dumpable; + + return 0; +} + static int dump_init(DumpState *s, int fd, bool paging, bool has_filter, int64_t begin, int64_t length, Error **errp) { diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index e0047df..597b19e 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -24,6 +24,7 @@ #include "sysemu/memory_mapping.h" #include "qapi/error.h" #include "qmp-commands.h" +#include "dump_bitmap.h" #include @@ -32,8 +33,13 @@ #define DISKDUMP_HEADER_BLOCKS (1) #define PHYS_BASE (0) #define DUMP_LEVEL (1) +#define ARCH_PFN_OFFSET (0) +#define FILENAME_BITMAP1 "kdump_bitmap1_XXXXXX" +#define FILENAME_BITMAP2 "kdump_bitmap2_XXXXXX" #define divideup(x, y) (((x) + ((y) - 1)) / (y)) +#define paddr_to_pfn(X, page_shift) \ + (((unsigned long long)(X) >> (page_shift)) - ARCH_PFN_OFFSET) typedef struct ArchDumpInfo { int d_machine; /* Architecture */ @@ -133,14 +139,18 @@ typedef struct DumpState { Error **errp; int page_size; + int page_shift; unsigned long long max_mapnr; int nr_cpus; void *dh; void *kh; + unsigned long long num_dumpable; off_t offset_sub_header; off_t offset_dump_bitmap; unsigned long len_dump_bitmap; + struct dump_bitmap *dump_bitmap1; + struct dump_bitmap *dump_bitmap2; off_t offset_page; } DumpState; -- 1.7.1