From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpIMV-0000iw-4Q for qemu-devel@nongnu.org; Wed, 19 Jun 2013 09:23:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpIMT-0002BD-9S for qemu-devel@nongnu.org; Wed, 19 Jun 2013 09:23:47 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39359 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpIMS-0002B5-Qv for qemu-devel@nongnu.org; Wed, 19 Jun 2013 09:23:45 -0400 Message-ID: <51C1B0DF.2080705@suse.de> Date: Wed, 19 Jun 2013 15:23:43 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1369709437-24969-1-git-send-email-qiaonuohan@cn.fujitsu.com> <1369709437-24969-5-git-send-email-qiaonuohan@cn.fujitsu.com> In-Reply-To: <1369709437-24969-5-git-send-email-qiaonuohan@cn.fujitsu.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 4/9] dump: Add API to create header of vmcore List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qiaonuohan@cn.fujitsu.com Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com, zhangxh@cn.fujitsu.com, kumagai-atsushi@mxc.nes.nec.co.jp, anderson@redhat.com Am 28.05.2013 04:50, schrieb qiaonuohan@cn.fujitsu.com: > From: Qiao Nuohan >=20 > Functions in this patch are used to gather data of header and sub heade= r in > kdump-compressed format. The following patch will use these functions t= o gather > data of header, then cache them into struct DumpState. >=20 > Signed-off-by: Qiao Nuohan > Reviewed-by: Zhang Xiaohe > --- > dump.c | 107 ++++++++++++++++++++++++++++++++++= ++++++++ > include/sysemu/dump_memory.h | 93 ++++++++++++++++++++++++++++++++++= ++ > 2 files changed, 200 insertions(+), 0 deletions(-) >=20 > diff --git a/dump.c b/dump.c > index 9ac66be..3b9d4ca 100644 > --- a/dump.c > +++ b/dump.c > @@ -681,6 +681,113 @@ static ram_addr_t get_start_block(DumpState *s) > return -1; > } > =20 > +static int create_header32(DumpState *s) > +{ > + struct disk_dump_header32 *dh; > + struct kdump_sub_header32 *kh; > + > + /* create common header, the version of kdump-compressed format is= 5th */ > + dh =3D g_malloc0(sizeof(struct disk_dump_header32)); > + > + strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE)); > + dh->header_version =3D 5; > + dh->block_size =3D s->page_size; > + dh->sub_hdr_size =3D sizeof(struct kdump_sub_header32) + s->note_s= ize; > + dh->sub_hdr_size =3D divideup(dh->sub_hdr_size, dh->block_size); > + dh->max_mapnr =3D s->max_mapnr; > + dh->nr_cpus =3D s->nr_cpus; > + dh->bitmap_blocks =3D divideup(s->len_dump_bitmap, s->page_size); > + > + memcpy(&(dh->utsname.machine), "i686", 4); > + > + s->dh =3D dh; > + > + /* create sub header */ > + kh =3D g_malloc0(sizeof(struct kdump_sub_header32)); > + > + kh->phys_base =3D PHYS_BASE; > + kh->dump_level =3D DUMP_LEVEL; > + > + kh->offset_note =3D DISKDUMP_HEADER_BLOCKS * dh->block_size + > + sizeof(struct kdump_sub_header32); > + kh->note_size =3D s->note_size; > + > + s->kh =3D kh; > + > + /* get gap between header and sub header */ > + s->offset_sub_header =3D DISKDUMP_HEADER_BLOCKS * dh->block_size - > + sizeof(struct disk_dump_header32); > + > + /* get gap between header and dump_bitmap */ > + s->offset_dump_bitmap =3D dh->sub_hdr_size * dh->block_size - > + (sizeof(struct kdump_sub_header32) + s->no= te_size); > + > + /* get offset of page desc */ > + s->offset_page =3D (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size + > + dh->bitmap_blocks) * dh->block_size; > + > + return 0; > +} Function always return 0 - make it void? > + > +static int create_header64(DumpState *s) > +{ > + struct disk_dump_header64 *dh; > + struct kdump_sub_header64 *kh; > + > + /* create common header, the version of kdump-compressed format is= 5th */ > + dh =3D g_malloc0(sizeof(struct disk_dump_header64)); > + > + strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE)); > + dh->header_version =3D 5; > + dh->block_size =3D s->page_size; > + dh->sub_hdr_size =3D sizeof(struct kdump_sub_header64) + s->note_s= ize; > + dh->sub_hdr_size =3D divideup(dh->sub_hdr_size, dh->block_size); > + dh->max_mapnr =3D s->max_mapnr; > + dh->nr_cpus =3D s->nr_cpus; > + dh->bitmap_blocks =3D divideup(s->len_dump_bitmap, s->page_size); > + > + memcpy(&(dh->utsname.machine), "x86_64", 6); > + > + s->dh =3D dh; > + > + /* create sub header */ > + kh =3D g_malloc0(sizeof(struct kdump_sub_header64)); > + > + kh->phys_base =3D PHYS_BASE; > + kh->dump_level =3D DUMP_LEVEL; > + > + kh->offset_note =3D DISKDUMP_HEADER_BLOCKS * dh->block_size + > + sizeof(struct kdump_sub_header64); > + kh->note_size =3D s->note_size; > + > + s->kh =3D kh; > + > + /* get gap between header and sub header */ > + s->offset_sub_header =3D DISKDUMP_HEADER_BLOCKS * dh->block_size - > + sizeof(struct disk_dump_header64); > + > + /* get gap between header and dump_bitmap */ > + s->offset_dump_bitmap =3D dh->sub_hdr_size * dh->block_size - > + (sizeof(struct kdump_sub_header64) + s->no= te_size); > + > + /* get offset of page desc */ > + s->offset_page =3D (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size + > + dh->bitmap_blocks) * dh->block_size; > + > + return 0; > +} > + > +/* > + * gather data of header and sub header > + */ > +static int create_header(DumpState *s) > +{ > + if (s->dump_info.d_machine =3D=3D EM_386) > + return create_header32(s); > + else > + return create_header64(s); > +} Braces for if and else missing. Surely EM_386 is not the only 32-bit machine. > + > static int dump_init(DumpState *s, int fd, bool paging, bool has_filte= r, > int64_t begin, int64_t length, Error **errp) > { > diff --git a/include/sysemu/dump_memory.h b/include/sysemu/dump_memory.= h > index ce22c05..56e0f40 100644 > --- a/include/sysemu/dump_memory.h > +++ b/include/sysemu/dump_memory.h > @@ -18,6 +18,87 @@ > #include "sysemu/memory_mapping.h" > #include "sysemu/dump.h" > =20 > +#define KDUMP_SIGNATURE "KDUMP " > +#define SIG_LEN (sizeof(KDUMP_SIGNATURE) - 1) > +#define DISKDUMP_HEADER_BLOCKS (1) > +#define PHYS_BASE (0) > +#define DUMP_LEVEL (1) > + > +#define divideup(x, y) (((x) + ((y) - 1)) / (y)) > + > +struct new_utsname { > + char sysname[65]; > + char nodename[65]; > + char release[65]; > + char version[65]; > + char machine[65]; > + char domainname[65]; > +}; > + > +struct disk_dump_header32 { > + char signature[SIG_LEN]; /* =3D "KDUMP " */ > + int header_version; /* Dump header version */ > + struct new_utsname utsname; /* copy of system_utsname */ > + char timestamp[8]; /* Time stamp */ > + unsigned int status; /* Above flags */ > + int block_size; /* Size of a block in byte */ > + int sub_hdr_size; /* Size of arch dependent header i= n block */ > + unsigned int bitmap_blocks; /* Size of Memory bitmap in block = */ > + unsigned int max_mapnr; /* =3D max_mapnr */ > + unsigned int total_ram_blocks; /* Number of blocks should be writ= ten */ > + unsigned int device_blocks; /* Number of total blocks in dump = device */ > + unsigned int written_blocks; /* Number of written blocks */ > + unsigned int current_cpu; /* CPU# which handles dump */ > + int nr_cpus; /* Number of CPUs */ > + struct task_struct *tasks[0]; > +}; > + > +struct disk_dump_header64 { > + char signature[SIG_LEN]; /* =3D "KDUMP " */ > + int header_version; /* Dump header version */ > + struct new_utsname utsname; /* copy of system_utsname */ > + char timestamp[20]; /* Time stamp */ > + unsigned int status; /* Above flags */ > + int block_size; /* Size of a block in byte */ > + int sub_hdr_size; /* Size of arch dependent header i= n block */ > + unsigned int bitmap_blocks; /* Size of Memory bitmap in block = */ > + unsigned int max_mapnr; /* =3D max_mapnr */ > + unsigned int total_ram_blocks; /* Number of blocks should be writ= ten */ > + unsigned int device_blocks; /* Number of total blocks in dump = device */ > + unsigned int written_blocks; /* Number of written blocks */ > + unsigned int current_cpu; /* CPU# which handles dump */ > + int nr_cpus; /* Number of CPUs */ > + struct task_struct *tasks[0]; > +}; If these are headers, shouldn't they be using int32_t / uint32_t just like the ones below? Also should tasks rather be struct task_struct tasks[0]? An array of pointers in the file is a bit hard to imagine... Also do any of these structs need QEMU_PACKED attribute? > + > +struct kdump_sub_header32 { > + uint32_t phys_base; > + uint32_t dump_level; /* header_version 1 and later */ > + uint32_t split; /* header_version 2 and later */ > + uint32_t start_pfn; /* header_version 2 and later */ > + uint32_t end_pfn; /* header_version 2 and later */ > + uint32_t offset_vmcoreinfo; /* header_version 3 and later */ > + uint32_t size_vmcoreinfo; /* header_version 3 and later */ > + uint32_t offset_note; /* header_version 4 and later */ > + uint32_t note_size; /* header_version 4 and later */ > + uint32_t offset_eraseinfo; /* header_version 5 and later */ > + uint32_t size_eraseinfo; /* header_version 5 and later */ > +}; > + > +struct kdump_sub_header64 { > + uint64_t phys_base; > + uint32_t dump_level; /* header_version 1 and later */ > + uint32_t split; /* header_version 2 and later */ > + uint64_t start_pfn; /* header_version 2 and later */ > + uint64_t end_pfn; /* header_version 2 and later */ > + uint64_t offset_vmcoreinfo; /* header_version 3 and later */ > + uint64_t size_vmcoreinfo; /* header_version 3 and later */ > + uint64_t offset_note; /* header_version 4 and later */ > + uint64_t note_size; /* header_version 4 and later */ > + uint64_t offset_eraseinfo; /* header_version 5 and later */ > + uint64_t size_eraseinfo; /* header_version 5 and later */ > +}; > + > typedef struct DumpState { > ArchDumpInfo dump_info; > MemoryMappingList list; > @@ -35,6 +116,18 @@ typedef struct DumpState { > int64_t begin; > int64_t length; > Error **errp; > + > + int page_size; > + unsigned long long max_mapnr; > + int nr_cpus; > + void *dh; > + void *kh; > + off_t offset_sub_header; > + > + off_t offset_dump_bitmap; > + unsigned long len_dump_bitmap; > + > + off_t offset_page; > } DumpState; > =20 > #endif Why unsigned long long and unsigned long respectively? Regards, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg