aboutsummaryrefslogtreecommitdiff
path: root/sbin/savecore/savecore.c
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2018-02-13 19:28:02 +0000
committerMark Johnston <markj@FreeBSD.org>2018-02-13 19:28:02 +0000
commit6026dcd7ca888f3433f4df34ede69a77c1eb7701 (patch)
tree0de05c03d3e12526dae1a59da5a95ddedd6c3738 /sbin/savecore/savecore.c
parent83ab0f9f33c1ba96cce50a48e27e40c8c2eead5a (diff)
downloadsrc-6026dcd7ca888f3433f4df34ede69a77c1eb7701.tar.gz
src-6026dcd7ca888f3433f4df34ede69a77c1eb7701.zip
Add support for zstd-compressed user and kernel core dumps.
This works similarly to the existing gzip compression support, but zstd is typically faster and gives better compression ratios. Support for this functionality must be configured by adding ZSTDIO to one's kernel configuration file. dumpon(8)'s new -Z option is used to configure zstd compression for kernel dumps. savecore(8) now recognizes and saves zstd-compressed kernel dumps with a .zst extension. Submitted by: cem (original version) Relnotes: yes Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D13101, https://reviews.freebsd.org/D13633
Notes
Notes: svn path=/head/; revision=329240
Diffstat (limited to 'sbin/savecore/savecore.c')
-rw-r--r--sbin/savecore/savecore.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index 14257421361c..5414b1910451 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -109,6 +109,7 @@ printheader(xo_handle_t *xo, const struct kerneldumpheader *h,
uint64_t dumplen;
time_t t;
const char *stat_str;
+ const char *comp_str;
xo_flush_h(xo);
xo_emit_h(xo, "{Lwc:Dump header from device}{:dump_device/%s}\n",
@@ -123,10 +124,21 @@ printheader(xo_handle_t *xo, const struct kerneldumpheader *h,
(long long)dumplen);
xo_emit_h(xo, "{P: }{Lwc:Blocksize}{:blocksize/%d}\n",
dtoh32(h->blocksize));
- xo_emit_h(xo, "{P: }{Lwc:Compression}{:compression/%s}\n",
- h->compression == KERNELDUMP_COMP_GZIP ?
- "gzip" : "none");
-
+ switch (h->compression) {
+ case KERNELDUMP_COMP_NONE:
+ comp_str = "none";
+ break;
+ case KERNELDUMP_COMP_GZIP:
+ comp_str = "gzip";
+ break;
+ case KERNELDUMP_COMP_ZSTD:
+ comp_str = "zstd";
+ break;
+ default:
+ comp_str = "???";
+ break;
+ }
+ xo_emit_h(xo, "{P: }{Lwc:Compression}{:compression/%s}\n", comp_str);
t = dtoh64(h->dumptime);
xo_emit_h(xo, "{P: }{Lwc:Dumptime}{:dumptime/%s}", ctime(&t));
xo_emit_h(xo, "{P: }{Lwc:Hostname}{:hostname/%s}\n", h->hostname);
@@ -249,6 +261,8 @@ saved_dump_size(int bounds)
dumpsize += file_size(path);
(void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
dumpsize += file_size(path);
+ (void)snprintf(path, sizeof(path), "vmcore.%d.zst", bounds);
+ dumpsize += file_size(path);
(void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
dumpsize += file_size(path);
(void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
@@ -268,6 +282,8 @@ saved_dump_remove(int bounds)
(void)unlink(path);
(void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
(void)unlink(path);
+ (void)snprintf(path, sizeof(path), "vmcore.%d.zst", bounds);
+ (void)unlink(path);
(void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
(void)unlink(path);
(void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
@@ -282,6 +298,7 @@ symlinks_remove(void)
(void)unlink("key.last");
(void)unlink("vmcore.last");
(void)unlink("vmcore.last.gz");
+ (void)unlink("vmcore.last.zstd");
(void)unlink("vmcore_encrypted.last");
(void)unlink("vmcore_encrypted.last.gz");
(void)unlink("textdump.tar.last");
@@ -615,6 +632,7 @@ DoFile(const char *savedir, const char *device)
case KERNELDUMP_COMP_NONE:
break;
case KERNELDUMP_COMP_GZIP:
+ case KERNELDUMP_COMP_ZSTD:
if (compress && verbose)
printf("dump is already compressed\n");
compress = false;
@@ -743,7 +761,8 @@ DoFile(const char *savedir, const char *device)
(isencrypted ? "vmcore_encrypted" : "vmcore"), bounds);
fp = zopen(corename, "w");
} else if (iscompressed && !isencrypted) {
- snprintf(corename, sizeof(corename), "vmcore.%d.gz", bounds);
+ snprintf(corename, sizeof(corename), "vmcore.%d.%s", bounds,
+ (kdhl.compression == KERNELDUMP_COMP_GZIP) ? "gz" : "zst");
fp = fopen(corename, "w");
} else {
snprintf(corename, sizeof(corename), "%s.%d",
@@ -845,9 +864,10 @@ DoFile(const char *savedir, const char *device)
}
}
if (compress || iscompressed) {
- snprintf(linkname, sizeof(linkname), "%s.last.gz",
+ snprintf(linkname, sizeof(linkname), "%s.last.%s",
istextdump ? "textdump.tar" :
- (isencrypted ? "vmcore_encrypted" : "vmcore"));
+ (isencrypted ? "vmcore_encrypted" : "vmcore"),
+ (kdhl.compression == KERNELDUMP_COMP_ZSTD) ? "zst" : "gz");
} else {
snprintf(linkname, sizeof(linkname), "%s.last",
istextdump ? "textdump.tar" :