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