On 04/11/2018 11:41 PM, David Sterba wrote:
On Wed, Apr 11, 2018 at 03:03:30PM +0800, Su Yue wrote:
This tests is most similar to xfstests generic/405.
It calls device mapper to create a thin provision device with small
backing size and big virtual size. mkfs.btrfs should fail on such

This test should pass after commit e805b143a4fe
("btrfs-progs: mkfs: return nozero value on thin provisioned device").

Signed-off-by: Su Yue <suy.f...@cn.fujitsu.com>

Thanks, test looks good overall, a few comments below.

Thanks, V2 has been sent.

  .../test.sh                                   | 93 +++++++++++++++++++
  1 file changed, 93 insertions(+)
  create mode 100755 

diff --git 
new file mode 100755
index 000000000000..f2e044da5d17
--- /dev/null
+++ b/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh
@@ -0,0 +1,93 @@
+# mkfs.btrfs must failed on a thin provision device with very small
+# backing size and big virtual size.
+source "$TEST_TOP/common"
+check_prereq mkfs.btrfs
+# Backing data dev

Please add some prefix to avoid any collisions, eg.
'btrfs-progs-thin-data'. It's easier to spot in logs or device listings
if eg. the test fails and the device needs to be removed manually.

+# Backing metadata dev
+# Backing pool dev (combination of above)
+# Thin volume
+       # wait for device to be fully settled
+       run_check $SUDO_HELPER udevadm settle
+       run_check $SUDO_HELPER dmsetup remove $DMTHIN_VOL_NAME
+       run_check $SUDO_HELPER dmsetup remove $DMTHIN_POOL_NAME
+       run_check $SUDO_HELPER dmsetup remove $DMTHIN_META_NAME
+       run_check $SUDO_HELPER dmsetup remove $DMTHIN_DATA_NAME

Missing quotes around the DMTHIN_* variables.

+sector_size=512                  # in bytes
+data_dev_size=$((1 * 1024 * 1024 / $sector_size))   # 1M
+virtual_size=$((1 * 1024 * 1024 * 1024 * 1024 / $sector_size))  # 1T
+cluster_size=1024        # 512k in sectors
+low_water=$((104857600 / $cluster_size/ $sector_size))  # 100M / 
$cluster_size, in sectors
+# Need to make linear metadata and data devs.  From kernel docs:
+# As a guide, we suggest you calculate the number of bytes to use in the
+# metadata device as 48 * $data_dev_size / $data_block_size but round it up
+# to 2MB (4096 sectors) if the answer is smaller.
+# So do that:
+meta_dev_size=$((48 * $data_dev_size / $cluster_size))
+if [ "$meta_dev_size" -lt "4096" ]; then
+        meta_dev_size=4096      # 2MB
+total_data_dev_size=$(($meta_dev_offset + $meta_dev_size + $data_dev_size))
+run_check truncate -s0 img
+chmod a+w img
+run_check truncate -s"$(($total_data_dev_size * $sector_size))" img
+dm_backing_dev=`run_check_stdout $SUDO_HELPER losetup --find --show img`
+# Metadata device
+DMTHIN_META_TABLE="0 $meta_dev_size linear $dm_backing_dev $meta_dev_offset"
+run_check $SUDO_HELPER dmsetup create $DMTHIN_META_NAME --table 
+# Data device
+data_dev_offset=$((meta_dev_offset + $meta_dev_size))
+DMTHIN_DATA_TABLE="0 $data_dev_size linear $dm_backing_dev $data_dev_offset"
+run_check $SUDO_HELPER dmsetup create $DMTHIN_DATA_NAME --table 
+# Zap the pool metadata dev
+run_check dd if=/dev/zero of=$DMTHIN_META_DEV bs=4096 count=1
+# Thin pool
+# "start length thin-pool metadata_dev data_dev data_block_size low_water_mark"
$cluster_size $low_water"
+run_check $SUDO_HELPER dmsetup create $DMTHIN_POOL_NAME --table 
+# Thin volume
+run_check $SUDO_HELPER dmsetup message $DMTHIN_POOL_DEV 0 "create_thin 
+# start length thin pool_dev dev_id [external_origin_dev]
+DMTHIN_VOL_TABLE="0 $virtual_size thin $DMTHIN_POOL_DEV $pool_id"
+run_check $SUDO_HELPER dmsetup create $DMTHIN_VOL_NAME --table 
+# mkfs.btrfs should fail due to the small backing device
+run_mustfail "should fail for samll backing size thin provision device" \
+            $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$DMTHIN_VOL_DEV"

What does $@ mean here? This would pass arguments from the script
itself, but we don't pass any.

+run_mayfail $SUDO_HELPER losetup -d $dm_backing_dev
+run_check truncate -s0 img
+rm img

To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to