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")
14 mnt=$TEST_DIR/$seq.mnt
15 # Override the default cleanup function.
18 rm -rf $mnt > /dev/null 2>&1
23 # Import common functions.
26 # real QA test starts here
28 _require_scratch_dev_pool 2
29 _scratch_dev_pool_get 2
31 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
32 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
34 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
36 rm -rf $mnt > /dev/null 2>&1
41 [[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
42 _fail "mounted device changed"
44 for sb_bytenr in 65536 67108864; do
45 echo -n "dd status=none if=$dev_foo of=$dev_bar bs=1 "\
46 "seek=$sb_bytenr skip=$sb_bytenr count=4096" >> $seqres.full
47 dd status=none if=$device_1 of=$device_2 bs=1 seek=$sb_bytenr \
48 skip=$sb_bytenr count=4096 > /dev/null 2>&1
49 echo ..:$? >> $seqres.full
52 # Original device is mounted, scan of its clone should fail
53 $BTRFS_UTIL_PROG device scan $device_2 >> $seqres.full 2>&1
54 [[ $? != 1 ]] && _fail "cloned device scan should fail"
56 [[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
57 _fail "mounted device changed"
59 # Original device scan should be successful
60 $BTRFS_UTIL_PROG device scan $device_1 >> $seqres.full 2>&1
62 _fail "if it fails here, then it means subvolume mount at boot may fail "\
65 $UMOUNT_PROG $mnt > /dev/null 2>&1
69 echo "Silence is golden"