Commit 7fd3abfa authored by Vivek Goyal's avatar Vivek Goyal Committed by Miklos Szeredi

virtiofs: do not use fuse_fill_super_common() for device installation

fuse_fill_super_common() allocates and installs one fuse_device.  Hence
virtiofs allocates and install all fuse devices by itself except one.

This makes logic little twisted.  There does not seem to be any real need
that why virtiofs can't allocate and install all fuse devices itself.

So opt out of fuse device allocation and installation while calling
fuse_fill_super_common().

Regular fuse still wants fuse_fill_super_common() to install fuse_device.
It needs to prevent against races where two mounters are trying to mount
fuse using same fd.  In that case one will succeed while other will get
-EINVAL.

virtiofs does not have this issue because sget_fc() resolves the race
w.r.t multiple mounters and only one instance of virtio_fs_fill_super()
should be in progress for same filesystem.
Signed-off-by: default avatarVivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 5157da2c
...@@ -1113,7 +1113,7 @@ EXPORT_SYMBOL_GPL(fuse_dev_free); ...@@ -1113,7 +1113,7 @@ EXPORT_SYMBOL_GPL(fuse_dev_free);
int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
{ {
struct fuse_dev *fud; struct fuse_dev *fud = NULL;
struct fuse_conn *fc = get_fuse_conn_super(sb); struct fuse_conn *fc = get_fuse_conn_super(sb);
struct inode *root; struct inode *root;
struct dentry *root_dentry; struct dentry *root_dentry;
...@@ -1155,9 +1155,12 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) ...@@ -1155,9 +1155,12 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
if (sb->s_user_ns != &init_user_ns) if (sb->s_user_ns != &init_user_ns)
sb->s_xattr = fuse_no_acl_xattr_handlers; sb->s_xattr = fuse_no_acl_xattr_handlers;
if (ctx->fudptr) {
err = -ENOMEM;
fud = fuse_dev_alloc_install(fc); fud = fuse_dev_alloc_install(fc);
if (!fud) if (!fud)
goto err; goto err;
}
fc->dev = sb->s_dev; fc->dev = sb->s_dev;
fc->sb = sb; fc->sb = sb;
...@@ -1191,7 +1194,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) ...@@ -1191,7 +1194,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
mutex_lock(&fuse_mutex); mutex_lock(&fuse_mutex);
err = -EINVAL; err = -EINVAL;
if (*ctx->fudptr) if (ctx->fudptr && *ctx->fudptr)
goto err_unlock; goto err_unlock;
err = fuse_ctl_add_conn(fc); err = fuse_ctl_add_conn(fc);
...@@ -1200,6 +1203,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) ...@@ -1200,6 +1203,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
list_add_tail(&fc->entry, &fuse_conn_list); list_add_tail(&fc->entry, &fuse_conn_list);
sb->s_root = root_dentry; sb->s_root = root_dentry;
if (ctx->fudptr)
*ctx->fudptr = fud; *ctx->fudptr = fud;
mutex_unlock(&fuse_mutex); mutex_unlock(&fuse_mutex);
return 0; return 0;
...@@ -1208,6 +1212,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) ...@@ -1208,6 +1212,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
mutex_unlock(&fuse_mutex); mutex_unlock(&fuse_mutex);
dput(root_dentry); dput(root_dentry);
err_dev_free: err_dev_free:
if (fud)
fuse_dev_free(fud); fuse_dev_free(fud);
err: err:
return err; return err;
......
...@@ -1103,7 +1103,7 @@ static int virtio_fs_fill_super(struct super_block *sb) ...@@ -1103,7 +1103,7 @@ static int virtio_fs_fill_super(struct super_block *sb)
err = -ENOMEM; err = -ENOMEM;
/* Allocate fuse_dev for hiprio and notification queues */ /* Allocate fuse_dev for hiprio and notification queues */
for (i = 0; i < VQ_REQUEST; i++) { for (i = 0; i < fs->nvqs; i++) {
struct virtio_fs_vq *fsvq = &fs->vqs[i]; struct virtio_fs_vq *fsvq = &fs->vqs[i];
fsvq->fud = fuse_dev_alloc(); fsvq->fud = fuse_dev_alloc();
...@@ -1111,18 +1111,15 @@ static int virtio_fs_fill_super(struct super_block *sb) ...@@ -1111,18 +1111,15 @@ static int virtio_fs_fill_super(struct super_block *sb)
goto err_free_fuse_devs; goto err_free_fuse_devs;
} }
ctx.fudptr = (void **)&fs->vqs[VQ_REQUEST].fud; /* virtiofs allocates and installs its own fuse devices */
ctx.fudptr = NULL;
err = fuse_fill_super_common(sb, &ctx); err = fuse_fill_super_common(sb, &ctx);
if (err < 0) if (err < 0)
goto err_free_fuse_devs; goto err_free_fuse_devs;
fc = fs->vqs[VQ_REQUEST].fud->fc;
for (i = 0; i < fs->nvqs; i++) { for (i = 0; i < fs->nvqs; i++) {
struct virtio_fs_vq *fsvq = &fs->vqs[i]; struct virtio_fs_vq *fsvq = &fs->vqs[i];
if (i == VQ_REQUEST)
continue; /* already initialized */
fuse_dev_install(fsvq->fud, fc); fuse_dev_install(fsvq->fud, fc);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment