From 01a05b337a5b647909e1d6670f57e7202318a5fb Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 23 Mar 2010 06:06:58 -0400 Subject: new helper: iterate_supers() ... and switch the simple "loop over superblocks and do something" loops to it. Signed-off-by: Al Viro --- fs/super.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'fs/super.c') diff --git a/fs/super.c b/fs/super.c index 95adbb3d8e5..2c3e370c60d 100644 --- a/fs/super.c +++ b/fs/super.c @@ -391,6 +391,36 @@ void sync_supers(void) spin_unlock(&sb_lock); } +/** + * iterate_supers - call function for all active superblocks + * @f: function to call + * @arg: argument to pass to it + * + * Scans the superblock list and calls given function, passing it + * locked superblock and given argument. + */ +void iterate_supers(void (*f)(struct super_block *, void *), void *arg) +{ + struct super_block *sb, *n; + + spin_lock(&sb_lock); + list_for_each_entry_safe(sb, n, &super_blocks, s_list) { + if (list_empty(&sb->s_instances)) + continue; + sb->s_count++; + spin_unlock(&sb_lock); + + down_read(&sb->s_umount); + if (sb->s_root) + f(sb, arg); + up_read(&sb->s_umount); + + spin_lock(&sb_lock); + __put_super(sb); + } + spin_unlock(&sb_lock); +} + /** * get_super - get the superblock of a device * @bdev: device to get the superblock for -- cgit v1.2.3