aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-05-05 09:41:25 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2009-06-11 21:36:06 -0400
commit5af7926ff33b68b3ba46531471c6e0564b285efc (patch)
treea25266f9db482ce9dd8e663148ffb0f1a524bd83
parente5004753388dcf5e1b8a52ac0ab807d232340fbb (diff)
enforce ->sync_fs is only called for rw superblock
Make sure a superblock really is writeable by checking MS_RDONLY under s_umount. sync_filesystems needed some re-arragement for that, but all but one sync_filesystem caller had the correct locking already so that we could add that check there. cachefiles grew s_umount locking. I've also added a WARN_ON to sync_filesystem to assert this for future callers. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/btrfs/super.c3
-rw-r--r--fs/cachefiles/interface.c2
-rw-r--r--fs/reiserfs/super.c21
-rw-r--r--fs/sync.c23
-rw-r--r--fs/ubifs/super.c3
5 files changed, 27 insertions, 25 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 52d84522c2c2..9f179d4832d5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -394,9 +394,6 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
394 struct btrfs_root *root = btrfs_sb(sb); 394 struct btrfs_root *root = btrfs_sb(sb);
395 int ret; 395 int ret;
396 396
397 if (sb->s_flags & MS_RDONLY)
398 return 0;
399
400 if (!wait) { 397 if (!wait) {
401 filemap_flush(root->fs_info->btree_inode->i_mapping); 398 filemap_flush(root->fs_info->btree_inode->i_mapping);
402 return 0; 399 return 0;
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index dafd484d7bda..431accd475a7 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -354,7 +354,9 @@ static void cachefiles_sync_cache(struct fscache_cache *_cache)
354 /* make sure all pages pinned by operations on behalf of the netfs are 354 /* make sure all pages pinned by operations on behalf of the netfs are
355 * written to disc */ 355 * written to disc */
356 cachefiles_begin_secure(cache, &saved_cred); 356 cachefiles_begin_secure(cache, &saved_cred);
357 down_read(&cache->mnt->mnt_sb->s_umount);
357 ret = sync_filesystem(cache->mnt->mnt_sb); 358 ret = sync_filesystem(cache->mnt->mnt_sb);
359 up_read(&cache->mnt->mnt_sb->s_umount);
358 cachefiles_end_secure(cache, saved_cred); 360 cachefiles_end_secure(cache, saved_cred);
359 361
360 if (ret == -EIO) 362 if (ret == -EIO)
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 1b52daa351c5..3da0401c0a96 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -64,18 +64,15 @@ static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
64 64
65static int reiserfs_sync_fs(struct super_block *s, int wait) 65static int reiserfs_sync_fs(struct super_block *s, int wait)
66{ 66{
67 if (!(s->s_flags & MS_RDONLY)) { 67 struct reiserfs_transaction_handle th;
68 struct reiserfs_transaction_handle th; 68
69 reiserfs_write_lock(s); 69 reiserfs_write_lock(s);
70 if (!journal_begin(&th, s, 1)) 70 if (!journal_begin(&th, s, 1))
71 if (!journal_end_sync(&th, s, 1)) 71 if (!journal_end_sync(&th, s, 1))
72 reiserfs_flush_old_commits(s); 72 reiserfs_flush_old_commits(s);
73 s->s_dirt = 0; /* Even if it's not true. 73 s->s_dirt = 0; /* Even if it's not true.
74 * We'll loop forever in sync_supers otherwise */ 74 * We'll loop forever in sync_supers otherwise */
75 reiserfs_write_unlock(s); 75 reiserfs_write_unlock(s);
76 } else {
77 s->s_dirt = 0;
78 }
79 return 0; 76 return 0;
80} 77}
81 78
diff --git a/fs/sync.c b/fs/sync.c
index 4487b5560dc8..89c37f732afa 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -51,6 +51,18 @@ int sync_filesystem(struct super_block *sb)
51{ 51{
52 int ret; 52 int ret;
53 53
54 /*
55 * We need to be protected against the filesystem going from
56 * r/o to r/w or vice versa.
57 */
58 WARN_ON(!rwsem_is_locked(&sb->s_umount));
59
60 /*
61 * No point in syncing out anything if the filesystem is read-only.
62 */
63 if (sb->s_flags & MS_RDONLY)
64 return 0;
65
54 ret = __sync_filesystem(sb, 0); 66 ret = __sync_filesystem(sb, 0);
55 if (ret < 0) 67 if (ret < 0)
56 return ret; 68 return ret;
@@ -79,25 +91,22 @@ static void sync_filesystems(int wait)
79 91
80 mutex_lock(&mutex); /* Could be down_interruptible */ 92 mutex_lock(&mutex); /* Could be down_interruptible */
81 spin_lock(&sb_lock); 93 spin_lock(&sb_lock);
82 list_for_each_entry(sb, &super_blocks, s_list) { 94 list_for_each_entry(sb, &super_blocks, s_list)
83 if (sb->s_flags & MS_RDONLY)
84 continue;
85 sb->s_need_sync = 1; 95 sb->s_need_sync = 1;
86 }
87 96
88restart: 97restart:
89 list_for_each_entry(sb, &super_blocks, s_list) { 98 list_for_each_entry(sb, &super_blocks, s_list) {
90 if (!sb->s_need_sync) 99 if (!sb->s_need_sync)
91 continue; 100 continue;
92 sb->s_need_sync = 0; 101 sb->s_need_sync = 0;
93 if (sb->s_flags & MS_RDONLY)
94 continue; /* hm. Was remounted r/o meanwhile */
95 sb->s_count++; 102 sb->s_count++;
96 spin_unlock(&sb_lock); 103 spin_unlock(&sb_lock);
104
97 down_read(&sb->s_umount); 105 down_read(&sb->s_umount);
98 if (sb->s_root) 106 if (!(sb->s_flags & MS_RDONLY) && sb->s_root)
99 __sync_filesystem(sb, wait); 107 __sync_filesystem(sb, wait);
100 up_read(&sb->s_umount); 108 up_read(&sb->s_umount);
109
101 /* restart only when sb is no longer on the list */ 110 /* restart only when sb is no longer on the list */
102 spin_lock(&sb_lock); 111 spin_lock(&sb_lock);
103 if (__put_super_and_need_restart(sb)) 112 if (__put_super_and_need_restart(sb))
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index e9f7a754c4f7..84f3c7fd1552 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -447,9 +447,6 @@ static int ubifs_sync_fs(struct super_block *sb, int wait)
447 if (!wait) 447 if (!wait)
448 return 0; 448 return 0;
449 449
450 if (sb->s_flags & MS_RDONLY)
451 return 0;
452
453 /* 450 /*
454 * VFS calls '->sync_fs()' before synchronizing all dirty inodes and 451 * VFS calls '->sync_fs()' before synchronizing all dirty inodes and
455 * pages, so synchronize them first, then commit the journal. Strictly 452 * pages, so synchronize them first, then commit the journal. Strictly