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

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