Start snapdir_iterate traversals to begin wtih the value of zero.

The microzap hash can sometimes be zero for single digit snapnames.
The zap cursor can then have a serialized value of two (for . and ..),
and skip the first entry in the avl tree for the .zfs/snapshot directory
listing, and therefore does not return all snapshots.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Cedric Berger <cedric@precidata.com>
Signed-off-by: Tony Perkins <tperkins@datto.com>
Closes #11039
This commit is contained in:
Tony Perkins 2020-09-27 20:46:22 -04:00 committed by Brian Behlendorf
parent 87f01fc158
commit 2132ae465d
2 changed files with 19 additions and 1 deletions

View File

@ -248,7 +248,8 @@ zpl_snapdir_iterate(struct file *filp, zpl_dir_context_t *ctx)
if (!zpl_dir_emit_dots(filp, ctx)) if (!zpl_dir_emit_dots(filp, ctx))
goto out; goto out;
pos = ctx->pos; /* Start the position at 0 if it already emitted . and .. */
pos = (ctx->pos == 2 ? 0 : ctx->pos);
while (error == 0) { while (error == 0) {
dsl_pool_config_enter(dmu_objset_pool(zfsvfs->z_os), FTAG); dsl_pool_config_enter(dmu_objset_pool(zfsvfs->z_os), FTAG);
error = -dmu_snapshot_list_next(zfsvfs->z_os, MAXNAMELEN, error = -dmu_snapshot_list_next(zfsvfs->z_os, MAXNAMELEN,

View File

@ -12,6 +12,7 @@
# #
# Copyright (c) 2012, 2016 by Delphix. All rights reserved. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
# Copyright (c) 2020 by Datto Inc. All rights reserved.
# #
# #
@ -23,6 +24,8 @@
# 2. Create multiple snapshots with a list of valid and invalid # 2. Create multiple snapshots with a list of valid and invalid
# snapshot names # snapshot names
# 3. Verify the valid snapshot creation # 3. Verify the valid snapshot creation
# 4. Verify creation of snapshots report the correct numbers by
# performing a snapshot directory listing
. $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/libtest.shlib
@ -34,6 +37,7 @@ function cleanup
datasetexists $ds && log_must zfs destroy -r $ds datasetexists $ds && log_must zfs destroy -r $ds
done done
zfs destroy -r $TESTPOOL/TESTFS4 zfs destroy -r $TESTPOOL/TESTFS4
zfs destroy -r $TESTPOOL/TESTFS5
} }
datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2
$TESTPOOL/$TESTFS3" $TESTPOOL/$TESTFS3"
@ -112,4 +116,17 @@ log_must zfs rename $TESTPOOL/$TESTFS3/TESTFSA$DATASET_XXX \
log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \ log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
$TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1 $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
MYTEST="TESTFS5"
ITERATIONS=10
NUM_SNAPS=5
for x in {1..$ITERATIONS}; do
log_must zfs create $TESTPOOL/$MYTEST
for y in {1..$NUM_SNAPS}; do
log_must zfs snapshot $TESTPOOL/$MYTEST@$y
done;
n=$(ls -1 /$TESTPOOL/$MYTEST/.zfs/snapshot | wc -l)
verify_eq $n $NUM_SNAPS "count"
zfs destroy -r $TESTPOOL/$MYTEST;
done;
log_pass "zfs multiple snapshot verified correctly" log_pass "zfs multiple snapshot verified correctly"