Skip to content

Commit 0cd1eb9

Browse files
rhvgoyalMiklos Szeredi
authored andcommitted
fuse: separate fuse device allocation and installation in fuse_conn
As of now fuse_dev_alloc() both allocates a fuse device and installs it in fuse_conn list. fuse_dev_alloc() can fail if fuse_device allocation fails. virtio-fs needs to initialize multiple fuse devices (one per virtio queue). It initializes one fuse device as part of call to fuse_fill_super_common() and rest of the devices are allocated and installed after that. But, we can't afford to fail after calling fuse_fill_super_common() as we don't have a way to undo all the actions done by fuse_fill_super_common(). So to avoid failures after the call to fuse_fill_super_common(), pre-allocate all fuse devices early and install them into fuse connection later. This patch provides two separate helpers for fuse device allocation and fuse device installation in fuse_conn. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent ae3aad7 commit 0cd1eb9

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

‎fs/fuse/cuse.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
508508
*/
509509
fuse_conn_init(&cc->fc, file->f_cred->user_ns, &fuse_dev_fiq_ops, NULL);
510510

511-
fud = fuse_dev_alloc(&cc->fc);
511+
fud = fuse_dev_alloc_install(&cc->fc);
512512
if (!fud) {
513513
kfree(cc);
514514
return -ENOMEM;

‎fs/fuse/dev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new)
22032203
if (new->private_data)
22042204
return -EINVAL;
22052205

2206-
fud = fuse_dev_alloc(fc);
2206+
fud = fuse_dev_alloc_install(fc);
22072207
if (!fud)
22082208
return -ENOMEM;
22092209

‎fs/fuse/fuse_i.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,9 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
929929
*/
930930
void fuse_conn_put(struct fuse_conn *fc);
931931

932-
struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
932+
struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc);
933+
struct fuse_dev *fuse_dev_alloc(void);
934+
void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc);
933935
void fuse_dev_free(struct fuse_dev *fud);
934936
void fuse_send_init(struct fuse_conn *fc);
935937

‎fs/fuse/inode.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb)
10451045
return 0;
10461046
}
10471047

1048-
struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc)
1048+
struct fuse_dev *fuse_dev_alloc(void)
10491049
{
10501050
struct fuse_dev *fud;
10511051
struct list_head *pq;
@@ -1061,16 +1061,33 @@ struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc)
10611061
}
10621062

10631063
fud->pq.processing = pq;
1064-
fud->fc = fuse_conn_get(fc);
10651064
fuse_pqueue_init(&fud->pq);
10661065

1066+
return fud;
1067+
}
1068+
EXPORT_SYMBOL_GPL(fuse_dev_alloc);
1069+
1070+
void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc)
1071+
{
1072+
fud->fc = fuse_conn_get(fc);
10671073
spin_lock(&fc->lock);
10681074
list_add_tail(&fud->entry, &fc->devices);
10691075
spin_unlock(&fc->lock);
1076+
}
1077+
EXPORT_SYMBOL_GPL(fuse_dev_install);
10701078

1079+
struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc)
1080+
{
1081+
struct fuse_dev *fud;
1082+
1083+
fud = fuse_dev_alloc();
1084+
if (!fud)
1085+
return NULL;
1086+
1087+
fuse_dev_install(fud, fc);
10711088
return fud;
10721089
}
1073-
EXPORT_SYMBOL_GPL(fuse_dev_alloc);
1090+
EXPORT_SYMBOL_GPL(fuse_dev_alloc_install);
10741091

10751092
void fuse_dev_free(struct fuse_dev *fud)
10761093
{
@@ -1132,7 +1149,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
11321149
if (sb->s_user_ns != &init_user_ns)
11331150
sb->s_xattr = fuse_no_acl_xattr_handlers;
11341151

1135-
fud = fuse_dev_alloc(fc);
1152+
fud = fuse_dev_alloc_install(fc);
11361153
if (!fud)
11371154
goto err;
11381155

0 commit comments

Comments
 (0)