libext2fs: don't use O_DIRECT for files on tmpfs
PATCH 1/1 libext2fs: don't use O_DIRECT for files on tmpfs
If a filesystem image is on tmpfs, opening it with O_DIRECT for reading the MMP will fail. This is unnecessary, since the image file can't really be open on another node at this point. If the open with O_DIRECT fails, retry without it when plausible.
Remove the special-casing of tmpfs from the mmp test cases.
Change-Id I41f4b31657b06f62f10be8d6e524d303dd36a321
Signed-off-by Andreas Dilger <[email protected]>
--- lib/ext2fs/mmp.c | 15 ++++++++++++++- tests/f_mmp/script | 11 ----------- tests/f_mmp_garbage/script | 11 ----------- tests/m_image_mmp/script | 11 ----------- tests/m_mmp/script | 10 ---------- tests/m_mmp_bad_csum/script | 10 ---------- tests/m_mmp_bad_magic/script | 10 ---------- tests/t_mmp_1on/script | 11 ----------- tests/t_mmp_2off/script | 11 ----------- 9 files changed, 14 insertions(+), 86 deletions(-)
lib/ext2fs/mmp.c +14 -1
@@ -57,8 +57,21 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)* regardless of how the io_manager is doing reads, to avoid caching of * the MMP block by the io_manager or the VM. It needs to be fresh. */ if (fs->mmp_fd <=0 ) { - fs->mmp_fd =open (fs->device_name,O_RDWR |O_DIRECT ); +int flags =O_RDWR |O_DIRECT ; + +retry: + fs->mmp_fd =open (fs->device_name, flags);if (fs->mmp_fd <0 ) { +struct stat st; + +/* Avoid O_DIRECT for filesystem image files if open +* fails, since it breaks when running on tmpfs. */ +if (errno ==EINVAL && (flags &O_DIRECT ) && +stat (fs->device_name, &st) ==0 && +S_ISREG (st.st_mode)) { + flags &= ~O_DIRECT ; + goto retry; + } retval =EXT2_ET_MMP_OPEN_DIRECT ; goto out; }
tests/f_mmp/script +0 -11
@@ -1,16 +1,5 @@ FSCK_OPT=-yf -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi - echo "make the test image ..." > $test_name.log $MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1 status=$?
tests/f_mmp_garbage/script +0 -11
@@ -1,16 +1,5 @@ FSCK_OPT=-yf -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ] ; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi - echo "make the test image ..." > $test_name.log $MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1 status=$?
tests/m_image_mmp/script +0 -11
@@ -1,14 +1,3 @@ -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi - $MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1 status=$? if [ "$status" != 0 ] ; then
tests/m_mmp/script +0 -10
@@ -3,16 +3,6 @@ FS_SIZE=65536 MKE2FS_DEVICE_SECTSIZE=2048 export MKE2FS_DEVICE_SECTSIZE -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi MKE2FS_OPTS="-b 4096 -O mmp" . $cmd_dir/run_mke2fs unset MKE2FS_DEVICE_SECTSIZE
tests/m_mmp_bad_csum/script +0 -10
@@ -1,13 +1,3 @@ -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi gzip -dc < $test_dir/image.gz > $TMPFILE OUT=$test_name.log
tests/m_mmp_bad_magic/script +0 -10
@@ -1,13 +1,3 @@ -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi gzip -dc < $test_dir/image.gz > $TMPFILE OUT=$test_name.log
tests/t_mmp_1on/script +0 -11
@@ -1,16 +1,5 @@ FSCK_OPT=-yf -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ] ; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi - $MKE2FS -q -F -o Linux -b 4096 $TMPFILE 100 > $test_name.log 2>&1 status=$? if [ "$status" != 0 ] ; then
tests/t_mmp_2off/script +0 -11
@@ -1,16 +1,5 @@ FSCK_OPT=-yf -# use current directory instead of /tmp becase tmpfs doesn't support DIO -rm -f $TMPFILE -TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) - -stat -f $TMPFILE | grep -q "Type: tmpfs" -if [ $? = 0 ]; then - rm -f $TMPFILE - echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" - return 0 -fi - $MKE2FS -q -F -o Linux -b 4096 -O mmp $TMPFILE 100 > $test_name.log 2>&1 status=$? if [ "$status" != 0 ] ; then
Signature · 1 line
2.21.0 (Apple Git-122)
Theodore Y. Ts'o
AppliedQuoted 9 lines · Andreas Dilger
If a filesystem image is on tmpfs, opening it with
O_DIRECTfor reading the MMP will fail. This is unnecessary, since the image file can't really be open on another node at this point. If the open withO_DIRECTfails, retry without it when plausible.Remove the special-casing of tmpfs from the mmp test cases.
Change-Id I41f4b31657b06f62f10be8d6e524d303dd36a321Signed-off-by Andreas Dilger <[email protected]>
Applied, thanks.
- Ted