Skip to content

Commit 12ad3ab

Browse files
Dave ChinnerAl Viro
Dave Chinner
authored and
Al Viro
committed
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 09cc9fc commit 12ad3ab

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

fs/fs-writeback.c

+1-27
Original file line numberDiff line numberDiff line change
@@ -460,32 +460,6 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
460460
return ret;
461461
}
462462

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-
*/
468-
static 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-
489463
/*
490464
* Write a portion of b_io inodes which belong to @sb.
491465
*
@@ -585,7 +559,7 @@ void writeback_inodes_wb(struct bdi_writeback *wb,
585559
struct inode *inode = wb_inode(wb->b_io.prev);
586560
struct super_block *sb = inode->i_sb;
587561

588-
if (!pin_sb_for_writeback(sb)) {
562+
if (!grab_super_passive(sb)) {
589563
requeue_io(inode);
590564
continue;
591565
}

fs/internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern struct file *get_empty_filp(void);
9797
* super.c
9898
*/
9999
extern int do_remount_sb(struct super_block *, int, void *, int);
100+
extern bool grab_super_passive(struct super_block *sb);
100101
extern void __put_super(struct super_block *sb);
101102
extern void put_super(struct super_block *sb);
102103
extern struct dentry *mount_fs(struct file_system_type *,

fs/super.c

+33
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,39 @@ static int grab_super(struct super_block *s) __releases(sb_lock)
242242
return 0;
243243
}
244244

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+
*/
257+
bool 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+
245278
/*
246279
* Superblock locking. We really ought to get rid of these two.
247280
*/

0 commit comments

Comments
 (0)