2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle. All Rights Reserved.
7 # Fuzzy test for FS image duplication.
9 # a9261d4125c9 ("btrfs: harden agaist duplicate fsid on scanned devices")
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
20 mnt=$TEST_DIR/$seq.mnt
23 rm -rf $mnt > /dev/null 2>&1
28 # get standard environment, filters and checks
32 # remove previous $seqres.full before test
35 # real QA test starts here
38 _require_scratch_dev_pool 2
39 _scratch_dev_pool_get 2
41 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
42 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
44 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
46 rm -rf $mnt > /dev/null 2>&1
51 [[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
52 _fail "mounted device changed"
54 for sb_bytenr in 65536 67108864; do
55 echo -n "dd status=none if=$dev_foo of=$dev_bar bs=1 "\
56 "seek=$sb_bytenr skip=$sb_bytenr count=4096" >> $seqres.full
57 dd status=none if=$device_1 of=$device_2 bs=1 seek=$sb_bytenr \
58 skip=$sb_bytenr count=4096 > /dev/null 2>&1
59 echo ..:$? >> $seqres.full
62 # Original device is mounted, scan of its clone should fail
63 $BTRFS_UTIL_PROG device scan $device_2 >> $seqres.full 2>&1
64 [[ $? != 1 ]] && _fail "cloned device scan should fail"
66 [[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
67 _fail "mounted device changed"
69 # Original device scan should be successful
70 $BTRFS_UTIL_PROG device scan $device_1 >> $seqres.full 2>&1
72 _fail "if it fails here, then it means subvolume mount at boot may fail "\
75 $UMOUNT_PROG $mnt > /dev/null 2>&1
79 echo "Silence is golden"