From: Darrick J. Wong <djwong@xxxxxxxxxx> In iomap mode, the kernel writes file data directly to the block device and does not flush the bdev page cache. We must open the filesystem in directio mode to avoid cache coherency issues when reading file data blocks. If we can't open the bdev in directio mode, we must not use iomap. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- misc/fuse2fs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 9eb067e1737054..72b9ec837209ca 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -1174,6 +1174,9 @@ static void *op_init(struct fuse_conn_info *conn struct fuse_context *ctxt = fuse_get_context(); struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data; ext2_filsys fs = ff->fs; +#ifdef HAVE_FUSE_IOMAP + int was_directio = ff->directio; +#endif errcode_t err; int ret; @@ -1196,6 +1199,15 @@ static void *op_init(struct fuse_conn_info *conn if (ff->iomap_state != IOMAP_DISABLED && fuse_set_feature_flag(conn, FUSE_CAP_IOMAP)) ff->iomap_state = IOMAP_ENABLED; + /* + * In iomap mode, the kernel writes file data directly to the block + * device and does not flush the bdev page cache. We must open the + * filesystem in directio mode to avoid cache coherency issues when + * reading file data. If we can't open the bdev in directio mode, we + * must not use iomap. + */ + if (fuse2fs_iomap_enabled(ff)) + ff->directio = 1; #endif #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0) @@ -1213,6 +1225,14 @@ static void *op_init(struct fuse_conn_info *conn */ if (!fs) { err = fuse2fs_open(ff, 0); +#ifdef HAVE_FUSE_IOMAP + if (err && fuse2fs_iomap_enabled(ff) && !was_directio) { + fuse_unset_feature_flag(conn, FUSE_CAP_IOMAP); + ff->iomap_state = IOMAP_DISABLED; + ff->directio = 0; + err = fuse2fs_open(ff, 0); + } +#endif if (err) goto mount_fail; fs = ff->fs;