From patchwork Thu Feb 13 15:30:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 320125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7A9E82C00AE for ; Fri, 14 Feb 2014 03:44:39 +1100 (EST) Received: from localhost ([::1]:47111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDyIh-0005po-Ad for incoming@patchwork.ozlabs.org; Thu, 13 Feb 2014 10:34:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDyGJ-00025T-99 for qemu-devel@nongnu.org; Thu, 13 Feb 2014 10:31:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDyGE-00009y-Dr for qemu-devel@nongnu.org; Thu, 13 Feb 2014 10:31:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDyGE-00009m-6O for qemu-devel@nongnu.org; Thu, 13 Feb 2014 10:31:34 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1DFVS41027641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Feb 2014 10:31:29 -0500 Received: from localhost (ovpn-113-138.phx2.redhat.com [10.3.113.138]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1DFVSax028328; Thu, 13 Feb 2014 10:31:28 -0500 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Thu, 13 Feb 2014 10:30:32 -0500 Message-Id: <1392305440-30465-15-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1392305440-30465-1-git-send-email-lcapitulino@redhat.com> References: <1392305440-30465-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 14/22] dump: add APIs to operate DataCache X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: qiaonuohan 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 Signed-off-by: Luiz Capitulino --- dump.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/dump.h | 9 +++++++++ 2 files changed, 56 insertions(+) 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);