Skip to contentSkip to conversation

generic: shutdown might leave NULL files with nonzero di_size

PATCH In review Zorro Lang 2 participants 2 messages Nov 9, 2022

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH v3 1/1 generic: shutdown might leave NULL files with nonzero di_size

An old issue might cause on-disk inode sizes are logged prematurely via the free eofblocks path on file close. Then fs shutdown might leave NULL files but their di_size > 0.

---

Hi,

V2 replace xfs_io fiemap command with stat command.
V3 replace the stat with the filefrag command, and change the supported_fs from xfs to generic.

Thanks,
Zorro

 tests/generic/999     | 46 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |  5 +++++
 2 files changed, 51 insertions(+)
 create mode 100755 tests/generic/999
 create mode 100644 tests/generic/999.out
tests/generic/999 new file +46 -0
new file mode 100755
index 00000000..ca666de7
@@ -0,0 +1,46 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 999
+#
+# Test an issue in the truncate codepath where on-disk inode sizes are logged
+# prematurely via the free eofblocks path on file close.
+#
+. ./common/preamble
+_begin_fstest auto shutdown
+
+# real QA test starts here
+_supported_fs generic
+_require_scratch
+_require_scratch_shutdown
+_require_command "$FILEFRAG_PROG" filefrag
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+echo "Create many small files with one extent at least"
+for ((i=0; i<10000; i++));do
+	$XFS_IO_PROG -f -c "pwrite 0 4k" $SCRATCH_MNT/file.$i >/dev/null 2>&1
+done
+
+echo "Shutdown the fs suddently"
+_scratch_shutdown
+
+echo "Cycle mount"
+_scratch_cycle_mount
+
+echo "Check file's (di_size > 0) extents"
+for f in $(find $SCRATCH_MNT -type f -size +0);do
+	# Check if the file has any extent
+	$FILEFRAG_PROG -v $f > $tmp.filefrag
+	grep -Eq ': 0 extents found' $tmp.filefrag
+	if [ $? -eq 0 ];then
+		echo " - $f get no extents, but its di_size > 0"
+		cat $tmp.filefrag
+		break
+	fi
+done
+
+# success, all done
+status=0
+exit
tests/generic/999.out new file +5 -0
new file mode 100644
index 00000000..50008783
@@ -0,0 +1,5 @@
+QA output created by 999
+Create many small files with one extent at least
+Shutdown the fs suddently
+Cycle mount
+Check file's (di_size > 0) extents
Signature · 1 line
2.31.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 55 lines · Zorro Lang

An old issue might cause on-disk inode sizes are logged prematurely via the free eofblocks path on file close. Then fs shutdown might leave NULL files but their di_size > 0.

---

Hi,

V2 replace xfs_io fiemap command with stat command.
V3 replace the stat with the filefrag command, and change the supported_fs from xfs to generic.

Thanks,
Zorro

 tests/generic/999     | 46 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |  5 +++++
 2 files changed, 51 insertions(+)
 create mode 100755 tests/generic/999
 create mode 100644 tests/generic/999.out
tests/generic/999 new file +27 -0
new file mode 100755
index 00000000..ca666de7
@@ -0,0 +1,46 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 999
+#
+# Test an issue in the truncate codepath where on-disk inode sizes are logged
+# prematurely via the free eofblocks path on file close.
+#
+. ./common/preamble
+_begin_fstest auto shutdown
+
+# real QA test starts here
+_supported_fs generic
+_require_scratch
+_require_scratch_shutdown
+_require_command "$FILEFRAG_PROG" filefrag
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+echo "Create many small files with one extent at least"
+for ((i=0; i<10000; i++));do
+	$XFS_IO_PROG -f -c "pwrite 0 4k" $SCRATCH_MNT/file.$i >/dev/null 2>&1
+done
+
+echo "Shutdown the fs suddently"
+_scratch_shutdown

tests/generic/999 line 37

Quoted 10 lines
tests/generic/999 new file +10 -0
+
+echo "Cycle mount"
+_scratch_cycle_mount
+
+echo "Check file's (di_size > 0) extents"
+for f in $(find $SCRATCH_MNT -type f -size +0);do
+	# Check if the file has any extent
+	$FILEFRAG_PROG -v $f > $tmp.filefrag
+	grep -Eq ': 0 extents found' $tmp.filefrag
+	if [ $? -eq 0 ];then

Bash nit: You could compress these two lines to:

if grep -E -q ': 0 extents found' $tmp.filefrag; then

But otherwise this looks good.

--D

Quoted 23 lines
tests/generic/999 new file +9 -0
+		echo " - $f get no extents, but its di_size > 0"
+		cat $tmp.filefrag
+		break
+	fi
+done
+
+# success, all done
+status=0
+exit
tests/generic/999.out new file +5 -0
new file mode 100644
index 00000000..50008783
@@ -0,0 +1,5 @@
+QA output created by 999
+Create many small files with one extent at least
+Shutdown the fs suddently
+Cycle mount
+Check file's (di_size > 0) extents
Signature · 1 line
2.31.1