Commit a8c7176b6ded413d5044a00f1d05477b95a6d7ad

Authored by Jan Kara
Committed by Al Viro
1 parent 5c0d6b60a0

vfs: Make sys_sync writeout also block device inodes

In case block device does not have filesystem mounted on it, sys_sync will just
ignore it and doesn't writeout its dirty pages. This is because writeback code
avoids writing inodes from superblock without backing device and
blockdev_superblock is such a superblock.  Since it's unexpected that sync
doesn't writeout dirty data for block devices be nice to users and change the
behavior to do so. So now we iterate over all block devices on blockdev_super
instead of iterating over all superblocks when syncing block devices.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 1 changed file with 11 additions and 7 deletions Side-by-side Diff

... ... @@ -85,12 +85,16 @@
85 85 sb->s_op->sync_fs(sb, *(int *)arg);
86 86 }
87 87  
88   -static void sync_blkdev_one_sb(struct super_block *sb, void *arg)
  88 +static void flush_one_bdev(struct block_device *bdev, void *arg)
89 89 {
90   - if (!(sb->s_flags & MS_RDONLY))
91   - __sync_blockdev(sb->s_bdev, *(int *)arg);
  90 + __sync_blockdev(bdev, 0);
92 91 }
93 92  
  93 +static void sync_one_bdev(struct block_device *bdev, void *arg)
  94 +{
  95 + sync_blockdev(bdev);
  96 +}
  97 +
94 98 /*
95 99 * sync everything. Start out by waking pdflush, because that writes back
96 100 * all queues in parallel.
97 101  
... ... @@ -102,10 +106,10 @@
102 106 wakeup_flusher_threads(0, WB_REASON_SYNC);
103 107 iterate_supers(writeback_inodes_one_sb, NULL);
104 108 iterate_supers(sync_fs_one_sb, &nowait);
105   - iterate_supers(sync_blkdev_one_sb, &nowait);
  109 + iterate_bdevs(flush_one_bdev, NULL);
106 110 iterate_supers(sync_inodes_one_sb, NULL);
107 111 iterate_supers(sync_fs_one_sb, &wait);
108   - iterate_supers(sync_blkdev_one_sb, &wait);
  112 + iterate_bdevs(sync_one_bdev, NULL);
109 113 if (unlikely(laptop_mode))
110 114 laptop_sync_completion();
111 115 return 0;
112 116  
... ... @@ -121,10 +125,10 @@
121 125 */
122 126 iterate_supers(sync_inodes_one_sb, &nowait);
123 127 iterate_supers(sync_fs_one_sb, &nowait);
124   - iterate_supers(sync_blkdev_one_sb, &nowait);
  128 + iterate_bdevs(flush_one_bdev, NULL);
125 129 iterate_supers(sync_inodes_one_sb, &nowait);
126 130 iterate_supers(sync_fs_one_sb, &nowait);
127   - iterate_supers(sync_blkdev_one_sb, &nowait);
  131 + iterate_bdevs(flush_one_bdev, NULL);
128 132 printk("Emergency Sync complete\n");
129 133 kfree(work);
130 134 }