Skip to content

Commit 6af1f61

Browse files
pcd1193182Paul Dagnelie
authored andcommitted
Fix zdb pool/ with -k
When examining the root dataset with zdb -k, we get into a mismatched state. main() knows we are not examining the whole pool, but it strips off the trailing slash. import_checkpointed_state() then thinks we are examining the whole pool, and does not update the target path appropriately. The fix is to directly inform import_checkpointed_state that we are examining a filesystem, and not the whole pool. Sponsored-by: Klara, Inc. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Rob Norris <[email protected]> Signed-off-by: Paul Dagnelie <[email protected]> Co-authored-by: Paul Dagnelie <[email protected]> Closes #17536
1 parent 8c4f625 commit 6af1f61

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cmd/zdb/zdb.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,19 +7708,20 @@ zdb_set_skip_mmp(char *target)
77087708
* applies to the new_path parameter if allocated.
77097709
*/
77107710
static char *
7711-
import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
7711+
import_checkpointed_state(char *target, nvlist_t *cfg, boolean_t target_is_spa,
7712+
char **new_path)
77127713
{
77137714
int error = 0;
77147715
char *poolname, *bogus_name = NULL;
77157716
boolean_t freecfg = B_FALSE;
77167717

77177718
/* If the target is not a pool, the extract the pool name */
77187719
char *path_start = strchr(target, '/');
7719-
if (path_start != NULL) {
7720+
if (target_is_spa || path_start == NULL) {
7721+
poolname = target;
7722+
} else {
77207723
size_t poolname_len = path_start - target;
77217724
poolname = strndup(target, poolname_len);
7722-
} else {
7723-
poolname = target;
77247725
}
77257726

77267727
if (cfg == NULL) {
@@ -7751,10 +7752,11 @@ import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
77517752
"with error %d\n", bogus_name, error);
77527753
}
77537754

7754-
if (new_path != NULL && path_start != NULL) {
7755-
if (asprintf(new_path, "%s%s", bogus_name, path_start) == -1) {
7755+
if (new_path != NULL && !target_is_spa) {
7756+
if (asprintf(new_path, "%s%s", bogus_name,
7757+
path_start != NULL ? path_start : "") == -1) {
77567758
free(bogus_name);
7757-
if (path_start != NULL)
7759+
if (!target_is_spa && path_start != NULL)
77587760
free(poolname);
77597761
return (NULL);
77607762
}
@@ -7983,7 +7985,7 @@ verify_checkpoint_blocks(spa_t *spa)
79837985
* name) so we can do verification on it against the current state
79847986
* of the pool.
79857987
*/
7986-
checkpoint_pool = import_checkpointed_state(spa->spa_name, NULL,
7988+
checkpoint_pool = import_checkpointed_state(spa->spa_name, NULL, B_TRUE,
79877989
NULL);
79887990
ASSERT(strcmp(spa->spa_name, checkpoint_pool) != 0);
79897991

@@ -9700,7 +9702,7 @@ main(int argc, char **argv)
97009702
char *checkpoint_target = NULL;
97019703
if (dump_opt['k']) {
97029704
checkpoint_pool = import_checkpointed_state(target, cfg,
9703-
&checkpoint_target);
9705+
target_is_spa, &checkpoint_target);
97049706

97059707
if (checkpoint_target != NULL)
97069708
target = checkpoint_target;

tests/zfs-tests/tests/functional/pool_checkpoint/checkpoint_zdb.ksh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ log_must eval "zdb $TESTPOOL | grep -q \"Checkpointed uberblock found\""
6363
log_mustnot eval "zdb -k $TESTPOOL | grep -q \"Checkpointed uberblock found\""
6464
log_mustnot eval "zdb $TESTPOOL | grep \"Dataset $FS1\""
6565
log_must eval "zdb -k $TESTPOOL | grep \"Dataset $CHECKPOINTED_FS1\""
66+
log_must eval "zdb -k $TESTPOOL/ | grep \"$TESTPOOL$BOGUS_SUFFIX\""
6667

6768
log_must zpool export $TESTPOOL
6869

6970
log_must eval "zdb -e $TESTPOOL | grep \"Checkpointed uberblock found\""
7071
log_mustnot eval "zdb -k -e $TESTPOOL | grep \"Checkpointed uberblock found\""
7172
log_mustnot eval "zdb -e $TESTPOOL | grep \"Dataset $FS1\""
7273
log_must eval "zdb -k -e $TESTPOOL | grep \"Dataset $CHECKPOINTED_FS1\""
74+
log_must eval "zdb -k -e $TESTPOOL/ | grep \"$TESTPOOL$BOGUS_SUFFIX\""
7375

7476
log_must zpool import $TESTPOOL
7577

0 commit comments

Comments
 (0)