Blame SOURCES/kexec-tools-2.0.20-makedumpfile-PATCH-Introduce-check-params-option.patch

73ea9d
From 989152e113bfcb4fbfbad6f3aed6f43be4455919 Mon Sep 17 00:00:00 2001
73ea9d
From: Kazuhito Hagio <k-hagio-ab@nec.com>
73ea9d
Date: Tue, 25 Feb 2020 16:04:55 -0500
73ea9d
Subject: [PATCH 4/7] [PATCH] Introduce --check-params option
73ea9d
73ea9d
Currently it's difficult to check whether a makedumpfile command-line
73ea9d
is valid or not without an actual panic.  This is inefficient and if
73ea9d
a wrong configuration is not tested, you will miss the vmcore when an
73ea9d
actual panic occurs.
73ea9d
73ea9d
In order for kdump facilities like kexec-tools to be able to check
73ea9d
the specified command-line parameters in advance, introduce the
73ea9d
--check-params option that only checks them and exits immediately.
73ea9d
73ea9d
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
73ea9d
---
73ea9d
 makedumpfile.8 |  5 ++++
73ea9d
 makedumpfile.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-------------
73ea9d
 makedumpfile.h |  2 ++
73ea9d
 print_info.c   |  4 ++++
73ea9d
 4 files changed, 69 insertions(+), 17 deletions(-)
73ea9d
73ea9d
diff --git a/makedumpfile-1.6.7/makedumpfile.8 b/makedumpfile-1.6.7/makedumpfile.8
73ea9d
index bf156a8..c5d4806 100644
73ea9d
--- a/makedumpfile-1.6.7/makedumpfile.8
73ea9d
+++ b/makedumpfile-1.6.7/makedumpfile.8
73ea9d
@@ -632,6 +632,11 @@ Show help message and LZO/snappy support status (enabled/disabled).
73ea9d
 \fB\-v\fR
73ea9d
 Show the version of makedumpfile.
73ea9d
 
73ea9d
+.TP
73ea9d
+\fB\-\-check-params\fR
73ea9d
+Only check whether the command-line parameters are valid or not, and exit.
73ea9d
+Preferable to be given as the first parameter.
73ea9d
+
73ea9d
 .SH ENVIRONMENT VARIABLES
73ea9d
 
73ea9d
 .TP 8
73ea9d
diff --git a/makedumpfile-1.6.7/makedumpfile.c b/makedumpfile-1.6.7/makedumpfile.c
73ea9d
index 607e07f..f5860a1 100644
73ea9d
--- a/makedumpfile-1.6.7/makedumpfile.c
73ea9d
+++ b/makedumpfile-1.6.7/makedumpfile.c
73ea9d
@@ -10972,12 +10972,6 @@ check_param_for_creating_dumpfile(int argc, char *argv[])
73ea9d
 	if (info->flag_generate_vmcoreinfo || info->flag_rearrange)
73ea9d
 		return FALSE;
73ea9d
 
73ea9d
-	if ((message_level < MIN_MSG_LEVEL)
73ea9d
-	    || (MAX_MSG_LEVEL < message_level)) {
73ea9d
-		message_level = DEFAULT_MSG_LEVEL;
73ea9d
-		MSG("Message_level is invalid.\n");
73ea9d
-		return FALSE;
73ea9d
-	}
73ea9d
 	if ((info->flag_compress && info->flag_elf_dumpfile)
73ea9d
 	    || (info->flag_read_vmcoreinfo && info->name_vmlinux)
73ea9d
 	    || (info->flag_read_vmcoreinfo && info->name_xen_syms))
73ea9d
@@ -11007,6 +11001,11 @@ check_param_for_creating_dumpfile(int argc, char *argv[])
73ea9d
 	if (info->flag_partial_dmesg && !info->flag_dmesg)
73ea9d
 		return FALSE;
73ea9d
 
73ea9d
+	if (info->flag_excludevm && !info->working_dir) {
73ea9d
+		MSG("-%c requires --work-dir\n", OPT_EXCLUDE_UNUSED_VM);
73ea9d
+		return FALSE;
73ea9d
+	}
73ea9d
+
73ea9d
 	if ((argc == optind + 2) && !info->flag_flatten
73ea9d
 				 && !info->flag_split
73ea9d
 				 && !info->flag_sadump_diskset) {
73ea9d
@@ -11402,6 +11401,23 @@ int show_mem_usage(void)
73ea9d
 	return TRUE;
73ea9d
 }
