]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: don't use O_DIRECT for files on tmpfs
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 21 Feb 2020 21:40:56 +0000 (14:40 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 7 Mar 2020 16:14:02 +0000 (11:14 -0500)
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>
lib/ext2fs/mmp.c
tests/f_mmp/script
tests/f_mmp_garbage/script
tests/m_image_mmp/script
tests/m_mmp/script
tests/m_mmp_bad_csum/script
tests/m_mmp_bad_magic/script
tests/t_mmp_1on/script
tests/t_mmp_2off/script

index 2da935e0dd1094972a6f7a2f40e8c3d2c5fadec5..e96a227327fcaa691d3aa9fe5d8eaef26bb8d999 100644 (file)
@@ -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) {
         * 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) {
                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;
                }
                        retval = EXT2_ET_MMP_OPEN_DIRECT;
                        goto out;
                }
index 07ae23215820671f596b60d3546c8192c7538ff5..f433bd5fca60921582e3a3a120cbb8d9eeb6924e 100644 (file)
@@ -1,16 +1,5 @@
 FSCK_OPT=-yf
 
 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=$?
 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=$?
index 6d451a676c1073c2fc83827e29a9fdf2320fd2b7..69be3387f77edc685c3ada86b28fe5689e718af9 100644 (file)
@@ -1,16 +1,5 @@
 FSCK_OPT=-yf
 
 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=$?
 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=$?
index bc6f320bbb9dd08759013e7c444f0201eb478b9a..5af6f552dbbdeae2d92bcf4557a10fd6818f52a0 100644 (file)
@@ -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
 $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
index 6a9394dee1b8b80a1684572937ab1538f9fb2802..e456183c10cb7346638456e202fc09669f316e1f 100644 (file)
@@ -3,16 +3,6 @@ FS_SIZE=65536
 MKE2FS_DEVICE_SECTSIZE=2048
 export MKE2FS_DEVICE_SECTSIZE
 
 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
 MKE2FS_OPTS="-b 4096 -O mmp"
 . $cmd_dir/run_mke2fs
 unset MKE2FS_DEVICE_SECTSIZE
index 4c8fe1657b5ed5e834459ff1787d614479e6a6e0..a5e222ebb005af8885b048d75892788350377d16 100644 (file)
@@ -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
 gzip -dc < $test_dir/image.gz > $TMPFILE
 
 OUT=$test_name.log
index 4c8fe1657b5ed5e834459ff1787d614479e6a6e0..a5e222ebb005af8885b048d75892788350377d16 100644 (file)
@@ -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
 gzip -dc < $test_dir/image.gz > $TMPFILE
 
 OUT=$test_name.log
index cfed2ca8c5b24e31310dac916a5a9d14a6905abc..733395ef3b20011fed89974457eb9aa28ce26f07 100644 (file)
@@ -1,16 +1,5 @@
 FSCK_OPT=-yf
 
 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
 $MKE2FS -q -F -o Linux -b 4096 $TMPFILE 100 > $test_name.log 2>&1
 status=$?
 if [ "$status" != 0 ] ; then
index 6556201fa8c48172b56d44d5651c8158c119dbd5..ccd859b2f41c235324097c50bc25757797481e34 100644 (file)
@@ -1,16 +1,5 @@
 FSCK_OPT=-yf
 
 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
 $MKE2FS -q -F -o Linux -b 4096 -O mmp $TMPFILE 100 > $test_name.log 2>&1
 status=$?
 if [ "$status" != 0 ] ; then