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

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