73ea9d
 
73ea9d
+static int set_message_level(char *str_ml)
73ea9d
+{
73ea9d
+	int ml;
73ea9d
+
73ea9d
+	ml = atoi(str_ml);
73ea9d
+	if ((ml < MIN_MSG_LEVEL) || (MAX_MSG_LEVEL < ml)) {
73ea9d
+		message_level = DEFAULT_MSG_LEVEL;
73ea9d
+		MSG("Message_level(%d) is invalid.\n", ml);
73ea9d
+		return FALSE;
73ea9d
+	}
73ea9d
+
73ea9d
+	if (info->flag_check_params)
73ea9d
+		return TRUE;
73ea9d
+
73ea9d
+	message_level = ml;
73ea9d
+	return TRUE;
73ea9d
+}
73ea9d
 
73ea9d
 static struct option longopts[] = {
73ea9d
 	{"split", no_argument, NULL, OPT_SPLIT},
73ea9d
@@ -11423,6 +11439,7 @@ static struct option longopts[] = {
73ea9d
 	{"splitblock-size", required_argument, NULL, OPT_SPLITBLOCK_SIZE},
73ea9d
 	{"work-dir", required_argument, NULL, OPT_WORKING_DIR},
73ea9d
 	{"num-threads", required_argument, NULL, OPT_NUM_THREADS},
73ea9d
+	{"check-params", no_argument, NULL, OPT_CHECK_PARAMS},
73ea9d
 	{0, 0, 0, 0}
73ea9d
 };
73ea9d
 
73ea9d
@@ -11521,7 +11538,8 @@ main(int argc, char *argv[])
73ea9d
 			info->flag_compress = DUMP_DH_COMPRESSED_LZO;
73ea9d
 			break;
73ea9d
 		case OPT_MESSAGE_LEVEL:
73ea9d
-			message_level = atoi(optarg);
73ea9d
+			if (!set_message_level(optarg))
73ea9d
+				goto out;
73ea9d
 			break;
73ea9d
 		case OPT_DUMP_DMESG:
73ea9d
 			info->flag_dmesg = 1;
73ea9d
@@ -11584,6 +11602,10 @@ main(int argc, char *argv[])
73ea9d
 		case OPT_NUM_THREADS:
73ea9d
 			info->num_threads = MAX(atoi(optarg), 0);
73ea9d
 			break;
73ea9d
+		case OPT_CHECK_PARAMS:
73ea9d
+			info->flag_check_params = TRUE;
73ea9d
+			message_level = DEFAULT_MSG_LEVEL;
73ea9d
+			break;
73ea9d
 		case '?':
73ea9d
 			MSG("Commandline parameter is invalid.\n");
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
@@ -11593,11 +11615,9 @@ main(int argc, char *argv[])
73ea9d
 	if (flag_debug)
73ea9d
 		message_level |= ML_PRINT_DEBUG_MSG;
73ea9d
 
73ea9d
-	if (info->flag_excludevm && !info->working_dir) {
73ea9d
-		ERRMSG("Error: -%c requires --work-dir\n", OPT_EXCLUDE_UNUSED_VM);
73ea9d
-		ERRMSG("Try `makedumpfile --help' for more information\n");
73ea9d
-		return COMPLETED;
73ea9d
-	}
73ea9d
+	if (info->flag_check_params)
73ea9d
+		/* suppress debugging messages */
73ea9d
+		message_level = DEFAULT_MSG_LEVEL;
73ea9d
 
73ea9d
 	if (info->flag_show_usage) {
73ea9d
 		print_usage();
73ea9d
@@ -11628,6 +11648,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (!open_files_for_generating_vmcoreinfo())
73ea9d
 			goto out;
73ea9d
 
73ea9d
@@ -11651,6 +11674,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (!check_dump_file(info->name_dumpfile))
73ea9d
 			goto out;
73ea9d
 
73ea9d
@@ -11671,6 +11697,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (!check_dump_file(info->name_dumpfile))
73ea9d
 			goto out;
73ea9d
 
73ea9d
@@ -11684,6 +11713,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (!check_dump_file(info->name_dumpfile))
73ea9d
 			goto out;
73ea9d
 		if (!dump_dmesg())
73ea9d
@@ -11697,6 +11729,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (!populate_kernel_version())
73ea9d
 			goto out;
73ea9d
 
73ea9d
@@ -11715,6 +11750,9 @@ main(int argc, char *argv[])
73ea9d
 			MSG("Try `makedumpfile --help' for more information.\n");
73ea9d
 			goto out;
73ea9d
 		}
73ea9d
+		if (info->flag_check_params)
73ea9d
+			goto check_ok;
73ea9d
+
73ea9d
 		if (info->flag_split) {
73ea9d
 			for (i = 0; i < info->num_dumpfile; i++) {
73ea9d
 				SPLITTING_FD_BITMAP(i) = -1;
73ea9d
@@ -11742,13 +11780,16 @@ main(int argc, char *argv[])
73ea9d
 			MSG("The dumpfile is saved to %s.\n", info->name_dumpfile);
73ea9d
 		}
73ea9d
 	}
73ea9d
+check_ok:
73ea9d
 	retcd = COMPLETED;
73ea9d
 out:
73ea9d
-	MSG("\n");
73ea9d
-	if (retcd != COMPLETED)
73ea9d
-		MSG("makedumpfile Failed.\n");
73ea9d
-	else if (!info->flag_mem_usage)
73ea9d
-		MSG("makedumpfile Completed.\n");
73ea9d
+	if (!info->flag_check_params) {
73ea9d
+		MSG("\n");
73ea9d
+		if (retcd != COMPLETED)
73ea9d
+			MSG("makedumpfile Failed.\n");
73ea9d
+		else if (!info->flag_mem_usage)
73ea9d
+			MSG("makedumpfile Completed.\n");
73ea9d
+	}
73ea9d
 
73ea9d
 	free_for_parallel();
73ea9d
 
73ea9d
diff --git a/makedumpfile-1.6.7/makedumpfile.h b/makedumpfile-1.6.7/makedumpfile.h
73ea9d
index 7217407..03fb4ce 100644
73ea9d
--- a/makedumpfile-1.6.7/makedumpfile.h
73ea9d
+++ b/makedumpfile-1.6.7/makedumpfile.h
73ea9d
@@ -1301,6 +1301,7 @@ struct DumpInfo {
73ea9d
 	int		flag_read_vmcoreinfo;    /* flag of reading vmcoreinfo file */
73ea9d
 	int		flag_show_usage;     /* flag of showing usage */
73ea9d
 	int		flag_show_version;   /* flag of showing version */
73ea9d
+	int		flag_check_params;   /* only check parameters */
73ea9d
 	int		flag_flatten;        /* flag of outputting flattened
73ea9d
 						format to a standard out */
73ea9d
 	int		flag_rearrange;      /* flag of creating dumpfile from
73ea9d
@@ -2362,6 +2363,7 @@ struct elf_prstatus {
73ea9d
 #define OPT_WORKING_DIR         OPT_START+15
73ea9d
 #define OPT_NUM_THREADS         OPT_START+16
73ea9d
 #define OPT_PARTIAL_DMESG       OPT_START+17
73ea9d
+#define OPT_CHECK_PARAMS        OPT_START+18
73ea9d
 
73ea9d
 /*
73ea9d
  * Function Prototype.
73ea9d
diff --git a/makedumpfile-1.6.7/print_info.c b/makedumpfile-1.6.7/print_info.c
73ea9d
index 0be12ea..e0c38b4 100644
73ea9d
--- a/makedumpfile-1.6.7/print_info.c
73ea9d
+++ b/makedumpfile-1.6.7/print_info.c
73ea9d
@@ -321,6 +321,10 @@ print_usage(void)
73ea9d
 	MSG("  [-v]:\n");
73ea9d
 	MSG("      Show the version of makedumpfile.\n");
73ea9d
 	MSG("\n");
73ea9d
+	MSG("  [--check-params]:\n");
73ea9d
+	MSG("      Only check whether the command-line parameters are valid or not, and exit.\n");
73ea9d
+	MSG("      Preferable to be given as the first parameter.\n");
73ea9d
+	MSG("\n");
73ea9d
 	MSG("  VMLINUX:\n");
73ea9d
 	MSG("      This is a pathname to the first kernel's vmlinux.\n");
73ea9d
 	MSG("      This file must have the debug information of the first kernel to analyze\n");
73ea9d
-- 
73ea9d
2.7.5
73ea9d