aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse/inode.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2006-04-11 01:54:55 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-11 09:18:48 -0400
commit0720b315976447cba3f0c3e211223b8cb82b0f93 (patch)
treeb8013f53bca7a72670961ea6f439612d1c631283 /fs/fuse/inode.c
parente5ac1d1e70a8c19a65a959d73650203df7a2e168 (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/inode.c')
-rw-r--r--fs/fuse/inode.c64
1 files changed, 22 insertions, 42 deletions
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 78700cbb9cd..620579a6910 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -414,37 +414,6 @@ static struct fuse_conn *new_conn(void)
414 return fc; 414 return fc;
415} 415}
416 416
417static struct fuse_conn *get_conn(struct file *file, struct super_block *sb)
418{
419 struct fuse_conn *fc;
420 int err;
421
422 err = -EINVAL;
423 if (file->f_op != &fuse_dev_operations)
424 goto out_err;
425
426 err = -ENOMEM;
427 fc = new_conn();
428 if (!fc)
429 goto out_err;
430
431 spin_lock(&fuse_lock);
432 err = -EINVAL;
433 if (file->private_data)
434 goto out_unlock;
435
436 kobject_get(&fc->kobj);
437 file->private_data = fc;
438 spin_unlock(&fuse_lock);
439 return fc;
440
441 out_unlock:
442 spin_unlock(&fuse_lock);
443 kobject_put(&fc->kobj);
444 out_err:
445 return ERR_PTR(err);
446}
447
448static struct inode *get_root_inode(struct super_block *sb, unsigned mode) 417static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
449{ 418{
450 struct fuse_attr attr; 419 struct fuse_attr attr;
@@ -526,12 +495,9 @@ static void fuse_send_init(struct fuse_conn *fc)
526 495
527static unsigned long long conn_id(void) 496static unsigned long long conn_id(void)
528{ 497{
498 /* BKL is held for ->get_sb() */
529 static unsigned long long ctr = 1; 499 static unsigned long long ctr = 1;
530 unsigned long long val; 500 return ctr++;
531 spin_lock(&fuse_lock);
532 val = ctr++;
533 spin_unlock(&fuse_lock);
534 return val;
535} 501}
536 502
537static int fuse_fill_super(struct super_block *sb, void *data, int silent) 503static int fuse_fill_super(struct super_block *sb, void *data, int silent)
@@ -556,10 +522,17 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
556 if (!file) 522 if (!file)
557 return -EINVAL; 523 return -EINVAL;
558 524
559 fc = get_conn(file, sb); 525 if (file->f_op != &fuse_dev_operations)
560 fput(file); 526 return -EINVAL;
561 if (IS_ERR(fc)) 527
562 return PTR_ERR(fc); 528 /* Setting file->private_data can't race with other mount()
529 instances, since BKL is held for ->get_sb() */
530 if (file->private_data)
531 return -EINVAL;
532
533 fc = new_conn();
534 if (!fc)
535 return -ENOMEM;
563 536
564 fc->flags = d.flags; 537 fc->flags = d.flags;
565 fc->user_id = d.user_id; 538 fc->user_id = d.user_id;
@@ -589,10 +562,16 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
589 goto err_put_root; 562 goto err_put_root;
590 563
591 sb->s_root = root_dentry; 564 sb->s_root = root_dentry;
592 spin_lock(&fuse_lock);
593 fc->mounted = 1; 565 fc->mounted = 1;
594 fc->connected = 1; 566 fc->connected = 1;
595 spin_unlock(&fuse_lock); 567 kobject_get(&fc->kobj);
568 file->private_data = fc;
569 /*
570 * atomic_dec_and_test() in fput() provides the necessary
571 * memory barrier for file->private_data to be visible on all
572 * CPUs after this
573 */
574 fput(file);
596 575
597 fuse_send_init(fc); 576 fuse_send_init(fc);
598 577
@@ -601,6 +580,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
601 err_put_root: 580 err_put_root:
602 dput(root_dentry); 581 dput(root_dentry);
603 err: 582 err:
583 fput(file);
604 kobject_put(&fc->kobj); 584 kobject_put(&fc->kobj);
605 return err; 585 return err;
606} 586}