aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Piggin <npiggin@kernel.dk>2010-08-17 14:37:35 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2010-08-18 08:35:47 -0400
commitee2ffa0dfdd2db19705f2ba1c6a4c0bfe8122dd8 (patch)
treee48400d1a33f8d2e68589ccfd61637aa64462f08
parentb04f784e5d19ed58892833dae845738972cea260 (diff)
fs: cleanup files_lock locking
fs: cleanup files_lock locking Lock tty_files with a new spinlock, tty_files_lock; provide helpers to manipulate the per-sb files list; unexport the files_lock spinlock. Cc: linux-kernel@vger.kernel.org Cc: Christoph Hellwig <hch@infradead.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Nick Piggin <npiggin@kernel.dk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/char/pty.c6
-rw-r--r--drivers/char/tty_io.c26
-rw-r--r--fs/file_table.c42
-rw-r--r--fs/open.c4
-rw-r--r--include/linux/fs.h7
-rw-r--r--include/linux/tty.h1
-rw-r--r--security/selinux/hooks.c4
7 files changed, 48 insertions, 42 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index ad46eae1f9b..2c64faa8efa 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -676,7 +676,11 @@ static int ptmx_open(struct inode *inode, struct file *filp)
676 676
677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
678 filp->private_data = tty; 678 filp->private_data = tty;
679 file_move(filp, &tty->tty_files); 679
680 file_sb_list_del(filp); /* __dentry_open has put it on the sb list */
681 spin_lock(&tty_files_lock);
682 list_add(&filp->f_u.fu_list, &tty->tty_files);
683 spin_unlock(&tty_files_lock);
680 684
681 retval = devpts_pty_new(inode, tty->link); 685 retval = devpts_pty_new(inode, tty->link);
682 if (retval) 686 if (retval)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 0350c42375a..cd5b829634e 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -136,6 +136,9 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
136DEFINE_MUTEX(tty_mutex); 136DEFINE_MUTEX(tty_mutex);
137EXPORT_SYMBOL(tty_mutex); 137EXPORT_SYMBOL(tty_mutex);
138 138
139/* Spinlock to protect the tty->tty_files list */
140DEFINE_SPINLOCK(tty_files_lock);
141
139static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *); 142static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
140static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *); 143static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
141ssize_t redirected_tty_write(struct file *, const char __user *, 144ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -235,11 +238,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
235 struct list_head *p; 238 struct list_head *p;
236 int count = 0; 239 int count = 0;
237 240
238 file_list_lock(); 241 spin_lock(&tty_files_lock);
239 list_for_each(p, &tty->tty_files) { 242 list_for_each(p, &tty->tty_files) {
240 count++; 243 count++;
241 } 244 }
242 file_list_unlock(); 245 spin_unlock(&tty_files_lock);
243 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 246 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
244 tty->driver->subtype == PTY_TYPE_SLAVE && 247 tty->driver->subtype == PTY_TYPE_SLAVE &&
245 tty->link && tty->link->count) 248 tty->link && tty->link->count)
@@ -519,7 +522,7 @@ void __tty_hangup(struct tty_struct *tty)
519 workqueue with the lock held */ 522 workqueue with the lock held */
520 check_tty_count(tty, "tty_hangup"); 523 check_tty_count(tty, "tty_hangup");
521 524
522 file_list_lock(); 525 spin_lock(&tty_files_lock);
523 /* This breaks for file handles being sent over AF_UNIX sockets ? */ 526 /* This breaks for file handles being sent over AF_UNIX sockets ? */
524 list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { 527 list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
525 if (filp->f_op->write == redirected_tty_write) 528 if (filp->f_op->write == redirected_tty_write)
@@ -530,7 +533,7 @@ void __tty_hangup(struct tty_struct *tty)
530 __tty_fasync(-1, filp, 0); /* can't block */ 533 __tty_fasync(-1, filp, 0); /* can't block */
531 filp->f_op = &hung_up_tty_fops; 534 filp->f_op = &hung_up_tty_fops;
532 } 535 }
533 file_list_unlock(); 536 spin_unlock(&tty_files_lock);
534 537
535 tty_ldisc_hangup(tty); 538 tty_ldisc_hangup(tty);
536 539
@@ -1424,9 +1427,9 @@ static void release_one_tty(struct work_struct *work)
1424 tty_driver_kref_put(driver); 1427 tty_driver_kref_put(driver);
1425 module_put(driver->owner); 1428 module_put(driver->owner);
1426 1429
1427 file_list_lock(); 1430 spin_lock(&tty_files_lock);
1428 list_del_init(&tty->tty_files); 1431 list_del_init(&tty->tty_files);
1429 file_list_unlock(); 1432 spin_unlock(&tty_files_lock);
1430 1433
1431 put_pid(tty->pgrp); 1434 put_pid(tty->pgrp);
1432 put_pid(tty->session); 1435 put_pid(tty->session);
@@ -1671,7 +1674,10 @@ int tty_release(struct inode *inode, struct file *filp)
1671 * - do_tty_hangup no longer sees this file descriptor as 1674 * - do_tty_hangup no longer sees this file descriptor as
1672 * something that needs to be handled for hangups. 1675 * something that needs to be handled for hangups.
1673 */ 1676 */
1674 file_kill(filp); 1677 spin_lock(&tty_files_lock);
1678 BUG_ON(list_empty(&filp->f_u.fu_list));
1679 list_del_init(&filp->f_u.fu_list);
1680 spin_unlock(&tty_files_lock);
1675 filp->private_data = NULL; 1681 filp->private_data = NULL;
1676 1682
1677 /* 1683 /*
@@ -1840,7 +1846,11 @@ got_driver:
1840 } 1846 }
1841 1847
1842 filp->private_data = tty; 1848 filp->private_data = tty;
1843 file_move(filp, &tty->tty_files); 1849 BUG_ON(list_empty(&filp->f_u.fu_list));
1850 file_sb_list_del(filp); /* __dentry_open has put it on the sb list */
1851 spin_lock(&tty_files_lock);
1852 list_add(&filp->f_u.fu_list, &tty->tty_files);
1853 spin_unlock(&tty_files_lock);
1844 check_tty_count(tty, "tty_open"); 1854 check_tty_count(tty, "tty_open");
1845 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1855 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1846 tty->driver->subtype == PTY_TYPE_MASTER) 1856 tty->driver->subtype == PTY_TYPE_MASTER)
diff --git a/fs/file_table.c b/fs/file_table.c
index edecd36fed9..6f0e62ecfdd 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -32,8 +32,7 @@ struct files_stat_struct files_stat = {
32 .max_files = NR_FILE 32 .max_files = NR_FILE
33}; 33};
34 34
35/* public. Not pretty! */ 35static __cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock);
36__cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock);
37 36
38/* SLAB cache for file structures */ 37/* SLAB cache for file structures */
39static struct kmem_cache *filp_cachep __read_mostly; 38static struct kmem_cache *filp_cachep __read_mostly;
@@ -249,7 +248,7 @@ static void __fput(struct file *file)
249 cdev_put(inode->i_cdev); 248 cdev_put(inode->i_cdev);
250 fops_put(file->f_op); 249 fops_put(file->f_op);
251 put_pid(file->f_owner.pid); 250 put_pid(file->f_owner.pid);
252 file_kill(file); 251 file_sb_list_del(file);
253 if (file->f_mode & FMODE_WRITE) 252 if (file->f_mode & FMODE_WRITE)
254 drop_file_write_access(file); 253 drop_file_write_access(file);
255 file->f_path.dentry = NULL; 254 file->f_path.dentry = NULL;
@@ -328,31 +327,29 @@ struct file *fget_light(unsigned int fd, int *fput_needed)
328 return file; 327 return file;
329} 328}
330 329
331
332void put_filp(struct file *file) 330void put_filp(struct file *file)
333{ 331{
334 if (atomic_long_dec_and_test(&file->f_count)) { 332 if (atomic_long_dec_and_test(&file->f_count)) {
335 security_file_free(file); 333 security_file_free(file);
336 file_kill(file); 334 file_sb_list_del(file);
337 file_free(file); 335 file_free(file);
338 } 336 }
339} 337}
340 338
341void file_move(struct file *file, struct list_head *list) 339void file_sb_list_add(struct file *file, struct super_block *sb)
342{ 340{
343 if (!list) 341 spin_lock(&files_lock);
344 return; 342 BUG_ON(!list_empty(&file->f_u.fu_list));
345 file_list_lock(); 343 list_add(&file->f_u.fu_list, &sb->s_files);
346 list_move(&file->f_u.fu_list, list); 344 spin_unlock(&files_lock);
347 file_list_unlock();
348} 345}
349 346
350void file_kill(struct file *file) 347void file_sb_list_del(struct file *file)
351{ 348{
352 if (!list_empty(&file->f_u.fu_list)) { 349 if (!list_empty(&file->f_u.fu_list)) {
353 file_list_lock(); 350 spin_lock(&files_lock);
354 list_del_init(&file->f_u.fu_list); 351 list_del_init(&file->f_u.fu_list);
355 file_list_unlock(); 352 spin_unlock(&files_lock);
356 } 353 }
357} 354}
358 355
@@ -361,7 +358,7 @@ int fs_may_remount_ro(struct super_block *sb)
361 struct file *file; 358 struct file *file;
362 359
363 /* Check that no files are currently opened for writing. */ 360 /* Check that no files are currently opened for writing. */
364 fi