All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Thierry <jthierry@redhat.com>
To: kexec@lists.infradead.org
Cc: bhsharma@redhat.com, Julien Thierry <jthierry@redhat.com>,
	k-hagio-ab@nec.com, lijiang@redhat.com
Subject: [MAKEDUMPFILE PATCH 1/2] Add option to prevent writing the dumpfile
Date: Tue, 24 Nov 2020 10:45:24 +0000	[thread overview]
Message-ID: <20201124104525.1070885-2-jthierry@redhat.com> (raw)
In-Reply-To: <20201124104525.1070885-1-jthierry@redhat.com>

Add a --dry-run option to run all operations without writing the
dump to the output file.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 makedumpfile.8 |  5 +++++
 makedumpfile.c | 33 +++++++++++++++++++++++++++++++--
 makedumpfile.h |  2 ++
 print_info.c   |  3 +++
 4 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/makedumpfile.8 b/makedumpfile.8
index 2fe2cd0..39a63ba 100644
--- a/makedumpfile.8
+++ b/makedumpfile.8
@@ -637,6 +637,11 @@ Show the version of makedumpfile.
 Only check whether the command-line parameters are valid or not, and exit.
 Preferable to be given as the first parameter.
 
+.TP
+\fB\-\-dry-run\fR
+Do not write the output dump file while still performing operations specified
+by other options.
+
 .SH ENVIRONMENT VARIABLES
 
 .TP 8
diff --git a/makedumpfile.c b/makedumpfile.c
index cdde040..90258f3 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -1366,7 +1366,9 @@ open_dump_file(void)
 	if (!info->flag_force)
 		open_flags |= O_EXCL;
 
