Skip to contentSkip to conversation

fstests: btrfs: make nospace_cache related test cases to work with latest v2 cache

PATCH Superseded Qu Wenruo 5 participants 7 messages Nov 10, 2021 – Nov 14, 2021 Btrfs file system

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v3 1/1 fstests: btrfs: make nospace_cache related test cases to work with latest v2 cache

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
 common/btrfs    | 11 +++++++++++
 tests/btrfs/102 |  2 +-
 tests/btrfs/140 |  5 ++---
 tests/btrfs/141 |  5 ++---
 tests/btrfs/142 |  5 ++---
 tests/btrfs/143 |  5 ++---
 tests/btrfs/151 |  4 ++--
 tests/btrfs/157 |  7 +++----
 tests/btrfs/158 |  7 +++----
 tests/btrfs/170 |  4 ++--
 tests/btrfs/199 |  4 ++--
 tests/btrfs/215 |  2 +-
 12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +11 -0
index ac880bdd..e21c452c 100644
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
 	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
 	return 1
 }
+
+_scratch_no_v1_cache_opt()
+{
+	_require_btrfs_command inspect-internal dump-tree
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +1 -1
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
 # 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 $(_scratch_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
tests/btrfs/140 +2 -3
index 5a5f828c..77d1cab9 100755
@@ -60,9 +60,8 @@ echo "step 1......mkfs.btrfs" >>$seqres.full
 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
+# makes sure data is written to the start position of the data chunk
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/141 +2 -3
index cf0979e9..9bde0977 100755
@@ -59,9 +59,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/142 +2 -3
index 1318be0f..ffe298d6 100755
@@ -37,9 +37,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/143 +2 -3
index 6736dcad..1f55cded 100755
@@ -44,9 +44,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/151 +2 -2
index 099e85cc..b343271f 100755
@@ -31,8 +31,8 @@ _scratch_dev_pool_get 3
 # 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 need to disable v1 cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 # if data chunk is empty, 'btrfs device remove' can change raid1 to
 # single.
tests/btrfs/157 +3 -4
index 0cfe3ce5..e779e33a 100755
@@ -64,9 +64,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_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" \
@@ -94,7 +93,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
 # step 3: read foobar to repair the bitrot
 echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
 od -x -j 64K $SCRATCH_MNT/foobar
tests/btrfs/158 +3 -4
index ad374eba..52d67001 100755
@@ -56,9 +56,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_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" \
@@ -85,7 +84,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
 # step 3: scrub filesystem to repair the bitrot
 echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
 
tests/btrfs/170 +2 -2
index 15382eb3..3efe085d 100755
@@ -27,9 +27,9 @@ _require_xfs_io_command "falloc" "-k"
 fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
 
-# Mount without space cache so that we can precisely fill all data space and
+# Mount without v1 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 $(_scratch_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
tests/btrfs/199 +2 -2
index 6aca62f4..7fa678e7 100755
@@ -67,7 +67,7 @@ loop_dev=$(_create_loop_device "$loop_file")
 loop_mnt=$tmp/loop_mnt
 
 mkdir -p $loop_mnt
-# - nospace_cache
+# - _scratch_no_v1_cache_opt
 #   Since v1 cache using DATA space, it can break data extent bytenr
 #   continuousness.
 # - nodatasum
@@ -75,7 +75,7 @@ mkdir -p $loop_mnt
 #   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 -o nodatasum,discard $(_scratch_no_v1_cache_opt) $loop_dev $loop_mnt
 
 # Craft the following extent layout:
 #         |  BG1 |      BG2        |       BG3            |
tests/btrfs/215 +1 -1
index fa622568..d62b2ff6 100755
@@ -30,7 +30,7 @@ _require_non_zoned_device $SCRATCH_DEV
 _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 $(_scratch_no_v1_cache_opt)
 
 pagesize=$(get_page_size)
 blocksize=$(_get_block_size $SCRATCH_MNT)
Signature · 1 line
2.33.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 20 lines · Qu Wenruo

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.

Quoted 6 lines

Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

Looks good.

Quoted 228 lines
---
  common/btrfs    | 11 +++++++++++
  tests/btrfs/102 |  2 +-
  tests/btrfs/140 |  5 ++---
  tests/btrfs/141 |  5 ++---
  tests/btrfs/142 |  5 ++---
  tests/btrfs/143 |  5 ++---
  tests/btrfs/151 |  4 ++--
  tests/btrfs/157 |  7 +++----
  tests/btrfs/158 |  7 +++----
  tests/btrfs/170 |  4 ++--
  tests/btrfs/199 |  4 ++--
  tests/btrfs/215 |  2 +-
  12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +11 -0
index ac880bdd..e21c452c 100644
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
  	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
  	return 1
  }
