aboutsummaryrefslogtreecommitdiff
path: root/fs/sync.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-05-05 15:41:25 +0200
committerAl Viro <viro@zeniv.linux.org.uk>2009-06-11 21:36:06 -0400
commit5af7926ff33b68b3ba46531471c6e0564b285efc (patch)
treea25266f9db482ce9dd8e663148ffb0f1a524bd83 /fs/sync.c
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>
Diffstat (limited to 'fs/sync.c')
-rw-r--r--fs/sync.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/fs/sync.c b/fs/sync.c
index 4487b5560dc..89c37f732af 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -51,6 +51,18 @@ int sync_filesystem(struct super_block *sb)
{
int ret;
+ /*
+ * We need to be protected against the filesystem going from
+ * r/o to r/w or vice versa.
+ */
+ WARN_ON(!rwsem_is_locked(&sb->s_umount));
+
+ /*
+ * No point in syncing out anything if the filesystem is read-only.
+ */
+ if (sb->s_flags & MS_RDONLY)
+ return 0;
+
ret = __sync_filesystem(sb, 0);
if (ret < 0)
return ret;
@@ -79,25 +91,22 @@ static void sync_filesystems(int wait)
mutex_lock(&mutex); /* Could be down_interruptible */
spin_lock(&sb_lock);
- list_for_each_entry(sb, &super_blocks, s_list) {
- if (sb->s_flags & MS_RDONLY)
- continue;
+ list_for_each_entry(sb, &super_blocks, s_list)
sb->s_need_sync = 1;
- }
restart:
list_for_each_entry(sb, &super_blocks, s_list) {
if (!sb->s_need_sync)
continue;
sb->s_need_sync = 0;
- if (sb->s_flags & MS_RDONLY)
- continue; /* hm. Was remounted r/o meanwhile */
sb->s_count++;
spin_unlock(&sb_lock);
+
down_read(&sb->s_umount);
- if (sb->s_root)
+ if (!(sb->s_flags & MS_RDONLY) && sb->s_root)
__sync_filesystem(sb, wait);
up_read(&sb->s_umount);
+
/* restart only when sb is no longer on the list */
spin_lock(&sb_lock);
if (__put_super_and_need_restart(sb))