-	if (info->flag_flatten) {
+	if (info->flag_dry_run) {
+		fd = -1;
+	} else if (info->flag_flatten) {
 		fd = STDOUT_FILENO;
 		info->name_dumpfile = filename_stdout;
 	} else if ((fd = open(info->name_dumpfile, open_flags,
@@ -1384,6 +1386,9 @@ check_dump_file(const char *path)
 {
 	char *err_str;
 
+	if (info->flag_dry_run)
+		return TRUE;
+
 	if (access(path, F_OK) != 0)
 		return TRUE; /* File does not exist */
 	if (info->flag_force) {
@@ -4643,6 +4648,8 @@ write_buffer(int fd, off_t offset, void *buf, size_t buf_size, char *file_name)
 		}
 		if (!write_and_check_space(fd, &fdh, sizeof(fdh), file_name))
 			return FALSE;
+	} else if (info->flag_dry_run && fd == info->fd_dumpfile) {
+		return TRUE;
 	} else {
 		if (lseek(fd, offset, SEEK_SET) == failed) {
 			ERRMSG("Can't seek the dump file(%s). %s\n",
@@ -9007,6 +9014,9 @@ close_dump_file(void)
 	if (info->flag_flatten)
 		return;
 
+	if (info->flag_dry_run)
+		return;
+
 	if (close(info->fd_dumpfile) < 0)
 		ERRMSG("Can't close the dump file(%s). %s\n",
 		    info->name_dumpfile, strerror(errno));
@@ -11032,7 +11042,8 @@ check_param_for_creating_dumpfile(int argc, char *argv[])
 		 */
 		info->name_memory   = argv[optind];
 
-	} else if ((argc == optind + 1) && info->flag_mem_usage) {
+	} else if ((argc == optind + 1) && (info->flag_mem_usage ||
+					    info->flag_dry_run)) {
 		/*
 		* Parameter for showing the page number of memory
 		* in different use from.
@@ -11412,6 +11423,7 @@ static struct option longopts[] = {
 	{"work-dir", required_argument, NULL, OPT_WORKING_DIR},
 	{"num-threads", required_argument, NULL, OPT_NUM_THREADS},
 	{"check-params", no_argument, NULL, OPT_CHECK_PARAMS},
+	{"dry-run", no_argument, NULL, OPT_DRY_RUN},
 	{0, 0, 0, 0}
 };
 
@@ -11578,6 +11590,9 @@ main(int argc, char *argv[])
 			info->flag_check_params = TRUE;
 			message_level = DEFAULT_MSG_LEVEL;
 			break;
+		case OPT_DRY_RUN:
+			info->flag_dry_run = TRUE;
+			break;
 		case '?':
 			MSG("Commandline parameter is invalid.\n");
 			MSG("Try `makedumpfile --help' for more information.\n");
@@ -11591,6 +11606,10 @@ main(int argc, char *argv[])
 		/* suppress debugging messages */
 		message_level = DEFAULT_MSG_LEVEL;
 
+	if (info->flag_dry_run)
+		/* Suppress progress indicator as dumpfile won't get written */
+		message_level &= ~ML_PRINT_PROGRESS;
+
 	if (info->flag_show_usage) {
 		print_usage();
 		return COMPLETED;
@@ -11661,6 +11680,9 @@ main(int argc, char *argv[])
 		if (!close_files_for_rearranging_dumpdata())
 			goto out;
 
+		if (info->flag_dry_run)
+			goto check_ok;
+
 		MSG("\n");
 		MSG("The dumpfile is saved to %s.\n", info->name_dumpfile);
 	} else if (info->flag_reassemble) {
@@ -11677,6 +11699,10 @@ main(int argc, char *argv[])
 
 		if (!reassemble_dumpfile())
 			goto out;
+
+		if (info->flag_dry_run)
+			goto check_ok;
+
 		MSG("\n");
 		MSG("The dumpfile is saved to %s.\n", info->name_dumpfile);
 	} else if (info->flag_dmesg) {
@@ -11739,6 +11765,9 @@ main(int argc, char *argv[])
 		if (!create_dumpfile())
 			goto out;
 
+		if (info->flag_dry_run)
+			goto check_ok;
+
 		MSG("\n");
 		if (info->flag_split) {
 			MSG("The dumpfiles are saved to ");
diff --git a/makedumpfile.h b/makedumpfile.h
index 698c054..58126cb 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -1321,6 +1321,7 @@ struct DumpInfo {
 	int		flag_vmemmap;        /* kernel supports vmemmap address space */
 	int		flag_excludevm;      /* -e - excluding unused vmemmap pages */
 	int		flag_use_count;      /* _refcount is named _count in struct page */
+	int		flag_dry_run;        /* do not create a vmcore file */
 	unsigned long	vaddr_for_vtop;      /* virtual address for debugging */
 	long		page_size;           /* size of page */
 	long		page_shift;
@@ -2364,6 +2365,7 @@ struct elf_prstatus {
 #define OPT_NUM_THREADS         OPT_START+16
 #define OPT_PARTIAL_DMESG       OPT_START+17
 #define OPT_CHECK_PARAMS        OPT_START+18
+#define OPT_DRY_RUN             OPT_START+19
 
 /*
  * Function Prototype.
diff --git a/print_info.c b/print_info.c
index e0c38b4..d2b0cb7 100644
--- a/print_info.c
+++ b/print_info.c
@@ -308,6 +308,9 @@ print_usage(void)
 	MSG("      the crashkernel range, then calculates the page number of different kind per\n");
 	MSG("      vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n");
 	MSG("\n");
+	MSG("  [--dry-run]:\n");
+	MSG("      This option runs makedumpfile without writting output dump file.\n");
+	MSG("\n");
 	MSG("  [-D]:\n");
 	MSG("      Print debugging message.\n");
 	MSG("\n");
-- 
2.25.4


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2020-11-24 10:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 10:45 [MAKDUMPFILE PATCH 0/2] Get stats without writing dumpfile Julien Thierry
2020-11-24 10:45 ` Julien Thierry [this message]
2021-01-18  6:43   ` [MAKEDUMPFILE PATCH 1/2] Add option to prevent writing the dumpfile HAGIO KAZUHITO(萩尾 一仁)
2021-01-28  9:00     ` HAGIO KAZUHITO(萩尾 一仁)
2021-02-04  8:21       ` HAGIO KAZUHITO(萩尾 一仁)
2020-11-24 10:45 ` [MAKEDUMPFILE PATCH 2/2] Add shorthand option to show report stats Julien Thierry
2021-01-18  7:19   ` HAGIO KAZUHITO(萩尾 一仁)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201124104525.1070885-2-jthierry@redhat.com \
    --to=jthierry@redhat.com \
    --cc=bhsharma@redhat.com \
    --cc=k-hagio-ab@nec.com \
    --cc=kexec@lists.infradead.org \
    --cc=lijiang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.