+
+_scratch_no_v1_cache_opt()
+{
+	_require_btrfs_command inspect-internal dump-tree
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +1 -1
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
  # 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 $(_scratch_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
tests/btrfs/140 +2 -3
index 5a5f828c..77d1cab9 100755
@@ -60,9 +60,8 @@ echo "step 1......mkfs.btrfs" >>$seqres.full
  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
+# makes sure data is written to the start position of the data chunk
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/141 +2 -3
index cf0979e9..9bde0977 100755
@@ -59,9 +59,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/142 +2 -3
index 1318be0f..ffe298d6 100755
@@ -37,9 +37,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/143 +2 -3
index 6736dcad..1f55cded 100755
@@ -44,9 +44,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/151 +2 -2
index 099e85cc..b343271f 100755
@@ -31,8 +31,8 @@ _scratch_dev_pool_get 3
  # 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 need to disable v1 cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  # if data chunk is empty, 'btrfs device remove' can change raid1 to
  # single.
tests/btrfs/157 +3 -4
index 0cfe3ce5..e779e33a 100755
@@ -64,9 +64,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_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" \
@@ -94,7 +93,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
  # step 3: read foobar to repair the bitrot
  echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
  od -x -j 64K $SCRATCH_MNT/foobar
tests/btrfs/158 +3 -4
index ad374eba..52d67001 100755
@@ -56,9 +56,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_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" \
@@ -85,7 +84,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
  # step 3: scrub filesystem to repair the bitrot
  echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
 
tests/btrfs/170 +2 -2
index 15382eb3..3efe085d 100755
@@ -27,9 +27,9 @@ _require_xfs_io_command "falloc" "-k"
  fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
  _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
 
-# Mount without space cache so that we can precisely fill all data space and
+# Mount without v1 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 $(_scratch_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
tests/btrfs/199 +2 -2
index 6aca62f4..7fa678e7 100755
@@ -67,7 +67,7 @@ loop_dev=$(_create_loop_device "$loop_file")
  loop_mnt=$tmp/loop_mnt
 
  mkdir -p $loop_mnt
-# - nospace_cache
+# - _scratch_no_v1_cache_opt
  #   Since v1 cache using DATA space, it can break data extent bytenr
  #   continuousness.
  # - nodatasum
@@ -75,7 +75,7 @@ mkdir -p $loop_mnt
  #   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 -o nodatasum,discard $(_scratch_no_v1_cache_opt) $loop_dev $loop_mnt
 
  # Craft the following extent layout:
  #         |  BG1 |      BG2        |       BG3            |
tests/btrfs/215 +1 -1
index fa622568..d62b2ff6 100755
@@ -30,7 +30,7 @@ _require_non_zoned_device $SCRATCH_DEV
  _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 $(_scratch_no_v1_cache_opt)
 
  pagesize=$(get_page_size)
  blocksize=$(_get_block_size $SCRATCH_MNT)
#2 lore raw
In reply to Qu Wenruo
Quoted 47 lines · Qu Wenruo

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
 common/btrfs    | 11 +++++++++++
 tests/btrfs/102 |  2 +-
 tests/btrfs/140 |  5 ++---
 tests/btrfs/141 |  5 ++---
 tests/btrfs/142 |  5 ++---
 tests/btrfs/143 |  5 ++---
 tests/btrfs/151 |  4 ++--
 tests/btrfs/157 |  7 +++----
 tests/btrfs/158 |  7 +++----
 tests/btrfs/170 |  4 ++--
 tests/btrfs/199 |  4 ++--
 tests/btrfs/215 |  2 +-
 12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +0 -0
index ac880bdd..e21c452c 100644

common/btrfs _scratch_btrfs_is_zoned() · line 449

Quoted 5 lines
common/btrfs +2 -0
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
 	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
 	return 1
 }
+
+_scratch_no_v1_cache_opt()

This name indicates it's a general helper, but it's btrfs-specific, how about _scratch_btrfs_no_v1_cache_opt ?

common/btrfs _scratch_btrfs_is_zoned() · line 451

