2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test 074-extsz-hints-vs-maxextlen
7 # Check some extent size hint boundary conditions that can result in
10 # In xfs_bmap_extsize_align(), we had,
11 # if ((temp = (align_alen % extsz))) {
12 # align_alen += extsz - temp;
14 # align_alen had the value of 2097151 (i.e. MAXEXTLEN) blocks. extsz had
15 # the value of 4096 blocks.
17 # align_alen % extsz will be 4095. so align_alen will end up having
18 # 2097151 + (4096 - 4095) = 2097152 i.e. (MAXEXTLEN + 1). Thus the length
19 # of the new extent will be larger than MAXEXTLEN. This will later cause
20 # the bmbt leaf to have an entry whose length is set to zero block count.
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
29 _destroy_loop_device $LOOP_DEV
30 rm -f $tmp.* $LOOP_FILE
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
42 # real QA test starts here
48 _require_xfs_io_command "falloc"
50 # we use loop devices for this so that we can create large files for prealloc
51 # without having to care about the underlying device size.
54 LOOP_FILE=$TEST_DIR/$seq.img
55 LOOP_MNT=$TEST_DIR/$seq.mnt
57 $XFS_IO_PROG -ft -c "truncate 1t" $LOOP_FILE >> $seqres.full
58 LOOP_DEV=`_create_loop_device $LOOP_FILE`
60 _mkfs_dev -d size=260g,agcount=2 $LOOP_DEV
61 _mount $LOOP_DEV $LOOP_MNT
63 BLOCK_SIZE=$(_get_file_block_size $LOOP_MNT)
65 # Corrupt the BMBT by creating extents larger than MAXEXTLEN
66 # For 4k blocksize, MAXEXTLEN * 4k = 2097151 * 4k = 8589930496 = ~8GiB
68 -c "extsize $(($BLOCK_SIZE * 4096))" \
69 -c "falloc 0 $(($BLOCK_SIZE * 2097152))" \
70 $LOOP_MNT/foo >> $seqres.full
73 _check_xfs_filesystem $LOOP_DEV none none
75 _mkfs_dev -f $LOOP_DEV
76 _mount $LOOP_DEV $LOOP_MNT
78 # check we trim both ends of the extent approproiately; this will fail
79 # on 1k block size filesystems without the correct fixes in place.
82 -c "falloc 1023m 2g" \
83 $LOOP_MNT/foo >> $seqres.full
86 _check_xfs_filesystem $LOOP_DEV none none
89 echo "Silence is golden"