xfs: readonly handling changes
cover xfs: readonly handling changes
A couple of changes to how xfs behaves w.r.t. readonly mounts.
1) write unmount record even for RO mounts (which may have done recovery)
2) remove readonly checks from xfs_release and xfs_inactive paths
Both of these stem from the fact that a readonly mount (as opposed to a ro,norecovery mount) is /not/ guaranteed to do no writes to the block device; in fact we write straightaway when we replay the log on an ro mount. Other "OMG don't write!" leftovers linger, and cause issues as described in the following 2 patches.
Dave suggested grand plans for coalescing more of this into common paths ala remount handling, i.e. a RO mount gets mounted RW and then just goes through the same transition to RO at the end, but I haven't put all that together yet, and these patches address a couple bugs in a more targeted fashion until that can happen.
Dave also objected earlier to my 2nd patch which allows orphan recovery to proceed on an ro mount. There may be filesystems out there with fairly long orphan inode lists which have never been recovered due to this bug, and I guess the concern was that $SOMEHOW, processing them now would cause $PROBLEMS. I'm at a loss for how to address these concerns; I tried to come up with a way to craft such a filesystem for a regression test, but failed. Once the flaw has been fixed in the kernel, I don't know how to recreate the situation at will for testing.
Christoph was concerned about the xfstest which demonstrates this flaw still failing, so resending these patches to see if we can make some progress.
Thanks,
-Eric
PATCH 1/2 xfs: write unmount record for ro mounts
There are dueling comments in the xfs code about intent for log writes when unmounting a readonly filesystem.
In xfs_mountfs, we see the intent:
/*
* Now the log is fully replayed, we can transition to full read-only
* mode for read-only mounts. This will sync all the metadata and clean
* the log so that the recovery we just performed does not have to be
* replayed again on the next mount.
*/
and it calls xfs_quiesce_attr(), but by the time we get to xfs_log_unmount_write(), it returns early for a RDONLY mount:
* Don't write out unmount record on read-only mounts.
Because of this, sequential ro mounts of a filesystem with a dirty log will replay the log each time, which seems odd.
Fix this by writing an unmount record even for RO mounts, as long as norecovery wasn't specified (don't write a clean log record if a dirty log may still be there!) and the log device is writable.
---
fs/xfs/xfs_log.c +5 -2
@@ -801,11 +801,14 @@int error;/* -* Don't write out unmount record on read-only mounts. +* Don't write out unmount record on norecovery mounts or ro devices. * Or, if we cd are doing a forced umount (typically because of IO errors). */ -if (mp->m_flags &XFS_MOUNT_RDONLY ) +if (mp->m_flags &XFS_MOUNT_NORECOVERY || +xfs_readonly_buftarg (log->l_mp->m_logdev_targp)) { +ASSERT (mp->m_flags &XFS_MOUNT_RDONLY );return 0 ; + } error =_xfs_log_force (mp,XFS_LOG_SYNC ,NULL );ASSERT (error || !(XLOG_FORCED_SHUTDOWN (log)));
Re: [PATCH 1/2] xfs: write unmount record for ro mounts
Looks good,
PATCH 2/2 xfs: toggle readonly state around xfs_log_mount_finish
In reply to Eric SandeenWhen we do log recovery on a readonly mount, unlinked inode processing does not happen due to the readonly checks in xfs_inactive(), which are trying to prevent any I/O on a readonly mount.
This is misguided - we do I/O on readonly mounts all the time, for consistency; for example, log recovery. So do the same RDONLY flag twiddling around xfs_log_mount_finish() as we do around xfs_log_mount(), for the same reason.
This all cries out for a big rework but for now this is a simple fix to an obvious problem.
---
fs/xfs/xfs_log.c +7 -0
@@ -743,16 +743,23 @@ struct xfs_mount *mp) {int error =0 ; +int readonly = (mp->m_flags &XFS_MOUNT_RDONLY );if (mp->m_flags &XFS_MOUNT_NORECOVERY ) {ASSERT (mp->m_flags &XFS_MOUNT_RDONLY );return 0 ; + }else if (readonly) { +/* Allow unlinked processing to proceed */ + mp->m_flags &= ~XFS_MOUNT_RDONLY ; } error =xlog_recover_finish (mp->m_log);if (!error)xfs_log_work_queue (mp); +if (readonly) + mp->m_flags |=XFS_MOUNT_RDONLY ; +return error; }
Re: [PATCH 2/2] xfs: toggle readonly state around xfs_log_mount_finish
Quoted 24 lines · Eric Sandeen
When we do log recovery on a readonly mount, unlinked inode processing does not happen due to the readonly checks in
xfs_inactive(), which are trying to prevent any I/O on a readonly mount.This is misguided - we do I/O on readonly mounts all the time, for consistency; for example, log recovery. So do the same RDONLY flag twiddling around
xfs_log_mount_finish()as we do aroundxfs_log_mount(), for the same reason.This all cries out for a big rework but for now this is a simple fix to an obvious problem.
Signed-off-by Eric Sandeen <[email protected]>Reviewed-by Brian Foster <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>---
fs/xfs/xfs_log.c +0
-0
fs/xfs/xfs_log.c line 746
Quoted 4 lines
fs/xfs/xfs_log.c +1
-0@@ -743,16 +743,23 @@ struct xfs_mount *mp) {int error =0 ; +int readonly = (mp->m_flags &XFS_MOUNT_RDONLY );
bool?
Otherwise looks good:
PATCH v2 2/2 xfs: toggle readonly state around xfs_log_mount_finish
In reply to Eric SandeenWhen we do log recovery on a readonly mount, unlinked inode processing does not happen due to the readonly checks in xfs_inactive(), which are trying to prevent any I/O on a readonly mount.
This is misguided - we do I/O on readonly mounts all the time, for consistency; for example, log recovery. So do the same RDONLY flag twiddling around xfs_log_mount_finish() as we do around xfs_log_mount(), for the same reason.
This all cries out for a big rework but for now this is a simple fix to an obvious problem.
---
V2: bool "readonly" per Christoph's request
fs/xfs/xfs_log.c +7 -0
@@ -743,16 +743,23 @@ struct xfs_mount *mp) {int error =0 ; +bool readonly = (mp->m_flags &XFS_MOUNT_RDONLY );if (mp->m_flags &XFS_MOUNT_NORECOVERY ) {ASSERT (mp->m_flags &XFS_MOUNT_RDONLY );return 0 ; + }else if (readonly) { +/* Allow unlinked processing to proceed */ + mp->m_flags &= ~XFS_MOUNT_RDONLY ; } error =xlog_recover_finish (mp->m_log);if (!error)xfs_log_work_queue (mp); +if (readonly) + mp->m_flags |=XFS_MOUNT_RDONLY ; +return error; }
Re: [PATCH 2/2 V2] xfs: toggle readonly state around xfs_log_mount_finish
Quoted 13 lines · Eric Sandeen
When we do log recovery on a readonly mount, unlinked inode processing does not happen due to the readonly checks in
xfs_inactive(), which are trying to prevent any I/O on a readonly mount.This is misguided - we do I/O on readonly mounts all the time, for consistency; for example, log recovery. So do the same RDONLY flag twiddling around
xfs_log_mount_finish()as we do aroundxfs_log_mount(), for the same reason.This all cries out for a big rework but for now this is a simple fix to an obvious problem.
Quoted 7 lines
Signed-off-by Eric Sandeen <[email protected]>Reviewed-by Brian Foster <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>---
V2: bool "readonly" per Christoph's request
Looks good, will test...
Quoted 34 lines
fs/xfs/xfs_log.c +7
-1@@ -743,16 +743,23 @@ struct xfs_mount *mp) {int error =0 ; +bool readonly = (mp->m_flags &XFS_MOUNT_RDONLY );if (mp->m_flags &XFS_MOUNT_NORECOVERY ) {ASSERT (mp->m_flags &XFS_MOUNT_RDONLY );return 0 ; + }else if (readonly) { +/* Allow unlinked processing to proceed */ + mp->m_flags &= ~XFS_MOUNT_RDONLY ; } error =xlog_recover_finish (mp->m_log);if (!error)xfs_log_work_queue (mp); +if (readonly) + mp->m_flags |=XFS_MOUNT_RDONLY ; +return error; } --To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html