btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 019
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/019
6 #
7 # btrfs send ENOENT regression test, kernel bugzilla 60673
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 tmp_dir=send_temp_$seq
16
17 status=1        # failure is the default!
18
19 _cleanup()
20 {
21         $BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/snap1 > /dev/null 2>&1
22         $BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/snap2 > /dev/null 2>&1
23         $BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send > /dev/null 2>&1
24         rm -rf $TEST_DIR/$tmp_dir
25         rm -f $tmp.*
26 }
27
28 trap "_cleanup ; exit \$status" 0 1 2 3 15
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35 _supported_fs btrfs
36 _require_test
37 _require_scratch
38
39 _scratch_mkfs > /dev/null 2>&1
40
41 #receive needs to be able to setxattrs, including the selinux context, if we use
42 #the normal nfs context thing it screws up our ability to set the
43 #security.selinux xattrs so we need to disable this for this test
44 export SELINUX_MOUNT_OPTIONS=""
45
46 _scratch_mount
47
48 mkdir $TEST_DIR/$tmp_dir
49 $BTRFS_UTIL_PROG subvolume create $TEST_DIR/$tmp_dir/send \
50         > $seqres.full 2>&1 || _fail "failed subvolume create"
51
52 SEND_TEST_DIR=$TEST_DIR/$tmp_dir/send
53
54 mkdir $SEND_TEST_DIR/test
55 touch $SEND_TEST_DIR/test/baz
56 touch $SEND_TEST_DIR/test/blah
57 mkdir $SEND_TEST_DIR/test/foo
58 touch $SEND_TEST_DIR/test/foo/bar
59
60 $BTRFS_UTIL_PROG subvolume snapshot -r $TEST_DIR/$tmp_dir/send \
61         $TEST_DIR/$tmp_dir/snap1 >> $seqres.full 2>&1 || _fail "failed snap1"
62
63 $BTRFS_UTIL_PROG send -f $TEST_DIR/$tmp_dir/send1.dump \
64         $TEST_DIR/$tmp_dir/snap1 >> $seqres.full 2>&1 || _fail "failed send"
65
66 $BTRFS_UTIL_PROG receive -f $TEST_DIR/$tmp_dir/send1.dump $SCRATCH_MNT \
67         >> $seqres.full 2>&1 || _fail "failed receive"
68
69 #recreate everything exactly the way it was exceptn in a different order so we
70 #get different inode numbers
71 rm -rf $SEND_TEST_DIR/test
72 mkdir $SEND_TEST_DIR/test
73 touch $SEND_TEST_DIR/test/baz
74 mkdir $SEND_TEST_DIR/test/foo
75 touch $SEND_TEST_DIR/test/foo/bar
76 touch $SEND_TEST_DIR/test/blah
77
78 $BTRFS_UTIL_PROG subvolume snapshot -r $TEST_DIR/$tmp_dir/send \
79         $TEST_DIR/$tmp_dir/snap2 >> $seqres.full 2>&1 || _fail "failed snap2"
80
81 $BTRFS_UTIL_PROG send -f $TEST_DIR/$tmp_dir/send2.dump \
82         -p $TEST_DIR/$tmp_dir/snap1 $TEST_DIR/$tmp_dir/snap2 \
83         >> $seqres.full 2>&1 || _fail "failed second send"
84
85 $BTRFS_UTIL_PROG receive -f $TEST_DIR/$tmp_dir/send2.dump $SCRATCH_MNT \
86         >> $seqres.full 2>&1 || _fail "failed second receive"
87
88 echo "Silence is golden"
89 status=0 ; exit