Use the extended fuse_entry2_out reply for FUSE_CREATE and FUSE_TMPFILE when FUSE_PASSTHROUGH_INO is enabled. If the server returns a backing id, the newly created inode is associated with the backing file for passthrough operations before the dentry is instantiated. Signed-off-by: Joanne Koong --- fs/fuse/dir.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index a11f9e4c1999..4c7e3e1604af 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -934,9 +934,12 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, struct fuse_create_in inarg; struct fuse_open_out *outopenp; struct fuse_entry_out outentry; + struct fuse_entry2_out outentry2; + struct fuse_statx *sx = NULL; struct fuse_inode *fi; struct fuse_file *ff; int epoch, err; + int backing_id; bool trunc = flags & O_TRUNC; /* Userspace expects S_IFREG in create mode */ @@ -957,7 +960,6 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, flags &= ~O_NOCTTY; memset(&inarg, 0, sizeof(inarg)); - memset(&outentry, 0, sizeof(outentry)); inarg.flags = flags; inarg.mode = mode; inarg.umask = current_umask(); @@ -975,8 +977,15 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, args.in_args[1].size = entry->d_name.len + 1; args.in_args[1].value = entry->d_name.name; args.out_numargs = 2; - args.out_args[0].size = sizeof(outentry); - args.out_args[0].value = &outentry; + if (fuse_use_entry2(fm->fc)) { + memset(&outentry2, 0, sizeof(outentry2)); + args.out_args[0].size = sizeof(outentry2); + args.out_args[0].value = &outentry2; + } else { + memset(&outentry, 0, sizeof(outentry)); + args.out_args[0].size = sizeof(outentry); + args.out_args[0].value = &outentry; + } /* Store outarg for fuse_finish_open() */ outopenp = &ff->args->open_outarg; args.out_args[1].size = sizeof(*outopenp); @@ -991,6 +1000,8 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, if (err) goto out_free_ff; + backing_id = fuse_process_entry2(fm->fc, &outentry2, &outentry, &sx); + err = -EIO; if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr)) @@ -999,16 +1010,26 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, ff->fh = outopenp->fh; ff->nodeid = outentry.nodeid; ff->open_flags = outopenp->open_flags; + + if (backing_id < 0) { + err = backing_id; + goto out_queue_forget; + } + inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, - &outentry.attr, NULL, ATTR_TIMEOUT(&outentry), 0, 0); + &outentry.attr, sx, ATTR_TIMEOUT(&outentry), 0, 0); if (!inode) { - flags &= ~(O_CREAT | O_EXCL | O_TRUNC); - fuse_sync_release(NULL, ff, flags, false); - fuse_chan_queue_forget(fm->fc->chan, forget, outentry.nodeid, 1); err = -ENOMEM; - goto out_err; + goto out_queue_forget; } kfree(forget); + if (backing_id) { + err = fuse_inode_set_passthrough(inode, backing_id); + if (err) { + iput(inode); + goto out_sync_release; + } + } d_instantiate(entry, inode); entry->d_time = epoch; fuse_change_entry_timeout(entry, &outentry); @@ -1035,6 +1056,12 @@ static int fuse_create_open(struct mnt_idmap *idmap, struct inode *dir, kfree(forget); out_err: return err; +out_queue_forget: + fuse_chan_queue_forget(fm->fc->chan, forget, outentry.nodeid, 1); +out_sync_release: + flags &= ~(O_CREAT | O_EXCL | O_TRUNC); + fuse_sync_release(NULL, ff, flags, false); + return err; } static int fuse_mknod(struct mnt_idmap *, struct inode *, struct dentry *, -- 2.52.0