Blame SOURCES/kvm-dump-add-API-to-write-header-of-flatten-format.patch

958e1b
From faa6207ac40f548cb7f033e07717e98c9bfb1249 Mon Sep 17 00:00:00 2001
958e1b
From: Laszlo Ersek <lersek@redhat.com>
958e1b
Date: Fri, 7 Nov 2014 17:17:52 +0100
958e1b
Subject: [PATCH 05/41] dump: add API to write header of flatten format
958e1b
958e1b
Message-id: <1415380693-16593-6-git-send-email-lersek@redhat.com>
958e1b
Patchwork-id: 62191
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 05/26] dump: add API to write header of flatten format
958e1b
Bugzilla: 1157798
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
RH-Acked-by: dgibson <dgibson@redhat.com>
958e1b
958e1b
From: qiaonuohan <qiaonuohan@cn.fujitsu.com>
958e1b
958e1b
flatten format will be used when writing kdump-compressed format. The format is
958e1b
also used by makedumpfile, you can refer to the following URL to get more
958e1b
detailed information about flatten format of kdump-compressed format:
958e1b
http://sourceforge.net/projects/makedumpfile/
958e1b
958e1b
The two functions here are used to write start flat header and end flat header
958e1b
to vmcore, and they will be called later when flatten format is used.
958e1b
958e1b
struct MakedumpfileHeader stored at the head of vmcore is used to indicate the
958e1b
vmcore is in flatten format.
958e1b
958e1b
struct MakedumpfileHeader {
958e1b
    char signature[16];     /* = "makedumpfile" */
958e1b
    int64_t type;           /* = 1 */
958e1b
    int64_t version;        /* = 1 */
958e1b
};
958e1b
958e1b
And struct MakedumpfileDataHeader, with offset and buf_size set to -1, is used
958e1b
to indicate the end of vmcore in flatten format.
958e1b
958e1b
struct MakedumpfileDataHeader {
958e1b
    int64_t offset;         /* = -1 */
958e1b
    int64_t buf_size;       /* = -1 */
958e1b
};
958e1b
958e1b
Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
958e1b
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
958e1b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
(cherry picked from commit fda053875e69120b2fde5fb34975ef5a49290f12)
958e1b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 dump.c                | 42 ++++++++++++++++++++++++++++++++++++++++++
958e1b
 include/sysemu/dump.h | 17 +++++++++++++++++
958e1b
 2 files changed, 59 insertions(+)
958e1b
958e1b
diff --git a/dump.c b/dump.c
958e1b
index fed8bd6..6c902e5 100644
958e1b
--- a/dump.c
958e1b
+++ b/dump.c
958e1b
@@ -692,6 +692,48 @@ static int create_vmcore(DumpState *s)
958e1b
     return 0;
958e1b
 }
958e1b
 
958e1b
+static int write_start_flat_header(int fd)
958e1b
+{
958e1b
+    uint8_t *buf;
958e1b
+    MakedumpfileHeader mh;
958e1b
+    int ret = 0;
958e1b
+
958e1b
+    memset(&mh, 0, sizeof(mh));
958e1b
+    strncpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
958e1b
+            strlen(MAKEDUMPFILE_SIGNATURE));
958e1b
+
958e1b
+    mh.type = cpu_to_be64(TYPE_FLAT_HEADER);
958e1b
+    mh.version = cpu_to_be64(VERSION_FLAT_HEADER);
958e1b
+
958e1b
+    buf = g_malloc0(MAX_SIZE_MDF_HEADER);
958e1b
+    memcpy(buf, &mh, sizeof(mh));
958e1b
+
958e1b
+    size_t written_size;
958e1b
+    written_size = qemu_write_full(fd, buf, MAX_SIZE_MDF_HEADER);
958e1b
+    if (written_size != MAX_SIZE_MDF_HEADER) {
958e1b
+        ret = -1;
958e1b
+    }
958e1b
+
958e1b
+    g_free(buf);
958e1b
+    return ret;
958e1b
+}
958e1b
+
958e1b
+static int write_end_flat_header(int fd)
958e1b
+{
958e1b
+    MakedumpfileDataHeader mdh;
958e1b
+
958e1b
+    mdh.offset = END_FLAG_FLAT_HEADER;
958e1b
+    mdh.buf_size = END_FLAG_FLAT_HEADER;
958e1b
+
958e1b
+    size_t written_size;
958e1b
+    written_size = qemu_write_full(fd, &mdh, sizeof(mdh));
958e1b
+    if (written_size != sizeof(mdh)) {
958e1b
+        return -1;
958e1b
+    }
958e1b
+
958e1b
+    return 0;
958e1b
+}
958e1b
+
958e1b
 static ram_addr_t get_start_block(DumpState *s)
958e1b
 {
958e1b
     GuestPhysBlock *block;
958e1b
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
958e1b
index 19fafb2..b32b390 100644
958e1b
--- a/include/sysemu/dump.h
958e1b
+++ b/include/sysemu/dump.h
958e1b
@@ -14,12 +14,29 @@
958e1b
 #ifndef DUMP_H
958e1b
 #define DUMP_H
958e1b
 
958e1b
+#define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
958e1b
+#define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
958e1b
+#define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
958e1b
+#define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
958e1b
+#define END_FLAG_FLAT_HEADER        (-1)
958e1b
+
958e1b
 typedef struct ArchDumpInfo {
958e1b
     int d_machine;  /* Architecture */
958e1b
     int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
958e1b
     int d_class;    /* ELFCLASS32 or ELFCLASS64 */
958e1b
 } ArchDumpInfo;
958e1b
 
958e1b
+typedef struct QEMU_PACKED MakedumpfileHeader {
958e1b
+    char signature[16];     /* = "makedumpfile" */
958e1b
+    int64_t type;
958e1b
+    int64_t version;
958e1b
+} MakedumpfileHeader;
958e1b
+
958e1b
+typedef struct QEMU_PACKED MakedumpfileDataHeader {
958e1b
+    int64_t offset;
958e1b
+    int64_t buf_size;
958e1b
+} MakedumpfileDataHeader;
958e1b
+
958e1b
 struct GuestPhysBlockList; /* memory_mapping.h */
958e1b
 int cpu_get_dump_info(ArchDumpInfo *info,
958e1b
                       const struct GuestPhysBlockList *guest_phys_blocks);
958e1b
-- 
958e1b
1.8.3.1
958e1b