Skip to content

Commit b21e04e

Browse files
pcd1193182Paul Dagnelie
andauthored
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 d323fbf commit b21e04e

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
@@ -7706,19 +7706,20 @@ zdb_set_skip_mmp(char *target)
77067706
* applies to the new_path parameter if allocated.
77077707
*/
77087708
static char *
7709-
import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
7709+
import_checkpointed_state(char *target, nvlist_t *cfg, boolean_t target_is_spa,
7710+
char **new_path)
77107711
{
77117712
int error = 0;
77127713
char *poolname, *bogus_name = NULL;
77137714
boolean_t freecfg = B_FALSE;
77147715

77157716
/* If the target is not a pool, the extract the pool name */
77167717
char *path_start = strchr(target, '/');
7717-
if (path_start != NULL) {
7718+
if (target_is_spa || path_start == NULL) {
7719+
poolname = target;
7720+
} else {
77187721
size_t poolname_len = path_start - target;
77197722
poolname = strndup(target, poolname_len);
7720-
} else {
7721-
poolname = target;
77227723
}
77237724

77247725
if (cfg == NULL) {
@@ -7749,10 +7750,11 @@ import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
77497750
"with error %d\n", bogus_name, error);
77507751
}
77517752

7752-
if (new_path != NULL && path_start != NULL) {
7753-
if (asprintf(new_path, "%s%s", bogus_name, path_start) == -1) {
7753+
if (new_path != NULL && !target_is_spa) {
7754+
if (asprintf(new_path, "%s%s", bogus_name,
7755+
path_start != NULL ? path_start : "") == -1) {
77547756
free(bogus_name);
7755-
if (path_start != NULL)
7757+
if (!target_is_spa && path_start != NULL)
77567758
free(poolname);
77577759
return (NULL);
77587760
}
@@ -7981,7 +7983,7 @@ verify_checkpoint_blocks(spa_t *spa)
79817983
* name) so we can do verification on it against the current state
79827984
* of the pool.
79837985
*/
7984-
checkpoint_pool = import_checkpointed_state(spa->spa_name, NULL,
7986+
checkpoint_pool = import_checkpointed_state(spa->spa_name, NULL, B_TRUE,
79857987
NULL);
79867988
ASSERT(strcmp(spa->spa_name, checkpoint_pool) != 0);
79877989

@@ -9705,7 +9707,7 @@ main(int argc, char **argv)
97059707
char *checkpoint_target = NULL;
97069708
if (dump_opt['k']) {
97079709
checkpoint_pool = import_checkpointed_state(target, cfg,
9708-
&checkpoint_target);
9710+
target_is_spa, &checkpoint_target);
97099711

97109712
if (checkpoint_target != NULL)
97119713
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)