Skip to content

Commit 2339f9c

Browse files
author
Miklos Szeredi
committed
fuse: support FSCONFIG_SET_FD for "fd" option
This is not only cleaner to use in userspace (no need to sprintf the fd to a string) but also allows userspace to detect that the devfd can be closed after the fsconfig call. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
1 parent 4ae404a commit 2339f9c

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

fs/fuse/inode.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ enum {
791791

792792
static const struct fs_parameter_spec fuse_fs_parameters[] = {
793793
fsparam_string ("source", OPT_SOURCE),
794-
fsparam_u32 ("fd", OPT_FD),
794+
fsparam_fd ("fd", OPT_FD),
795795
fsparam_u32oct ("rootmode", OPT_ROOTMODE),
796796
fsparam_uid ("user_id", OPT_USER_ID),
797797
fsparam_gid ("group_id", OPT_GROUP_ID),
@@ -803,13 +803,9 @@ static const struct fs_parameter_spec fuse_fs_parameters[] = {
803803
{}
804804
};
805805

806-
static int fuse_opt_fd(struct fs_context *fsc, int fd)
806+
static int fuse_opt_fd(struct fs_context *fsc, struct file *file)
807807
{
808808
struct fuse_fs_context *ctx = fsc->fs_private;
809-
struct file *file __free(fput) = fget(fd);
810-
811-
if (!file)
812-
return -EBADF;
813809

814810
if (file->f_op != &fuse_dev_operations)
815811
return invalfc(fsc, "fd is not a fuse device");
@@ -865,7 +861,15 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
865861
return 0;
866862

867863
case OPT_FD:
868-
return fuse_opt_fd(fsc, result.uint_32);
864+
if (param->type == fs_value_is_file) {
865+
return fuse_opt_fd(fsc, param->file);
866+
} else {
867+
struct file *file __free(fput) = fget(result.uint_32);
868+
if (!file)
869+
return -EBADF;
870+
871+
return fuse_opt_fd(fsc, file);
872+
}
869873

870874
case OPT_ROOTMODE:
871875
if (!fuse_valid_type(result.uint_32))

0 commit comments

Comments
 (0)