All of lore.kernel.org
 help / color / mirror / Atom feed
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
To: kexec@lists.infradead.org
Subject: [PATCH v2 08/14] Implement readmem() interface on sadump-related formats
Date: Fri, 28 Oct 2011 18:48:47 +0900	[thread overview]
Message-ID: <20111028094847.20940.48793.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20111028094454.20940.1209.stgit@localhost6.localdomain6>

Very similar to the ones in kdump-compressed format.

Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
---

 makedumpfile.c |    8 +++
 sadump_info.c  |  145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sadump_info.h  |   13 +++++
 3 files changed, 165 insertions(+), 1 deletions(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index 5ceb986..205d3de 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -346,6 +346,9 @@ readmem(int type_addr, unsigned long long addr, void *bufptr, size_t size)
 	if (info->flag_refiltering)
 		return readpmem_kdump_compressed(paddr, bufptr, read_size);
 
+	if (info->flag_sadump)
+		return readpmem_sadump(paddr, bufptr, read_size);
+
 	if (!(offset = paddr_to_offset(paddr))) {
 		ERRMSG("Can't convert a physical address(%llx) to offset.\n",
 		    paddr);
@@ -3436,6 +3439,9 @@ create_1st_bitmap(void)
 	if (info->flag_refiltering)
 		return copy_1st_bitmap_from_memory();
 
+	if (info->flag_sadump)
+		return sadump_copy_1st_bitmap_from_memory();
+
 	/*
 	 * At first, clear all the bits on the 1st-bitmap.
 	 */
@@ -4535,7 +4541,7 @@ read_pfn(unsigned long long pfn, unsigned char *buf)
 	size_t size1, size2;
 
 	paddr = pfn_to_paddr(pfn);
-	if (info->flag_refiltering) {
+	if (info->flag_refiltering || info->flag_sadump) {
 		if (!readmem(PADDR, paddr, buf, info->page_size)) {
 			ERRMSG("Can't get the page data.\n");
 			return FALSE;
diff --git a/sadump_info.c b/sadump_info.c
index 2efeb63..abc81d9 100644
--- a/sadump_info.c
+++ b/sadump_info.c
@@ -50,6 +50,9 @@ static int read_device_diskset(struct sadump_diskset_info *sdi, void *buf,
 			       size_t bytes, ulong *offset);
 static int read_sadump_header(char *filename);
 static int read_sadump_header_diskset(int diskid, struct sadump_diskset_info *sdi);
+static unsigned long long pfn_to_block(unsigned long long pfn);
+static int lookup_diskset(unsigned long long whole_offset, int *diskid,
+			  unsigned long long *disk_offset);
 
 static struct sadump_info sadump_info = {};
 static struct sadump_info *si = &sadump_info;
@@ -88,6 +91,45 @@ check_and_get_sadump_header_info(char *filename)
 	return TRUE;
 }
 
+int
+sadump_copy_1st_bitmap_from_memory(void)
+{
+	struct sadump_header *sh = si->sh_memory;
+	char buf[si->sh_memory->block_size];
+	off_t offset_page;
+	unsigned long bitmap_offset, bitmap_len;
+
+	bitmap_offset =	si->sub_hdr_offset + sh->block_size*sh->sub_hdr_size;
+	bitmap_len = sh->block_size * sh->bitmap_blocks;
+
+	if (lseek(info->fd_memory, bitmap_offset, SEEK_SET) < 0) {
+		ERRMSG("Can't seek %s. %s\n",
+		       info->name_memory, strerror(errno));
+		return FALSE;
+	}
+	if (lseek(info->bitmap1->fd, info->bitmap1->offset, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the bitmap(%s). %s\n",
+		       info->bitmap1->file_name, strerror(errno));
+		return FALSE;
+	}
+	offset_page = 0;
+	while (offset_page < bitmap_len) {
+		if (read(info->fd_memory, buf, sizeof(buf)) != sizeof(buf)) {
+			ERRMSG("Can't read %s. %s\n",
+			       info->name_memory, strerror(errno));
+			return FALSE;
+		}
+		if (write(info->bitmap1->fd, buf, sizeof(buf)) != sizeof(buf)) {
+			ERRMSG("Can't write the bitmap(%s). %s\n",
+			       info->bitmap1->file_name, strerror(errno));
+			return FALSE;
+		}
+		offset_page += sizeof(buf);
+	}
+
+	return TRUE;
+}
+
 static char *
 guid_to_str(efi_guid_t *guid, char *buf, size_t buflen)
 {
@@ -625,6 +667,109 @@ sadump_get_max_mapnr(void)
 }
 
 int
+readpmem_sadump(unsigned long long paddr, void *bufptr, size_t size)
+{
+	unsigned long long pfn, block, whole_offset, perdisk_offset;
+	ulong page_offset;
+	char buf[info->page_size];
+	int fd_memory;
+
+	pfn = paddr_to_pfn(paddr);
+	page_offset = paddr % info->page_size;
+
+	if (pfn >= si->sh_memory->max_mapnr)
+		goto error;
+
+	if (!is_dumpable(info->bitmap_memory, pfn)) {
+		ERRMSG("pfn(%llx) is excluded from %s.\n", pfn,
+		       info->name_memory);
+		goto error;
+	}
+
+	block = pfn_to_block(pfn);
+	whole_offset = block * si->sh_memory->block_size;
+
+	if (info->flag_sadump == SADUMP_DISKSET) {
+		int diskid;
+
+		if (!lookup_diskset(whole_offset, &diskid, &perdisk_offset))
+			goto error;
+
+		fd_memory = si->diskset_info[diskid].fd_memory;
+		perdisk_offset += si->diskset_info[diskid].data_offset;
+
+	} else {
+		fd_memory = info->fd_memory;
+		perdisk_offset = whole_offset + si->data_offset;
+
+	}
+
+	if (lseek(fd_memory, perdisk_offset, SEEK_SET) < 0)
+		goto error;
+
+	if (read(fd_memory, buf, sizeof(buf)) != sizeof(buf))
+		goto error;
+
+	memcpy(bufptr, buf + page_offset, size);
+
+	return size;
+
+error:
+	DEBUG_MSG("type_addr: %d, addr:%llx, size:%zd\n", PADDR, paddr, size);
+
+	return FALSE;
+}
+
+static unsigned long long
+pfn_to_block(unsigned long long pfn)
+{
+	unsigned long long block, section, p;
+
+	section = pfn / SADUMP_PF_SECTION_NUM;
+
+	if (section)
+		block = si->block_table[section - 1];
+	else
+		block = 0;
+
+	for (p = section * SADUMP_PF_SECTION_NUM; p < pfn; ++p)
+		if (is_dumpable(info->bitmap_memory, p))
+			block++;
+
+	return block;
+}
+
+static int
+lookup_diskset(unsigned long long whole_offset, int *diskid,
+	       unsigned long long *disk_offset)
+{
+	unsigned long long offset = whole_offset;
+	int i;
+
+	for (i = 0; i < si->num_disks; ++i) {
+		struct sadump_diskset_info *sdi = &si->diskset_info[i];
+		unsigned long long used_device_i, data_offset_i, ram_size;
+
+		used_device_i = sdi->sph_memory->used_device;
+		data_offset_i = sdi->data_offset;
+
+		ram_size = used_device_i - data_offset_i;
+
+		if (offset < ram_size)
+			break;
+		offset -= ram_size;
+	}
+
+	if (i == si->num_disks)
+		return FALSE;
+
+	*diskid = i;
+	*disk_offset = offset;
+
+	return TRUE;
+}
+
+int
 sadump_add_diskset_info(char *name_memory)
 {
 	si->num_disks++;
diff --git a/sadump_info.h b/sadump_info.h
index 0a04141..b6b9cdd 100644
--- a/sadump_info.h
+++ b/sadump_info.h
@@ -25,10 +25,12 @@
 #if defined(__x86__) || defined(__x86_64__)
 
 int check_and_get_sadump_header_info(char *filename);
+int sadump_copy_1st_bitmap_from_memory(void);
 int sadump_initialize_bitmap_memory(void);
 int sadump_get_nr_cpus(int *nr_cpus);
 int sadump_set_timestamp(struct timeval *ts);
 unsigned long long sadump_get_max_mapnr(void);
+int readpmem_sadump(unsigned long long paddr, void *bufptr, size_t size);
 int sadump_add_diskset_info(char *name_memory);
 long sadump_page_size(void);
 char *sadump_head_disk_name_memory(void);
@@ -51,6 +53,11 @@ static inline int check_and_get_sadump_header_info(char *filename)
 	return TRUE;
 }
 
+static inline int sadump_copy_1st_bitmap_from_memory(void)
+{
+	return FALSE;
+}
+
 static inline int sadump_initialize_bitmap_memory(void)
 {
 	return FALSE;
@@ -71,6 +78,12 @@ static inline unsigned long long sadump_get_max_mapnr(void)
 	return 0;
 }
 
+static inline int readpmem_sadump(unsigned long long paddr,
+				  void *bufptr, size_t size)
+{
+	return FALSE;
+}
+
 static inline int sadump_add_diskset_info(char *name_memory)
 {
 	return TRUE;


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2011-10-28  9:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28  9:48 [PATCH v2 00/14] Support Fujitsu Stand Alone Dump Format HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 01/14] Add sadump module header file HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 02/14] Extend DumpInfo structure HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 03/14] Implement command-line processing HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 04/14] Verify and read VMCORE(s) in sadump-related formats HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 05/14] Export helpers for bitmap table handling HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 06/14] Initialize internal data according to sadump-related formats HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 07/14] Initialize debug information for ELF note extraction HATAYAMA Daisuke
2011-10-28  9:48 ` HATAYAMA Daisuke [this message]
2011-10-28  9:48 ` [PATCH v2 09/14] Estimate phys_base based on linux_banner position HATAYAMA Daisuke
2011-10-28  9:48 ` [PATCH v2 10/14] Generate and save VMCOREINFO and ELF note information HATAYAMA Daisuke
2011-12-20  8:18   ` Atsushi Kumagai
2011-12-20  9:31     ` HATAYAMA Daisuke
2011-12-21  8:22       ` Atsushi Kumagai
2011-12-21  8:39         ` HATAYAMA Daisuke
2011-10-28  9:49 ` [PATCH v2 11/14] Procees CPUs based on online ones HATAYAMA Daisuke
2011-10-28  9:49 ` [PATCH v2 12/14] Read kexec backup region HATAYAMA Daisuke
2011-10-28  9:49 ` [PATCH v2 13/14] Add description of sadump-related formts in usage information HATAYAMA Daisuke
2011-10-28  9:49 ` [PATCH v2 14/14] Add description of sadump-related formats in manual page HATAYAMA Daisuke
2011-10-28 12:05 ` [PATCH v2 00/14] Support Fujitsu Stand Alone Dump Format tachibana
2011-12-15  6:47   ` HATAYAMA Daisuke
2011-12-15  8:55     ` tachibana
2011-12-15  9:09       ` HATAYAMA Daisuke

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=20111028094847.20940.48793.stgit@localhost6.localdomain6 \
    --to=d.hatayama@jp.fujitsu.com \
    --cc=kexec@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.