aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sync.c')
-rw-r--r--fs/sync.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/fs/sync.c b/fs/sync.c
index 11e3d1c44901..eb8722dc556f 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -29,16 +29,6 @@
29 */ 29 */
30static int __sync_filesystem(struct super_block *sb, int wait) 30static int __sync_filesystem(struct super_block *sb, int wait)
31{ 31{
32 /*
33 * This should be safe, as we require bdi backing to actually
34 * write out data in the first place
35 */
36 if (sb->s_bdi == &noop_backing_dev_info)
37 return 0;
38
39 if (sb->s_qcop && sb->s_qcop->quota_sync)
40 sb->s_qcop->quota_sync(sb, -1, wait);
41
42 if (wait) 32 if (wait)
43 sync_inodes_sb(sb); 33 sync_inodes_sb(sb);
44 else 34 else
@@ -77,29 +67,48 @@ int sync_filesystem(struct super_block *sb)
77} 67}
78EXPORT_SYMBOL_GPL(sync_filesystem); 68EXPORT_SYMBOL_GPL(sync_filesystem);
79 69
80static void sync_one_sb(struct super_block *sb, void *arg) 70static void sync_inodes_one_sb(struct super_block *sb, void *arg)
81{ 71{
82 if (!(sb->s_flags & MS_RDONLY)) 72 if (!(sb->s_flags & MS_RDONLY))
83 __sync_filesystem(sb, *(int *)arg); 73 sync_inodes_sb(sb);
84} 74}
85/* 75
86 * Sync all the data for all the filesystems (called by sys_sync() and 76static void sync_fs_one_sb(struct super_block *sb, void *arg)
87 * emergency sync)
88 */
89static void sync_filesystems(int wait)
90{ 77{
91 iterate_supers(sync_one_sb, &wait); 78 if (!(sb->s_flags & MS_RDONLY) && sb->s_op->sync_fs)
79 sb->s_op->sync_fs(sb, *(int *)arg);
80}
81
82static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
83{
84 filemap_fdatawrite(bdev->bd_inode->i_mapping);
85}
86
87static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
88{
89 filemap_fdatawait(bdev->bd_inode->i_mapping);
92} 90}
93 91
94/* 92/*
95 * sync everything. Start out by waking pdflush, because that writes back 93 * Sync everything. We start by waking flusher threads so that most of
96 * all queues in parallel. 94 * writeback runs on all devices in parallel. Then we sync all inodes reliably
95 * which effectively also waits for all flusher threads to finish doing
96 * writeback. At this point all data is on disk so metadata should be stable
97 * and we tell filesystems to sync their metadata via ->sync_fs() calls.
98 * Finally, we writeout all block devices because some filesystems (e.g. ext2)
99 * just write metadata (such as inodes or bitmaps) to block device page cache
100 * and do not sync it on their own in ->sync_fs().
97 */ 101 */
98SYSCALL_DEFINE0(sync) 102SYSCALL_DEFINE0(sync)
99{ 103{
104 int nowait = 0, wait = 1;
105
100 wakeup_flusher_threads(0, WB_REASON_SYNC); 106 wakeup_flusher_threads(0, WB_REASON_SYNC);
101 sync_filesystems(0); 107 iterate_supers(sync_inodes_one_sb, NULL);
102 sync_filesystems(1); 108 iterate_supers(sync_fs_one_sb, &nowait);
109 iterate_supers(sync_fs_one_sb, &wait);
110 iterate_bdevs(fdatawrite_one_bdev, NULL);
111 iterate_bdevs(fdatawait_one_bdev, NULL);
103 if (unlikely(laptop_mode)) 112 if (unlikely(laptop_mode))
104 laptop_sync_completion(); 113 laptop_sync_completion();
105 return 0; 114 return 0;
@@ -107,12 +116,18 @@ SYSCALL_DEFINE0(sync)
107 116
108static void do_sync_work(struct work_struct *work) 117static void do_sync_work(struct work_struct *work)
109{ 118{
119 int nowait = 0;
120
110 /* 121 /*
111 * Sync twice to reduce the possibility we skipped some inodes / pages 122 * Sync twice to reduce the possibility we skipped some inodes / pages
112 * because they were temporarily locked 123 * because they were temporarily locked
113 */ 124 */
114 sync_filesystems(0); 125 iterate_supers(sync_inodes_one_sb, &nowait);
115 sync_filesystems(0); 126 iterate_supers(sync_fs_one_sb, &nowait);
127 iterate_bdevs(fdatawrite_one_bdev, NULL);
128 iterate_supers(sync_inodes_one_sb, &nowait);
129 iterate_supers(sync_fs_one_sb, &nowait);
130 iterate_bdevs(fdatawrite_one_bdev, NULL);
116 printk("Emergency Sync complete\n"); 131 printk("Emergency Sync complete\n");
117 kfree(work); 132 kfree(work);
118} 133}