Quoted 2 lines
common/btrfs +2 -0
+{
+	_require_btrfs_command inspect-internal dump-tree

This will call _notrun if btrfs command doesn't have inspect-internal dump-tree sub-command, and _notrun will call exit, but ...

Quoted 12 lines
common/btrfs +7 -0
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +0 -0
index e5a1b068..c1678b5d 100755

tests/btrfs/102 _scratch_mkfs >>$seqres.full 2>&1 · line 25

Quoted 5 lines
tests/btrfs/102 +1 -1
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
 # 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 $(_scratch_no_v1_cache_opt)

_scratch_no_v1_cache_opt is called in a sub-shell, so the _notrun will just exit the sub-shell, not the test itself. Should call the _require rule in test.

Thanks,
Eryu

Quoted 185 lines
tests/btrfs/102 +0 -0
 # 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
tests/btrfs/140 +2 -3
index 5a5f828c..77d1cab9 100755
@@ -60,9 +60,8 @@ echo "step 1......mkfs.btrfs" >>$seqres.full
 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
+# makes sure data is written to the start position of the data chunk
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/141 +2 -3
index cf0979e9..9bde0977 100755
@@ -59,9 +59,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/142 +2 -3
index 1318be0f..ffe298d6 100755
@@ -37,9 +37,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/143 +2 -3
index 6736dcad..1f55cded 100755
@@ -44,9 +44,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_no_v1_cache_opt)
 
 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
 	_filter_xfs_io_offset
tests/btrfs/151 +2 -2
index 099e85cc..b343271f 100755
@@ -31,8 +31,8 @@ _scratch_dev_pool_get 3
 # 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 need to disable v1 cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 # if data chunk is empty, 'btrfs device remove' can change raid1 to
 # single.
tests/btrfs/157 +3 -4
index 0cfe3ce5..e779e33a 100755
@@ -64,9 +64,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_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" \
@@ -94,7 +93,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
 # step 3: read foobar to repair the bitrot
 echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
 od -x -j 64K $SCRATCH_MNT/foobar
tests/btrfs/158 +3 -4
index ad374eba..52d67001 100755
@@ -56,9 +56,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
 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 $(_scratch_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" \
@@ -85,7 +84,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
 # step 3: scrub filesystem to repair the bitrot
 echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
 
tests/btrfs/170 +2 -2
index 15382eb3..3efe085d 100755
@@ -27,9 +27,9 @@ _require_xfs_io_command "falloc" "-k"
 fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
 
-# Mount without space cache so that we can precisely fill all data space and
+# Mount without v1 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 $(_scratch_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
tests/btrfs/199 +2 -2
index 6aca62f4..7fa678e7 100755
@@ -67,7 +67,7 @@ loop_dev=$(_create_loop_device "$loop_file")
 loop_mnt=$tmp/loop_mnt
 
 mkdir -p $loop_mnt
-# - nospace_cache
+# - _scratch_no_v1_cache_opt
 #   Since v1 cache using DATA space, it can break data extent bytenr
 #   continuousness.
 # - nodatasum
@@ -75,7 +75,7 @@ mkdir -p $loop_mnt
 #   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 -o nodatasum,discard $(_scratch_no_v1_cache_opt) $loop_dev $loop_mnt
 
 # Craft the following extent layout:
 #         |  BG1 |      BG2        |       BG3            |
tests/btrfs/215 +1 -1
index fa622568..d62b2ff6 100755
@@ -30,7 +30,7 @@ _require_non_zoned_device $SCRATCH_DEV
 _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 $(_scratch_no_v1_cache_opt)
 
 pagesize=$(get_page_size)
 blocksize=$(_get_block_size $SCRATCH_MNT)
Signature · 1 line
2.33.0
#3 lore raw
Quoted 76 lines · Eryu Guan
Quoted 47 lines · Qu Wenruo

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
  common/btrfs    | 11 +++++++++++
  tests/btrfs/102 |  2 +-
  tests/btrfs/140 |  5 ++---
  tests/btrfs/141 |  5 ++---
  tests/btrfs/142 |  5 ++---
  tests/btrfs/143 |  5 ++---
  tests/btrfs/151 |  4 ++--
  tests/btrfs/157 |  7 +++----
  tests/btrfs/158 |  7 +++----
  tests/btrfs/170 |  4 ++--
  tests/btrfs/199 |  4 ++--
  tests/btrfs/215 |  2 +-
  12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +0 -0
index ac880bdd..e21c452c 100644

common/btrfs _scratch_btrfs_is_zoned() · line 449

Quoted 5 lines
common/btrfs +2 -0
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
  	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
  	return 1
  }
