[RFC PATCH] xfs: use log_incompat feature instead of speculate matching

Gao Xiang
2020-08-24T08:19:23Z

From: Gao Xiang <hsiangkao@redhat.com>

Use a log_incompat feature just to be safe.
If the current mount is in RO state, it will defer
to next RW remount.

Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---

After some careful thinking, I think it's probably not working for
supported V4 XFS filesystem. So, I think we'd probably insist on the
previous way (correct me if I'm wrong)...

(since xfs_sb_to_disk() refuses to set up any feature bits for non V5
fses. That is another awkward setting here (doesn't write out/check
feature bits for V4 even though using V4 sb reserved fields) and
unless let V4 completely RO since this commit. )

Just send out as a RFC patch. Not fully tested after I thought as above.

fs/xfs/libxfs/xfs_format.h | 4 +++-
fs/xfs/xfs_inode.c | 3 ++-
fs/xfs/xfs_mount.c | 9 +++++++++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 31b7ece985bb..9f6c2766f6a6 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -479,7 +479,9 @@ xfs_sb_has_incompat_feature(
return (sbp->sb_features_incompat & feature) != 0;
}

-#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
+#define XFS_SB_FEAT_INCOMPAT_LOG_NEW_UNLINK (1 << 0)
+#define XFS_SB_FEAT_INCOMPAT_LOG_ALL \
+ (XFS_SB_FEAT_INCOMPAT_LOG_NEW_UNLINK)
#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL
static inline bool
xfs_sb_has_incompat_log_feature(
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 7ee778bcde06..e8eee1437611 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1952,7 +1952,8 @@ xfs_iunlink_update_bucket(
if (!log || log->l_flags & XLOG_RECOVERY_NEEDED) {
ASSERT(cur_agino != NULLAGINO);

- if (be32_to_cpu(agi->agi_unlinked[0]) != cur_agino)
+ if (!(mp->m_sb.sb_features_log_incompat &
+ XFS_SB_FEAT_INCOMPAT_LOG_NEW_UNLINK))
bucket_index = cur_agino % XFS_AGI_UNLINKED_BUCKETS;
}

diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index f28c969af272..91d8b22524c6 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -836,6 +836,15 @@ xfs_mountfs(
goto out_fail_wait;
}

+ if (!(sbp->sb_features_log_incompat &
+ XFS_SB_FEAT_INCOMPAT_LOG_NEW_UNLINK) &&
+ !(mp->m_flags & XFS_MOUNT_RDONLY)) {
+ xfs_warn(mp, "will switch to long iunlinked list on r/w");
+ sbp->sb_features_log_incompat |=
+ XFS_SB_FEAT_INCOMPAT_LOG_NEW_UNLINK;
+ mp->m_update_sb = true;
+ }
+
/* Make sure the summary counts are ok. */
error = xfs_check_summary_counts(mp);
if (error)
--
2.24.0