Blame SOURCES/kexec-tools-2.0.20-makedumpfile-Add-dry-run-option-to-prevent-writing.patch

e8a34c
From 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f Mon Sep 17 00:00:00 2001
e8a34c
From: Julien Thierry <jthierry@redhat.com>
e8a34c
Date: Tue, 24 Nov 2020 10:45:24 +0000
e8a34c
Subject: [PATCH] [PATCH 1/2] Add --dry-run option to prevent writing the
e8a34c
 dumpfile
e8a34c
e8a34c
Add a --dry-run option to run all operations without writing the
e8a34c
dump to the output file.
e8a34c
e8a34c
Signed-off-by: Julien Thierry <jthierry@redhat.com>
e8a34c
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
e8a34c
---
e8a34c
 makedumpfile.8 |  6 ++++++
e8a34c
 makedumpfile.c | 37 ++++++++++++++++++++++++++++++-------
e8a34c
 makedumpfile.h |  2 ++
e8a34c
 print_info.c   |  3 +++
e8a34c
 4 files changed, 41 insertions(+), 7 deletions(-)
e8a34c
e8a34c
diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8
e8a34c
index b68a7e3..5e902cd 100644
e8a34c
--- a/makedumpfile-1.6.8/makedumpfile.8
e8a34c
+++ b/makedumpfile-1.6.8/makedumpfile.8
e8a34c
@@ -637,6 +637,12 @@ Show the version of makedumpfile.
e8a34c
 Only check whether the command-line parameters are valid or not, and exit.
e8a34c
 Preferable to be given as the first parameter.
e8a34c
 
e8a34c
+.TP
e8a34c
+\fB\-\-dry-run\fR
e8a34c
+Do not write the output dump file while still performing operations specified
e8a34c
+by other options.
e8a34c
+This option cannot be used with the --dump-dmesg, --reassemble and -g options.
e8a34c
+
e8a34c
 .SH ENVIRONMENT VARIABLES
e8a34c
 
e8a34c
 .TP 8
e8a34c
diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c
e8a34c
index ecd63fa..8c80c49 100644
e8a34c
--- a/makedumpfile-1.6.8/makedumpfile.c
e8a34c
+++ b/makedumpfile-1.6.8/makedumpfile.c
e8a34c
@@ -1372,6 +1372,8 @@ open_dump_file(void)
e8a34c
 	if (info->flag_flatten) {
e8a34c
 		fd = STDOUT_FILENO;
e8a34c
 		info->name_dumpfile = filename_stdout;
e8a34c
+	} else if (info->flag_dry_run) {
e8a34c
+		fd = -1;
e8a34c
 	} else if ((fd = open(info->name_dumpfile, open_flags,
e8a34c
 	    S_IRUSR|S_IWUSR)) < 0) {
e8a34c
 		ERRMSG("Can't open the dump file(%s). %s\n",
e8a34c
@@ -4711,6 +4713,9 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name)
e8a34c
 {
e8a34c
 	int status, written_size = 0;
e8a34c
 
e8a34c
+	if (info->flag_dry_run)
e8a34c
+		return TRUE;
e8a34c
+
e8a34c
 	while (written_size < buf_size) {
e8a34c
 		status = write(fd, buf + written_size,
e8a34c
 				   buf_size - written_size);
e8a34c
@@ -4748,13 +4753,12 @@ write_buffer(int fd, off_t offset, void *buf, size_t buf_size, char *file_name)
e8a34c
 		}
e8a34c
 		if (!write_and_check_space(fd, &fdh, sizeof(fdh), file_name))
e8a34c
 			return FALSE;
e8a34c
-	} else {
e8a34c
-		if (lseek(fd, offset, SEEK_SET) == failed) {
e8a34c
-			ERRMSG("Can't seek the dump file(%s). %s\n",
e8a34c
-			    file_name, strerror(errno));
e8a34c
-			return FALSE;
e8a34c
-		}
e8a34c
+	} else if (!info->flag_dry_run &&
e8a34c
+		    lseek(fd, offset, SEEK_SET) == failed) {
e8a34c
+		ERRMSG("Can't seek the dump file(%s). %s\n", file_name, strerror(errno));
e8a34c
+		return FALSE;
e8a34c
 	}
e8a34c
+
e8a34c
 	if (!write_and_check_space(fd, buf, buf_size, file_name))
e8a34c
 		return FALSE;
e8a34c
 
e8a34c
@@ -9112,7 +9116,7 @@ close_dump_memory(void)
e8a34c
 void
e8a34c
 close_dump_file(void)
e8a34c
 {
e8a34c
-	if (info->flag_flatten)
e8a34c
+	if (info->flag_flatten || info->flag_dry_run)
e8a34c
 		return;
e8a34c
 
e8a34c
 	if (close(info->fd_dumpfile) < 0)
e8a34c
@@ -10985,6 +10989,11 @@ check_param_for_generating_vmcoreinfo(int argc, char *argv[])
e8a34c
 
e8a34c
 		return FALSE;
e8a34c
 
e8a34c
+	if (info->flag_dry_run) {
e8a34c
+		MSG("--dry-run cannot be used with -g.\n");
e8a34c
+		return FALSE;
e8a34c
+	}
e8a34c
+
e8a34c
 	return TRUE;
e8a34c
 }
e8a34c
 
e8a34c
@@ -11029,6 +11038,11 @@ check_param_for_reassembling_dumpfile(int argc, char *argv[])
e8a34c
 	    || info->flag_exclude_xen_dom || info->flag_split)
