[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230911183905.GA1960@templeofstupid.com>
Date: Mon, 11 Sep 2023 11:39:05 -0700
From: Krister Johansen <kjlx@...pleofstupid.com>
To: Theodore Ts'o <tytso@....edu>, linux-ext4@...r.kernel.org
Subject: [e2fsprogs PATCH v2] resize2fs: use directio when reading superblock
Invocations of resize2fs intermittently report failure due to superblock
checksum mismatches in this author's environment. This might happen a few
times a week. The following script can make this happen within minutes.
(It assumes /dev/nvme1n1 is available and not in use by anything else).
#!/usr/bin/bash
set -euxo pipefail
while true
do
parted /dev/nvme1n1 mklabel gpt mkpart primary 2048s 2099200s
sleep .5
mkfs.ext4 /dev/nvme1n1p1
mount -t ext4 /dev/nvme1n1p1 /mnt
stress-ng --temp-path /mnt -D 4 &
STRESS_PID=$!
sleep 1
growpart /dev/nvme1n1 1
resize2fs /dev/nvme1n1p1
kill $STRESS_PID
wait $STRESS_PID
umount /mnt
wipefs -a /dev/nvme1n1p1
wipefs -a /dev/nvme1n1
done
After trying a few possible solutions, adding an O_DIRECT read to the open
path in resize2fs eliminated the occurrences on test systems. ext2fs_open2
uses a negative count value when calling io_channel_read_blk to get the
superblock. According to unix_read_block, negative offsets are to be read
direct. However, when strace-ing a program without this fix, the
underlying device was opened without O_DIRECT. Adding the flags in the
patch ensures the device is opend with O_DIRECT and that the superblock
read appears consistent.
Signed-off-by: Krister Johansen <kjlx@...pleofstupid.com>
---
v2:
- Only set DIRECT_IO flag when resizing a mounted filesystem. (Feedback from
Theodore Ts'o)
---
resize/main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/resize/main.c b/resize/main.c
index 94f5ec6d..f914c050 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -409,6 +409,8 @@ int main (int argc, char ** argv)
if (!(mount_flags & EXT2_MF_MOUNTED) && !print_min_size)
io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
+ if (mount_flags & EXT2_MF_MOUNTED)
+ io_flags |= EXT2_FLAG_DIRECT_IO;
io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
if (undo_file) {
--
2.25.1
Powered by blists - more mailing lists