+
+_scratch_no_v1_cache_opt()

This name indicates it's a general helper, but it's btrfs-specific, how about _scratch_btrfs_no_v1_cache_opt ?

common/btrfs _scratch_btrfs_is_zoned() · line 451

Quoted 2 lines
common/btrfs +2 -0
+{
+	_require_btrfs_command inspect-internal dump-tree

This will call _notrun if btrfs command doesn't have inspect-internal dump-tree sub-command, and _notrun will call exit, but ...

Quoted 13 lines
common/btrfs +7 -0
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +0 -0
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
  # Mount our filesystem without space caches enabled so that we do not get any
Quoted 8 lines

tests/btrfs/102 _scratch_mkfs >>$seqres.full 2>&1 · line 25

Quoted 4 lines
tests/btrfs/102 +1 -1
  # 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 $(_scratch_no_v1_cache_opt)

_scratch_no_v1_cache_opt is called in a sub-shell, so the _notrun will just exit the sub-shell, not the test itself. Should call the _require rule in test.

That means we will have a hard dependency on binding _scratch_btrfs_no_v1_cache_opt() with _require rule then.

Then a sudden "_require_btrfs_command inspect-internal dump-tree" without context could be sometimes confusing AFAIK.

Considering "inspect-internal" should be in btrfs-progs for a very long time, any non-EOF distro should have them already, can we just remove the _require rule?

Thanks,
Qu

Quoted 189 lines

Thanks,
Eryu

Quoted 185 lines
tests/btrfs/102 +0 -0
  # 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
tests/btrfs/140 +2 -3
index 5a5f828c..77d1cab9 100755
@@ -60,9 +60,8 @@ echo "step 1......mkfs.btrfs" >>$seqres.full
  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
+# makes sure data is written to the start position of the data chunk
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/141 +2 -3
index cf0979e9..9bde0977 100755
@@ -59,9 +59,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/142 +2 -3
index 1318be0f..ffe298d6 100755
@@ -37,9 +37,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/143 +2 -3
index 6736dcad..1f55cded 100755
@@ -44,9 +44,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_no_v1_cache_opt)
 
  $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -b 128K 0 128K" "$SCRATCH_MNT/foobar" |\
  	_filter_xfs_io_offset
tests/btrfs/151 +2 -2
index 099e85cc..b343271f 100755
@@ -31,8 +31,8 @@ _scratch_dev_pool_get 3
  # 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 need to disable v1 cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  # if data chunk is empty, 'btrfs device remove' can change raid1 to
  # single.
tests/btrfs/157 +3 -4
index 0cfe3ce5..e779e33a 100755
@@ -64,9 +64,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_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" \
@@ -94,7 +93,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
  # step 3: read foobar to repair the bitrot
  echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
  od -x -j 64K $SCRATCH_MNT/foobar
tests/btrfs/158 +3 -4
index ad374eba..52d67001 100755
@@ -56,9 +56,8 @@ _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
  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 $(_scratch_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" \
@@ -85,7 +84,7 @@ $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
 
  # step 3: scrub filesystem to repair the bitrot
  echo "step 3......repair the bitrot" >> $seqres.full
-_scratch_mount -o nospace_cache
+_scratch_mount $(_scratch_no_v1_cache_opt)
 
  $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
 
tests/btrfs/170 +2 -2
index 15382eb3..3efe085d 100755
@@ -27,9 +27,9 @@ _require_xfs_io_command "falloc" "-k"
  fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
  _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
 
-# Mount without space cache so that we can precisely fill all data space and
+# Mount without v1 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 $(_scratch_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
tests/btrfs/199 +2 -2
index 6aca62f4..7fa678e7 100755
@@ -67,7 +67,7 @@ loop_dev=$(_create_loop_device "$loop_file")
  loop_mnt=$tmp/loop_mnt
 
  mkdir -p $loop_mnt
-# - nospace_cache
+# - _scratch_no_v1_cache_opt
  #   Since v1 cache using DATA space, it can break data extent bytenr
  #   continuousness.
  # - nodatasum
@@ -75,7 +75,7 @@ mkdir -p $loop_mnt
  #   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 -o nodatasum,discard $(_scratch_no_v1_cache_opt) $loop_dev $loop_mnt
 
  # Craft the following extent layout:
  #         |  BG1 |      BG2        |       BG3            |
tests/btrfs/215 +1 -2
index fa622568..d62b2ff6 100755
@@ -30,7 +30,7 @@ _require_non_zoned_device $SCRATCH_DEV
  _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 $(_scratch_no_v1_cache_opt)
 
  pagesize=$(get_page_size)
  blocksize=$(_get_block_size $SCRATCH_MNT)
--

2.33.0

#4 lore raw
Quoted 88 lines · Qu Wenruo
Quoted 76 lines · Eryu Guan
Quoted 47 lines · Qu Wenruo

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
 common/btrfs    | 11 +++++++++++
 tests/btrfs/102 |  2 +-
 tests/btrfs/140 |  5 ++---
 tests/btrfs/141 |  5 ++---
 tests/btrfs/142 |  5 ++---
 tests/btrfs/143 |  5 ++---
 tests/btrfs/151 |  4 ++--
 tests/btrfs/157 |  7 +++----
 tests/btrfs/158 |  7 +++----
 tests/btrfs/170 |  4 ++--
 tests/btrfs/199 |  4 ++--
 tests/btrfs/215 |  2 +-
 12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +0 -0
index ac880bdd..e21c452c 100644

common/btrfs _scratch_btrfs_is_zoned() · line 449

Quoted 5 lines
common/btrfs +2 -0
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
 	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
 	return 1
 }
