yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From b170e55f6dff27d44e32667af0f79a4c2704711b Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Fri, 7 Nov 2014 17:18:08 +0100
9ae3a8
Subject: [PATCH 21/41] dump: simplify write_start_flat_header()
9ae3a8
9ae3a8
Message-id: <1415380693-16593-22-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 62207
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH 21/26] dump: simplify write_start_flat_header()
9ae3a8
Bugzilla: 1157798
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
RH-Acked-by: dgibson <dgibson@redhat.com>
9ae3a8
9ae3a8
Currently, the function
9ae3a8
- defines and populates an auto variable of type MakedumpfileHeader
9ae3a8
- allocates and zeroes a buffer of size MAX_SIZE_MDF_HEADER (4096)
9ae3a8
- copies the former into the latter (covering an initial portion of the
9ae3a8
  latter)
9ae3a8
9ae3a8
Fill in the MakedumpfileHeader structure in its final place (the alignment
9ae3a8
is OK because the structure lives at the address returned by g_malloc0()).
9ae3a8
9ae3a8
Approximately-suggested-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
(cherry picked from commit 92ba1401e0f81ea170803045c1ae366bf5d9d87e)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 dump.c | 20 +++++++++-----------
9ae3a8
 1 file changed, 9 insertions(+), 11 deletions(-)
9ae3a8
9ae3a8
diff --git a/dump.c b/dump.c
9ae3a8
index 533b914..ee28777 100644
9ae3a8
--- a/dump.c
9ae3a8
+++ b/dump.c
9ae3a8
@@ -717,27 +717,25 @@ static int create_vmcore(DumpState *s)
9ae3a8
 
9ae3a8
 static int write_start_flat_header(int fd)
9ae3a8
 {
9ae3a8
-    uint8_t *buf;
9ae3a8
-    MakedumpfileHeader mh;
9ae3a8
+    MakedumpfileHeader *mh;
9ae3a8
     int ret = 0;
9ae3a8
 
9ae3a8
-    memset(&mh, 0, sizeof(mh));
9ae3a8
-    memcpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
9ae3a8
-           MIN(sizeof mh.signature, sizeof MAKEDUMPFILE_SIGNATURE));
9ae3a8
+    QEMU_BUILD_BUG_ON(sizeof *mh > MAX_SIZE_MDF_HEADER);
9ae3a8
+    mh = g_malloc0(MAX_SIZE_MDF_HEADER);
9ae3a8
 
9ae3a8
-    mh.type = cpu_to_be64(TYPE_FLAT_HEADER);
9ae3a8
-    mh.version = cpu_to_be64(VERSION_FLAT_HEADER);
9ae3a8
+    memcpy(mh->signature, MAKEDUMPFILE_SIGNATURE,
9ae3a8
+           MIN(sizeof mh->signature, sizeof MAKEDUMPFILE_SIGNATURE));
9ae3a8
 
9ae3a8
-    buf = g_malloc0(MAX_SIZE_MDF_HEADER);
9ae3a8
-    memcpy(buf, &mh, sizeof(mh));
9ae3a8
+    mh->type = cpu_to_be64(TYPE_FLAT_HEADER);
9ae3a8
+    mh->version = cpu_to_be64(VERSION_FLAT_HEADER);
9ae3a8
 
9ae3a8
     size_t written_size;
9ae3a8
-    written_size = qemu_write_full(fd, buf, MAX_SIZE_MDF_HEADER);
9ae3a8
+    written_size = qemu_write_full(fd, mh, MAX_SIZE_MDF_HEADER);
9ae3a8
     if (written_size != MAX_SIZE_MDF_HEADER) {
9ae3a8
         ret = -1;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    g_free(buf);
9ae3a8
+    g_free(mh);
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8