linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libext2fs: Always swab MMP block on BE machines
@ 2011-09-30 19:41 Darrick J. Wong
  2011-09-30 21:09 ` Andreas Dilger
  2011-09-30 23:03 ` Ted Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Darrick J. Wong @ 2011-09-30 19:41 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

The MMP code in libext2fs tries to gate MMP block swab'ing with this test:

#ifdef EXT2FS_ENABLE_SWAPFS
if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))

However, EXT2FS_ENABLE_SWAPFS never seems to be defined anywhere (all possible
#define's were cleaned out of e2fsprogs ages ago), and even if any still
existed, the field fs->super->s_magic is always in host byteorder, so the test
always fails.  So, we can change the #ifdef to WORDS_BIGENDIAN (which is
conditionally defined on BE platforms) and get rid of the broken if test.

(This fix came up while testing the metadata checksumming patchset)

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---

 lib/ext2fs/mmp.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
index ed6ee42..91f4fb2 100644
--- a/lib/ext2fs/mmp.c
+++ b/lib/ext2fs/mmp.c
@@ -91,9 +91,8 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 	}
 
 	mmp_cmp = fs->mmp_cmp;
-#ifdef EXT2FS_ENABLE_SWAPFS
-	if (fs->flags & EXT2_FLAG_SWAP_BYTES)
-		ext2fs_swap_mmp(mmp_cmp);
+#ifdef WORDS_BIGENDIAN
+	ext2fs_swap_mmp(mmp_cmp);
 #endif
 
 	if (buf != NULL && buf != fs->mmp_cmp)
@@ -122,18 +121,16 @@ errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 	    fs->super->s_mmp_block > ext2fs_blocks_count(fs->super))
 		return EXT2_ET_MMP_BAD_BLOCK;
 
-#ifdef EXT2FS_ENABLE_SWAPFS
-	if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
-		ext2fs_swap_mmp(mmp_s);
+#ifdef WORDS_BIGENDIAN
+	ext2fs_swap_mmp(mmp_s);
 #endif
 
 	/* I was tempted to make this use O_DIRECT and the mmp_fd, but
 	 * this caused no end of grief, while leaving it as-is works. */
 	retval = io_channel_write_blk64(fs->io, mmp_blk, -fs->blocksize, buf);
 
-#ifdef EXT2FS_ENABLE_SWAPFS
-	if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
-		ext2fs_swap_mmp(mmp_s);
+#ifdef WORDS_BIGENDIAN
+	ext2fs_swap_mmp(mmp_s);
 #endif
 
 	/* Make sure the block gets to disk quickly */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] libext2fs: Always swab MMP block on BE machines
  2011-09-30 19:41 [PATCH] libext2fs: Always swab MMP block on BE machines Darrick J. Wong
@ 2011-09-30 21:09 ` Andreas Dilger
  2011-09-30 23:03 ` Ted Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Dilger @ 2011-09-30 21:09 UTC (permalink / raw)
  To: djwong; +Cc: Theodore Ts'o, linux-ext4

On 2011-09-30, at 1:41 PM, Darrick J. Wong wrote:
> The MMP code in libext2fs tries to gate MMP block swab'ing with this test:
> 
> #ifdef EXT2FS_ENABLE_SWAPFS
> if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))

We've never run Lustre on big-endian servers (clients generally work),
so it's possible this has been in our patch for years.

Thanks for the catch.

> However, EXT2FS_ENABLE_SWAPFS never seems to be defined anywhere (all possible
> #define's were cleaned out of e2fsprogs ages ago), and even if any still
> existed, the field fs->super->s_magic is always in host byteorder, so the test
> always fails.  So, we can change the #ifdef to WORDS_BIGENDIAN (which is
> conditionally defined on BE platforms) and get rid of the broken if test.
> 
> (This fix came up while testing the metadata checksumming patchset)
> 
> Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
> ---
> 
> lib/ext2fs/mmp.c |   15 ++++++---------
> 1 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
> index ed6ee42..91f4fb2 100644
> --- a/lib/ext2fs/mmp.c
> +++ b/lib/ext2fs/mmp.c
> @@ -91,9 +91,8 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
> 	}
> 
> 	mmp_cmp = fs->mmp_cmp;
> -#ifdef EXT2FS_ENABLE_SWAPFS
> -	if (fs->flags & EXT2_FLAG_SWAP_BYTES)
> -		ext2fs_swap_mmp(mmp_cmp);
> +#ifdef WORDS_BIGENDIAN
> +	ext2fs_swap_mmp(mmp_cmp);
> #endif
> 
> 	if (buf != NULL && buf != fs->mmp_cmp)
> @@ -122,18 +121,16 @@ errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
> 	    fs->super->s_mmp_block > ext2fs_blocks_count(fs->super))
> 		return EXT2_ET_MMP_BAD_BLOCK;
> 
> -#ifdef EXT2FS_ENABLE_SWAPFS
> -	if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
> -		ext2fs_swap_mmp(mmp_s);
> +#ifdef WORDS_BIGENDIAN
> +	ext2fs_swap_mmp(mmp_s);
> #endif
> 
> 	/* I was tempted to make this use O_DIRECT and the mmp_fd, but
> 	 * this caused no end of grief, while leaving it as-is works. */
> 	retval = io_channel_write_blk64(fs->io, mmp_blk, -fs->blocksize, buf);
> 
> -#ifdef EXT2FS_ENABLE_SWAPFS
> -	if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
> -		ext2fs_swap_mmp(mmp_s);
> +#ifdef WORDS_BIGENDIAN
> +	ext2fs_swap_mmp(mmp_s);
> #endif
> 
> 	/* Make sure the block gets to disk quickly */
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libext2fs: Always swab MMP block on BE machines
  2011-09-30 19:41 [PATCH] libext2fs: Always swab MMP block on BE machines Darrick J. Wong
  2011-09-30 21:09 ` Andreas Dilger
@ 2011-09-30 23:03 ` Ted Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Ted Ts'o @ 2011-09-30 23:03 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-ext4

On Fri, Sep 30, 2011 at 12:41:26PM -0700, Darrick J. Wong wrote:
> The MMP code in libext2fs tries to gate MMP block swab'ing with this test:
> 
> #ifdef EXT2FS_ENABLE_SWAPFS
> if (fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
> 
> However, EXT2FS_ENABLE_SWAPFS never seems to be defined anywhere (all possible
> #define's were cleaned out of e2fsprogs ages ago), and even if any still
> existed, the field fs->super->s_magic is always in host byteorder, so the test
> always fails.  So, we can change the #ifdef to WORDS_BIGENDIAN (which is
> conditionally defined on BE platforms) and get rid of the broken if test.
> 
> (This fix came up while testing the metadata checksumming patchset)
> 
> Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>

Applied, thanks.

						- Ted

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-30 23:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-30 19:41 [PATCH] libext2fs: Always swab MMP block on BE machines Darrick J. Wong
2011-09-30 21:09 ` Andreas Dilger
2011-09-30 23:03 ` Ted Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).