aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Dilger <adilger@whamcloud.com>2020-02-21 14:40:56 -0700
committerTheodore Ts'o <tytso@mit.edu>2020-03-07 11:14:02 -0500
commit947315c86645e3ac3e814a49a7e7ab4b3498f64b (patch)
tree83aae96bae091c38e7fc687fb4503ac6430dcd0a
parent937650f78e2d0e087048acd2a878139b27df3625 (diff)
downloade2fsprogs-947315c86645e3ac3e814a49a7e7ab4b3498f64b.tar.gz
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 <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--lib/ext2fs/mmp.c15
-rw-r--r--tests/f_mmp/script11
-rw-r--r--tests/f_mmp_garbage/script11
-rw-r--r--tests/m_image_mmp/script11
-rw-r--r--tests/m_mmp/script10
-rw-r--r--tests/m_mmp_bad_csum/script10
-rw-r--r--tests/m_mmp_bad_magic/script10
-rw-r--r--tests/t_mmp_1on/script11
-rw-r--r--tests/t_mmp_2off/script11
9 files changed, 14 insertions, 86 deletions
diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
index 2da935e0d..e96a22732 100644
--- a/lib/ext2fs/mmp.c
+++ b/lib/ext2fs/mmp.c
@@ -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;
}
diff --git a/tests/f_mmp/script b/tests/f_mmp/script
index 07ae23215..f433bd5fc 100644
--- a/tests/f_mmp/script
+++ b/tests/f_mmp/script
@@ -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=$?
diff --git a/tests/f_mmp_garbage/script b/tests/f_mmp_garbage/script
index 6d451a676..69be3387f 100644
--- a/tests/f_mmp_garbage/script
+++ b/tests/f_mmp_garbage/script
@@ -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=$?
diff --git a/tests/m_image_mmp/script b/tests/m_image_mmp/script
index bc6f320bb..5af6f552d 100644
--- a/tests/m_image_mmp/script
+++ b/tests/m_image_mmp/script
@@ -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
diff --git a/tests/m_mmp/script b/tests/m_mmp/script
index 6a9394dee..e456183c1 100644
--- a/tests/m_mmp/script
+++ b/tests/m_mmp/script
@@ -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
diff --git a/tests/m_mmp_bad_csum/script b/tests/m_mmp_bad_csum/script
index 4c8fe1657..a5e222ebb 100644
--- a/tests/m_mmp_bad_csum/script
+++ b/tests/m_mmp_bad_csum/script
@@ -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
diff --git a/tests/m_mmp_bad_magic/script b/tests/m_mmp_bad_magic/script
index 4c8fe1657..a5e222ebb 100644
--- a/tests/m_mmp_bad_magic/script
+++ b/tests/m_mmp_bad_magic/script
@@ -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
diff --git a/tests/t_mmp_1on/script b/tests/t_mmp_1on/script
index cfed2ca8c..733395ef3 100644
--- a/tests/t_mmp_1on/script
+++ b/tests/t_mmp_1on/script
@@ -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
diff --git a/tests/t_mmp_2off/script b/tests/t_mmp_2off/script
index 6556201fa..ccd859b2f 100644
--- a/tests/t_mmp_2off/script
+++ b/tests/t_mmp_2off/script
@@ -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