Skip to contentSkip to conversation

fstests: random fixes and 6.14 stragglers

PATCH New Darrick J. Wong 4 participants 25 messages Mar 21, 2025 – Apr 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fstests: random fixes and 6.14 stragglers

Hi everyone,

Here's a fairly small series of patches for fstests -- the first two add functional testing for some new utilities that went into xfsprogs 6.14, and the last one is all bug fixes. This time around I'm dropping the /tmp checks and have added a few more bug fixes.

The following patches have not yet earned their review tags:

[PATCHSET 3/3] fstests: more random fixes for v2025.03.17
[PATCH 2/4] generic/537: disable quota mount options for pre-metadir [PATCH 4/4] xfs/818: fix some design issues

--D

#1 lore raw

PATCH 1/3 fstests: test dumping fs directory trees

Hi all,

Here's a functional test for recovering parts or entire filesystem trees with xfs_db.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=rdump

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=rdump
---
Commits in this patchset:
* xfs: test filesystem recovery with rdump

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
#2 lore raw

PATCH 1/1 xfs: test filesystem recovery with rdump

From: Darrick J. Wong <[email protected]>

Test how well we can dump a fully populated filesystem's contents.

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
tests/xfs/1895 new file +153 -0
new file mode 100755
index 00000000000000..18b534d328e9fd
@@ -0,0 +1,153 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 1895
+#
+# Populate a XFS filesystem, ensure that rdump can "recover" the contents to
+# another directory, and compare the contents.
+#
+. ./common/preamble
+_begin_fstest auto scrub
+
+_cleanup()
+{
+	command -v _kill_fsstress &>/dev/null && _kill_fsstress
+	cd /
+	test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_xfs_db_command "rdump"
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+	(cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+	(cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+	# columns:	raw mode in hex,
+	# 		major rdev for special
+	# 		minor rdev for special
+	# 		uid of owner
+	# 		gid of owner
+	# 		file type
+	# 		total size
+	# 		mtime
+	# 		name
+	# We can't directly control directory sizes so filter them.
+	# Too many things can bump (or not) atime so don't test that.
+	(cd $1 ; find . -print0 |
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' |
+		sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+		sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+	diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+make_stat_files() {
+	for file in "${FILES[@]}"; do
+		find "$1/$file" -print0 | xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n'
+	done | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.files.$2
+}
+
+cmp_stat_files()
+{
+	diff -u $tmp.stat.files.$1 $tmp.stat.files.$2
+}
+
+make_stat_dir() {
+	find "$1" -print0 | \
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.dir.$2
+}
+
+cmp_stat_dir()
+{
+	diff -u $tmp.stat.dir.$1 $tmp.stat.dir.$2
+}
+
+FILES=(
+	"/S_IFDIR.FMT_INLINE"
+	"/S_IFBLK"
+	"/S_IFCHR"
+	"/S_IFLNK.FMT_LOCAL"
+	"/S_IFIFO"
+	"/S_IFDIR.FMT_INLINE/00000001"
+	"/ATTR.FMT_EXTENTS_REMOTE3K"
+	"/S_IFREG.FMT_EXTENTS"
+	"/S_IFREG.FMT_BTREE"
+	"/BNOBT"
+	"/S_IFDIR.FMT_BLOCK"
+)
+DIR="/S_IFDIR.FMT_LEAF"
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles
+
+echo "Format and populate"
+_scratch_populate_cached nofill > $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 500 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+make_stat_files $SCRATCH_MNT before
+make_stat_dir $SCRATCH_MNT/$DIR before
+_scratch_unmount
+
+echo "Recover filesystem"
+dumpdir1=$testfiles/rdump
+dumpdir2=$testfiles/sdump
+dumpdir3=$testfiles/tdump
+rm -r -f $dumpdir1 $dumpdir2 $dumpdir3
+
+# as of linux 6.12 fchownat does not work on symlinks
+_scratch_xfs_db -c "rdump / $dumpdir1" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump ${FILES[*]} $dumpdir2" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump $DIR $dumpdir3" | sed -e '/could not be set/d'
+
+echo "Check file contents"
+make_stat $dumpdir1 after
+cmp_stat before after
+cmp_md5 $dumpdir1 before
+
+echo "Check selected files contents"
+make_stat_files $dumpdir2 after
+cmp_stat_files before after
+
+echo "Check single dir extraction contents"
+make_stat_dir $dumpdir3 after
+cmp_stat_dir before after
+
+# remount so we can check this fs
+_scratch_mount
+
+# success, all done
+status=0
+exit
tests/xfs/1895.out new file +6 -0
new file mode 100644
index 00000000000000..de639ed3fc7e38
@@ -0,0 +1,6 @@
+QA output created by 1895
+Format and populate
+Recover filesystem
+Check file contents
+Check selected files contents
+Check single dir extraction contents
#3 lore raw

Re: [PATCH 1/1] xfs: test filesystem recovery with rdump

Quoted 25 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Test how well we can dump a fully populated filesystem's contents.

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
tests/xfs/1895 new file +5 -0
new file mode 100755
index 00000000000000..18b534d328e9fd
@@ -0,0 +1,153 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 1895

tests/xfs/1895 line 15

Quoted 10 lines
tests/xfs/1895 new file +10 -0
+#
+# Populate a XFS filesystem, ensure that rdump can "recover" the contents to
+# another directory, and compare the contents.
+#
+. ./common/preamble
+_begin_fstest auto scrub
+
+_cleanup()
+{
+	command -v _kill_fsstress &>/dev/null && _kill_fsstress

I'm wondering why you always do "command -v _kill_fsstress &>/dev/null" before _kill_fsstress, isn't _kill_fsstress a common helper in common/rc ?

Thanks,
Zorro

Quoted 151 lines
tests/xfs/1895 new file +138 -0
+	cd /
+	test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_xfs_db_command "rdump"
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+	(cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+	(cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+	# columns:	raw mode in hex,
+	# 		major rdev for special
+	# 		minor rdev for special
+	# 		uid of owner
+	# 		gid of owner
+	# 		file type
+	# 		total size
+	# 		mtime
+	# 		name
+	# We can't directly control directory sizes so filter them.
+	# Too many things can bump (or not) atime so don't test that.
+	(cd $1 ; find . -print0 |
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' |
+		sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+		sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+	diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+make_stat_files() {
+	for file in "${FILES[@]}"; do
+		find "$1/$file" -print0 | xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n'
+	done | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.files.$2
+}
+
+cmp_stat_files()
+{
+	diff -u $tmp.stat.files.$1 $tmp.stat.files.$2
+}
+
+make_stat_dir() {
+	find "$1" -print0 | \
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.dir.$2
+}
+
+cmp_stat_dir()
+{
+	diff -u $tmp.stat.dir.$1 $tmp.stat.dir.$2
+}
+
+FILES=(
+	"/S_IFDIR.FMT_INLINE"
+	"/S_IFBLK"
+	"/S_IFCHR"
+	"/S_IFLNK.FMT_LOCAL"
+	"/S_IFIFO"
+	"/S_IFDIR.FMT_INLINE/00000001"
+	"/ATTR.FMT_EXTENTS_REMOTE3K"
+	"/S_IFREG.FMT_EXTENTS"
+	"/S_IFREG.FMT_BTREE"
+	"/BNOBT"
+	"/S_IFDIR.FMT_BLOCK"
+)
+DIR="/S_IFDIR.FMT_LEAF"
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles
+
+echo "Format and populate"
+_scratch_populate_cached nofill > $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 500 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+make_stat_files $SCRATCH_MNT before
+make_stat_dir $SCRATCH_MNT/$DIR before
+_scratch_unmount
+
+echo "Recover filesystem"
+dumpdir1=$testfiles/rdump
+dumpdir2=$testfiles/sdump
+dumpdir3=$testfiles/tdump
+rm -r -f $dumpdir1 $dumpdir2 $dumpdir3
+
+# as of linux 6.12 fchownat does not work on symlinks
+_scratch_xfs_db -c "rdump / $dumpdir1" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump ${FILES[*]} $dumpdir2" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump $DIR $dumpdir3" | sed -e '/could not be set/d'
+
+echo "Check file contents"
+make_stat $dumpdir1 after
+cmp_stat before after
+cmp_md5 $dumpdir1 before
+
+echo "Check selected files contents"
+make_stat_files $dumpdir2 after
+cmp_stat_files before after
+
+echo "Check single dir extraction contents"
+make_stat_dir $dumpdir3 after
+cmp_stat_dir before after
+
+# remount so we can check this fs
+_scratch_mount
+
+# success, all done
+status=0
+exit
tests/xfs/1895.out new file +6 -0
new file mode 100644
index 00000000000000..de639ed3fc7e38
@@ -0,0 +1,6 @@
+QA output created by 1895
+Format and populate
+Recover filesystem
+Check file contents
+Check selected files contents
+Check single dir extraction contents
#4 lore raw

Re: [PATCH 1/1] xfs: test filesystem recovery with rdump

Quoted 31 lines · Zorro Lang
Quoted 30 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Test how well we can dump a fully populated filesystem's contents.

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
tests/xfs/1895 new file +10 -0
new file mode 100755
index 00000000000000..18b534d328e9fd
@@ -0,0 +1,153 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 1895
+#
+# Populate a XFS filesystem, ensure that rdump can "recover" the contents to
+# another directory, and compare the contents.
+#
+. ./common/preamble
Quoted 8 lines

tests/xfs/1895 line 15

Quoted 5 lines
tests/xfs/1895 new file +5 -0
+_begin_fstest auto scrub
+
+_cleanup()
+{
+	command -v _kill_fsstress &>/dev/null && _kill_fsstress

I'm wondering why you always do "command -v _kill_fsstress &>/dev/null" before _kill_fsstress, isn't _kill_fsstress a common helper in common/rc ?

Yeah, I probably copy-pasta'd that from common/preamble. Will remove it before the next posting, assuming you don't decide to fix+merge it.

--D

Quoted 156 lines

Thanks,
Zorro

Quoted 151 lines
tests/xfs/1895 new file +138 -0
+	cd /
+	test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_xfs_db_command "rdump"
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+	(cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+	(cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+	# columns:	raw mode in hex,
+	# 		major rdev for special
+	# 		minor rdev for special
+	# 		uid of owner
+	# 		gid of owner
+	# 		file type
+	# 		total size
+	# 		mtime
+	# 		name
+	# We can't directly control directory sizes so filter them.
+	# Too many things can bump (or not) atime so don't test that.
+	(cd $1 ; find . -print0 |
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' |
+		sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+		sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+	diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+make_stat_files() {
+	for file in "${FILES[@]}"; do
+		find "$1/$file" -print0 | xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n'
+	done | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.files.$2
+}
+
+cmp_stat_files()
+{
+	diff -u $tmp.stat.files.$1 $tmp.stat.files.$2
+}
+
+make_stat_dir() {
+	find "$1" -print0 | \
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.dir.$2
+}
+
+cmp_stat_dir()
+{
+	diff -u $tmp.stat.dir.$1 $tmp.stat.dir.$2
+}
+
+FILES=(
+	"/S_IFDIR.FMT_INLINE"
+	"/S_IFBLK"
+	"/S_IFCHR"
+	"/S_IFLNK.FMT_LOCAL"
+	"/S_IFIFO"
+	"/S_IFDIR.FMT_INLINE/00000001"
+	"/ATTR.FMT_EXTENTS_REMOTE3K"
+	"/S_IFREG.FMT_EXTENTS"
+	"/S_IFREG.FMT_BTREE"
+	"/BNOBT"
+	"/S_IFDIR.FMT_BLOCK"
+)
+DIR="/S_IFDIR.FMT_LEAF"
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles
+
+echo "Format and populate"
+_scratch_populate_cached nofill > $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 500 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+make_stat_files $SCRATCH_MNT before
+make_stat_dir $SCRATCH_MNT/$DIR before
+_scratch_unmount
+
+echo "Recover filesystem"
+dumpdir1=$testfiles/rdump
+dumpdir2=$testfiles/sdump
+dumpdir3=$testfiles/tdump
+rm -r -f $dumpdir1 $dumpdir2 $dumpdir3
+
+# as of linux 6.12 fchownat does not work on symlinks
+_scratch_xfs_db -c "rdump / $dumpdir1" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump ${FILES[*]} $dumpdir2" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump $DIR $dumpdir3" | sed -e '/could not be set/d'
+
+echo "Check file contents"
+make_stat $dumpdir1 after
+cmp_stat before after
+cmp_md5 $dumpdir1 before
+
+echo "Check selected files contents"
+make_stat_files $dumpdir2 after
+cmp_stat_files before after
+
+echo "Check single dir extraction contents"
+make_stat_dir $dumpdir3 after
+cmp_stat_dir before after
+
+# remount so we can check this fs
+_scratch_mount
+
+# success, all done
+status=0
+exit
tests/xfs/1895.out new file +6 -0
new file mode 100644
index 00000000000000..de639ed3fc7e38
@@ -0,0 +1,6 @@
+QA output created by 1895
+Format and populate
+Recover filesystem
+Check file contents
+Check selected files contents
+Check single dir extraction contents
#5 lore raw

Re: [PATCH 1/1] xfs: test filesystem recovery with rdump

Quoted 41 lines · Darrick J. Wong
Quoted 31 lines · Zorro Lang
Quoted 30 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Test how well we can dump a fully populated filesystem's contents.

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
tests/xfs/1895 new file +10 -0
new file mode 100755
index 00000000000000..18b534d328e9fd
@@ -0,0 +1,153 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 1895
+#
+# Populate a XFS filesystem, ensure that rdump can "recover" the contents to
+# another directory, and compare the contents.
+#
+. ./common/preamble
Quoted 8 lines

tests/xfs/1895 line 15

Quoted 5 lines
tests/xfs/1895 new file +5 -0
+_begin_fstest auto scrub
+
+_cleanup()
+{
+	command -v _kill_fsstress &>/dev/null && _kill_fsstress

I'm wondering why you always do "command -v _kill_fsstress &>/dev/null" before _kill_fsstress, isn't _kill_fsstress a common helper in common/rc ?

Quoted 2 lines

Yeah, I probably copy-pasta'd that from common/preamble. Will remove it before the next posting, assuming you don't decide to fix+merge it.

I can "fix+merge" that:) if you don't have more changes, except:

- command -v _kill_fsstress &>/dev/null && _kill_fsstress
+ _kill_fsstress

Thanks,
Zorro

Quoted 160 lines

--D

Quoted 156 lines

Thanks,
Zorro

Quoted 151 lines
tests/xfs/1895 new file +138 -0
+	cd /
+	test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_xfs_db_command "rdump"
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+	(cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+	(cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+	# columns:	raw mode in hex,
+	# 		major rdev for special
+	# 		minor rdev for special
+	# 		uid of owner
+	# 		gid of owner
+	# 		file type
+	# 		total size
+	# 		mtime
+	# 		name
+	# We can't directly control directory sizes so filter them.
+	# Too many things can bump (or not) atime so don't test that.
+	(cd $1 ; find . -print0 |
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' |
+		sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+		sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+	diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+make_stat_files() {
+	for file in "${FILES[@]}"; do
+		find "$1/$file" -print0 | xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n'
+	done | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.files.$2
+}
+
+cmp_stat_files()
+{
+	diff -u $tmp.stat.files.$1 $tmp.stat.files.$2
+}
+
+make_stat_dir() {
+	find "$1" -print0 | \
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.dir.$2
+}
+
+cmp_stat_dir()
+{
+	diff -u $tmp.stat.dir.$1 $tmp.stat.dir.$2
+}
+
+FILES=(
+	"/S_IFDIR.FMT_INLINE"
+	"/S_IFBLK"
+	"/S_IFCHR"
+	"/S_IFLNK.FMT_LOCAL"
+	"/S_IFIFO"
+	"/S_IFDIR.FMT_INLINE/00000001"
+	"/ATTR.FMT_EXTENTS_REMOTE3K"
+	"/S_IFREG.FMT_EXTENTS"
+	"/S_IFREG.FMT_BTREE"
+	"/BNOBT"
+	"/S_IFDIR.FMT_BLOCK"
+)
+DIR="/S_IFDIR.FMT_LEAF"
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles
+
+echo "Format and populate"
+_scratch_populate_cached nofill > $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 500 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+make_stat_files $SCRATCH_MNT before
+make_stat_dir $SCRATCH_MNT/$DIR before
+_scratch_unmount
+
+echo "Recover filesystem"
+dumpdir1=$testfiles/rdump
+dumpdir2=$testfiles/sdump
+dumpdir3=$testfiles/tdump
+rm -r -f $dumpdir1 $dumpdir2 $dumpdir3
+
+# as of linux 6.12 fchownat does not work on symlinks
+_scratch_xfs_db -c "rdump / $dumpdir1" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump ${FILES[*]} $dumpdir2" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump $DIR $dumpdir3" | sed -e '/could not be set/d'
+
+echo "Check file contents"
+make_stat $dumpdir1 after
+cmp_stat before after
+cmp_md5 $dumpdir1 before
+
+echo "Check selected files contents"
+make_stat_files $dumpdir2 after
+cmp_stat_files before after
+
+echo "Check single dir extraction contents"
+make_stat_dir $dumpdir3 after
+cmp_stat_dir before after
+
+# remount so we can check this fs
+_scratch_mount
+
+# success, all done
+status=0
+exit
tests/xfs/1895.out new file +6 -0
new file mode 100644
index 00000000000000..de639ed3fc7e38
@@ -0,0 +1,6 @@
+QA output created by 1895
+Format and populate
+Recover filesystem
+Check file contents
+Check selected files contents
+Check single dir extraction contents
#6 lore raw

Re: [PATCH 1/1] xfs: test filesystem recovery with rdump

Quoted 42 lines · Zorro Lang
Quoted 41 lines · Darrick J. Wong
Quoted 39 lines · Zorro Lang
Quoted 25 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Test how well we can dump a fully populated filesystem's contents.

---
 tests/xfs/1895     |  153 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/1895.out |    6 ++
 2 files changed, 159 insertions(+)
 create mode 100755 tests/xfs/1895
 create mode 100644 tests/xfs/1895.out
tests/xfs/1895 new file +5 -0
new file mode 100755
index 00000000000000..18b534d328e9fd
@@ -0,0 +1,153 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 1895

tests/xfs/1895 line 15

Quoted 10 lines
tests/xfs/1895 new file +10 -0
+#
+# Populate a XFS filesystem, ensure that rdump can "recover" the contents to
+# another directory, and compare the contents.
+#
+. ./common/preamble
+_begin_fstest auto scrub
+
+_cleanup()
+{
+	command -v _kill_fsstress &>/dev/null && _kill_fsstress

I'm wondering why you always do "command -v _kill_fsstress &>/dev/null" before _kill_fsstress, isn't _kill_fsstress a common helper in common/rc ?

Quoted 7 lines
Quoted 2 lines

Yeah, I probably copy-pasta'd that from common/preamble. Will remove it before the next posting, assuming you don't decide to fix+merge it.

I can "fix+merge" that:) if you don't have more changes, except:

- command -v _kill_fsstress &>/dev/null && _kill_fsstress
+ _kill_fsstress

No changes other than applying hch's rvb that he attached to the other thread.

--D

Quoted 164 lines

Thanks,
Zorro

Quoted 160 lines

--D

Quoted 156 lines

Thanks,
Zorro

Quoted 151 lines
tests/xfs/1895 new file +138 -0
+	cd /
+	test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_xfs_db_command "rdump"
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+	(cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+	(cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+	# columns:	raw mode in hex,
+	# 		major rdev for special
+	# 		minor rdev for special
+	# 		uid of owner
+	# 		gid of owner
+	# 		file type
+	# 		total size
+	# 		mtime
+	# 		name
+	# We can't directly control directory sizes so filter them.
+	# Too many things can bump (or not) atime so don't test that.
+	(cd $1 ; find . -print0 |
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' |
+		sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+		sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+	diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+make_stat_files() {
+	for file in "${FILES[@]}"; do
+		find "$1/$file" -print0 | xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n'
+	done | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.files.$2
+}
+
+cmp_stat_files()
+{
+	diff -u $tmp.stat.files.$1 $tmp.stat.files.$2
+}
+
+make_stat_dir() {
+	find "$1" -print0 | \
+		xargs -0 stat -c '%f %t:%T %u %g %F %s %Y %n' | sed \
+		-e 's/ directory [1-9][0-9]* / directory SIZE /g' \
+		-e "s| $1| DUMPDIR|g" \
+		| sort > $tmp.stat.dir.$2
+}
+
+cmp_stat_dir()
+{
+	diff -u $tmp.stat.dir.$1 $tmp.stat.dir.$2
+}
+
+FILES=(
+	"/S_IFDIR.FMT_INLINE"
+	"/S_IFBLK"
+	"/S_IFCHR"
+	"/S_IFLNK.FMT_LOCAL"
+	"/S_IFIFO"
+	"/S_IFDIR.FMT_INLINE/00000001"
+	"/ATTR.FMT_EXTENTS_REMOTE3K"
+	"/S_IFREG.FMT_EXTENTS"
+	"/S_IFREG.FMT_BTREE"
+	"/BNOBT"
+	"/S_IFDIR.FMT_BLOCK"
+)
+DIR="/S_IFDIR.FMT_LEAF"
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles
+
+echo "Format and populate"
+_scratch_populate_cached nofill > $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 500 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+make_stat_files $SCRATCH_MNT before
+make_stat_dir $SCRATCH_MNT/$DIR before
+_scratch_unmount
+
+echo "Recover filesystem"
+dumpdir1=$testfiles/rdump
+dumpdir2=$testfiles/sdump
+dumpdir3=$testfiles/tdump
+rm -r -f $dumpdir1 $dumpdir2 $dumpdir3
+
+# as of linux 6.12 fchownat does not work on symlinks
+_scratch_xfs_db -c "rdump / $dumpdir1" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump ${FILES[*]} $dumpdir2" | sed -e '/could not be set/d'
+_scratch_xfs_db -c "rdump $DIR $dumpdir3" | sed -e '/could not be set/d'
+
+echo "Check file contents"
+make_stat $dumpdir1 after
+cmp_stat before after
+cmp_md5 $dumpdir1 before
+
+echo "Check selected files contents"
+make_stat_files $dumpdir2 after
+cmp_stat_files before after
+
+echo "Check single dir extraction contents"
+make_stat_dir $dumpdir3 after
+cmp_stat_dir before after
+
+# remount so we can check this fs
+_scratch_mount
+
+# success, all done
+status=0
+exit
tests/xfs/1895.out new file +6 -0
new file mode 100644
index 00000000000000..de639ed3fc7e38
@@ -0,0 +1,6 @@
+QA output created by 1895
+Format and populate
+Recover filesystem
+Check file contents
+Check selected files contents
+Check single dir extraction contents
#7 lore raw

PATCH 2/3 fstests: test handling emoji filenames better

In reply to Darrick J. Wong

Hi all,

Ted told me about some bugs that the ext4 Unicode casefolding code has suffered over the past year -- they tried stripping out zero width joiner (ZWJ) codepoints to try to eliminate casefolded lookup comparison issues, but doing so corrupts compound emoji handling in filenames.

This short series amends the Unicode testing in generic/453 and 454 to examine these compound emoji.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-emoji-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=scrub-emoji-fixes
---
Commits in this patchset:
* generic/45[34]: add colored emoji variants to unicode tests

---
 tests/generic/453 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/454 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
#8 lore raw

PATCH 1/1 generic/45[34]: add colored emoji variants to unicode tests

From: Darrick J. Wong <[email protected]>

Ted told me this morning about a recent problem with kernel Unicode name casefolding vs. emoji -- initially, someone decided that zero-width joiners should be stripped out of filenames during comparisons, which lead to malicious git pulls of branches containing "<zwj>.git/config" files overwriting git repo config files. A quick fix was to stop ignoring the "ignorable" code points, but that broke emoji in filenames, because emoji use zero-width joiners to combine simpler emoji into more complex ones, or alter skin tones, or colors, etc. Reportedly the casefolding code will also fold a red heart into a black one.

So. To our filename support test, let's add various colors of heart emoji and various skin tones of heart-hands; and compound emoji consisting of multiple emoji glued together with zero width joiners. This actually caused a buffer overflow in the string-escaping functions of xfs_scrub phase 5 because I hadn't anticipated that we'd end up with a filename consisting *entirely* of nonprinting bytes.

---
 tests/generic/453 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/454 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
tests/generic/453 +55 -0
index 04945ad1085b2d..bd5ce8b2bb11d9 100755
@@ -203,6 +203,36 @@ setf "job offer.pdf" "actual period"
 setf "llamapirate\xf3\xa0\x80\x81\xf3\xa0\x81\x94\xf3\xa0\x81\xa8\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\xb3\xf3\xa0\x81\xa1\xf3\xa0\x81\xac\xf3\xa0\x81\xa5\xf3\xa0\x81\xb3\xf3\xa0\x80\xa0\xf3\xa0\x81\xa6\xf3\xa0\x81\xaf\xf3\xa0\x81\xb2\xf3\xa0\x80\xa0\xf3\xa0\x81\x93\xf3\xa0\x81\xa5\xf3\xa0\x81\xa1\xf3\xa0\x81\xb4\xf3\xa0\x81\xb4\xf3\xa0\x81\xac\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\xb7\xf3\xa0\x81\xa5\xf3\xa0\x81\xb2\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\x95\xf3\xa0\x81\x93\xf3\xa0\x81\x84\xf3\xa0\x80\xa0\xf3\xa0\x80\xb1\xf3\xa0\x80\xb2\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x81\xbf"
 setf "llamapirate"
 
+# colored heart emoji to check if casefolding whacks emoji
+setf "\xf0\x9f\x92\x9c" "purple"
+setf "\xf0\x9f\x92\x99" "blue"
+setf "\xf0\x9f\x92\x9a" "green"
+setf "\xf0\x9f\x92\x9b" "yellow"
+setf "\xf0\x9f\xab\x80" "heart"
+setf "\xe2\x9d\xa4\xef\xb8\x8f" "red"
+setf "\xf0\x9f\xa4\x8e" "brown"
+setf "\xf0\x9f\xa4\x8d" "white"
+setf "\xf0\x9f\x96\xa4" "black"
+setf "\xf0\x9f\xa7\xa1" "orange"
+setf "\xe2\x99\xa5\xef\xb8\x8f" "red suit"
+
+# zero width joiners exist in the middle of emoji sequences aren't supposed
+# to be normalized to nothing, but apparently this caused issues with
+# casefolding on ext4; also the mending heart caused a crash in xfs_scrub
+setf "\xf0\x9f\x92\x94" "broken heart"
+setf "\xe2\x9d\xa4\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\xa9\xb9" "mending heart"
+setf "\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbb\xe2\x80\x8d\xe2\x9d\xa4\xef\xb8
+\x8f\xe2\x80\x8d\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbc" "couple with heart"
+setf "\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbb\xe2\x80\x8d\xe2\x9d\xa4\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbf" "couple with heart, light and dark skin tone"
+
+# emoji heart hands with skin tone variations
+setf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbf" "dark"
+setf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbe" "medium dark"
+setf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbd" "medium"
+setf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbc" "medium light"
+setf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbb" "light"
+setf "\xf0\x9f\xab\xb6" "neutral"
+
 ls -laR $testdir >> $seqres.full
 
 echo "Test files"
@@ -276,6 +306,31 @@ testf "job offer.pdf" "actual period"
 testf "llamapirate\xf3\xa0\x80\x81\xf3\xa0\x81\x94\xf3\xa0\x81\xa8\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\xb3\xf3\xa0\x81\xa1\xf3\xa0\x81\xac\xf3\xa0\x81\xa5\xf3\xa0\x81\xb3\xf3\xa0\x80\xa0\xf3\xa0\x81\xa6\xf3\xa0\x81\xaf\xf3\xa0\x81\xb2\xf3\xa0\x80\xa0\xf3\xa0\x81\x93\xf3\xa0\x81\xa5\xf3\xa0\x81\xa1\xf3\xa0\x81\xb4\xf3\xa0\x81\xb4\xf3\xa0\x81\xac\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\xb7\xf3\xa0\x81\xa5\xf3\xa0\x81\xb2\xf3\xa0\x81\xa5\xf3\xa0\x80\xa0\xf3\xa0\x81\x95\xf3\xa0\x81\x93\xf3\xa0\x81\x84\xf3\xa0\x80\xa0\xf3\xa0\x80\xb1\xf3\xa0\x80\xb2\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x80\xb0\xf3\xa0\x81\xbf"
 testf "llamapirate"
 
+testf "\xf0\x9f\x92\x9c" "purple"
+testf "\xf0\x9f\x92\x99" "blue"
+testf "\xf0\x9f\x92\x9a" "green"
+testf "\xf0\x9f\x92\x9b" "yellow"
+testf "\xf0\x9f\xab\x80" "heart"
+testf "\xe2\x9d\xa4\xef\xb8\x8f" "red"
+testf "\xf0\x9f\xa4\x8e" "brown"
+testf "\xf0\x9f\xa4\x8d" "white"
+testf "\xf0\x9f\x96\xa4" "black"
+testf "\xf0\x9f\xa7\xa1" "orange"
+testf "\xe2\x99\xa5\xef\xb8\x8f" "red suit"
+
+testf "\xf0\x9f\x92\x94" "broken heart"
+testf "\xe2\x9d\xa4\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\xa9\xb9" "mending heart"
+testf "\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbb\xe2\x80\x8d\xe2\x9d\xa4\xef\xb8
+\x8f\xe2\x80\x8d\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbc" "couple with heart"
+testf "\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbb\xe2\x80\x8d\xe2\x9d\xa4\xef\xb8\x8f\xe2\x80\x8d\xf0\x9f\xa7\x91\xf0\x9f\x8f\xbf" "couple with heart, light and dark skin tone"
+
+testf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbf" "dark"
+testf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbe" "medium dark"
+testf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbd" "medium"
+testf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbc" "medium light"
+testf "\xf0\x9f\xab\xb6\xf0\x9f\x8f\xbb" "light"
+testf "\xf0\x9f\xab\xb6" "neutral"
+
 echo "Uniqueness of inodes?"
 stat -c '%i' "${testdir}/"* | sort | uniq -c | while read nr inum; do
 	if [ "${nr}" -gt 1 ]; then
tests/generic/454 +55 -0

67 lines not on this page · raw message

#9 lore raw

PATCH 3/3 fstests: more random fixes for v2025.03.17

In reply to Darrick J. Wong

Hi all,

Here's the usual odd fixes for fstests.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=random-fixes

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=random-fixes
---
Commits in this patchset:
* xfs/614: determine the sector size of the fs image by doing a test format
* generic/537: disable quota mount options for pre-metadir rt filesystems
* common/populate: drop fallocate mode 0 requirement
* xfs/818: fix some design issues

---
 common/populate   |    1 -
 tests/generic/537 |   17 +++++++++++++++++
 tests/xfs/614     |   13 ++++++++-----
 tests/xfs/818     |   19 ++++++++++++++++---
 4 files changed, 41 insertions(+), 9 deletions(-)
#10 lore raw

PATCH 1/4 xfs/614: determine the sector size of the fs image by doing a test format

From: Darrick J. Wong <[email protected]>

In some cases (such as xfs always_cow=1), the configuration of the test filesystem determines the sector size of the filesystem that we're going to simulate formatting. Concretely, even if TEST_DEV is a block device with 512b sectors, the directio geometry can specify 4k writes to avoid nasty RMW cycles. When this happens, mkfs.xfs will set the sector size to that 4k accordingly, but the golden output selection is wrong. Fix this.

---
 tests/xfs/614 |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
tests/xfs/614 +8 -5
index 2a799fbf3ed71c..e182f073fddd64 100755
@@ -25,13 +25,16 @@ _require_test
 $MKFS_XFS_PROG 2>&1 | grep -q concurrency || \
 	_notrun "mkfs does not support concurrency options"
 
-test_dev_lbasize=$(blockdev --getss $TEST_DEV)
-seqfull=$0
-_link_out_file "lba${test_dev_lbasize}"
-
+# Figure out what sector size mkfs will use to format, which might be dependent
+# upon the directio write geometry of the test filesystem.
 loop_file=$TEST_DIR/$seq.loop
-
 rm -f "$loop_file"
+truncate -s 16M "$loop_file"
+$MKFS_XFS_PROG -f -N "$loop_file" | _filter_mkfs 2>$tmp.mkfs >/dev/null
+. $tmp.mkfs
+seqfull=$0
+_link_out_file "lba${sectsz}"
+
 for sz in 16M 512M 1G 2G 16G 64G 256G 512G 1T 2T 4T 16T 64T 256T 512T 1P; do
 	for cpus in 2 4 8 16 32 40 64 96 160 512; do
 		truncate -s "$sz" "$loop_file"
#11 lore raw

PATCH 2/4 generic/537: disable quota mount options for pre-metadir rt filesystems

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this regression in generic/537:

mount: /opt: permission denied.
dmesg(1) may have more information after failed mount system call.
mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed (see /var/tmp/fstests/generic/537.full for details)

for reasons explained in the giant comment. TLDR: quota and rt aren't compatible on older xfs filesystems so we have to work around that.

---
 tests/generic/537 |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tests/generic/537 +17 -0
index f57bc1561dd57e..3be743c4133f4f 100755
@@ -18,6 +18,7 @@ _begin_fstest auto quick trim
 
 # Import common functions.
 . ./common/filter
+. ./common/quota
 
 _require_scratch
 _require_fstrim
@@ -36,6 +37,22 @@ _scratch_mount -o ro >> $seqres.full 2>&1
 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1
 _scratch_unmount
 
+# As of kernel commit 9f0902091c332b ("xfs: Do not allow norecovery mount with
+# quotacheck"), it is no longer possible to mount with "norecovery" and any
+# quota mount option if the quota mount options would require a metadata update
+# such as quotacheck.  For a pre-metadir XFS filesystem with a realtime volume
+# and quota-enabling options, the first two mount attempts will have succeeded
+# but with quotas disabled.  The mount option parsing for this next mount
+# attempt will see the same quota-enabling options and a lack of qflags in the
+# ondisk metadata and reject the mount because it thinks that will require
+# quotacheck.  Edit out the quota mount options for this specific
+# configuration.
+if [ "$FSTYP" = "xfs" ]; then
+	if [ "$USE_EXTERNAL" = "yes" ] && [ -n "$SCRATCH_RTDEV" ]; then
+		_qmount_option ""
+	fi
+fi
+
 echo "fstrim on ro mount with no log replay"
 norecovery="norecovery"
 test $FSTYP = "btrfs" && norecovery=nologreplay
Reviewed-by on v1 2/4
#12 lore raw

Re: [PATCH 2/4] generic/537: disable quota mount options for pre-metadir rt filesystems

Quoted 40 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this regression in generic/537:

mount: /opt: permission denied.
dmesg(1) may have more information after failed mount system call.
mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed (see /var/tmp/fstests/generic/537.full for details)

for reasons explained in the giant comment. TLDR: quota and rt aren't compatible on older xfs filesystems so we have to work around that.

---
 tests/generic/537 |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tests/generic/537 +6 -0
index f57bc1561dd57e..3be743c4133f4f 100755
@@ -18,6 +18,7 @@ _begin_fstest auto quick trim
 
 # Import common functions.
 . ./common/filter
+. ./common/quota
 
 _require_scratch
 _require_fstrim
@@ -36,6 +37,22 @@ _scratch_mount -o ro >> $seqres.full 2>&1
 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1
 _scratch_unmount
 
+# As of kernel commit 9f0902091c332b ("xfs: Do not allow norecovery mount with
+# quotacheck"), it is no longer possible to mount with "norecovery" and any
+# quota mount option if the quota mount options would require a metadata update
+# such as quotacheck.  For a pre-metadir XFS filesystem with a realtime volume
+# and quota-enabling options, the first two mount attempts will have succeeded

tests/generic/537 _scratch_mount -o ro >> $seqres.full 2>&1 · line 54

Quoted 10 lines
tests/generic/537 +10 -0
+# but with quotas disabled.  The mount option parsing for this next mount
+# attempt will see the same quota-enabling options and a lack of qflags in the
+# ondisk metadata and reject the mount because it thinks that will require
+# quotacheck.  Edit out the quota mount options for this specific
+# configuration.
+if [ "$FSTYP" = "xfs" ]; then
+	if [ "$USE_EXTERNAL" = "yes" ] && [ -n "$SCRATCH_RTDEV" ]; then
+		_qmount_option ""
+	fi
+fi

I don't know if there's a better way, maybe a _require_no_quota, or _disable_qmount?

Anyway, for this single case, it's fine for me.

Quoted 5 lines
tests/generic/537 +1 -0
+
 echo "fstrim on ro mount with no log replay"
 norecovery="norecovery"
 test $FSTYP = "btrfs" && norecovery=nologreplay
#13 lore raw

Re: [PATCH 2/4] generic/537: disable quota mount options for pre-metadir rt filesystems

Quoted 45 lines · Zorro Lang
Quoted 44 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this regression in generic/537:

mount: /opt: permission denied.
dmesg(1) may have more information after failed mount system call.
mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed mount -o uquota,gquota,pquota, -o ro,norecovery -ortdev=/dev/sdb4 /dev/sda4 /opt failed (see /var/tmp/fstests/generic/537.full for details)

for reasons explained in the giant comment. TLDR: quota and rt aren't compatible on older xfs filesystems so we have to work around that.

---
 tests/generic/537 |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tests/generic/537 +10 -0
index f57bc1561dd57e..3be743c4133f4f 100755
@@ -18,6 +18,7 @@ _begin_fstest auto quick trim
 
 # Import common functions.
 . ./common/filter
+. ./common/quota
 
 _require_scratch
 _require_fstrim
@@ -36,6 +37,22 @@ _scratch_mount -o ro >> $seqres.full 2>&1
 $FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1
 _scratch_unmount
 
+# As of kernel commit 9f0902091c332b ("xfs: Do not allow norecovery mount with
+# quotacheck"), it is no longer possible to mount with "norecovery" and any
+# quota mount option if the quota mount options would require a metadata update
+# such as quotacheck.  For a pre-metadir XFS filesystem with a realtime volume
+# and quota-enabling options, the first two mount attempts will have succeeded
+# but with quotas disabled.  The mount option parsing for this next mount
+# attempt will see the same quota-enabling options and a lack of qflags in the
+# ondisk metadata and reject the mount because it thinks that will require
+# quotacheck.  Edit out the quota mount options for this specific
Quoted 8 lines

tests/generic/537 _scratch_mount -o ro >> $seqres.full 2>&1 · line 54

Quoted 6 lines
tests/generic/537 +6 -0
+# configuration.
+if [ "$FSTYP" = "xfs" ]; then
+	if [ "$USE_EXTERNAL" = "yes" ] && [ -n "$SCRATCH_RTDEV" ]; then
+		_qmount_option ""
+	fi
+fi

I don't know if there's a better way, maybe a _require_no_quota, or _disable_qmount?

_require_no_quota would decrease test coverage.

There is no such helper as _disable_qmount...?

Quoted 3 lines

Anyway, for this single case, it's fine for me.

Thanks!

--D

Quoted 7 lines
Quoted 5 lines
tests/generic/537 +1 -0
+
 echo "fstrim on ro mount with no log replay"
 norecovery="norecovery"
 test $FSTYP = "btrfs" && norecovery=nologreplay
#14 lore raw

PATCH 3/4 common/populate: drop fallocate mode 0 requirement

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

None of the _scratch_$FSTYP_populate functions use fallocate mode 0 (aka preallocation) to run, so drop the _require check. This enables xfs/349 and friends to work on always-cow xfs filesystems.

---
 common/populate |    1 -
 1 file changed, 1 deletion(-)
common/populate +0 -1
index a1be26d5b24adf..7352f598a0c700 100644
@@ -8,7 +8,6 @@
 . ./common/quota
 
 _require_populate_commands() {
-	_require_xfs_io_command "falloc"
 	_require_xfs_io_command "fpunch"
 	_require_test_program "punch-alternating"
 	_require_test_program "popdir.pl"
#15 lore raw

PATCH 4/4 xfs/818: fix some design issues

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

While QA'ing zoned filesystem support, I discovered some design errors in this test:

1) Since we're test formatting a sparse file on an xfs filesystem, there's no need to play games with optimal device size; we can create a totally sparse file that's the same size as SCRATCH_DEV.

2) mkfs.xfs cannot create realtime files, so if it fails with that, there's no need to continue the test.

3) If mkfs -p fails for none of the proscribed reasons, it should exit the test. The final cat $tmp.mkfs will take care of tweaking the golden output to register the test failure for further investigation.

Cc <[email protected]> # v2025.03.09
Fixes 6d39dc34e61e11 ("xfs: test filesystem creation with xfs_protofile")
---
 tests/xfs/818 |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tests/xfs/818 +16 -3
index aeb462353df7e9..bc809390b9e340 100755
@@ -75,9 +75,8 @@ _run_fsstress -n 1000 -d $SCRATCH_MNT/newfiles
 make_stat $SCRATCH_MNT before
 make_md5 $SCRATCH_MNT before
 
-kb_needed=$(du -k -s $SCRATCH_MNT | awk '{print $1}')
-img_size=$((kb_needed * 2))
-test "$img_size" -lt $((300 * 1024)) && img_size=$((300 * 1024))
+scratch_sectors="$(blockdev --getsz $SCRATCH_DEV)"
+img_size=$((scratch_sectors * 512 / 1024))
 
 echo "Clone image with protofile"
 $XFS_PROTOFILE_PROG $SCRATCH_MNT > $testfiles/protofile
@@ -99,7 +98,21 @@ if ! _try_mkfs_dev -p $testfiles/protofile $testfiles/image &> $tmp.mkfs; then
 	if grep -q 'No space left on device' $tmp.mkfs; then
 		_notrun "not enough space in filesystem"
 	fi
+
+	# mkfs cannot create realtime files.
+	#
+	# If zoned=1 is in MKFS_OPTIONS, mkfs will create an internal realtime
+	# volume with rtinherit=1 and fail, so we need to _notrun that case.
+	#
+	# If zoned=1 is /not/ in MKFS_OPTIONS, we didn't pass a realtime device
+	# to mkfs so it will not create realtime files.  The format should work
+	# just fine.
+	if grep -q 'creating realtime files from proto file not supported' $tmp.mkfs; then
+		_notrun "mkfs cannot create realtime files"
+	fi
+
 	cat $tmp.mkfs
+	exit
 fi
 
 _mount $testfiles/image $testfiles/mount
Reviewed-by on v1 4/4
#16 lore raw

Re: [PATCH 4/4] xfs/818: fix some design issues

Quoted 12 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

While QA'ing zoned filesystem support, I discovered some design errors in this test:

1) Since we're test formatting a sparse file on an xfs filesystem, there's no need to play games with optimal device size; we can create a totally sparse file that's the same size as SCRATCH_DEV.

2) mkfs.xfs cannot create realtime files, so if it fails with that, there's no need to continue the test.

Quoted 8 lines

3) If mkfs -p fails for none of the proscribed reasons, it should exit the test. The final cat $tmp.mkfs will take care of tweaking the golden output to register the test failure for further investigation.

Cc <[email protected]> # v2025.03.09
Fixes 6d39dc34e61e11 ("xfs: test filesystem creation with xfs_protofile")

---

Make sense to me,

Quoted 43 lines
 tests/xfs/818 |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tests/xfs/818 +16 -3
index aeb462353df7e9..bc809390b9e340 100755
@@ -75,9 +75,8 @@ _run_fsstress -n 1000 -d $SCRATCH_MNT/newfiles
 make_stat $SCRATCH_MNT before
 make_md5 $SCRATCH_MNT before
 
-kb_needed=$(du -k -s $SCRATCH_MNT | awk '{print $1}')
-img_size=$((kb_needed * 2))
-test "$img_size" -lt $((300 * 1024)) && img_size=$((300 * 1024))
+scratch_sectors="$(blockdev --getsz $SCRATCH_DEV)"
+img_size=$((scratch_sectors * 512 / 1024))
 
 echo "Clone image with protofile"
 $XFS_PROTOFILE_PROG $SCRATCH_MNT > $testfiles/protofile
@@ -99,7 +98,21 @@ if ! _try_mkfs_dev -p $testfiles/protofile $testfiles/image &> $tmp.mkfs; then
 	if grep -q 'No space left on device' $tmp.mkfs; then
 		_notrun "not enough space in filesystem"
 	fi
+
+	# mkfs cannot create realtime files.
+	#
+	# If zoned=1 is in MKFS_OPTIONS, mkfs will create an internal realtime
+	# volume with rtinherit=1 and fail, so we need to _notrun that case.
+	#
+	# If zoned=1 is /not/ in MKFS_OPTIONS, we didn't pass a realtime device
+	# to mkfs so it will not create realtime files.  The format should work
+	# just fine.
+	if grep -q 'creating realtime files from proto file not supported' $tmp.mkfs; then
+		_notrun "mkfs cannot create realtime files"
+	fi
+
 	cat $tmp.mkfs
+	exit
 fi
 
 _mount $testfiles/image $testfiles/mount
#17 lore raw

PATCH 1/1 xfsprogs: localize the python programs

In reply to Darrick J. Wong

Hi all,

We ship two Python programs in the main xfsprogs package, but neither of them actually participate in gettext, which means that the output is always English no matter what user's locale settings are. Fix that by adding them to the autogenerated message catalog.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=localization
---
Commits in this patchset:
* xfs_protofile: rename source code to .py.in
* xfs_scrub_all: rename source code to .py.in
* Makefile: inject package name/version/bugreport into pot file
* xfs_protofile: add messages to localization catalog
* xfs_scrub_all: localize the strings in the program

---
 configure.ac              |    3 +-
 include/builddefs.in      |    1 +
 include/buildrules        |    9 ++++++-
 libfrog/Makefile          |   18 ++++++++++++-
 libfrog/gettext.py.in     |   12 +++++++++
 mkfs/Makefile             |   11 +++++---
 mkfs/xfs_protofile.py.in  |   21 +++++++++------
 scrub/Makefile            |   11 +++++---
 scrub/xfs_scrub_all.py.in |   62 +++++++++++++++++++++++++++------------------
 9 files changed, 103 insertions(+), 45 deletions(-)
 create mode 100644 libfrog/gettext.py.in
 rename mkfs/{xfs_protofile.in => xfs_protofile.py.in} (85%)
 rename scrub/{xfs_scrub_all.in => xfs_scrub_all.py.in} (89%)
#18 lore raw

PATCH 1/5 xfs_protofile: rename source code to .py.in

From: Darrick J. Wong <[email protected]>

Rename this source code file to have an extention of ".py.in" so that editors and xgettext can "smartly" detect the source code type from the file extension. This will become important for adding localization to the strings printed. No functional changes.

---
 mkfs/Makefile            |    4 ++--
 mkfs/xfs_protofile.py.in |    0 
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename mkfs/{xfs_protofile.in => xfs_protofile.py.in} (100%)
mkfs/Makefile +2 -2
index 3d3f08ad54f844..b1369e1853a98f 100644
@@ -6,7 +6,7 @@ TOPDIR = ..
 include $(TOPDIR)/include/builddefs
 
 LTCOMMAND = mkfs.xfs
-XFS_PROTOFILE = xfs_protofile
+XFS_PROTOFILE = xfs_protofile.py
 
 HFILES =
 CFILES = proto.c xfs_mkfs.c
@@ -38,7 +38,7 @@ $(XFS_PROTOFILE): $(XFS_PROTOFILE).in
 install: default
 	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
-	$(INSTALL) -m 755 $(XFS_PROTOFILE) $(PKG_SBIN_DIR)
+	$(INSTALL) -m 755 $(XFS_PROTOFILE) $(PKG_SBIN_DIR)/xfs_protofile
 	$(INSTALL) -m 755 -d $(MKFS_CFG_DIR)
 	$(INSTALL) -m 644 $(CFGFILES) $(MKFS_CFG_DIR)
 
mkfs/xfs_protofile.py.in renamed from mkfs/xfs_protofile.in +0 -0
similarity index 100%
rename from mkfs/xfs_protofile.in
rename to mkfs/xfs_protofile.py.in
#19 lore raw

PATCH 2/5 xfs_scrub_all: rename source code to .py.in

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Rename this source code file to have an extention of ".py.in" so that editors and xgettext can "smartly" detect the source code type from the file extension. This will become important for adding localization to the strings printed. No functional changes.

---
 scrub/Makefile            |    6 +++---
 scrub/xfs_scrub_all.py.in |    0 
 2 files changed, 3 insertions(+), 3 deletions(-)
 rename scrub/{xfs_scrub_all.in => xfs_scrub_all.py.in} (100%)
scrub/Makefile +3 -3
index 934b9062651bf1..b8105f69e4cc57 100644
@@ -14,7 +14,7 @@ [email protected]
 ifeq ($(SCRUB_PREREQS),yes)
 LTCOMMAND = xfs_scrub
 INSTALL_SCRUB = install-scrub
-XFS_SCRUB_ALL_PROG = xfs_scrub_all
+XFS_SCRUB_ALL_PROG = xfs_scrub_all.py
 XFS_SCRUB_FAIL_PROG = xfs_scrub_fail
 XFS_SCRUB_ARGS = -p
 XFS_SCRUB_SERVICE_ARGS = -b -o autofsck
@@ -116,7 +116,7 @@ xfs_scrub_all.timer: xfs_scrub_all.timer.in $(builddefs)
 	@echo "    [SED]    $@"
 	$(Q)$(SED) -e "s|@pkg_state_dir@|$(PKG_STATE_DIR)|g" < $< > $@
 
-xfs_scrub_all: xfs_scrub_all.in $(builddefs)
+$(XFS_SCRUB_ALL_PROG): $(XFS_SCRUB_ALL_PROG).in $(builddefs)
 	@echo "    [SED]    $@"
 	$(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
 		   -e "s|@scrub_svcname@|$(scrub_svcname)|g" \
@@ -168,7 +168,7 @@ install-crond: default $(CRONTABS)
 install-scrub: default
 	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
-	$(INSTALL) -m 755 $(XFS_SCRUB_ALL_PROG) $(PKG_SBIN_DIR)
+	$(INSTALL) -m 755 $(XFS_SCRUB_ALL_PROG) $(PKG_SBIN_DIR)/xfs_scrub_all
 	$(INSTALL) -m 755 -d $(PKG_STATE_DIR)
 
 install-udev: $(UDEV_RULES)
scrub/xfs_scrub_all.py.in renamed from scrub/xfs_scrub_all.in +0 -0
similarity index 100%
rename from scrub/xfs_scrub_all.in
rename to scrub/xfs_scrub_all.py.in
#20 lore raw

PATCH 3/5 Makefile: inject package name/version/bugreport into pot file

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Inject the package name and version ("xfsprogs") and the bug reporting URL into the generated gettext .pot file. This isn't strictly necessary, it's more just polish.

---
 configure.ac         |    1 +
 include/builddefs.in |    1 +
 include/buildrules   |   10 +++++++++-
 3 files changed, 11 insertions(+), 1 deletion(-)
configure.ac +1 -0
index f039bc9128fa4b..71596711685a8a 100644
@@ -4,6 +4,7 @@ AC_CONFIG_AUX_DIR([.])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_SRCDIR([include/libxfs.h])
 AC_PREFIX_DEFAULT(/usr)
+AC_SUBST(PACKAGE_BUGREPORT)
 
 # Default CFLAGS if nobody specifies anything else
 if test "${CFLAGS+set}" != "set"; then
include/builddefs.in +1 -0
index fe2a7824a8653f..04b4e0880a84b8 100644
@@ -42,6 +42,7 @@ PKG_GROUP	= @pkg_group@
 PKG_RELEASE	= @pkg_release@
 PKG_VERSION	= @pkg_version@
 PKG_DISTRIBUTION= @pkg_distribution@
+PKG_BUGREPORT	= @PACKAGE_BUGREPORT@
 
 prefix		= @prefix@
 exec_prefix	= @exec_prefix@
include/buildrules +9 -1
index 6b76abced9ed0c..ae047ac41fe27c 100644
@@ -85,9 +85,17 @@ endif
 endif
 
 ifdef POTHEAD
+XGETTEXT_FLAGS=\
+	--language=C \
+	--keyword=_ \
+	--keyword=N_ \
+	--package-name=$(PKG_NAME) \
+	--package-version=$(PKG_VERSION) \
+	--msgid-bugs-address=$(PKG_BUGREPORT)
+
 $(POTHEAD): $(XGETTEXTFILES)
 	@echo "    [GETTXT] $@"
-	$(Q)$(XGETTEXT) --language=C --keyword=_ --keyword=N_ -o $@ $(XGETTEXTFILES)
+	$(Q)$(XGETTEXT) $(XGETTEXT_FLAGS) -o $@ $(XGETTEXTFILES)
 
 # Update translations
 update-po: $(POTHEAD) $(wildcard $(TOPDIR)/po/*.po)
#21 lore raw

PATCH 4/5 xfs_protofile: add messages to localization catalog

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Add the source code of these two Python programs to the list of files that are scanned for the gettext message catalog. This will enable localization of the outputs of these programs.

---
 configure.ac             |    2 +-
 include/buildrules       |    1 -
 libfrog/Makefile         |   18 +++++++++++++++++-
 libfrog/gettext.py.in    |   12 ++++++++++++
 mkfs/Makefile            |    7 +++++--
 mkfs/xfs_protofile.py.in |   21 ++++++++++++---------
 6 files changed, 47 insertions(+), 14 deletions(-)
 create mode 100644 libfrog/gettext.py.in
configure.ac +1 -1
index 71596711685a8a..4202144710d187 100644
@@ -130,7 +130,7 @@ test -n "$multiarch" && enable_lib64=no
 # to "find" is required, to avoid including such directories in the
 # list.
 LOCALIZED_FILES=""
-for lfile in `find ${srcdir} -path './.??*' -prune -o -name '*.c' -type f -print || exit 1`; do
+for lfile in `find ${srcdir} -path './.??*' -prune -o -name '*.c' -print -o -name '*.py.in' -print || exit 1`; do
     LOCALIZED_FILES="$LOCALIZED_FILES \$(TOPDIR)/$lfile"
 done
 AC_SUBST(LOCALIZED_FILES)
include/buildrules +0 -1
index ae047ac41fe27c..871e92db02de14 100644
@@ -86,7 +86,6 @@ endif
 
 ifdef POTHEAD
 XGETTEXT_FLAGS=\
-	--language=C \
 	--keyword=_ \
 	--keyword=N_ \
 	--package-name=$(PKG_NAME) \
libfrog/Makefile +17 -1
index fc7e506d96bbad..b64ca4597f4ea9 100644
@@ -64,11 +64,20 @@ randbytes.h \
 scrub.h \
 workqueue.h
 
+GETTEXT_PY = \
+	gettext.py
+
 LSRCFILES += gen_crc32table.c
 
 LDIRT = gen_crc32table crc32table.h
 
-default: ltdepend $(LTLIBRARY)
+ifeq ($(ENABLE_GETTEXT),yes)
+HAVE_GETTEXT = True
+else
+HAVE_GETTEXT = False
+endif
+
+default: ltdepend $(LTLIBRARY) $(GETTEXT_PY)
 
 crc32table.h: gen_crc32table.c crc32defs.h
 	@echo "    [CC]     gen_crc32table"
@@ -76,6 +85,13 @@ crc32table.h: gen_crc32table.c crc32defs.h
 	@echo "    [GENERATE] $@"
 	$(Q) ./gen_crc32table > crc32table.h
 
+$(GETTEXT_PY): $(GETTEXT_PY).in $(TOPDIR)/include/builddefs
+	@echo "    [SED]    $@"
+	$(Q)$(SED) -e "s|@HAVE_GETTEXT@|$(HAVE_GETTEXT)|g" \
+		   -e "s|@PACKAGE@|$(PKG_NAME)|g" \
+		   -e "s|@LOCALEDIR@|$(PKG_LOCALE_DIR)|g" \
+		   < $< > $@
+
 include $(BUILDRULES)
 
 install install-dev: default
libfrog/gettext.py.in new file +12 -0
new file mode 100644
index 00000000000000..61559f7373b6b3
@@ -0,0 +1,12 @@
+
+if __name__ == '__main__':
+	if @HAVE_GETTEXT@:
+		import gettext
+		# set up gettext before main so that we can set up _().
+		gettext.bindtextdomain("@PACKAGE@", "@LOCALEDIR@")
+		gettext.textdomain("@PACKAGE@")
+		_ = gettext.gettext
+	else:
+		def _(a):
+			return a
+
mkfs/Makefile +5 -2
index b1369e1853a98f..04905bd5101ccb 100644
@@ -30,9 +30,12 @@ default: depend $(LTCOMMAND) $(CFGFILES) $(XFS_PROTOFILE)
 
 include $(BUILDRULES)
 
-$(XFS_PROTOFILE): $(XFS_PROTOFILE).in
+$(XFS_PROTOFILE): $(XFS_PROTOFILE).in $(TOPDIR)/include/builddefs $(TOPDIR)/libfrog/gettext.py
 	@echo "    [SED]    $@"
-	$(Q)$(SED) -e "s|@pkg_version@|$(PKG_VERSION)|g" < $< > $@
+	$(Q)$(SED) -e "s|@pkg_version@|$(PKG_VERSION)|g" \
+		   -e '/@INIT_GETTEXT@/r $(TOPDIR)/libfrog/gettext.py' \
+		   -e '/@INIT_GETTEXT@/d' \
+		   < $< > $@
 	$(Q)chmod a+x $@
 
 install: default
mkfs/xfs_protofile.py.in +12 -9
index e83c39f5325846..040454da1da4df 100644
@@ -7,6 +7,7 @@
 
 # Walk a filesystem tree to generate a protofile for mkfs.
 
+@INIT_GETTEXT@
 import os
 import argparse
 import sys
@@ -86,12 +87,12 @@ def walk_tree(path, depth):
 
 	for fname in files:
 		if ' ' in fname:
-			raise ValueError( \
-				f'{fname}: Spaces not allowed in file names.')
+			msg = _("Spaces not allowed in file names.")
+			raise ValueError(f'{fname}: {msg}')
 	for fname in dirs:
 		if ' ' in fname:
-			raise Exception( \
-				f'{fname}: Spaces not allowed in file names.')
+			msg = _("Spaces not allowed in subdirectory names.")
+			raise Exception(f'{fname}: {msg}')
 
 	fname_width = max_fname_len(files)
 	for fname in files:
@@ -114,15 +115,17 @@ def walk_tree(path, depth):
 
 def main():
 	parser = argparse.ArgumentParser( \
-			description = "Generate mkfs.xfs protofile for a directory tree.")
-	parser.add_argument('paths', metavar = 'paths', type = str, \
-			nargs = '*', help = 'Directory paths to walk.')
-	parser.add_argument("-V", help = "Report version and exit.", \
+			description = _("Generate mkfs.xfs protofile for a directory tree."))
+	parser.add_argument('paths', metavar = _('paths'), type = str, \
+			nargs = '*', help = _('Directory paths to walk.'))
+	parser.add_argument("-V", help = _("Report version and exit."), \
 			action = "store_true")
 	args = parser.parse_args()
 
 	if args.V:
-		print("xfs_protofile version @pkg_version@")
+		msg = _("xfs_protofile version")
+		pkgver = "@pkg_version@"
+		print(f"{msg} {pkgver}")
 		sys.exit(0)
 
 	emit_proto_header()
#22 lore raw

PATCH 5/5 xfs_scrub_all: localize the strings in the program

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Use gettext to localize the output of this program. While we're at it, convert everything to f-strings to make it easier for translators to understand the string. f-strings introduce a runtime requirement of Python 3.6, which includes Debian 10 and RHEL 7.

---
 scrub/Makefile            |    7 ++++-
 scrub/xfs_scrub_all.py.in |   62 +++++++++++++++++++++++++++------------------
 2 files changed, 42 insertions(+), 27 deletions(-)
scrub/Makefile +5 -2
index b8105f69e4cc57..3636a47942e98e 100644
@@ -116,7 +116,7 @@ xfs_scrub_all.timer: xfs_scrub_all.timer.in $(builddefs)
 	@echo "    [SED]    $@"
 	$(Q)$(SED) -e "s|@pkg_state_dir@|$(PKG_STATE_DIR)|g" < $< > $@
 
-$(XFS_SCRUB_ALL_PROG): $(XFS_SCRUB_ALL_PROG).in $(builddefs)
+$(XFS_SCRUB_ALL_PROG): $(XFS_SCRUB_ALL_PROG).in $(builddefs) $(TOPDIR)/libfrog/gettext.py
 	@echo "    [SED]    $@"
 	$(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
 		   -e "s|@scrub_svcname@|$(scrub_svcname)|g" \
@@ -124,7 +124,10 @@ $(XFS_SCRUB_ALL_PROG): $(XFS_SCRUB_ALL_PROG).in $(builddefs)
 		   -e "s|@pkg_version@|$(PKG_VERSION)|g" \
 		   -e "s|@stampfile@|$(XFS_SCRUB_ALL_AUTO_MEDIA_SCAN_STAMP)|g" \
 		   -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \
-		   -e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" < $< > $@
+		   -e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" \
+		   -e '/@INIT_GETTEXT@/r $(TOPDIR)/libfrog/gettext.py' \
+		   -e '/@INIT_GETTEXT@/d' \
+		   < $< > $@
 	$(Q)chmod a+x $@
 
 xfs_scrub_fail: xfs_scrub_fail.in $(builddefs)
scrub/xfs_scrub_all.py.in +37 -25

178 lines not on this page · raw message

Reviewed-by on v1 1/1
#23 lore raw

Re: [PATCHSET] xfsprogs: localize the python programs

In reply to Darrick J. Wong
Quoted 24 lines · Darrick J. Wong

Hi all,

We ship two Python programs in the main xfsprogs package, but neither of them actually participate in gettext, which means that the output is always English no matter what user's locale settings are. Fix that by adding them to the autogenerated message catalog.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=localization
---
Commits in this patchset:
* xfs_protofile: rename source code to .py.in
* xfs_scrub_all: rename source code to .py.in
* Makefile: inject package name/version/bugreport into pot file
* xfs_protofile: add messages to localization catalog
* xfs_scrub_all: localize the strings in the program

Quoted 15 lines
---
 configure.ac              |    3 +-
 include/builddefs.in      |    1 +
 include/buildrules        |    9 ++++++-
 libfrog/Makefile          |   18 ++++++++++++-
 libfrog/gettext.py.in     |   12 +++++++++
 mkfs/Makefile             |   11 +++++---
 mkfs/xfs_protofile.py.in  |   21 +++++++++------
 scrub/Makefile            |   11 +++++---
 scrub/xfs_scrub_all.py.in |   62 +++++++++++++++++++++++++++------------------
 9 files changed, 103 insertions(+), 45 deletions(-)
 create mode 100644 libfrog/gettext.py.in
 rename mkfs/{xfs_protofile.in => xfs_protofile.py.in} (85%)
 rename scrub/{xfs_scrub_all.in => xfs_scrub_all.py.in} (89%)

The patchset looks good to me

Signature · 1 line
- Andrey
Reviewed-by on v1 1/1
#24 lore raw

Re: [PATCHSET] xfsprogs: localize the python programs

In reply to Darrick J. Wong
Quoted 15 lines · Darrick J. Wong

Hi all,

We ship two Python programs in the main xfsprogs package, but neither of them actually participate in gettext, which means that the output is always English no matter what user's locale settings are. Fix that by adding them to the autogenerated message catalog.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

Quoted 10 lines

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=localization
---
Commits in this patchset:
* xfs_protofile: rename source code to .py.in
* xfs_scrub_all: rename source code to .py.in
* Makefile: inject package name/version/bugreport into pot file
* xfs_protofile: add messages to localization catalog
* xfs_scrub_all: localize the strings in the program
---

For the series...

Quoted 15 lines
 configure.ac              |    3 +-
 include/builddefs.in      |    1 +
 include/buildrules        |    9 ++++++-
 libfrog/Makefile          |   18 ++++++++++++-
 libfrog/gettext.py.in     |   12 +++++++++
 mkfs/Makefile             |   11 +++++---
 mkfs/xfs_protofile.py.in  |   21 +++++++++------
 scrub/Makefile            |   11 +++++---
 scrub/xfs_scrub_all.py.in |   62 +++++++++++++++++++++++++++------------------
 9 files changed, 103 insertions(+), 45 deletions(-)
 create mode 100644 libfrog/gettext.py.in
 rename mkfs/{xfs_protofile.in => xfs_protofile.py.in} (85%)
 rename scrub/{xfs_scrub_all.in => xfs_scrub_all.py.in} (89%)