[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/32] dump: add APIs to operate DataCache
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 12/32] dump: add APIs to operate DataCache |
Date: |
Mon, 3 Mar 2014 12:12:03 -0500 |
From: qiaonuohan <address@hidden>
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 <address@hidden>
Reviewed-by: Laszlo Ersek <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
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);
--
1.8.1.4
- [Qemu-devel] [PULL 00/32] QMP queue, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 02/32] MAINTAINERS: update status for HMP, QAPI and QMP trees, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 01/32] QMP: Allow dot separated dict path arguments in qmp-shell, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 04/32] dump: add argument to write_elfxx_notes, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 07/32] dump: add API to write elf notes to buffer, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 08/32] dump: add support for lzo/snappy, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 09/32] dump: add members to DumpState and init some of them, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 05/32] dump: add API to write header of flatten format, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 11/32] dump: add API to write dump_bitmap, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 06/32] dump: add API to write vmcore, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 12/32] dump: add APIs to operate DataCache,
Luiz Capitulino <=
- [Qemu-devel] [PULL 10/32] dump: add API to write dump header, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 03/32] dump: const-qualify the buf of WriteCoreDumpFunction, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 14/32] dump: make kdump-compressed format available for 'dump-guest-memory', Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 13/32] dump: add API to write dump pages, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 15/32] Define the architecture for compressed dump format, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 16/32] dump: add 'query-dump-guest-memory-capability' command, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 17/32] qmp: Check for returned data from __json_read in get_events, Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 19/32] monitor: Remove left-over code in do_info_profile., Luiz Capitulino, 2014/03/03
- [Qemu-devel] [PULL 18/32] qerror: Improve QERR_DEVICE_NOT_ACTIVE message, Luiz Capitulino, 2014/03/03