+
+_scratch_no_v1_cache_opt()

This name indicates it's a general helper, but it's btrfs-specific, how about _scratch_btrfs_no_v1_cache_opt ?

common/btrfs _scratch_btrfs_is_zoned() · line 451

Quoted 2 lines
common/btrfs +2 -0
+{
+	_require_btrfs_command inspect-internal dump-tree

This will call _notrun if btrfs command doesn't have inspect-internal dump-tree sub-command, and _notrun will call exit, but ...

Quoted 13 lines
common/btrfs +7 -0
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +0 -0
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
 # Mount our filesystem without space caches enabled so that we do not get any
Quoted 8 lines

tests/btrfs/102 _scratch_mkfs >>$seqres.full 2>&1 · line 25

Quoted 4 lines
tests/btrfs/102 +1 -1
 # 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 $(_scratch_no_v1_cache_opt)

_scratch_no_v1_cache_opt is called in a sub-shell, so the _notrun will just exit the sub-shell, not the test itself. Should call the _require rule in test.

Quoted 5 lines

That means we will have a hard dependency on binding _scratch_btrfs_no_v1_cache_opt() with _require rule then.

Then a sudden "_require_btrfs_command inspect-internal dump-tree" without context could be sometimes confusing AFAIK.

That's true.

Quoted 4 lines

Considering "inspect-internal" should be in btrfs-progs for a very long time, any non-EOF distro should have them already, can we just remove the _require rule?

It seems like that dump-tree sub-command was added in 2016 in v4.5, so I guess I'm fine with it.

Thanks,
Eryu

author
#5 lore raw
Quoted 98 lines · Eryu Guan
Quoted 88 lines · Qu Wenruo
Quoted 76 lines · Eryu Guan
Quoted 47 lines · Qu Wenruo

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
  common/btrfs    | 11 +++++++++++
  tests/btrfs/102 |  2 +-
  tests/btrfs/140 |  5 ++---
  tests/btrfs/141 |  5 ++---
  tests/btrfs/142 |  5 ++---
  tests/btrfs/143 |  5 ++---
  tests/btrfs/151 |  4 ++--
  tests/btrfs/157 |  7 +++----
  tests/btrfs/158 |  7 +++----
  tests/btrfs/170 |  4 ++--
  tests/btrfs/199 |  4 ++--
  tests/btrfs/215 |  2 +-
  12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +0 -0
index ac880bdd..e21c452c 100644

common/btrfs _scratch_btrfs_is_zoned() · line 449

Quoted 5 lines
common/btrfs +2 -0
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
  	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
  	return 1
  }
+
+_scratch_no_v1_cache_opt()

This name indicates it's a general helper, but it's btrfs-specific, how about _scratch_btrfs_no_v1_cache_opt ?

common/btrfs _scratch_btrfs_is_zoned() · line 451

