new helper: iterate_supers_type()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 4 Jun 2011 00:16:57 +0000 (20:16 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 20 Jul 2011 05:43:04 +0000 (01:43 -0400)
Call the given function for all superblocks of given type.  Function
gets a superblock (with s_umount locked shared) and (void *) argument
supplied by caller of iterator.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/super.c
include/linux/fs.h

index ab3d672..444da95 100644 (file)
@@ -451,6 +451,42 @@ void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
        spin_unlock(&sb_lock);
 }
 
+/**
+ *     iterate_supers_type - call function for superblocks of given type
+ *     @type: fs type
+ *     @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_type(struct file_system_type *type,
+       void (*f)(struct super_block *, void *), void *arg)
+{
+       struct super_block *sb, *p = NULL;
+
+       spin_lock(&sb_lock);
+       list_for_each_entry(sb, &type->fs_supers, s_instances) {
+               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);
+               if (p)
+                       __put_super(p);
+               p = sb;
+       }
+       if (p)
+               __put_super(p);
+       spin_unlock(&sb_lock);
+}
+
+EXPORT_SYMBOL(iterate_supers_type);
+
 /**
  *     get_super - get the superblock of a device
  *     @bdev: device to get the superblock for
index b5b9792..a8735e7 100644 (file)
@@ -2432,6 +2432,8 @@ extern struct super_block *get_active_super(struct block_device *bdev);
 extern struct super_block *user_get_super(dev_t);
 extern void drop_super(struct super_block *sb);
 extern void iterate_supers(void (*)(struct super_block *, void *), void *);
+extern void iterate_supers_type(struct file_system_type *,
+                               void (*)(struct super_block *, void *), void *);
 
 extern int dcache_dir_open(struct inode *, struct file *);
 extern int dcache_dir_close(struct inode *, struct file *);