43a831cddfa38a178ce2f41bac48638f4ba7f122
[xfstests-dev.git] / tests / btrfs / 053
1 #! /bin/bash
2 # FS QA Test No. btrfs/053
3 #
4 # Verify that btrfs send is able to replicate xattrs larger than PATH_MAX.
5 # This is possible if the b+tree leaf size is larger than 4Kb (mkfs.btrfs's
6 # default is max(16Kb, PAGE_SIZE) as of btrfs-progs v3.12, and max(4Kb,
7 # PAGE_SIZE in older versions).
8 #
9 # This issue is fixed by the following linux kernel btrfs patch:
10 #
11 #   Btrfs: send, use the right limits for xattr names and values
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41     rm -fr $send_files_dir
42     rm -fr $tmp
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/attr
49
50 # real QA test starts here
51 _supported_fs btrfs
52 _supported_os Linux
53 _require_test
54 _require_scratch
55 _require_fssum
56 _require_attrs
57 _need_to_be_root
58
59 # max(16384, PAGE_SIZE) is the default leaf/node size on btrfs-progs v3.12+.
60 # Older versions just use max(4096, PAGE_SIZE).
61 # mkfs.btrfs can't create an fs with a leaf/node size smaller than PAGE_SIZE.
62 leaf_size=$(echo -e "16384\n`getconf PAGE_SIZE`" | sort -nr | head -1)
63
64 send_files_dir=$TEST_DIR/btrfs-test-$seq
65
66 rm -f $seqres.full
67 rm -fr $send_files_dir
68 mkdir $send_files_dir
69
70 _scratch_mkfs "-l $leaf_size" >/dev/null 2>&1
71 _scratch_mount
72
73 echo "hello world" > $SCRATCH_MNT/foobar
74
75 $SETFATTR_PROG -n user.xattr_name_1 -v `$PERL_PROG -e 'print "A" x 6000;'` \
76         $SCRATCH_MNT/foobar
77
78 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
79 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
80
81 # Update existing xattr value and add a new xattr too.
82 $SETFATTR_PROG -n user.xattr_name_1 -v `$PERL_PROG -e 'print "Z" x 6666;'` \
83         $SCRATCH_MNT/foobar
84 $SETFATTR_PROG -n user.xattr_name_2 -v `$PERL_PROG -e 'print "U" x 5555;'` \
85         $SCRATCH_MNT/foobar
86
87 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
88 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
89         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
90
91 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
92 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
93         -f $send_files_dir/2.snap
94
95 _scratch_unmount
96 _check_scratch_fs
97
98 _scratch_mkfs "-l $leaf_size" >/dev/null 2>&1
99 _scratch_mount
100
101 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
102 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
103
104 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
105 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
106
107 status=0
108 exit