diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2006-04-11 01:54:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-04-11 09:18:48 -0400 |
commit | 0720b315976447cba3f0c3e211223b8cb82b0f93 (patch) | |
tree | b8013f53bca7a72670961ea6f439612d1c631283 /fs/fuse/dev.c | |
parent | e5ac1d1e70a8c19a65a959d73650203df7a2e168 (diff) |
[PATCH] fuse: simplify locking
This is in preparation for removing the global spinlock in favor of a
per-mount one.
The only critical part is the interaction between fuse_dev_release() and
fuse_fill_super(): fuse_dev_release() must see the assignment to
file->private_data, otherwise it will leak the reference to fuse_conn.
This is ensured by the fput() operation, which will synchronize the assignment
with other CPU's that may do a final fput() soon after this.
Also redundant locking is removed from fuse_fill_super(), where exclusion is
already ensured by the BKL held for this function by the VFS.
Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/fuse/dev.c')
-rw-r--r-- | fs/fuse/dev.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 75c6e9166c39..c510533c6849 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c | |||
@@ -23,13 +23,11 @@ static kmem_cache_t *fuse_req_cachep; | |||
23 | 23 | ||
24 | static struct fuse_conn *fuse_get_conn(struct file *file) | 24 | static struct fuse_conn *fuse_get_conn(struct file *file) |
25 | { | 25 | { |
26 | struct fuse_conn *fc; | 26 | /* |
27 | spin_lock(&fuse_lock); | 27 | * Lockless access is OK, because file->private data is set |
28 | fc = file->private_data; | 28 | * once during mount and is valid until the file is released. |
29 | if (fc && !fc->connected) | 29 | */ |
30 | fc = NULL; | 30 | return file->private_data; |
31 | spin_unlock(&fuse_lock); | ||
32 | return fc; | ||
33 | } | 31 | } |
34 | 32 | ||
35 | static void fuse_request_init(struct fuse_req *req) | 33 | static void fuse_request_init(struct fuse_req *req) |
@@ -607,19 +605,16 @@ static ssize_t fuse_dev_readv(struct file *file, const struct iovec *iov, | |||
607 | unsigned long nr_segs, loff_t *off) | 605 | unsigned long nr_segs, loff_t *off) |
608 | { | 606 | { |
609 | int err; | 607 | int err; |
610 | struct fuse_conn *fc; | ||
611 | struct fuse_req *req; | 608 | struct fuse_req *req; |
612 | struct fuse_in *in; | 609 | struct fuse_in *in; |
613 | struct fuse_copy_state cs; | 610 | struct fuse_copy_state cs; |
614 | unsigned reqsize; | 611 | unsigned reqsize; |
612 | struct fuse_conn *fc = fuse_get_conn(file); | ||
613 | if (!fc) | ||
614 | return -EPERM; | ||
615 | 615 | ||
616 | restart: | 616 | restart: |
617 | spin_lock(&fuse_lock); | 617 | spin_lock(&fuse_lock); |
618 | fc = file->private_data; | ||
619 | err = -EPERM; | ||
620 | if (!fc) | ||
621 | goto err_unlock; | ||
622 | |||
623 | err = -EAGAIN; | 618 | err = -EAGAIN; |
624 | if ((file->f_flags & O_NONBLOCK) && fc->connected && | 619 | if ((file->f_flags & O_NONBLOCK) && fc->connected && |
625 | list_empty(&fc->pending)) | 620 | list_empty(&fc->pending)) |
@@ -915,17 +910,13 @@ void fuse_abort_conn(struct fuse_conn *fc) | |||
915 | 910 | ||
916 | static int fuse_dev_release(struct inode *inode, struct file *file) | 911 | static int fuse_dev_release(struct inode *inode, struct file *file) |
917 | { | 912 | { |
918 | struct fuse_conn *fc; | 913 | struct fuse_conn *fc = fuse_get_conn(file); |
919 | |||
920 | spin_lock(&fuse_lock); | ||
921 | fc = file->private_data; | ||
922 | if (fc) { | 914 | if (fc) { |
915 | spin_lock(&fuse_lock); | ||
923 | fc->connected = 0; | 916 | fc->connected = 0; |
924 | end_requests(fc, &fc->pending); | 917 | end_requests(fc, &fc->pending); |
925 | end_requests(fc, &fc->processing); | 918 | end_requests(fc, &fc->processing); |
926 | } | 919 | spin_unlock(&fuse_lock); |
927 | spin_unlock(&fuse_lock); | ||
928 | if (fc) { | ||
929 | fasync_helper(-1, file, 0, &fc->fasync); | 920 | fasync_helper(-1, file, 0, &fc->fasync); |
930 | kobject_put(&fc->kobj); | 921 | kobject_put(&fc->kobj); |
931 | } | 922 | } |