]> git.proxmox.com Git - mirror_qemu.git/commitdiff
dump: add API to write vmcore
authorqiaonuohan <qiaonuohan@cn.fujitsu.com>
Tue, 18 Feb 2014 06:11:28 +0000 (14:11 +0800)
committerLuiz Capitulino <lcapitulino@redhat.com>
Fri, 28 Feb 2014 16:49:02 +0000 (11:49 -0500)
Function is used to write vmcore in flatten format. In flatten format, data is
written block by block, and in front of each block, a struct
MakedumpfileDataHeader is stored there to indicate the offset and size of the
data block.

struct MakedumpfileDataHeader {
    int64_t offset;
    int64_t buf_size;
};

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
dump.c

diff --git a/dump.c b/dump.c
index f233b3e54c0a813c6d8b413d737053388bba820b..238ffa5917851f9e09759cd61f91d8a53adb1f15 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -728,6 +728,27 @@ static int write_end_flat_header(int fd)
     return 0;
 }
 
+static int write_buffer(int fd, off_t offset, const void *buf, size_t size)
+{
+    size_t written_size;
+    MakedumpfileDataHeader mdh;
+
+    mdh.offset = cpu_to_be64(offset);
+    mdh.buf_size = cpu_to_be64(size);
+
+    written_size = qemu_write_full(fd, &mdh, sizeof(mdh));
+    if (written_size != sizeof(mdh)) {
+        return -1;
+    }
+
+    written_size = qemu_write_full(fd, buf, size);
+    if (written_size != size) {
+        return -1;
+    }
+
+    return 0;
+}
+
 static ram_addr_t get_start_block(DumpState *s)
 {
     GuestPhysBlock *block;