Skip to content

Commit

Permalink
Add a "zstream decompress" subcommand
Browse files Browse the repository at this point in the history
It can be used to repair a ZFS file system corrupted by ZFS bug openzfs#12762.
Use it like this:

zfs send -c <DS> | \
zstream decompress <OBJECT>,<OFFSET>[,<COMPRESSION_ALGO>] ... | \
zfs recv <DST_DS>

Reviewed-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Alan Somers <asomers@gmail.com>
Sponsored-by:  Axcient
Workaround for openzfs#12762
Closes openzfs#13256
  • Loading branch information
asomers authored and andrewc12 committed Sep 23, 2022
1 parent 67de83a commit 504f809
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/zstream/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ CPPCHECKTARGETS += zstream
zstream_SOURCES = \
%D%/zstream.c \
%D%/zstream.h \
%D%/zstream_decompress.c \
%D%/zstream_dump.c \
%D%/zstream_redup.c \
%D%/zstream_token.c

zstream_LDADD = \
libzfs.la \
libzfs_core.la \
libzpool.la \
libnvpair.la

PHONY += install-exec-hook
Expand Down
4 changes: 4 additions & 0 deletions cmd/zstream/zstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ zstream_usage(void)
"\tzstream dump [-vCd] FILE\n"
"\t... | zstream dump [-vCd]\n"
"\n"
"\tzstream decompress [-v] [OBJECT,OFFSET[,TYPE]] ...\n"
"\n"
"\tzstream token resume_token\n"
"\n"
"\tzstream redup [-v] FILE | ...\n");
Expand All @@ -61,6 +63,8 @@ main(int argc, char *argv[])

if (strcmp(subcommand, "dump") == 0) {
return (zstream_do_dump(argc - 1, argv + 1));
} else if (strcmp(subcommand, "decompress") == 0) {
return (zstream_do_decompress(argc - 1, argv + 1));
} else if (strcmp(subcommand, "token") == 0) {
return (zstream_do_token(argc - 1, argv + 1));
} else if (strcmp(subcommand, "redup") == 0) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/zstream/zstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
extern "C" {
#endif

extern void *safe_calloc(size_t n);
extern int sfread(void *buf, size_t size, FILE *fp);
extern void *safe_malloc(size_t size);
extern int zstream_do_redup(int, char *[]);
extern int zstream_do_dump(int, char *[]);
extern int zstream_do_decompress(int argc, char *argv[]);
extern int zstream_do_token(int, char *[]);
extern void zstream_usage(void);

Expand Down
Loading

0 comments on commit 504f809

Please sign in to comment.