Skip to contentSkip to conversation

fix bug in is_dumpable_file()

PATCH In review Pingfan Liu 1 participant 2 messages Nov 19, 2019 – Nov 27, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix bug in is_dumpable_file()

is_dumpable_file() is inconsistent with write_kdump_bitmap_file(). In the former one, bitmap->offset takes account for the header. But the later one does not.

It makes things more mussy where info->bitmap1/bitmap2's offset do not account for header, while info->bitmap_memory does.

Making all of these consistent by not accounting for header.

---
 makedumpfile.c | 5 +----
 makedumpfile.h | 5 +++--
 sadump_info.c  | 4 ++--
 3 files changed, 6 insertions(+), 8 deletions(-)
makedumpfile.c +1 -4
index d76a435..496e212 100644
@@ -3637,7 +3637,6 @@ initialize_bitmap_memory(void)
 	struct disk_dump_header	*dh;
 	struct kdump_sub_header *kh;
 	struct dump_bitmap *bmp;
-	off_t bitmap_offset;
 	off_t bitmap_len, max_sect_len;
 	mdf_pfn_t pfn;
 	int i, j;
@@ -3647,8 +3646,6 @@ initialize_bitmap_memory(void)
 	kh = info->kh_memory;
 	block_size = dh->block_size;
 
-	bitmap_offset
-	    = (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size) * block_size;
 	bitmap_len = block_size * dh->bitmap_blocks;
 
 	bmp = malloc(sizeof(struct dump_bitmap));
@@ -3667,7 +3664,7 @@ initialize_bitmap_memory(void)
 	bmp->file_name = info->name_memory;
 	bmp->no_block  = -1;
 	memset(bmp->buf, 0, BUFSIZE_BITMAP);
-	bmp->offset = bitmap_offset + bitmap_len / 2;
+	bmp->offset = bitmap_len / 2;
 	info->bitmap_memory = bmp;
 
 	if (dh->header_version >= 6)
makedumpfile.h +3 -2
index 24b2f69..3c02e83 100644
@@ -1171,6 +1171,7 @@ struct dump_bitmap {
 	int		no_block;
 	char		*file_name;
 	char		*buf;
+	/* offset in bitmap section */
 	off_t		offset;
 };
 
@@ -2204,10 +2205,10 @@ is_dumpable_buffer(struct dump_bitmap *bitmap, mdf_pfn_t pfn, struct cycle *cycl
 static inline int
 is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
-	off_t offset;
+	off_t offset = info->offset_bitmap1;
 	ssize_t rcode;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
-		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
+		offset += bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
 			ERRMSG("Can't seek the bitmap(%s). %s\n",
 				bitmap->file_name, strerror(errno));
sadump_info.c +2 -2
index 46867ce..a3d51b9 100644
@@ -137,11 +137,11 @@ sadump_is_on(char *bitmap, mdf_pfn_t i)
 static inline int
 sadump_is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
-	off_t offset;
+	off_t offset = info->offset_bitmap1;
 	ssize_t rcode;
 
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
-		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
+		offset += bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		lseek(bitmap->fd, offset, SEEK_SET);
 		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
 		if (rcode != BUFSIZE_BITMAP)
Signature · 7 lines
2.7.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
author
#1 lore raw

NACKed by myself due to a misunderstand of the code.

Quoted 80 lines · Pingfan Liu

is_dumpable_file() is inconsistent with write_kdump_bitmap_file(). In the former one, bitmap->offset takes account for the header. But the later one does not.

It makes things more mussy where info->bitmap1/bitmap2's offset do not account for header, while info->bitmap_memory does.

Making all of these consistent by not accounting for header.

---
 makedumpfile.c | 5 +----
 makedumpfile.h | 5 +++--
 sadump_info.c  | 4 ++--
 3 files changed, 6 insertions(+), 8 deletions(-)
makedumpfile.c +1 -4
index d76a435..496e212 100644
@@ -3637,7 +3637,6 @@ initialize_bitmap_memory(void)
 	struct disk_dump_header	*dh;
 	struct kdump_sub_header *kh;
 	struct dump_bitmap *bmp;
-	off_t bitmap_offset;
 	off_t bitmap_len, max_sect_len;
 	mdf_pfn_t pfn;
 	int i, j;
@@ -3647,8 +3646,6 @@ initialize_bitmap_memory(void)
 	kh = info->kh_memory;
 	block_size = dh->block_size;
 
-	bitmap_offset
-	    = (DISKDUMP_HEADER_BLOCKS + dh->sub_hdr_size) * block_size;
 	bitmap_len = block_size * dh->bitmap_blocks;
 
 	bmp = malloc(sizeof(struct dump_bitmap));
@@ -3667,7 +3664,7 @@ initialize_bitmap_memory(void)
 	bmp->file_name = info->name_memory;
 	bmp->no_block  = -1;
 	memset(bmp->buf, 0, BUFSIZE_BITMAP);
-	bmp->offset = bitmap_offset + bitmap_len / 2;
+	bmp->offset = bitmap_len / 2;
 	info->bitmap_memory = bmp;
 
 	if (dh->header_version >= 6)
makedumpfile.h +3 -2
index 24b2f69..3c02e83 100644
@@ -1171,6 +1171,7 @@ struct dump_bitmap {
 	int		no_block;
 	char		*file_name;
 	char		*buf;
+	/* offset in bitmap section */
 	off_t		offset;
 };
 
@@ -2204,10 +2205,10 @@ is_dumpable_buffer(struct dump_bitmap *bitmap, mdf_pfn_t pfn, struct cycle *cycl
 static inline int
 is_dumpable_file(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {
-	off_t offset;
+	off_t offset = info->offset_bitmap1;
 	ssize_t rcode;
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
-		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
+		offset += bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		if (lseek(bitmap->fd, offset, SEEK_SET) < 0 ) {
 			ERRMSG("Can't seek the bitmap(%s). %s\n",
 				bitmap->file_name, strerror(errno));
sadump_info.c +0 -0
index 46867ce..a3d51b9 100644
@@ -137,11 +137,11 @@ sadump_is_on(char *bitmap, mdf_pfn_t i)
 static inline int
 sadump_is_dumpable(struct dump_bitmap *bitmap, mdf_pfn_t pfn)
 {

sadump_info.c sadump_is_on(char *bitmap, mdf_pfn_t i) · line 147

Quoted 10 lines
sadump_info.c +2 -2
-	off_t offset;
+	off_t offset = info->offset_bitmap1;
 	ssize_t rcode;
 
 	if (pfn == 0 || bitmap->no_block != pfn/PFN_BUFBITMAP) {
-		offset = bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
+		offset += bitmap->offset + BUFSIZE_BITMAP*(pfn/PFN_BUFBITMAP);
 		lseek(bitmap->fd, offset, SEEK_SET);
 		rcode = read(bitmap->fd, bitmap->buf, BUFSIZE_BITMAP);
 		if (rcode != BUFSIZE_BITMAP)

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec