From 97c82f59c1bc03f2ad28c298097b8596afd3634b Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 3 Jul 2024 14:22:03 -0700 Subject: [PATCH] xfs: encode the rtbitmap in big endian format Currently, the ondisk realtime bitmap file is accessed in units of 32-bit words. There's no endian translation of the contents of this file, which means that the Bad Things Happen(tm) if you go from (say) x86 to powerpc. Since we have a new feature flag, let's take the opportunity to enforce an endianness on the file. Signed-off-by: Darrick J. Wong --- libxfs/xfs_format.h | 4 +++- libxfs/xfs_rtbitmap.h | 7 ++++++- repair/rt.c | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index c76e2319d..673daa8bd 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -724,10 +724,12 @@ struct xfs_agfl { /* * Realtime bitmap information is accessed by the word, which is currently - * stored in host-endian format. + * stored in host-endian format. Starting with the realtime groups feature, + * the words are stored in be32 ondisk. */ union xfs_rtword_raw { __u32 old; + __be32 rtg; }; /* diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 6318b7f81..3c55d58a6 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -190,6 +190,8 @@ xfs_rtbitmap_getword( { union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index); + if (xfs_has_rtgroups(args->mp)) + return be32_to_cpu(word->rtg); return word->old; } @@ -202,7 +204,10 @@ xfs_rtbitmap_setword( { union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index); - word->old = value; + if (xfs_has_rtgroups(args->mp)) + word->rtg = cpu_to_be32(value); + else + word->old = value; } /* diff --git a/repair/rt.c b/repair/rt.c index 15fa7de1f..2506feaf8 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -24,7 +24,10 @@ set_rtword( union xfs_rtword_raw *word, xfs_rtword_t value) { - word->old = value; + if (xfs_has_rtgroups(mp)) + word->rtg = cpu_to_be32(value); + else + word->old = value; } static inline void -- 2.50.1