Skip to contentSkip to conversation

xfs: return error from sync_filesystem during remount

PATCH In review Darrick J. Wong 2 participants 3 messages Feb 5, 2022 – Feb 7, 2022 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: return error from sync_filesystem during remount

From: Darrick J. Wong <[email protected]>

In xfs_fs_reconfigure, check the return value from sync_filesystem and fail the remount if there was an internal error.

---
 fs/xfs/xfs_super.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_super.c +3 -1
index 4c0dee78b2f8..5f3781879c63 100644
@@ -1831,7 +1831,9 @@ xfs_fs_reconfigure(
 	if (error)
 		return error;
 
-	sync_filesystem(mp->m_super);
+	error = sync_filesystem(mp->m_super);
+	if (error)
+		return error;
 
 	/* inode32 -> inode64 */
 	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
#1 lore raw
Quoted 15 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xfs_fs_reconfigure, check the return value from sync_filesystem and fail the remount if there was an internal error.

---
 fs/xfs/xfs_super.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_super.c +0 -0
index 4c0dee78b2f8..5f3781879c63 100644

fs/xfs/xfs_super.c xfs_fs_reconfigure( · line 1839

Quoted 10 lines
fs/xfs/xfs_super.c +3 -1
@@ -1831,7 +1831,9 @@ xfs_fs_reconfigure(
 	if (error)
 		return error;
 
-	sync_filesystem(mp->m_super);
+	error = sync_filesystem(mp->m_super);
+	if (error)
+		return error;
 
 	/* inode32 -> inode64 */
 	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {

Ummm, so why do we even need to call sync_filesystem() unconditionally here? The only case where we have to actually write back anything on a remount is the rw->ro case, otherwise we aren't changing any state that requires data or metadata writeback.

I had a look at why sync_filesytem() was there, and it goes back to this commit that moved it from the VFS remount code:

commit 02b9984d640873b7b3809e63f81a0d7e13496886

Author: Theodore Ts'o <[email protected]>
Date:   Thu Mar 13 10:14:33 2014 -0400

fs: push sync_filesystem() down to the file system's remount_fs()

Previously, the no-op "mount -o mount /dev/xxx" operation when the file system is already mounted read-write causes an implied, unconditional syncfs(). This seems pretty stupid, and it's certainly documented or guaraunteed to do this, nor is it particularly useful, except in the case where the file system was mounted rw and is getting remounted read-only.

However, it's possible that there might be some file systems that are actually depending on this behavior. In most file systems, it's probably fine to only call sync_filesystem() when transitioning from read-write to read-only, and there are some file systems where this is not needed at all (for example, for a pseudo-filesystem or something like romfs).

And later on __ext4_remount got modified to only call sync_filesystem() on rw->ro transition. We do not depend on sync_filesystem() for anything here except in the rw->ro remount case, so why don't we just move the sync_filesystem() call to xfs_remount_ro()? We already have an error path there for failing to clean the filesystem, and avoids the possibility of other random mount option changes failing because some because there is some random pending data writeback error....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 55 lines · Dave Chinner
Quoted 15 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

In xfs_fs_reconfigure, check the return value from sync_filesystem and fail the remount if there was an internal error.

---
 fs/xfs/xfs_super.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_super.c +0 -0
index 4c0dee78b2f8..5f3781879c63 100644

fs/xfs/xfs_super.c xfs_fs_reconfigure( · line 1839

Quoted 10 lines
fs/xfs/xfs_super.c +3 -1
@@ -1831,7 +1831,9 @@ xfs_fs_reconfigure(
 	if (error)
 		return error;
 
-	sync_filesystem(mp->m_super);
+	error = sync_filesystem(mp->m_super);
+	if (error)
+		return error;
 
 	/* inode32 -> inode64 */
 	if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {

Ummm, so why do we even need to call sync_filesystem() unconditionally here? The only case where we have to actually write back anything on a remount is the rw->ro case, otherwise we aren't changing any state that requires data or metadata writeback.

I had a look at why sync_filesytem() was there, and it goes back to this commit that moved it from the VFS remount code:

commit 02b9984d640873b7b3809e63f81a0d7e13496886

Author: Theodore Ts'o <[email protected]>
Date:   Thu Mar 13 10:14:33 2014 -0400

fs: push sync_filesystem() down to the file system's remount_fs()

Previously, the no-op "mount -o mount /dev/xxx" operation when the file system is already mounted read-write causes an implied, unconditional syncfs(). This seems pretty stupid, and it's certainly documented or guaraunteed to do this, nor is it particularly useful, except in the case where the file system was mounted rw and is getting remounted read-only.

However, it's possible that there might be some file systems that are actually depending on this behavior. In most file systems, it's probably fine to only call sync_filesystem() when transitioning from read-write to read-only, and there are some file systems where this is not needed at all (for example, for a pseudo-filesystem or something like romfs).

Quoted 8 lines

And later on __ext4_remount got modified to only call sync_filesystem() on rw->ro transition. We do not depend on sync_filesystem() for anything here except in the rw->ro remount case, so why don't we just move the sync_filesystem() call to xfs_remount_ro()? We already have an error path there for failing to clean the filesystem, and avoids the possibility of other random mount option changes failing because some because there is some random pending data writeback error....

That's a good question. I was doing the minimum needed to fix a callsite. Ted's commit seems to have pushed an unconditional (and unchecked) call from the VFS into the first line of the filesystem implementation.

Anyway I'll change the patch to move the call to xfs_remount_ro and report back. (Or rather, I did that last night, so we'll see what the CI system reports...)

--D

Quoted 6 lines

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]