summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2011-07-08 00:14:41 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2011-07-20 01:44:38 -0400
commit12ad3ab66103e6582ca69c0c9de18b13487eaaef (patch)
tree52d1ecd11d48faa7e6f8d6600c8e76807b0985a5
parent09cc9fc7a7c3d872065426d7fb0f0ad6d3eb90fc (diff)
superblock: move pin_sb_for_writeback() to fs/super.c
The per-sb shrinker has the same requirement as the writeback threads of ensuring that the superblock is usable and pinned for the time it takes to run the work. Both need to take a passive reference to the sb, take a read lock on the s_umount lock and then only continue if an unmount is not in progress. pin_sb_for_writeback() does this exactly, so move it to fs/super.c and rename it to grab_super_passive() and exporting it via fs/internal.h for all the VFS code to be able to use. Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/fs-writeback.c28
-rw-r--r--fs/internal.h1
-rw-r--r--fs/super.c33
3 files changed, 35 insertions, 27 deletions
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 0f015a0468de..b8c507ca42f7 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -461,32 +461,6 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
461} 461}
462 462
463/* 463/*
464 * For background writeback the caller does not have the sb pinned
465 * before calling writeback. So make sure that we do pin it, so it doesn't
466 * go away while we are writing inodes from it.
467 */
468static bool pin_sb_for_writeback(struct super_block *sb)
469{
470 spin_lock(&sb_lock);
471 if (list_empty(&sb->s_instances)) {
472 spin_unlock(&sb_lock);
473 return false;
474 }
475
476 sb->s_count++;
477 spin_unlock(&sb_lock);
478
479 if (down_read_trylock(&sb->s_umount)) {
480 if (sb->s_root)
481 return true;
482 up_read(&sb->s_umount);
483 }
484
485 put_super(sb);
486 return false;
487}
488
489/*
490 * Write a portion of b_io inodes which belong to @sb. 464 * Write a portion of b_io inodes which belong to @sb.
491 * 465 *
492 * If @only_this_sb is true, then find and write all such 466 * If @only_this_sb is true, then find and write all such
@@ -585,7 +559,7 @@ void writeback_inodes_wb(struct bdi_writeback *wb,
585 struct inode *inode = wb_inode(wb->b_io.prev); 559 struct inode *inode = wb_inode(wb->b_io.prev);
586 struct super_block *sb = inode->i_sb; 560 struct super_block *sb = inode->i_sb;
587 561
588 if (!pin_sb_for_writeback(sb)) { 562 if (!grab_super_passive(sb)) {
589 requeue_io(inode); 563 requeue_io(inode);
590 continue; 564 continue;
591 } 565 }
diff --git a/fs/internal.h b/fs/internal.h
index ae47c48bedde..fe327c20af83 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -97,6 +97,7 @@ extern struct file *get_empty_filp(void);
97 * super.c 97 * super.c
98 */ 98 */
99extern int do_remount_sb(struct super_block *, int, void *, int); 99extern int do_remount_sb(struct super_block *, int, void *, int);
100extern bool grab_super_passive(struct super_block *sb);
100extern void __put_super(struct super_block *sb); 101extern void __put_super(struct super_block *sb);
101extern void put_super(struct super_block *sb); 102extern void put_super(struct super_block *sb);
102extern struct dentry *mount_fs(struct file_system_type *, 103extern struct dentry *mount_fs(struct file_system_type *,
diff --git a/fs/super.c b/fs/super.c
index 73ab9f9b3571..e63c754447ce 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -243,6 +243,39 @@ static int grab_super(struct super_block *s) __releases(sb_lock)
243} 243}
244 244
245/* 245/*
246 * grab_super_passive - acquire a passive reference
247 * @s: reference we are trying to grab
248 *
249 * Tries to acquire a passive reference. This is used in places where we
250 * cannot take an active reference but we need to ensure that the
251 * superblock does not go away while we are working on it. It returns
252 * false if a reference was not gained, and returns true with the s_umount
253 * lock held in read mode if a reference is gained. On successful return,
254 * the caller must drop the s_umount lock and the passive reference when
255 * done.
256 */
257bool grab_super_passive(struct super_block *sb)
258{
259 spin_lock(&sb_lock);
260 if (list_empty(&sb->s_instances)) {
261 spin_unlock(&sb_lock);
262 return false;
263 }
264
265 sb->s_count++;
266 spin_unlock(&sb_lock);
267
268 if (down_read_trylock(&sb->s_umount)) {
269 if (sb->s_root)
270 return true;
271 up_read(&sb->s_umount);
272 }
273
274 put_super(sb);
275 return false;
276}
277
278/*
246 * Superblock locking. We really ought to get rid of these two. 279 * Superblock locking. We really ought to get rid of these two.
247 */ 280 */
248void lock_super(struct super_block * sb) 281void lock_super(struct super_block * sb)