Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

new helper: iterate_supers()

... and switch the simple "loop over superblocks and do something"
loops to it.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 01a05b33 35cf7ba0

+57 -83
+9 -17
fs/buffer.c
··· 560 560 return err; 561 561 } 562 562 563 + static void do_thaw_one(struct super_block *sb, void *unused) 564 + { 565 + char b[BDEVNAME_SIZE]; 566 + while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb)) 567 + printk(KERN_WARNING "Emergency Thaw on %s\n", 568 + bdevname(sb->s_bdev, b)); 569 + } 570 + 563 571 static void do_thaw_all(struct work_struct *work) 564 572 { 565 - struct super_block *sb, *n; 566 - char b[BDEVNAME_SIZE]; 567 - 568 - spin_lock(&sb_lock); 569 - list_for_each_entry_safe(sb, n, &super_blocks, s_list) { 570 - if (list_empty(&sb->s_instances)) 571 - continue; 572 - sb->s_count++; 573 - spin_unlock(&sb_lock); 574 - down_read(&sb->s_umount); 575 - while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb)) 576 - printk(KERN_WARNING "Emergency Thaw on %s\n", 577 - bdevname(sb->s_bdev, b)); 578 - up_read(&sb->s_umount); 579 - spin_lock(&sb_lock); 580 - } 581 - spin_unlock(&sb_lock); 573 + iterate_supers(do_thaw_one, NULL); 582 574 kfree(work); 583 575 printk(KERN_WARNING "Emergency Thaw complete\n"); 584 576 }
+2 -23
fs/drop_caches.c
··· 8 8 #include <linux/writeback.h> 9 9 #include <linux/sysctl.h> 10 10 #include <linux/gfp.h> 11 - #include "internal.h" 12 11 13 12 /* A global variable is a bit ugly, but it keeps the code simple */ 14 13 int sysctl_drop_caches; 15 14 16 - static void drop_pagecache_sb(struct super_block *sb) 15 + static void drop_pagecache_sb(struct super_block *sb, void *unused) 17 16 { 18 17 struct inode *inode, *toput_inode = NULL; 19 18 ··· 33 34 iput(toput_inode); 34 35 } 35 36 36 - static void drop_pagecache(void) 37 - { 38 - struct super_block *sb, *n; 39 - 40 - spin_lock(&sb_lock); 41 - list_for_each_entry_safe(sb, n, &super_blocks, s_list) { 42 - if (list_empty(&sb->s_instances)) 43 - continue; 44 - sb->s_count++; 45 - spin_unlock(&sb_lock); 46 - down_read(&sb->s_umount); 47 - if (sb->s_root) 48 - drop_pagecache_sb(sb); 49 - up_read(&sb->s_umount); 50 - spin_lock(&sb_lock); 51 - __put_super(sb); 52 - } 53 - spin_unlock(&sb_lock); 54 - } 55 - 56 37 static void drop_slab(void) 57 38 { 58 39 int nr_objects; ··· 48 69 proc_dointvec_minmax(table, write, buffer, length, ppos); 49 70 if (write) { 50 71 if (sysctl_drop_caches & 1) 51 - drop_pagecache(); 72 + iterate_supers(drop_pagecache_sb, NULL); 52 73 if (sysctl_drop_caches & 2) 53 74 drop_slab(); 54 75 }
+9 -24
fs/quota/quota.c
··· 18 18 #include <linux/quotaops.h> 19 19 #include <linux/types.h> 20 20 #include <linux/writeback.h> 21 - #include "../internal.h" 22 21 23 22 static int check_quotactl_permission(struct super_block *sb, int type, int cmd, 24 23 qid_t id) ··· 45 46 return security_quotactl(cmd, type, id, sb); 46 47 } 47 48 49 + static void quota_sync_one(struct super_block *sb, void *arg) 50 + { 51 + if (sb->s_qcop && sb->s_qcop->quota_sync) 52 + sb->s_qcop->quota_sync(sb, *(int *)arg, 1); 53 + } 54 + 48 55 static int quota_sync_all(int type) 49 56 { 50 - struct super_block *sb, *n; 51 57 int ret; 52 58 53 59 if (type >= MAXQUOTAS) 54 60 return -EINVAL; 55 61 ret = security_quotactl(Q_SYNC, type, 0, NULL); 56 - if (ret) 57 - return ret; 58 - 59 - spin_lock(&sb_lock); 60 - list_for_each_entry_safe(sb, n, &super_blocks, s_list) { 61 - if (list_empty(&sb->s_instances)) 62 - continue; 63 - if (!sb->s_qcop || !sb->s_qcop->quota_sync) 64 - continue; 65 - 66 - sb->s_count++; 67 - spin_unlock(&sb_lock); 68 - down_read(&sb->s_umount); 69 - if (sb->s_root) 70 - sb->s_qcop->quota_sync(sb, type, 1); 71 - up_read(&sb->s_umount); 72 - spin_lock(&sb_lock); 73 - __put_super(sb); 74 - } 75 - spin_unlock(&sb_lock); 76 - 77 - return 0; 62 + if (!ret) 63 + iterate_supers(quota_sync_one, &type); 64 + return ret; 78 65 } 79 66 80 67 static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id,
+30
fs/super.c
··· 392 392 } 393 393 394 394 /** 395 + * iterate_supers - call function for all active superblocks 396 + * @f: function to call 397 + * @arg: argument to pass to it 398 + * 399 + * Scans the superblock list and calls given function, passing it 400 + * locked superblock and given argument. 401 + */ 402 + void iterate_supers(void (*f)(struct super_block *, void *), void *arg) 403 + { 404 + struct super_block *sb, *n; 405 + 406 + spin_lock(&sb_lock); 407 + list_for_each_entry_safe(sb, n, &super_blocks, s_list) { 408 + if (list_empty(&sb->s_instances)) 409 + continue; 410 + sb->s_count++; 411 + spin_unlock(&sb_lock); 412 + 413 + down_read(&sb->s_umount); 414 + if (sb->s_root) 415 + f(sb, arg); 416 + up_read(&sb->s_umount); 417 + 418 + spin_lock(&sb_lock); 419 + __put_super(sb); 420 + } 421 + spin_unlock(&sb_lock); 422 + } 423 + 424 + /** 395 425 * get_super - get the superblock of a device 396 426 * @bdev: device to get the superblock for 397 427 *
+6 -19
fs/sync.c
··· 77 77 } 78 78 EXPORT_SYMBOL_GPL(sync_filesystem); 79 79 80 + static void sync_one_sb(struct super_block *sb, void *arg) 81 + { 82 + if (!(sb->s_flags & MS_RDONLY) && sb->s_bdi) 83 + __sync_filesystem(sb, *(int *)arg); 84 + } 80 85 /* 81 86 * Sync all the data for all the filesystems (called by sys_sync() and 82 87 * emergency sync) 83 88 */ 84 89 static void sync_filesystems(int wait) 85 90 { 86 - struct super_block *sb, *n; 87 - 88 - spin_lock(&sb_lock); 89 - list_for_each_entry_safe(sb, n, &super_blocks, s_list) { 90 - if (list_empty(&sb->s_instances)) 91 - continue; 92 - sb->s_count++; 93 - spin_unlock(&sb_lock); 94 - 95 - down_read(&sb->s_umount); 96 - if (!(sb->s_flags & MS_RDONLY) && sb->s_root && sb->s_bdi) 97 - __sync_filesystem(sb, wait); 98 - up_read(&sb->s_umount); 99 - 100 - /* restart only when sb is no longer on the list */ 101 - spin_lock(&sb_lock); 102 - __put_super(sb); 103 - } 104 - spin_unlock(&sb_lock); 91 + iterate_supers(sync_one_sb, &wait); 105 92 } 106 93 107 94 /*
+1
include/linux/fs.h
··· 2324 2324 extern struct super_block *get_active_super(struct block_device *bdev); 2325 2325 extern struct super_block *user_get_super(dev_t); 2326 2326 extern void drop_super(struct super_block *sb); 2327 + extern void iterate_supers(void (*)(struct super_block *, void *), void *); 2327 2328 2328 2329 extern int dcache_dir_open(struct inode *, struct file *); 2329 2330 extern int dcache_dir_close(struct inode *, struct file *);