e8a34c
 		return FALSE;
e8a34c
 
e8a34c
+	if (info->flag_dry_run) {
e8a34c
+		MSG("--dry-run cannot be used with --reassemble.\n");
e8a34c
+		return FALSE;
e8a34c
+	}
e8a34c
+
e8a34c
 	if ((info->splitting_info
e8a34c
 	    = malloc(sizeof(struct splitting_info) * info->num_dumpfile))
e8a34c
 	    == NULL) {
e8a34c
@@ -11057,6 +11071,11 @@ check_param_for_creating_dumpfile(int argc, char *argv[])
e8a34c
 	    || (info->flag_read_vmcoreinfo && info->name_xen_syms))
e8a34c
 		return FALSE;
e8a34c
 
e8a34c
+	if (info->flag_dry_run && info->flag_dmesg) {
e8a34c
+		MSG("--dry-run cannot be used with --dump-dmesg.\n");
e8a34c
+		return FALSE;
e8a34c
+	}
e8a34c
+
e8a34c
 	if (info->flag_flatten && info->flag_split)
e8a34c
 		return FALSE;
e8a34c
 
e8a34c
@@ -11520,6 +11539,7 @@ static struct option longopts[] = {
e8a34c
 	{"work-dir", required_argument, NULL, OPT_WORKING_DIR},
e8a34c
 	{"num-threads", required_argument, NULL, OPT_NUM_THREADS},
e8a34c
 	{"check-params", no_argument, NULL, OPT_CHECK_PARAMS},
e8a34c
+	{"dry-run", no_argument, NULL, OPT_DRY_RUN},
e8a34c
 	{0, 0, 0, 0}
e8a34c
 };
e8a34c
 
e8a34c
@@ -11686,6 +11706,9 @@ main(int argc, char *argv[])
e8a34c
 			info->flag_check_params = TRUE;
e8a34c
 			message_level = DEFAULT_MSG_LEVEL;
e8a34c
 			break;
e8a34c
+		case OPT_DRY_RUN:
e8a34c
+			info->flag_dry_run = TRUE;
e8a34c
+			break;
e8a34c
 		case '?':
e8a34c
 			MSG("Commandline parameter is invalid.\n");
e8a34c
 			MSG("Try `makedumpfile --help' for more information.\n");
e8a34c
diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h
e8a34c
index 5f50080..4c4222c 100644
e8a34c
--- a/makedumpfile-1.6.8/makedumpfile.h
e8a34c
+++ b/makedumpfile-1.6.8/makedumpfile.h
e8a34c
@@ -1322,6 +1322,7 @@ struct DumpInfo {
e8a34c
 	int		flag_vmemmap;        /* kernel supports vmemmap address space */
e8a34c
 	int		flag_excludevm;      /* -e - excluding unused vmemmap pages */
e8a34c
 	int		flag_use_count;      /* _refcount is named _count in struct page */
e8a34c
+	int		flag_dry_run;        /* do not create a vmcore file */
e8a34c
 	unsigned long	vaddr_for_vtop;      /* virtual address for debugging */
e8a34c
 	long		page_size;           /* size of page */
e8a34c
 	long		page_shift;
e8a34c
@@ -2425,6 +2426,7 @@ struct elf_prstatus {
e8a34c
 #define OPT_NUM_THREADS         OPT_START+16
e8a34c
 #define OPT_PARTIAL_DMESG       OPT_START+17
e8a34c
 #define OPT_CHECK_PARAMS        OPT_START+18
e8a34c
+#define OPT_DRY_RUN             OPT_START+19
e8a34c
 
e8a34c
 /*
e8a34c
  * Function Prototype.
e8a34c
diff --git a/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c
e8a34c
index e0c38b4..d2b0cb7 100644
e8a34c
--- a/makedumpfile-1.6.8/print_info.c
e8a34c
+++ b/makedumpfile-1.6.8/print_info.c
e8a34c
@@ -308,6 +308,9 @@ print_usage(void)
e8a34c
 	MSG("      the crashkernel range, then calculates the page number of different kind per\n");
e8a34c
 	MSG("      vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n");
e8a34c
 	MSG("\n");
e8a34c
+	MSG("  [--dry-run]:\n");
e8a34c
+	MSG("      This option runs makedumpfile without writting output dump file.\n");
e8a34c
+	MSG("\n");
e8a34c
 	MSG("  [-D]:\n");
e8a34c
 	MSG("      Print debugging message.\n");
e8a34c
 	MSG("\n");
e8a34c
-- 
e8a34c
2.29.2
e8a34c