From: Darrick J. Wong Cache the iomaps we generate in the kernel for better performance. Signed-off-by: "Darrick J. Wong" --- misc/fuse2fs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index d0478af036a25e..f863042a4db074 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -5505,6 +5505,7 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino, { struct fuse_context *ctxt = fuse_get_context(); struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data; + struct fuse_session *se = fuse_get_session(ctxt->fuse); struct ext2_inode_large inode; ext2_filsys fs; errcode_t err; @@ -5560,6 +5561,24 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino, } } + /* + * Cache the mapping in the kernel so that we can reuse them for + * subsequent IO. Note that we have to return NULL mappings to the + * kernel to prompt it to re-try the cache. + */ + write_iomap->type = FUSE_IOMAP_TYPE_NULL; + err = fuse_lowlevel_notify_iomap_upsert(se, nodeid, attr_ino, + read_iomap, write_iomap); + if (err) { + ret = translate_error(fs, attr_ino, err); + goto out_unlock; + } + + /* Null out the read mapping to encourage a retry. */ + read_iomap->type = FUSE_IOMAP_TYPE_NULL; + read_iomap->dev = FUSE_IOMAP_DEV_NULL; + read_iomap->addr = FUSE_IOMAP_NULL_ADDR; + out_unlock: fuse2fs_finish(ff, ret); return ret;