Skip to content

Commit d701902

Browse files
neilbrownbrauner
authored andcommitted
fuse: return correct dentry for ->mkdir
fuse already uses d_splice_alias() to ensure an appropriate dentry is found for a newly created dentry. Now that ->mkdir can return that dentry we do so. This requires changing create_new_entry() to return a dentry and handling that change in all callers. Note that when create_new_entry() is asked to create anything other than a directory we can be sure it will NOT return an alternate dentry as d_splice_alias() only returns an alternate dentry for directories. So we don't need to check for that case when passing one the result. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: NeilBrown <neilb@suse.de> Link: https://lore.kernel.org/r/174112490070.33508.15852253149143067890@noble.neil.brown.name Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3f92c7b commit d701902

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

fs/fuse/dir.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,9 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
781781
/*
782782
* Code shared between mknod, mkdir, symlink and link
783783
*/
784-
static int create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm,
785-
struct fuse_args *args, struct inode *dir,
786-
struct dentry *entry, umode_t mode)
784+
static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm,
785+
struct fuse_args *args, struct inode *dir,
786+
struct dentry *entry, umode_t mode)
787787
{
788788
struct fuse_entry_out outarg;
789789
struct inode *inode;
@@ -792,11 +792,11 @@ static int create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm,
792792
struct fuse_forget_link *forget;
793793

794794
if (fuse_is_bad(dir))
795-
return -EIO;
795+
return ERR_PTR(-EIO);
796796

797797
forget = fuse_alloc_forget();
798798
if (!forget)
799-
return -ENOMEM;
799+
return ERR_PTR(-ENOMEM);
800800

801801
memset(&outarg, 0, sizeof(outarg));
802802
args->nodeid = get_node_id(dir);
@@ -826,29 +826,43 @@ static int create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm,
826826
&outarg.attr, ATTR_TIMEOUT(&outarg), 0, 0);
827827
if (!inode) {
828828
fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1);
829-
return -ENOMEM;
829+
return ERR_PTR(-ENOMEM);
830830
}
831831
kfree(forget);
832832

833833
d_drop(entry);
834834
d = d_splice_alias(inode, entry);
835835
if (IS_ERR(d))
836-
return PTR_ERR(d);
836+
return d;
837837

838-
if (d) {
838+
if (d)
839839
fuse_change_entry_timeout(d, &outarg);
840-
dput(d);
841-
} else {
840+
else
842841
fuse_change_entry_timeout(entry, &outarg);
843-
}
844842
fuse_dir_changed(dir);
845-
return 0;
843+
return d;
846844

847845
out_put_forget_req:
848846
if (err == -EEXIST)
849847
fuse_invalidate_entry(entry);
850848
kfree(forget);
851-
return err;
849+
return ERR_PTR(err);
850+
}
851+
852+
static int create_new_nondir(struct mnt_idmap *idmap, struct fuse_mount *fm,
853+
struct fuse_args *args, struct inode *dir,
854+
struct dentry *entry, umode_t mode)
855+
{
856+
/*
857+
* Note that when creating anything other than a directory we
858+
* can be sure create_new_entry() will NOT return an alternate
859+
* dentry as d_splice_alias() only returns an alternate dentry
860+
* for directories. So we don't need to check for that case
861+
* when passing back the result.
862+
*/
863+
WARN_ON_ONCE(S_ISDIR(mode));
864+
865+
return PTR_ERR(create_new_entry(idmap, fm, args, dir, entry, mode));
852866
}
853867

854868
static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,
@@ -871,7 +885,7 @@ static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir,
871885
args.in_args[0].value = &inarg;
872886
args.in_args[1].size = entry->d_name.len + 1;
873887
args.in_args[1].value = entry->d_name.name;
874-
return create_new_entry(idmap, fm, &args, dir, entry, mode);
888+
return create_new_nondir(idmap, fm, &args, dir, entry, mode);
875889
}
876890

877891
static int fuse_create(struct mnt_idmap *idmap, struct inode *dir,
@@ -917,7 +931,7 @@ static struct dentry *fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir,
917931
args.in_args[0].value = &inarg;
918932
args.in_args[1].size = entry->d_name.len + 1;
919933
args.in_args[1].value = entry->d_name.name;
920-
return ERR_PTR(create_new_entry(idmap, fm, &args, dir, entry, S_IFDIR));
934+
return create_new_entry(idmap, fm, &args, dir, entry, S_IFDIR);
921935
}
922936

923937
static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,
@@ -934,7 +948,7 @@ static int fuse_symlink(struct mnt_idmap *idmap, struct inode *dir,
934948
args.in_args[1].value = entry->d_name.name;
935949
args.in_args[2].size = len;
936950
args.in_args[2].value = link;
937-
return create_new_entry(idmap, fm, &args, dir, entry, S_IFLNK);
951+
return create_new_nondir(idmap, fm, &args, dir, entry, S_IFLNK);
938952
}
939953

940954
void fuse_flush_time_update(struct inode *inode)
@@ -1131,7 +1145,7 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
11311145
args.in_args[0].value = &inarg;
11321146
args.in_args[1].size = newent->d_name.len + 1;
11331147
args.in_args[1].value = newent->d_name.name;
1134-
err = create_new_entry(&invalid_mnt_idmap, fm, &args, newdir, newent, inode->i_mode);
1148+
err = create_new_nondir(&invalid_mnt_idmap, fm, &args, newdir, newent, inode->i_mode);
11351149
if (!err)
11361150
fuse_update_ctime_in_cache(inode);
11371151
else if (err == -EINTR)

0 commit comments

Comments
 (0)