In the coming btrfs-progs v5.15 release, mkfs.btrfs will change to
use v2 cache by default.
However nospace_cache mount option will not work with v2 cache, as
it would make v2 cache out of sync with on-disk used space.
So mounting a btrfs with v2 cache using "nospace_cache" will make
btrfs to reject the mount.
There are quite some test cases relying on nospace_cache to prevent
v1 cache to take up data space.
For those test cases, we no longer need the "nospace_cache" mount
option if the filesystem is already using v2 cache. Since v2 cache
is using metadata space, it will no longer take up data space, thus
no extra mount options for those test cases.
By this, we can keep those existing tests to run without problem for
both v1 and v2 cache.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
12 files changed:
test -f /sys/fs/btrfs/$fsid/devinfo/1/fsid ||\
_notrun "Need btrfs sysfs fsid support"
}
test -f /sys/fs/btrfs/$fsid/devinfo/1/fsid ||\
_notrun "Need btrfs sysfs fsid support"
}
+
+# If test doesn't want v1 cache to take up data space, there's no longer need
+# the "nospace_cache" mount option if the filesystem is already using v2 cache.
+# Since v2 cache is using metadata space, it will no longer take up data space.
+_btrfs_no_v1_cache_opt()
+{
+ if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+ grep -q "FREE_SPACE_TREE"; then
+ return
+ fi
+ echo -n "-onospace_cache"
+}
# Mount our filesystem without space caches enabled so that we do not get any
# space used from the initial data block group that mkfs creates (space caches
# used space from data block groups).
# Mount our filesystem without space caches enabled so that we do not get any
# space used from the initial data block group that mkfs creates (space caches
# used space from data block groups).
-_scratch_mount "-o nospace_cache"
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# Need an fs with at least 2Gb to make sure mkfs.btrfs does not create an fs
# using mixed block groups (used both for data and metadata). We really need
# Need an fs with at least 2Gb to make sure mkfs.btrfs does not create an fs
# using mixed block groups (used both for data and metadata). We really need
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache
+# make sure data is written to the start position of the data chunk
+_scratch_mount $(_btrfs_no_v1_cache_opt)
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache
+# make sure data is written to the start position of the data chunk
+_scratch_mount $(_btrfs_no_v1_cache_opt)
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache,nodatasum
+# make sure data is written to the start position of the data chunk
+_scratch_mount -o nodatasum $(_btrfs_no_v1_cache_opt)
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid1 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache,nodatasum
+# make sure data is written to the start position of the data chunk
+_scratch_mount -o nodatasum $(_btrfs_no_v1_cache_opt)
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
_filter_xfs_io_offset
# create raid1 for data
_scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
# create raid1 for data
_scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
-# we need an empty data chunk, so nospace_cache is required.
-_scratch_mount -onospace_cache
+# we need an empty data chunk, so $(_btrfs_no_v1_cache_opt) is required.
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# if data chunk is empty, 'btrfs device remove' can change raid1 to
# single.
# if data chunk is empty, 'btrfs device remove' can change raid1 to
# single.
mkfs_opts="-d raid6 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid6 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache
+# make sure data is written to the start position of the data chunk
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
# step 3: read foobar to repair the bitrot
echo "step 3......repair the bitrot" >> $seqres.full
# step 3: read foobar to repair the bitrot
echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# read the 2nd stripe, i.e. [64K, 128K), to trigger repair
od -x -j 64K $SCRATCH_MNT/foobar
# read the 2nd stripe, i.e. [64K, 128K), to trigger repair
od -x -j 64K $SCRATCH_MNT/foobar
mkfs_opts="-d raid6 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
mkfs_opts="-d raid6 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
-# -o nospace_cache makes sure data is written to the start position of the data
-# chunk
-_scratch_mount -o nospace_cache
+# make sure data is written to the start position of the data chunk
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
# step 3: scrub filesystem to repair the bitrot
echo "step 3......repair the bitrot" >> $seqres.full
# step 3: scrub filesystem to repair the bitrot
echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_btrfs_no_v1_cache_opt)
$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
# Mount without space cache so that we can precisely fill all data space and
# unallocated space later (space cache v1 uses data block groups).
# Mount without space cache so that we can precisely fill all data space and
# unallocated space later (space cache v1 uses data block groups).
-_scratch_mount "-o nospace_cache"
+_scratch_mount $(_btrfs_no_v1_cache_opt)
# Create our test file and allocate 1826.25Mb of space for it.
# This will exhaust the existing data block group and all unallocated space on
# Create our test file and allocate 1826.25Mb of space for it.
# This will exhaust the existing data block group and all unallocated space on
loop_mnt=$tmp/loop_mnt
mkdir -p $loop_mnt
loop_mnt=$tmp/loop_mnt
mkdir -p $loop_mnt
+# - $(_btrfs_no_v1_cache_opt)
# Since v1 cache using DATA space, it can break data extent bytenr
# continuousness.
# - nodatasum
# Since v1 cache using DATA space, it can break data extent bytenr
# continuousness.
# - nodatasum
# Disabling datasum could reduce the margin caused by metadata to minimal
# - discard
# What we're testing
# Disabling datasum could reduce the margin caused by metadata to minimal
# - discard
# What we're testing
-_mount -o nospace_cache,nodatasum,discard $loop_dev $loop_mnt
+_mount $(_btrfs_no_v1_cache_opt) -o nodatasum,discard $loop_dev $loop_mnt
# Craft the following extent layout:
# | BG1 | BG2 | BG3 |
# Craft the following extent layout:
# | BG1 | BG2 | BG3 |
_scratch_mkfs > /dev/null
# disable freespace inode to ensure file is the first thing in the data
# blobk group
_scratch_mkfs > /dev/null
# disable freespace inode to ensure file is the first thing in the data
# blobk group
-_scratch_mount -o nospace_cache
+_scratch_mount $(_btrfs_no_v1_cache_opt)
pagesize=$(get_page_size)
blocksize=$(_get_block_size $SCRATCH_MNT)
pagesize=$(get_page_size)
blocksize=$(_get_block_size $SCRATCH_MNT)