Skip to contentSkip to conversation

makedumpfile: fix two bugs with --dry-run

PATCH In review Philipp Rudo 2 participants 4 messages Aug 12, 2021 – Aug 16, 2021

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

cover makedumpfile: fix two bugs with --dry-run

Hi,

While playing with the --dry-run option I noticed two bugs. You can find the fixes below.

Thanks
Philipp

Philipp Rudo (2):
makedumpfile: Fix bad file descriptor error when using --dry-run
makedumpfile: Fix --dry-run for incomplete dumps

 makedumpfile.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 7 lines
2.31.1


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

PATCH 1/2 makedumpfile: Fix bad file descriptor error when using --dry-run

When running makedumpfile with the --dry-run option it fails with

	[...]
	write_and_check_space: Can't seek the dump file(vmcore). Bad file descriptor
	[...]

This is because for --dry-run no dump file is created and a dummy file descriptor of -1 is used. Thus the lseek in write_and_check_space will fail. Fix this by treating a dry run as if writing to STDOUT.

Fixes f0cfa86 ("[PATCH v2 3/3] Add -L option to limit output file size")
---
 makedumpfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
makedumpfile.c +1 -1
index b1b3b42..30f9725 100644
@@ -4712,7 +4712,7 @@ write_and_check_space(int fd, void *buf, size_t buf_size, const char* desc,
 	int retval = 0;
 	off_t pos;
 
-	if (fd == STDOUT_FILENO) {
+	if (fd == STDOUT_FILENO || info->flag_dry_run) {
 		pos = write_bytes;
 	} else {
 		pos = lseek(fd, 0, SEEK_CUR);
Signature · 7 lines
2.31.1


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

PATCH 2/2 makedumpfile: Fix --dry-run for incomplete dumps

In reply to Philipp Rudo

When running out of space during a dry run, e.g. by limiting the output size using the -L option, makedumpfile fails with

[...]
Can't write the dump file(vmcore). Size limit(104857600) reached.
get_nr_pages: Can't seek end of the dump file(vmcore). __read_disk_dump_header: Can't open a file(vmcore). No such file or directory [...]

This is because for --dry-run no dump file is created and a dummy file descriptor of -1 is used. Thus the file operations in get_nr_pages and check_and_modify_*_headers fail. Fix the first error by using write_bytes as file size for the output file and the second one by always returning TRUE for check_and_modify_headers.

Fixes 3422e1d ("[PATCH 1/2] Add --dry-run option to prevent writing the dumpfile")
---
 makedumpfile.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
makedumpfile.c +8 -1
index 30f9725..c063267 100644
@@ -5113,6 +5113,9 @@ check_and_modify_multiple_kdump_headers() {
 int
 check_and_modify_headers()
 {
+	if (info->flag_dry_run)
+		return TRUE;
+
 	if (info->flag_elf_dumpfile)
 		return check_and_modify_elf_headers(info->name_dumpfile);
 	else
@@ -7996,7 +7999,11 @@ get_nr_pages(void *buf, struct cache_data *cd_page){
 	int size, file_end, nr_pages;
 	page_desc_t *pd = buf;
 
-	file_end = lseek(cd_page->fd, 0, SEEK_END);
+	if (info->flag_dry_run)
+		file_end = write_bytes;
+	else
+		file_end = lseek(cd_page->fd, 0, SEEK_END);
+
 	if (file_end < 0) {
 		ERRMSG("Can't seek end of the dump file(%s).\n", cd_page->file_name);
 		return -1;
Signature · 7 lines
2.31.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw
In reply to Philipp Rudo

-----Original Message-----

Quoted 12 lines

Hi,

While playing with the --dry-run option I noticed two bugs. You can find the fixes below.

Thanks
Philipp

Philipp Rudo (2):
makedumpfile: Fix bad file descriptor error when using --dry-run
makedumpfile: Fix --dry-run for incomplete dumps

Quoted 5 lines
 makedumpfile.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

--
2.31.1

Thank you for the fixes, applied.
https://github.com/makedumpfile/makedumpfile/compare/efef023...5684d4c

Kazu

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