Skip to content

Commit

Permalink
Allow zhack label repair to restore detached devices.
Browse files Browse the repository at this point in the history
This commit expands on the zhack label repair command in d04b5c9 by
adding the -u option to undetach a device by regenerating uberblocks,
in addition to the existing functionality of fixing checksums, now
represented by -c. Previous behavior is retained in the case of no
options.

The changes are heavily inspired by Jeff Bonwick's labelfix
utility, as archived at:

https://gist.github.com/jjwhitney/baaa63144da89726e482

Additionally, it is now capable of properly determining the size of
block devices and other media, as well as handling sizes which are
not divisible by 2^18. This should make it viable for use on physical
devices and partitions, in addition to files.

These changes should make it possible to import zpools that have had
their uberblocks erased, such as in the case of pools rendered
inaccessible by erroneous detach commands.

Signed-off-by: buzzingwires <buzzingwires@outlook.com>
  • Loading branch information
buzzingwires committed Apr 29, 2023
1 parent 71d191e commit edcfa50
Show file tree
Hide file tree
Showing 10 changed files with 928 additions and 161 deletions.
508 changes: 415 additions & 93 deletions cmd/zhack.c

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions man/man1/zhack.1
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,29 @@ feature is now required to read the pool MOS.
.It Xo
.Nm zhack
.Cm label repair
.Op Fl cu
.Ar device
.Xc
Repair corrupted labels by rewriting the checksum using the presumed valid
contents of the label.
Repair labels of a specified
.Ar device
according to options.
.Pp
Flags may be combined to do their functions simultaneously.
.
.Pp
The
.Fl c
flag repairs corrupted label checksums
.
.Pp
The
.Fl u
flag restores the label on a detached device
.Pp
Example:
.Nm zhack Cm label repair Fl cu Ar device
Fix checksums and undetach a device
.
.El
.
.Sh GLOBAL OPTIONS
Expand Down
3 changes: 2 additions & 1 deletion tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ tests = ['zfs_wait_deleteq', 'zfs_wait_getsubopt']
tags = ['functional', 'cli_root', 'zfs_wait']

[tests/functional/cli_root/zhack]
tests = ['zhack_label_checksum']
tests = ['zhack_label_repair_001', 'zhack_label_repair_002',
'zhack_label_repair_003', 'zhack_label_repair_004']
pre =
post =
tags = ['functional', 'cli_root', 'zhack']
Expand Down
6 changes: 5 additions & 1 deletion tests/zfs-tests/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ nobase_dist_datadir_zfs_tests_tests_DATA += \
functional/cli_root/zpool_upgrade/zpool_upgrade.cfg \
functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib \
functional/cli_root/zpool_wait/zpool_wait.kshlib \
functional/cli_root/zhack/library.kshlib \
functional/cli_user/misc/misc.cfg \
functional/cli_user/zfs_list/zfs_list.cfg \
functional/cli_user/zfs_list/zfs_list.kshlib \
Expand Down Expand Up @@ -931,7 +932,10 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zfs/zfs_001_neg.ksh \
functional/cli_root/zfs/zfs_002_pos.ksh \
functional/cli_root/zfs/zfs_003_neg.ksh \
functional/cli_root/zhack/zhack_label_checksum.ksh \
functional/cli_root/zhack/zhack_label_repair_001.ksh \
functional/cli_root/zhack/zhack_label_repair_002.ksh \
functional/cli_root/zhack/zhack_label_repair_003.ksh \
functional/cli_root/zhack/zhack_label_repair_004.ksh \
functional/cli_root/zpool_add/add_nested_replacing_spare.ksh \
functional/cli_root/zpool_add/add-o_ashift.ksh \
functional/cli_root/zpool_add/add_prop_ashift.ksh \
Expand Down
Loading

0 comments on commit edcfa50

Please sign in to comment.