diff options
author | Serapheim Dimitropoulos <[email protected]> | 2018-10-30 09:46:18 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-10-30 11:46:18 -0500 |
commit | 0a544c174d54d9adcea2faf5817596174582139e (patch) | |
tree | e6dae62fe20d54d8313ce699784c83c33f2281e9 | |
parent | 63a77ae3cff2eea8f7d92c5ab2ab99af664b34a5 (diff) |
zdb -k does not work on Linux when used with -e
This minor bug was introduced with the port of the feature from
OpenZFS to ZoL. This patch fixes the issue that was caused by
a minor re-ordering from the original code.
Reviewed-by: Matthew Ahrens <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Tim Chase <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Serapheim Dimitropoulos <[email protected]>
Closes #8001
-rw-r--r-- | cmd/zdb/zdb.c | 29 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh | 26 | ||||
-rw-r--r-- | tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib | 11 |
3 files changed, 50 insertions, 16 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index cdea1e584..737217538 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -6057,17 +6057,6 @@ main(int argc, char **argv) error = 0; target = argv[0]; - char *checkpoint_pool = NULL; - char *checkpoint_target = NULL; - if (dump_opt['k']) { - checkpoint_pool = import_checkpointed_state(target, cfg, - &checkpoint_target); - - if (checkpoint_target != NULL) - target = checkpoint_target; - - } - if (strpbrk(target, "/@") != NULL) { size_t targetlen; @@ -6113,6 +6102,24 @@ main(int argc, char **argv) } } + /* + * import_checkpointed_state makes the assumption that the + * target pool that we pass it is already part of the spa + * namespace. Because of that we need to make sure to call + * it always after the -e option has been processed, which + * imports the pool to the namespace if it's not in the + * cachefile. + */ + char *checkpoint_pool = NULL; + char *checkpoint_target = NULL; + if (dump_opt['k']) { + checkpoint_pool = import_checkpointed_state(target, cfg, + &checkpoint_target); + + if (checkpoint_target != NULL) + target = checkpoint_target; + } + if (target_pool != target) free(target_pool); diff --git a/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh b/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh index 50c45b5b4..fdefc0c3b 100755 --- a/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh +++ b/tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh @@ -19,7 +19,7 @@ # # DESCRIPTION: -# Ensure that checkpoint verification within zdb wowrks as +# Ensure that checkpoint verification within zdb works as # we expect. # # STRATEGY: @@ -30,10 +30,12 @@ # 5. Verify zdb finds checkpoint when run on current state # 6. Verify zdb finds old dataset when run on checkpointed # state -# 7. Discard checkpoint -# 8. Verify zdb does not find the checkpoint anymore in the +# 7. Export pool, and verify the same things with zdb to +# test the -e option. +# 8. Import pool and discard checkpoint +# 9. Verify zdb does not find the checkpoint anymore in the # current state. -# 9. Verify that zdb cannot find the checkpointed state +# 10.Verify that zdb cannot find the checkpointed state # anymore when trying to open it for verification. # @@ -68,6 +70,22 @@ zdb $TESTPOOL | grep "Dataset $FS1" && \ zdb -k $TESTPOOL | grep "Dataset $CHECKPOINTED_FS1" || \ log_fail "zdb could not find destroyed dataset in checkpoint" +log_must zpool export $TESTPOOL + +zdb -e $TESTPOOL | grep "Checkpointed uberblock found" || \ + log_fail "zdb could not find checkpointed uberblock" + +zdb -k -e $TESTPOOL | grep "Checkpointed uberblock found" && \ + log_fail "zdb found checkpointed uberblock in checkpointed state" + +zdb -e $TESTPOOL | grep "Dataset $FS1" && \ + log_fail "zdb found destroyed dataset in current state" + +zdb -k -e $TESTPOOL | grep "Dataset $CHECKPOINTED_FS1" || \ + log_fail "zdb could not find destroyed dataset in checkpoint" + +log_must zpool import $TESTPOOL + log_must zpool checkpoint -d $TESTPOOL zdb $TESTPOOL | grep "Checkpointed uberblock found" && \ diff --git a/tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib b/tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib index cac05b392..3638e3dfe 100644 --- a/tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib +++ b/tests/zfs-tests/tests/functional/pool_checkpoint/pool_checkpoint.kshlib @@ -161,7 +161,16 @@ function cleanup_nested_pool function cleanup_test_pool { log_must zpool destroy $TESTPOOL - zpool labelclear -f "$TESTDISK" + + # + # We always clear the labels of all disks + # between tests so imports from zpool or + # or zdb do not get confused with leftover + # data from old pools. + # + for disk in $DISKS; do + zpool labelclear -f $disk + done } function cleanup_nested_pools |