[PATCH] enforce ->sync_fs is only called for rw superblock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>

Index: vfs-2.6/fs/btrfs/super.c
===================================================================
--- vfs-2.6.orig/fs/btrfs/super.c	2009-05-05 14:42:32.418684967 +0200
+++ vfs-2.6/fs/btrfs/super.c	2009-05-05 14:43:26.114791975 +0200
@@ -388,9 +388,6 @@ int btrfs_sync_fs(struct super_block *sb
 	struct btrfs_root *root = btrfs_sb(sb);
 	int ret;
 
-	if (sb->s_flags & MS_RDONLY)
-		return 0;
-
 	if (!wait) {
 		filemap_flush(root->fs_info->btree_inode->i_mapping);
 		return 0;
Index: vfs-2.6/fs/reiserfs/super.c
===================================================================
--- vfs-2.6.orig/fs/reiserfs/super.c	2009-05-05 14:42:32.409683962 +0200
+++ vfs-2.6/fs/reiserfs/super.c	2009-05-05 14:43:26.115812984 +0200
@@ -64,18 +64,15 @@ static int reiserfs_statfs(struct dentry
 
 static int reiserfs_sync_fs(struct super_block *s, int wait)
 {
-	if (!(s->s_flags & MS_RDONLY)) {
-		struct reiserfs_transaction_handle th;
-		reiserfs_write_lock(s);
-		if (!journal_begin(&th, s, 1))
-			if (!journal_end_sync(&th, s, 1))
-				reiserfs_flush_old_commits(s);
-		s->s_dirt = 0;	/* Even if it's not true.
-				 * We'll loop forever in sync_supers otherwise */
-		reiserfs_write_unlock(s);
-	} else {
-		s->s_dirt = 0;
-	}
+	struct reiserfs_transaction_handle th;
+
+	reiserfs_write_lock(s);
+	if (!journal_begin(&th, s, 1))
+		if (!journal_end_sync(&th, s, 1))
+			reiserfs_flush_old_commits(s);
+	s->s_dirt = 0;	/* Even if it's not true.
+			 * We'll loop forever in sync_supers otherwise */
+	reiserfs_write_unlock(s);
 	return 0;
 }
 
Index: vfs-2.6/fs/sync.c
===================================================================
--- vfs-2.6.orig/fs/sync.c	2009-05-05 14:42:32.461659153 +0200
+++ vfs-2.6/fs/sync.c	2009-05-05 14:43:26.116811296 +0200
@@ -49,6 +49,18 @@ int sync_filesystem(struct super_block *
 {
 	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;
@@ -77,25 +89,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))
Index: vfs-2.6/fs/ubifs/super.c
===================================================================
--- vfs-2.6.orig/fs/ubifs/super.c	2009-05-05 14:42:32.425659668 +0200
+++ vfs-2.6/fs/ubifs/super.c	2009-05-05 14:43:26.117816731 +0200
@@ -447,9 +447,6 @@ static int ubifs_sync_fs(struct super_bl
 	if (!wait)
 		return 0;
 
-	if (sb->s_flags & MS_RDONLY)
-		return 0;
-
 	/*
 	 * VFS calls '->sync_fs()' before synchronizing all dirty inodes and
 	 * pages, so synchronize them first, then commit the journal. Strictly
Index: vfs-2.6/fs/cachefiles/interface.c
===================================================================
--- vfs-2.6.orig/fs/cachefiles/interface.c	2009-05-05 14:44:12.435813797 +0200
+++ vfs-2.6/fs/cachefiles/interface.c	2009-05-05 14:44:47.300661498 +0200
@@ -354,7 +354,9 @@ static void cachefiles_sync_cache(struct
 	/* make sure all pages pinned by operations on behalf of the netfs are
 	 * written to disc */
 	cachefiles_begin_secure(cache, &saved_cred);
+	down_read(&sb->s_umount);
 	ret = sync_filesystem(cache->mnt->mnt_sb);
+	up_read(&sb->s_umount);
 	cachefiles_end_secure(cache, saved_cred);
 
 	if (ret == -EIO)
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux