fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 432
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 432
6 #
7 # Ensure that metadump copies large directory extents
8 #
9 # Metadump helpfully discards directory (and xattr) extents that are
10 # longer than 1000 blocks.  This is a little silly since a hardlink farm
11 # can easily create such a monster.
12 #
13 # Now that we've upped metadump's default too-long-extent discard
14 # threshold to 2^21 blocks, make sure we never do that again.
15 #
16 . ./common/preamble
17 _begin_fstest auto quick dir metadata
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22         cd /
23         rm -f "$tmp".* $metadump_file $metadump_img
24 }
25
26 # Import common functions.
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs xfs
31 _require_scratch
32
33 rm -f "$seqres.full"
34
35 echo "Format and mount"
36 # We need to create a directory with a huuuge extent record.  Normally
37 # a rapidly expanding directory gets its blocks allocated in lockstep --
38 # physically we end up writing (a couple of dir data blocks) followed by
39 # (a da btree block) over and over.
40 #
41 # Therefore, we crank the directory block size up to maximum and the
42 # filesystem down to minimum so that we have to allocate 64 blocks at
43 # a time, trying to end up with the result that we have > 1000 blocks
44 # allocated in a single extent.
45 #
46 # In theory the math works out here -- ~65500 bytes for a da leaf block /
47 # 8 bytes per da leaf entry == ~8187 hash entries for a da node.  65500
48 # bytes for a dir data block / 264 bytes per dirent == ~248 dirents per
49 # block.  8187 hashes/dablk / 248 dirents/dirblock = ~33 dirblocks per
50 # dablock.  33 dirblocks * 64k mean that we can expand a directory by
51 # 2112k before we have to allocate another da btree block.
52 _scratch_mkfs -b size=1k -n size=64k > "$seqres.full" 2>&1
53 _scratch_mount >> "$seqres.full" 2>&1
54
55 metadump_file="$TEST_DIR/meta-$seq"
56 metadump_img="$TEST_DIR/img-$seq"
57 rm -f $metadump_file $metadump_img
58 testdir="$SCRATCH_MNT/test-$seq"
59 max_fname_len=255
60 blksz=$(_get_block_size $SCRATCH_MNT)
61
62 # Try to create a directory w/ extents
63 blocks=1050
64 names=$((blocks * (blksz / max_fname_len)))
65 echo "Create huge dir"
66 mkdir -p $testdir
67 touch $SCRATCH_MNT/a
68 seq 0 $names | while read f; do
69         name="$testdir/$(printf "%0${max_fname_len}d" $f)"
70         ln $SCRATCH_MNT/a $name
71 done
72 dir_inum=$(stat -c %i $testdir)
73
74 echo "Check for > 1000 block extent?"
75 _scratch_unmount
76 check_for_long_extent() {
77         inum=$1
78
79         _scratch_xfs_db -x -c "inode $dir_inum" -c bmap | \
80                 sed -e 's/^.*count \([0-9]*\) flag.*$/\1/g' | \
81                 awk '{if ($1 > 1000) { printf("yes, %d\n", $1); } }'
82 }
83 extlen="$(check_for_long_extent $dir_inum)"
84 echo "qualifying extent: $extlen blocks" >> $seqres.full
85 test -n "$extlen" || _notrun "could not create dir extent > 1000 blocks"
86
87 echo "Try to metadump"
88 _scratch_xfs_metadump $metadump_file -w
89 xfs_mdrestore $metadump_file $metadump_img
90
91 echo "Check restored metadump image"
92 $XFS_REPAIR_PROG -n $metadump_img >> $seqres.full 2>&1
93
94 # success, all done
95 status=0
96 exit