Skip to contentSkip to conversation

fs: add a remount,ro coherency point

PATCH In review Nick Piggin 3 participants 5 messages Mar 30, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: add a remount,ro coherency point

fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

---
 fs/super.c |    8 ++++++++
 1 file changed, 8 insertions(+)
fs/super.c +8 -0
Index: linux-2.6/fs/super.c
===================================================================
@@ -647,6 +647,14 @@ int do_remount_sb(struct super_block *sb
 		acct_auto_close(sb);
 	shrink_dcache_sb(sb);
 	fsync_super(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly
+	    then copy the filesystem from bdev, we could get stale data,
+	    so invalidate it to give a best effort at coherency. */
+	if (flags & MS_RDONLY && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);
 
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Nick Piggin

fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

Nick, Thank you for taking the time to fix this.

Signature · 15 lines
==============================================================
Jorge Boncompte - Ingenieria y Gestion de RED
DTI2 - Desarrollo de la Tecnologia de las Comunicaciones
--------------------------------------------------------------
C/ Abogado Enriquez Barrios, 5   14004 CORDOBA (SPAIN)
Tlf: +34 957 761395 / FAX: +34 957 450380
==============================================================
- Sin pistachos no hay Rock & Roll...
- Without wicker a basket cannot be made.
==============================================================

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to Nick Piggin

Hi Nick,

Quoted 17 lines · Nick Piggin

fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

---
 fs/super.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Index: linux-2.6/fs/super.c
===================================================================

fs/super.c int do_remount_sb(struct super_block *sb · line 648

Quoted 2 lines
fs/super.c +0 -0
@@ -647,6 +647,14 @@ int do_remount_sb(struct super_block *sb
 		acct_auto_close(sb);
 	shrink_dcache_sb(sb);

Not a question to this patch: can we avoid shrink_dcache_sb() on ro=>rw remounts? They will happen at system boot time, and eliminating the shrink_dcache_sb() could help reduce the boot time.

fs/super.c int do_remount_sb(struct super_block *sb · line 657

Quoted 9 lines
fs/super.c +8 -0
 	fsync_super(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly
+	    then copy the filesystem from bdev, we could get stale data,
+	    so invalidate it to give a best effort at coherency. */
+	if (flags & MS_RDONLY && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);

Or move the above lines to...

fs/super.c int do_remount_sb(struct super_block *sb · line 660

Quoted 2 lines
fs/super.c +0 -0
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
        if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
                if (force)
                        mark_files_ro(sb);
                else if (!fs_may_remount_ro(sb))
                        return -EBUSY;
                retval = vfs_dq_off(sb, 1);
                if (retval < 0 && retval != -ENOSYS)
                        return -EBUSY;
        }

...here?

Thanks,
Fengguang

#3 lore raw
Quoted 15 lines · Wu Fengguang

Hi Nick,

Quoted 12 lines · Nick Piggin

fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

---
 fs/super.c |    8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 11 lines

fs/super.c int do_remount_sb(struct super_block *sb · line 648

Quoted 7 lines

Index: linux-2.6/fs/super.c
===================================================================

fs/super.c +0 -0
@@ -647,6 +647,14 @@ int do_remount_sb(struct super_block *sb
 		acct_auto_close(sb);
 	shrink_dcache_sb(sb);

Not a question to this patch: can we avoid shrink_dcache_sb() on ro=>rw remounts? They will happen at system boot time, and eliminating the shrink_dcache_sb() could help reduce the boot time.

I don't see why not. Yes it might reduce dcache misses a little bit.

Quoted 24 lines

fs/super.c int do_remount_sb(struct super_block *sb · line 657

Quoted 9 lines
fs/super.c +8 -0
 	fsync_super(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly
+	    then copy the filesystem from bdev, we could get stale data,
+	    so invalidate it to give a best effort at coherency. */
+	if (flags & MS_RDONLY && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);

Or move the above lines to...

fs/super.c int do_remount_sb(struct super_block *sb · line 659

Quoted 2 lines
fs/super.c +0 -0
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
        if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
                if (force)
                        mark_files_ro(sb);
                else if (!fs_may_remount_ro(sb))
                        return -EBUSY;
                retval = vfs_dq_off(sb, 1);
                if (retval < 0 && retval != -ENOSYS)
                        return -EBUSY;
        }
Quoted 1 line

...here?

Oh... hmm, actually it probably makes even more sensse after we perform the remount (there might be further changes to the filesystem in the meantime, or the remount may fail).

How about this instead?
--
fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

---
 fs/super.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
fs/super.c +13 -3
Index: linux-2.6/fs/super.c
===================================================================
@@ -637,7 +637,7 @@ retry:
 int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
 {
 	int retval;
-	int remount_rw;
+	int remount_rw, remount_ro;
 	
 #ifdef CONFIG_BLOCK
 	if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev))
@@ -648,9 +648,12 @@ int do_remount_sb(struct super_block *sb
 	shrink_dcache_sb(sb);
 	fsync_super(sb);
 
+	remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
+	remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY);
+
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
-	if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
+	if (remount_ro) {
 		if (force)
 			mark_files_ro(sb);
 		else if (!fs_may_remount_ro(sb))
@@ -659,7 +662,6 @@ int do_remount_sb(struct super_block *sb
 		if (retval < 0 && retval != -ENOSYS)
 			return -EBUSY;
 	}
-	remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY);
 
 	if (sb->s_op->remount_fs) {
 		lock_super(sb);
@@ -671,6 +673,14 @@ int do_remount_sb(struct super_block *sb
 	sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
 	if (remount_rw)
 		DQUOT_ON_REMOUNT(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly
+	    then copy the filesystem from bdev, we could get stale data,
+	    so invalidate it to give a best effort at coherency. */
+	if (remount_ro && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);
 	return 0;
 }
 
Reviewed-by
#4 lore raw
Quoted 28 lines · Nick Piggin
Quoted 15 lines · Wu Fengguang

Hi Nick,

Quoted 12 lines · Nick Piggin

fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

---
 fs/super.c |    8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 11 lines

fs/super.c int do_remount_sb(struct super_block *sb · line 648

Quoted 7 lines

Index: linux-2.6/fs/super.c
===================================================================

fs/super.c +0 -0
@@ -647,6 +647,14 @@ int do_remount_sb(struct super_block *sb
 		acct_auto_close(sb);
 	shrink_dcache_sb(sb);

Not a question to this patch: can we avoid shrink_dcache_sb() on ro=>rw remounts? They will happen at system boot time, and eliminating the shrink_dcache_sb() could help reduce the boot time.

Quoted 2 lines

I don't see why not. Yes it might reduce dcache misses a little bit.

So I'll send a patch after yours :-)

Quoted 31 lines
Quoted 25 lines

fs/super.c int do_remount_sb(struct super_block *sb · line 683

Quoted 10 lines
fs/super.c +8 -0
 	fsync_super(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly
+	    then copy the filesystem from bdev, we could get stale data,
+	    so invalidate it to give a best effort at coherency. */
+	if (flags & MS_RDONLY && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);

Or move the above lines to...

fs/super.c int do_remount_sb(struct super_block *sb · line 655

Quoted 2 lines
fs/super.c +0 -0
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
        if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
                if (force)
                        mark_files_ro(sb);
                else if (!fs_may_remount_ro(sb))
                        return -EBUSY;
                retval = vfs_dq_off(sb, 1);
                if (retval < 0 && retval != -ENOSYS)
                        return -EBUSY;
        }
Quoted 1 line

...here?

Oh... hmm, actually it probably makes even more sensse after we perform the remount (there might be further changes to the filesystem in the meantime, or the remount may fail).

Quoted 7 lines

How about this instead?
--
fs: invalidate sb->s_bdev on remount,ro

Fixes a problem reported by "Jorge Boncompte [DTI2]" <[email protected]> who is trying to snapshot a minix filesystem image.

Quoted 20 lines
---
 fs/super.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Index: linux-2.6/fs/super.c
===================================================================

fs/super.c +1 -1
@@ -637,7 +637,7 @@ retry:
 int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
 {
 	int retval;
-	int remount_rw;
+	int remount_rw, remount_ro;
 
 #ifdef CONFIG_BLOCK
 	if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev))

fs/super.c int do_remount_sb(struct super_block *sb · line 652

Quoted 5 lines
fs/super.c +2 -0
@@ -648,9 +648,12 @@ int do_remount_sb(struct super_block *sb
 	shrink_dcache_sb(sb);
 	fsync_super(sb);
 
+	remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
+	remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY);

Wow, the twins are exactly I wanted :)

Quoted 16 lines
fs/super.c +1 -2
 	/* If we are remounting RDONLY and current sb is read/write,
 	   make sure there are no rw files opened */
-	if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
+	if (remount_ro) {
 		if (force)
 			mark_files_ro(sb);
 		else if (!fs_may_remount_ro(sb))
@@ -659,7 +662,6 @@ int do_remount_sb(struct super_block *sb
 		if (retval < 0 && retval != -ENOSYS)
 			return -EBUSY;
 	}
-	remount_rw = !(flags & MS_RDONLY) && (sb->s_flags & MS_RDONLY);
 
 	if (sb->s_op->remount_fs) {
 		lock_super(sb);

fs/super.c int do_remount_sb(struct super_block *sb · line 679

Quoted 7 lines
fs/super.c +4 -0
@@ -671,6 +673,14 @@ int do_remount_sb(struct super_block *sb
 	sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
 	if (remount_rw)
 		DQUOT_ON_REMOUNT(sb);
+	 /* Some filesystems modify their metadata via some other path
+	    than the bdev buffer cache (eg. use a private mapping, or
+	    directories in pagecache, etc). Also file data modifications
+	    go via their own mappings. So If we try to mount readonly

~ forgot to point you to this

fs/super.c int do_remount_sb(struct super_block *sb · line 680

Quoted 1 line
fs/super.c +1 -0
+	    then copy the filesystem from bdev, we could get stale data,

~~~~ this 'if...then' clause will be misleading

fs/super.c int do_remount_sb(struct super_block *sb · line 681

Quoted 1 line
fs/super.c +1 -0
+	    so invalidate it to give a best effort at coherency. */

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry I'm not that good at English...

Quoted 9 lines
fs/super.c +2 -1
+	if (remount_ro && sb->s_bdev)
+		invalidate_bdev(sb->s_bdev);
 	return 0;
 }
 
--

To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html