Commit 0d179aa5 authored by Tejun Heo's avatar Tejun Heo Committed by Miklos Szeredi

fuse: separate out fuse_conn_init() from new_conn()

Separate out fuse_conn_init() from new_conn() and while at it
initialize fuse_conn->entry during conn initialization.

This will be used by CUSE.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
parent b93f858a
...@@ -649,6 +649,11 @@ void fuse_invalidate_entry_cache(struct dentry *entry); ...@@ -649,6 +649,11 @@ void fuse_invalidate_entry_cache(struct dentry *entry);
*/ */
struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
/**
* Initialize fuse_conn
*/
int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb);
/** /**
* Release reference to fuse_conn * Release reference to fuse_conn
*/ */
......
...@@ -462,13 +462,11 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) ...@@ -462,13 +462,11 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
return 0; return 0;
} }
static struct fuse_conn *new_conn(struct super_block *sb) int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb)
{ {
struct fuse_conn *fc;
int err; int err;
fc = kzalloc(sizeof(*fc), GFP_KERNEL); memset(fc, 0, sizeof(*fc));
if (fc) {
spin_lock_init(&fc->lock); spin_lock_init(&fc->lock);
mutex_init(&fc->inst_mutex); mutex_init(&fc->inst_mutex);
atomic_set(&fc->count, 1); atomic_set(&fc->count, 1);
...@@ -480,6 +478,7 @@ static struct fuse_conn *new_conn(struct super_block *sb) ...@@ -480,6 +478,7 @@ static struct fuse_conn *new_conn(struct super_block *sb)
INIT_LIST_HEAD(&fc->io); INIT_LIST_HEAD(&fc->io);
INIT_LIST_HEAD(&fc->interrupts); INIT_LIST_HEAD(&fc->interrupts);
INIT_LIST_HEAD(&fc->bg_queue); INIT_LIST_HEAD(&fc->bg_queue);
INIT_LIST_HEAD(&fc->entry);
atomic_set(&fc->num_waiting, 0); atomic_set(&fc->num_waiting, 0);
fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
fc->bdi.unplug_io_fn = default_unplug_io_fn; fc->bdi.unplug_io_fn = default_unplug_io_fn;
...@@ -490,7 +489,7 @@ static struct fuse_conn *new_conn(struct super_block *sb) ...@@ -490,7 +489,7 @@ static struct fuse_conn *new_conn(struct super_block *sb)
fc->dev = sb->s_dev; fc->dev = sb->s_dev;
err = bdi_init(&fc->bdi); err = bdi_init(&fc->bdi);
if (err) if (err)
goto error_kfree; goto error_mutex_destroy;
if (sb->s_bdev) { if (sb->s_bdev) {
err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk", err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk",
MAJOR(fc->dev), MINOR(fc->dev)); MAJOR(fc->dev), MINOR(fc->dev));
...@@ -516,16 +515,16 @@ static struct fuse_conn *new_conn(struct super_block *sb) ...@@ -516,16 +515,16 @@ static struct fuse_conn *new_conn(struct super_block *sb)
fc->blocked = 1; fc->blocked = 1;
fc->attr_version = 1; fc->attr_version = 1;
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
}
return fc;
error_bdi_destroy: return 0;
error_bdi_destroy:
bdi_destroy(&fc->bdi); bdi_destroy(&fc->bdi);
error_kfree: error_mutex_destroy:
mutex_destroy(&fc->inst_mutex); mutex_destroy(&fc->inst_mutex);
kfree(fc); return err;
return NULL;
} }
EXPORT_SYMBOL_GPL(fuse_conn_init);
void fuse_conn_put(struct fuse_conn *fc) void fuse_conn_put(struct fuse_conn *fc)
{ {
...@@ -828,10 +827,16 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) ...@@ -828,10 +827,16 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
if (file->f_op != &fuse_dev_operations) if (file->f_op != &fuse_dev_operations)
return -EINVAL; return -EINVAL;
fc = new_conn(sb); fc = kmalloc(sizeof(*fc), GFP_KERNEL);
if (!fc) if (!fc)
return -ENOMEM; return -ENOMEM;
err = fuse_conn_init(fc, sb);
if (err) {
kfree(fc);
return err;
}
fc->flags = d.flags; fc->flags = d.flags;
fc->user_id = d.user_id; fc->user_id = d.user_id;
fc->group_id = d.group_id; fc->group_id = d.group_id;
......
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