Quoted 2 lines
common/btrfs +2 -0
+{
+	_require_btrfs_command inspect-internal dump-tree

This will call _notrun if btrfs command doesn't have inspect-internal dump-tree sub-command, and _notrun will call exit, but ...

Quoted 13 lines
common/btrfs +7 -0
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +0 -0
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
  # Mount our filesystem without space caches enabled so that we do not get any
Quoted 8 lines

tests/btrfs/102 _scratch_mkfs >>$seqres.full 2>&1 · line 25

Quoted 4 lines
tests/btrfs/102 +1 -1
  # 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 $(_scratch_no_v1_cache_opt)

_scratch_no_v1_cache_opt is called in a sub-shell, so the _notrun will just exit the sub-shell, not the test itself. Should call the _require rule in test.

Quoted 5 lines

That means we will have a hard dependency on binding _scratch_btrfs_no_v1_cache_opt() with _require rule then.

Then a sudden "_require_btrfs_command inspect-internal dump-tree" without context could be sometimes confusing AFAIK.

That's true.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

Considering "inspect-internal" should be in btrfs-progs for a very long time, any non-EOF distro should have them already, can we just remove the _require rule?

It seems like that dump-tree sub-command was added in 2016 in v4.5, so I guess I'm fine with it.

Mind to remove the _require rule at merge time?
Or do I need to resend?

Thanks,
Qu

Quoted 4 lines

Thanks,
Eryu

#6 lore raw
Quoted 105 lines · Qu Wenruo
Quoted 102 lines · Eryu Guan
Quoted 88 lines · Qu Wenruo
Quoted 76 lines · Eryu Guan
Quoted 47 lines · Qu Wenruo

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.

---
Changelog:
v2:
- Add _scratch_no_v1_cache_opt() function
v3:
- Add _require_btrfs_command for _scratch_no_v1_cache_opt()

---
  common/btrfs    | 11 +++++++++++
  tests/btrfs/102 |  2 +-
  tests/btrfs/140 |  5 ++---
  tests/btrfs/141 |  5 ++---
  tests/btrfs/142 |  5 ++---
  tests/btrfs/143 |  5 ++---
  tests/btrfs/151 |  4 ++--
  tests/btrfs/157 |  7 +++----
  tests/btrfs/158 |  7 +++----
  tests/btrfs/170 |  4 ++--
  tests/btrfs/199 |  4 ++--
  tests/btrfs/215 |  2 +-
  12 files changed, 33 insertions(+), 28 deletions(-)
common/btrfs +0 -0
index ac880bdd..e21c452c 100644

common/btrfs _scratch_btrfs_is_zoned() · line 449

Quoted 5 lines
common/btrfs +2 -0
@@ -445,3 +445,14 @@ _scratch_btrfs_is_zoned()
  	[ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0
  	return 1
  }
+
+_scratch_no_v1_cache_opt()

This name indicates it's a general helper, but it's btrfs-specific, how about _scratch_btrfs_no_v1_cache_opt ?

common/btrfs _scratch_btrfs_is_zoned() · line 451

Quoted 2 lines
common/btrfs +2 -0
+{
+	_require_btrfs_command inspect-internal dump-tree

This will call _notrun if btrfs command doesn't have inspect-internal dump-tree sub-command, and _notrun will call exit, but ...

Quoted 13 lines
common/btrfs +7 -0
+
+	if $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV |\
+	   grep -q "FREE_SPACE_TREE"; then
+		return
+	fi
+	echo -n "-onospace_cache"
+}
tests/btrfs/102 +0 -0
index e5a1b068..c1678b5d 100755
@@ -22,7 +22,7 @@ _scratch_mkfs >>$seqres.full 2>&1
  # Mount our filesystem without space caches enabled so that we do not get any
Quoted 8 lines

tests/btrfs/102 _scratch_mkfs >>$seqres.full 2>&1 · line 25

Quoted 4 lines
tests/btrfs/102 +1 -1
  # 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 $(_scratch_no_v1_cache_opt)

_scratch_no_v1_cache_opt is called in a sub-shell, so the _notrun will just exit the sub-shell, not the test itself. Should call the _require rule in test.

Quoted 5 lines

That means we will have a hard dependency on binding _scratch_btrfs_no_v1_cache_opt() with _require rule then.

Then a sudden "_require_btrfs_command inspect-internal dump-tree" without context could be sometimes confusing AFAIK.

That's true.

Quoted 4 lines

Considering "inspect-internal" should be in btrfs-progs for a very long time, any non-EOF distro should have them already, can we just remove the _require rule?

Quoted 5 lines
Quoted 2 lines

It seems like that dump-tree sub-command was added in 2016 in v4.5, so I guess I'm fine with it.

Mind to remove the _require rule at merge time?
Or do I need to resend?

A new version is preferred, as it's not only delete the _require rule, but also needs a function rename, and a rebase against latest master branch. The patch currently doesn't apply due to conflit.

Thanks,
Eryu