From: Stefan Hajnoczi <stefanha@gmail.com>
To: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com,
zhangxh@cn.fujitsu.com, anderson@redhat.com,
kumagai-atsushi@mxc.nes.nec.co.jp, afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH v5 5/9] dump: add API to write dump header
Date: Tue, 16 Jul 2013 10:18:16 +0800 [thread overview]
Message-ID: <20130716021816.GB32278@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1373355014-14846-6-git-send-email-qiaonuohan@cn.fujitsu.com>
On Tue, Jul 09, 2013 at 03:30:10PM +0800, Qiao Nuohan wrote:
> +/* write common header, sub header and elf note to vmcore */
> +static int create_header32(DumpState *s)
> +{
> + int ret = 0;
> + DiskDumpHeader32 *dh;
> + KdumpSubHeader32 *kh;
> + size_t size;
> +
> + /* write common header, the version of kdump-compressed format is 5th */
> + size = sizeof(DiskDumpHeader32);
> + dh = g_malloc0(size);
> +
> + strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
> + dh->header_version = 5;
> + dh->block_size = s->page_size;
> + dh->sub_hdr_size = sizeof(struct KdumpSubHeader32) + s->note_size;
> + dh->sub_hdr_size = divideup(dh->sub_hdr_size, dh->block_size);
> + dh->max_mapnr = s->max_mapnr;
> + dh->nr_cpus = s->nr_cpus;
> + dh->bitmap_blocks = divideup(s->len_dump_bitmap, s->page_size);
> + memcpy(&(dh->utsname.machine), "i686", 4);
> +
> + if (write_buffer(s->fd, s->flag_flatten, 0, dh, size) < 0) {
> + ret = -1;
> + goto out;
> + }
> +
> + /* write sub header */
> + size = sizeof(KdumpSubHeader32);
> + kh = g_malloc0(size);
> +
> + kh->phys_base = PHYS_BASE;
> + kh->dump_level = DUMP_LEVEL;
> +
> + kh->offset_note = DISKDUMP_HEADER_BLOCKS * dh->block_size + size;
> + kh->note_size = s->note_size;
> +
> + if (write_buffer(s->fd, s->flag_flatten, dh->block_size, kh, size) < 0) {
> + ret = -1;
> + goto out;
> + }
> +
> + /* write note */
> + s->note_buf = g_malloc(s->note_size);
> + s->note_buf_offset = 0;
> +
> + /* use s->note_buf to store notes temporarily */
> + if (write_elf32_notes(buf_write_note, s) < 0) {
> + ret = -1;
> + goto out;
> + }
> +
> + if (write_buffer(s->fd, s->flag_flatten, kh->offset_note, s->note_buf,
> + s->note_size) < 0) {
> + ret = -1;
> + goto out;
> + }
> +
> + /* get offset of dump_bitmap */
> + s->offset_dump_bitmap = (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size) *
> + dh->block_size;
> +
> + /* get offset of page */
> + s->offset_page = (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size +
> + dh->bitmap_blocks) * dh->block_size;
> +
> +out:
> + g_free(dh);
> + g_free(kh);
> + g_free(s->note_buf);
These variables must be initialized to NULL so that an early goto out
does not access uninitialized memory.
> +
> + return ret;
> +}
> +
> +/* write common header, sub header and elf note to vmcore */
> +static int create_header64(DumpState *s)
> +{
> + int ret = 0;
> + DiskDumpHeader64 *dh;
> + KdumpSubHeader64 *kh;
Same here.
> diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
> index 81cbaa8..54ae4e5 100644
> --- a/include/sysemu/dump.h
> +++ b/include/sysemu/dump.h
> @@ -20,6 +20,14 @@
> #define VERSION_FLAT_HEADER (1) /* version of flattened format */
> #define END_FLAG_FLAT_HEADER (-1)
>
> +#define KDUMP_SIGNATURE "KDUMP "
> +#define SIG_LEN (sizeof(KDUMP_SIGNATURE) - 1)
> +#define PHYS_BASE (0)
> +#define DUMP_LEVEL (1)
> +#define DISKDUMP_HEADER_BLOCKS (1)
> +
> +#define divideup(x, y) (((x) + ((y) - 1)) / (y))
Please use QEMU's DIV_ROUND_UP().
next prev parent reply other threads:[~2013-07-16 2:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 7:30 [Qemu-devel] [PATCH v5 0/9] Make 'dump-guest-memory' dump in kdump-compressed format Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 1/9] dump: Add argument to write_elfxx_notes Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 2/9] dump: Add API to write header of flatten format Qiao Nuohan
2013-07-16 2:06 ` Stefan Hajnoczi
2013-07-16 3:50 ` Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 3/9] dump: Add API to write vmcore Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 4/9] dump: Add API to write elf notes to buffer Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 5/9] dump: add API to write dump header Qiao Nuohan
2013-07-16 2:18 ` Stefan Hajnoczi [this message]
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 6/9] dump: Add API to write dump_bitmap Qiao Nuohan
2013-07-16 2:25 ` Stefan Hajnoczi
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 7/9] dump: Add APIs to operate DataCache Qiao Nuohan
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 8/9] dump: Add API to write dump pages Qiao Nuohan
2013-07-16 2:43 ` Stefan Hajnoczi
2013-07-16 3:40 ` Qiao Nuohan
2013-07-16 16:28 ` Eric Blake
2013-07-09 7:30 ` [Qemu-devel] [PATCH v5 9/9] dump: Make kdump-compressed format available for 'dump-guest-memory' Qiao Nuohan
2013-07-09 7:36 ` [Qemu-devel] [PATCH v5 0/9] Make 'dump-guest-memory' dump in kdump-compressed format Qiao Nuohan
2013-07-15 9:56 ` Qiao Nuohan
2013-07-16 2:45 ` Stefan Hajnoczi
2013-07-31 9:26 ` Qiao Nuohan
2013-07-31 12:23 ` Laszlo Ersek
2013-07-31 13:10 ` Luiz Capitulino
2013-08-02 3:25 ` Qiao Nuohan
2013-08-02 3:41 ` Amos Kong
2013-08-02 3:43 ` Qiao Nuohan
2013-08-02 3:37 ` Qiao Nuohan
2013-12-13 2:07 ` Qiao Nuohan
2013-12-13 2:25 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130716021816.GB32278@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=afaerber@suse.de \
--cc=anderson@redhat.com \
--cc=kumagai-atsushi@mxc.nes.nec.co.jp \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qiaonuohan@cn.fujitsu.com \
--cc=zhangxh@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).