summaryrefslogtreecommitdiff
path: root/dump.c
diff options
context:
space:
mode:
authorqiaonuohan <qiaonuohan@cn.fujitsu.com>2014-02-18 14:11:34 +0800
committerLuiz Capitulino <lcapitulino@redhat.com>2014-02-28 11:52:03 -0500
commit64cfba6a47411092c941c8d17256fb5673cc8cbf (patch)
treeb2af0c388d7029ac775dceffd45baf20a020153c /dump.c
parentd0686c7291fe8f0210e7a666f80892fa71395510 (diff)
dump: add APIs to operate DataCache
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> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'dump.c')
-rw-r--r--dump.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/dump.c b/dump.c
index 57555346df..a7a85d33c3 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;