]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
authorZiyang Zhang <ZiyangZhang@linux.alibaba.com>
Mon, 12 Dec 2022 05:56:45 +0000 (13:56 +0800)
committerZorro Lang <zlang@kernel.org>
Tue, 13 Dec 2022 09:14:49 +0000 (17:14 +0800)
Sometimes "$((128 * dblksz / 40))" dirents cannot make sure that
S_IFDIR.FMT_BTREE could become btree format for its DATA fork.

Actually we just observed it can fail after apply our inode
extent-to-btree workaround. The root cause is that the kernel may be
too good at allocating consecutive blocks so that the data fork is
still in extents format.

Therefore instead of using a fixed number, let's make sure the number
of extents is large enough than (inode size - inode core size) /
sizeof(xfs_bmbt_rec_t).

Reviewed-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Suggested-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Ziyang Zhang <ZiyangZhang@linux.alibaba.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/populate
common/xfs

index 6e00499734c7898900fb6267438307e3a590a85d..8f7f21135668b1fbdbe92c6e47a141b0f4fcc8a2 100644 (file)
@@ -71,6 +71,37 @@ __populate_create_dir() {
        done
 }
 
+# Create a large directory and ensure that it's a btree format
+__populate_xfs_create_btree_dir() {
+       local name="$1"
+       local isize="$2"
+       local missing="$3"
+       local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
+       # We need enough extents to guarantee that the data fork is in
+       # btree format.  Cycling the mount to use xfs_db is too slow, so
+       # watch for when the extent count exceeds the space after the
+       # inode core.
+       local max_nextents="$(((isize - icore_size) / 16))"
+       local nr=0
+
+       mkdir -p "${name}"
+       while true; do
+               local creat=mkdir
+               test "$((nr % 20))" -eq 0 && creat=touch
+               $creat "${name}/$(printf "%.08d" "$nr")"
+               if [ "$((nr % 40))" -eq 0 ]; then
+                       local nextents="$(_xfs_get_fsxattr nextents $name)"
+                       [ $nextents -gt $max_nextents ] && break
+               fi
+               nr=$((nr+1))
+       done
+
+       test -z "${missing}" && return
+       seq 1 2 "${nr}" | while read d; do
+               rm -rf "${name}/$(printf "%.08d" "$d")"
+       done
+}
+
 # Add a bunch of attrs to a file
 __populate_create_attr() {
        name="$1"
@@ -176,6 +207,7 @@ _scratch_xfs_populate() {
 
        blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
        dblksz="$(_xfs_get_dir_blocksize "$SCRATCH_MNT")"
+       isize="$(_xfs_get_inode_size "$SCRATCH_MNT")"
        crc="$(_xfs_has_feature "$SCRATCH_MNT" crc -v)"
        if [ $crc -eq 1 ]; then
                leaf_hdr_size=64
@@ -226,7 +258,7 @@ _scratch_xfs_populate() {
 
        # - BTREE
        echo "+ btree dir"
-       __populate_create_dir "${SCRATCH_MNT}/S_IFDIR.FMT_BTREE" "$((128 * dblksz / 40))" true
+       __populate_xfs_create_btree_dir "${SCRATCH_MNT}/S_IFDIR.FMT_BTREE" "$isize" true
 
        # Symlinks
        # - FMT_LOCAL
index 04ae121d4d03a07eddefb5572077d88cee87a4c7..65a5b5b29efe07bed0d5d0079677084141694fbc 100644 (file)
@@ -1496,6 +1496,15 @@ _require_xfsrestore_xflag()
                        _notrun 'xfsrestore does not support -x flag.'
 }
 
+# Number of bytes reserved for a full inode record, which includes the
+# immediate fork areas.
+_xfs_get_inode_size()
+{
+       local mntpoint="$1"
+
+       $XFS_INFO_PROG "$mntpoint" | sed -n '/meta-data=.*isize/s/^.*isize=\([0-9]*\).*$/\1/p'
+}
+
 # Number of bytes reserved for only the inode record, excluding the
 # immediate fork areas.
 _xfs_get_inode_core_bytes()