kexec-tools/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch
Tao Liu e1ab0275c0 Add --dry-run option to prevent writing the dumpfile
Backport from upstream.

commit 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f
Author: Julien Thierry <jthierry@redhat.com>
Date:   Tue Nov 24 10:45:24 2020 +0000

    [PATCH 1/2] Add --dry-run option to prevent writing the dumpfile

    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>
    Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-04-28 15:45:08 +08:00

178 lines
5.9 KiB
Diff

From 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f Mon Sep 17 00:00:00 2001
From: Julien Thierry <jthierry@redhat.com>
Date: Tue, 24 Nov 2020 10:45:24 +0000
Subject: [PATCH 02/12] [PATCH 1/2] Add --dry-run option to prevent writing the
dumpfile
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>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
---
makedumpfile.8 | 6 ++++++
makedumpfile.c | 37 ++++++++++++++++++++++++++++++-------
makedumpfile.h | 2 ++
print_info.c | 3 +++
4 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8
index b68a7e3..5e902cd 100644
--- a/makedumpfile-1.6.8/makedumpfile.8
+++ b/makedumpfile-1.6.8/makedumpfile.8
@@ -637,6 +637,12 @@ 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.
+This option cannot be used with the --dump-dmesg, --reassemble and -g options.
+
.SH ENVIRONMENT VARIABLES
.TP 8
diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c
index ecd63fa..8c80c49 100644
--- a/makedumpfile-1.6.8/makedumpfile.c
+++ b/makedumpfile-1.6.8/makedumpfile.c
@@ -1372,6 +1372,8 @@ open_dump_file(void)
if (info->flag_flatten) {
fd = STDOUT_FILENO;
info->name_dumpfile = filename_stdout;
+ } else if (info->flag_dry_run) {
+ fd = -1;
} else if ((fd = open(info->name_dumpfile, open_flags,
S_IRUSR|S_IWUSR)) < 0) {
ERRMSG("Can't open the dump file(%s). %s\n",
@@ -4711,6 +4713,9 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name)
{
int status, written_size = 0;
+ if (info->flag_dry_run)
+ return TRUE;
+
while (written_size < buf_size) {
status = write(fd, buf + written_size,
buf_size - written_size);
@@ -4748,13 +4753,12 @@ 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 (lseek(fd, offset, SEEK_SET) == failed) {
- ERRMSG("Can't seek the dump file(%s). %s\n",
- file_name, strerror(errno));
- return FALSE;
- }
+ } else if (!info->flag_dry_run &&
+ lseek(fd, offset, SEEK_SET) == failed) {
+ ERRMSG("Can't seek the dump file(%s). %s\n", file_name, strerror(errno));
+ return FALSE;
}
+
if (!write_and_check_space(fd, buf, buf_size, file_name))
return FALSE;
@@ -9112,7 +9116,7 @@ close_dump_memory(void)
void
close_dump_file(void)
{
- if (info->flag_flatten)
+ if (info->flag_flatten || info->flag_dry_run)
return;
if (close(info->fd_dumpfile) < 0)
@@ -10985,6 +10989,11 @@ check_param_for_generating_vmcoreinfo(int argc, char *argv[])
return FALSE;
+ if (info->flag_dry_run) {
+ MSG("--dry-run cannot be used with -g.\n");
+ return FALSE;
+ }
+
return TRUE;
}
@@ -11029,6 +11038,11 @@ check_param_for_reassembling_dumpfile(int argc, char *argv[])
|| info->flag_exclude_xen_dom || info->flag_split)
return FALSE;
+ if (info->flag_dry_run) {
+ MSG("--dry-run cannot be used with --reassemble.\n");
+ return FALSE;
+ }
+
if ((info->splitting_info
= malloc(sizeof(struct splitting_info) * info->num_dumpfile))
== NULL) {
@@ -11057,6 +11071,11 @@ check_param_for_creating_dumpfile(int argc, char *argv[])
|| (info->flag_read_vmcoreinfo && info->name_xen_syms))
return FALSE;
+ if (info->flag_dry_run && info->flag_dmesg) {
+ MSG("--dry-run cannot be used with --dump-dmesg.\n");
+ return FALSE;
+ }
+
if (info->flag_flatten && info->flag_split)
return FALSE;
@@ -11520,6 +11539,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}
};
@@ -11686,6 +11706,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");
diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h
index 5f50080..4c4222c 100644
--- a/makedumpfile-1.6.8/makedumpfile.h
+++ b/makedumpfile-1.6.8/makedumpfile.h
@@ -1322,6 +1322,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;
@@ -2425,6 +2426,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/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c
index e0c38b4..d2b0cb7 100644
--- a/makedumpfile-1.6.8/print_info.c
+++ b/makedumpfile-1.6.8/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.29.2