From d068535c216b842315c9c7226cc57e2b3dc7c7c3 Mon Sep 17 00:00:00 2001 From: Liu Bo Date: Thu, 9 Apr 2020 13:31:39 +0800 Subject: [PATCH] alinux: virtiofs: simplify mount options task #28910367 Rather than explicitly specifying "-o default_permissions,allow_other", virtiofs can set some default values for them. With this, we can simply do "mount -t virtio_fs atest /mnt/test/ -otag=myfs-1,dax". Signed-off-by: Liu Bo Reviewed-by: Joseph Qi --- fs/fuse/fuse_i.h | 2 +- fs/fuse/inode.c | 14 ++++++++++++-- fs/fuse/virtio_fs.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 835bb6024f7d..379ea2a9a70a 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1002,7 +1002,7 @@ void fuse_dev_free(struct fuse_dev *fud); * Parse a mount options string */ int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev, - struct user_namespace *user_ns); + struct user_namespace *user_ns, int is_virtiofs); /** * Fill in superblock and initialize fuse connection diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 2e622217c539..e647c56f7b22 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -468,13 +468,19 @@ static int fuse_match_uint(substring_t *s, unsigned int *res) } int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev, - struct user_namespace *user_ns) + struct user_namespace *user_ns, int is_virtiofs) { char *p; memset(d, 0, sizeof(struct fuse_mount_data)); d->max_read = ~0; d->blksize = FUSE_DEFAULT_BLKSIZE; + if (is_virtiofs) { + d->rootmode = S_IFDIR; + d->default_permissions = 1; + d->allow_other = 1; + } + while ((p = strsep(&opt, ",")) != NULL) { int token; int value; @@ -549,6 +555,10 @@ int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev, } } + /* no need to check rootmode/user_id/group_id for virtiofs */ + if (is_virtiofs) + return 1; + if (!d->rootmode_present || !d->user_id_present || !d->group_id_present) return 0; @@ -1201,7 +1211,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) struct fuse_req *init_req; err = -EINVAL; - if (!parse_fuse_opt(data, &d, is_bdev, sb->s_user_ns)) + if (!parse_fuse_opt(data, &d, is_bdev, sb->s_user_ns, false)) goto err; if (!d.fd_present) goto err; diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 4a8195a5b26a..1e919633c8fc 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1035,7 +1035,7 @@ static int virtio_fs_fill_super(struct super_block *sb, void *data, mutex_lock(&virtio_fs_mutex); err = -EINVAL; - if (!parse_fuse_opt(data, &d, is_bdev, sb->s_user_ns)) + if (!parse_fuse_opt(data, &d, is_bdev, sb->s_user_ns, true)) goto err; if (d.fd_present) { -- GitLab