cleanup and bugfix for xfs tests related to btree format
v5 cover cleanup and bugfix for xfs tests related to btree format
The first patch add a helper in common/xfs to export the inode core size which is needed by some xfs test cases.
The second patch ensure that S_IFDIR.FMT_BTREE is in btree format while populating dir.
V5:
- rename _xfs_inode_core_bytes() to _xfs_get_inode_core_bytes()
- rename _xfs_inode_size() to _xfs_get_inode_size()
- use one pipe in _xfs_get_inode_size()
- use local variables in __populate_xfs_create_btree_dir()
V4:
- let the new helper function accept the "missing" parameter
- make _xfs_inode_core_bytes echo 176 or 96 so tests can work correctly on both v4 and v5
V3:
- refactor xfs tests cases using inode core size
V2:
- take Darrick's advice to cleanup code
Ziyang Zhang (2):
common/xfs: Add a helper to export inode core size common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 24 ++++++++++++++++++++++++ tests/xfs/335 | 3 ++- tests/xfs/336 | 3 ++- tests/xfs/337 | 3 ++- tests/xfs/341 | 3 ++- tests/xfs/342 | 3 ++- 7 files changed, 67 insertions(+), 6 deletions(-)
Signature · 1 line
2.18.4
PATCH v5 1/2 common/xfs: Add a helper to export inode core size
Some xfs test cases need the number of bytes reserved for only the inode record, excluding the immediate fork areas. Now the value is hard-coded and it is not a good chioce. Add a helper in common/xfs to export the inode core size.
--- common/xfs | 15 +++++++++++++++ tests/xfs/335 | 3 ++- tests/xfs/336 | 3 ++- tests/xfs/337 | 3 ++- tests/xfs/341 | 3 ++- tests/xfs/342 | 3 ++- 6 files changed, 25 insertions(+), 5 deletions(-)
common/xfs +15 -0
@@ -1486,3 +1486,18 @@ _require_xfsrestore_xflag() $XFSRESTORE_PROG -h 2>&1 | grep -q -e '-x' || \ _notrun 'xfsrestore does not support -x flag.' } + +# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas. +_xfs_get_inode_core_bytes() +{ + local dir="$1" + + if _xfs_has_feature "$dir" crc; then + # v5 filesystems + echo 176 + else + # v4 filesystems + echo 96 + fi +}
tests/xfs/335 +2 -1
@@ -31,7 +31,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" echo "Create a three-level rtrmapbt" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 ))
tests/xfs/336 +2 -1
@@ -42,7 +42,8 @@ rm -rf $metadump_file echo "Create a three-level rtrmapbt" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 ))
tests/xfs/337 +2 -1
@@ -33,7 +33,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_ptrs=$(( (blksz - 56) / 56 )) bt_recs=$(( (blksz - 56) / 32 ))
tests/xfs/341 +2 -1
@@ -33,7 +33,8 @@ rtextsz_blks=$((rtextsz / blksz)) # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) blocks=$((i_ptrs * bt_recs + 1))
tests/xfs/342 +2 -1
@@ -30,7 +30,8 @@ blksz="$(_get_block_size $SCRATCH_MNT)" # inode core size is at least 176 bytes; btree header is 56 bytes; # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes. -i_ptrs=$(( (isize - 176) / 56 )) +i_core_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)" +i_ptrs=$(( (isize - i_core_size) / 56 )) bt_recs=$(( (blksz - 56) / 32 )) blocks=$((i_ptrs * bt_recs + 1))
Signature · 1 line
2.18.4
PATCH v5 2/2 common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
In reply to Ziyang ZhangSometimes "$((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).
--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)
common/populate +33 -1
@@ -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_inode_core_bytes)" + # 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
common/xfs +9 -0
@@ -1487,6 +1487,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()
Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 27 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0
common/populate __populate_create_dir() { · line 79
Quoted 9 lines
common/populate +6
-0@@ -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_inode_core_bytes)"
Doesn't this helper require a path argument now?
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0@@ -71,6 +71,37 @@ __populate_create_dir() { done }
Quoted 8 lines
common/populate __populate_create_dir() { · line 79
Quoted 6 lines
common/populate +6
-0+# 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_inode_core_bytes)"Doesn't this helper require a path argument now?
What kind of "path" argument? I think he copy it from __populate_create_dir(), and keep using the "name" as the root path to create files/dir.
Quoted 72 lines
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 41 lines · Zorro Lang
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0@@ -71,6 +71,37 @@ __populate_create_dir() { done }Quoted 8 lines
common/populate __populate_create_dir() { · line 79
Quoted 6 lines
common/populate +6
-0+# 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_inode_core_bytes)"Doesn't this helper require a path argument now?
Quoted 2 lines
What kind of "path" argument? I think he copy it from
__populate_create_dir(), and keep using the "name" as the root path to create files/dir.
This path argument, from
https://lore.kernel.org/fstests/[email protected]/T/#u
+# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas.
+_xfs_get_inode_core_bytes()
+{
+ local dir="$1"
+
+ if _xfs_has_feature "$dir" crc; then
--D
Quoted 73 lines
Quoted 72 lines
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 48 lines · Darrick J. Wong
Quoted 41 lines · Zorro Lang
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0@@ -71,6 +71,37 @@ __populate_create_dir() { done }Quoted 8 lines
common/populate __populate_create_dir() { · line 79
Quoted 6 lines
common/populate +6
-0+# 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_inode_core_bytes)"Doesn't this helper require a path argument now?
Quoted 2 lines
What kind of "path" argument? I think he copy it from
__populate_create_dir(), and keep using the "name" as the root path to create files/dir.This path argument, from
https://lore.kernel.org/fstests/[email protected]/T/#u
Review
Quoted 7 lines
(quoted diff) +7
-0+# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas. +_xfs_get_inode_core_bytes() +{ + local dir="$1" + + if _xfs_has_feature "$dir" crc; then
Oh, sorry I thought you mean __populate_xfs_create_btree_dir() require a path argument...
Yes, and this helper's name should be _xfs_get_inode_core_bytes(), not _xfs_inode_core_bytes(). I didn't find _xfs_inode_core_bytes from current fstests. So it should be:
local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
Hi Ziyang,
Please modify this place, and check all other places which call _xfs_get_inode_core_bytes and _xfs_get_inode_size, to make sure they're all changed correctly.
Thanks,
Zorro
Quoted 77 lines
--D
Quoted 73 lines
Quoted 72 lines
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 60 lines · Zorro Lang
Quoted 48 lines · Darrick J. Wong
Quoted 41 lines · Zorro Lang
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0@@ -71,6 +71,37 @@ __populate_create_dir() { done }Quoted 8 lines
common/populate __populate_create_dir() { · line 79
Quoted 6 lines
common/populate +6
-0+# 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_inode_core_bytes)"Doesn't this helper require a path argument now?
Quoted 2 lines
What kind of "path" argument? I think he copy it from
__populate_create_dir(), and keep using the "name" as the root path to create files/dir.This path argument, from
https://lore.kernel.org/fstests/[email protected]/T/#uReview
Quoted 7 lines
(quoted diff) +7
-0+# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas. +_xfs_get_inode_core_bytes() +{ + local dir="$1" + + if _xfs_has_feature "$dir" crc; thenOh, sorry I thought you mean
__populate_xfs_create_btree_dir()require a path argument...
Quoted 5 lines
Yes, and this helper's name should be
_xfs_get_inode_core_bytes(), not_xfs_inode_core_bytes(). I didn't find_xfs_inode_core_bytesfrom current fstests. So it should be:local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
Hmm... wait a moment. The work directory of __populate_xfs_create_btree_dir() is "local name=$1", but the "$name" maybe not a mountpoint.
So we need to get the fs dev/mnt before calling _xfs_get_inode_core_bytes:
local icore_size="$(_xfs_get_inode_core_bytes `_df_dir $name | awk '{print $1}'`)"Or use $TEST_MNT directly?
Thanks,
Zorro
Quoted 88 lines
Hi Ziyang,
Please modify this place, and check all other places which call
_xfs_get_inode_core_bytesand_xfs_get_inode_size, to make sure they're all changed correctly.Thanks,
ZorroQuoted 77 lines
--D
Quoted 73 lines
Quoted 72 lines
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
Quoted 67 lines · Zorro Lang
Quoted 60 lines · Zorro Lang
Quoted 48 lines · Darrick J. Wong
Quoted 41 lines · Zorro Lang
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Ziyang Zhang
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 <[email protected]>Reviewed-by Allison Henderson <[email protected]>Suggested-by "Darrick J. Wong" <[email protected]>Signed-off-by Gao Xiang <[email protected]>Signed-off-by Ziyang Zhang <[email protected]>--- common/populate | 34 +++++++++++++++++++++++++++++++++- common/xfs | 9 +++++++++ 2 files changed, 42 insertions(+), 1 deletion(-)common/populate +0
-0@@ -71,6 +71,37 @@ __populate_create_dir() { done }Quoted 8 lines
common/populate __populate_create_dir() { · line 79
Quoted 6 lines
common/populate +6
-0+# 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_inode_core_bytes)"Doesn't this helper require a path argument now?
Quoted 2 lines
What kind of "path" argument? I think he copy it from
__populate_create_dir(), and keep using the "name" as the root path to create files/dir.This path argument, from
https://lore.kernel.org/fstests/[email protected]/T/#uReview
Quoted 7 lines
(quoted diff) +7
-0+# Number of bytes reserved for only the inode record, excluding the +# immediate fork areas. +_xfs_get_inode_core_bytes() +{ + local dir="$1" + + if _xfs_has_feature "$dir" crc; thenOh, sorry I thought you mean
__populate_xfs_create_btree_dir()require a path argument...Quoted 5 lines
Yes, and this helper's name should be
_xfs_get_inode_core_bytes(), not_xfs_inode_core_bytes(). I didn't find_xfs_inode_core_bytesfrom current fstests. So it should be:local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
Quoted 8 lines
Hmm... wait a moment. The work directory of
__populate_xfs_create_btree_dir()is "local name=$1", but the "$name" maybe not a mountpoint.So we need to get the fs dev/mnt before calling
_xfs_get_inode_core_bytes:local icore_size="$(_xfs_get_inode_core_bytes `_df_dir $name | awk '{print $1}'`)"Or use $TEST_MNT directly?
The __populate* functions only modify the scratch filesystem, so your original suggestion is correct:
local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
--D
Quoted 92 lines
Thanks,
ZorroQuoted 88 lines
Hi Ziyang,
Please modify this place, and check all other places which call
_xfs_get_inode_core_bytesand_xfs_get_inode_size, to make sure they're all changed correctly.Thanks,
ZorroQuoted 77 lines
--D
Quoted 73 lines
Quoted 72 lines
--D
Quoted 68 lines
common/populate +27
-1+ # 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_LOCALcommon/xfs +9
-0@@ -1487,6 +1487,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()Signature · 1 line
2.18.4
Re: [PATCH V5 2/2] common/populate: Ensure that S_IFDIR.FMT_BTREE is in btree format
In reply to Zorro LangQuoted 6 lines · Zorro Lang
Yes, and this helper's name should be
_xfs_get_inode_core_bytes(), not_xfs_inode_core_bytes(). I didn't find_xfs_inode_core_bytesfrom current fstests. So it should be:local icore_size="$(_xfs_get_inode_core_bytes $SCRATCH_MNT)"
Quoted 8 lines
Hi Ziyang,
Please modify this place, and check all other places which call
_xfs_get_inode_core_bytesand_xfs_get_inode_size, to make sure they're all changed correctly.Thanks,
Zorro
Hi Zorro,
You are correct. Sorry for my mistake.
I should use _xfs_get_inode_core_bytes here and add a path argument($SCRATCH_MNT). I will send a new version.
Regards,
Zhang