Skip to contentSkip to conversation

superblock endianess annotations

PATCH In review Christoph Hellwig 2 participants 3 messages Jul 20, 2007 – Jul 23, 2007 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 superblock endianess annotations

Creates a new xfs_dsb_t that is __be annotated and keeps xfs_sb_t for the incore one. xfs_xlatesb is renamed to xfs_sb_to_disk and only handles the incore -> disk conversion. A new helper xfs_sb_from_disk handles the other direction and doesn't need the slightly hacky table-driven approach because we only ever read the full sb from disk.

The handling of shared r/o filesystems has been buggy on little endian system and fixing this required shuffling around of some code in that area.

fs/xfs/xfs_fsops.c +1 -3
Index: linux-2.6-xfs/fs/xfs/xfs_fsops.c
===================================================================
@@ -136,7 +136,6 @@ xfs_growfs_data_private(
 	xfs_rfsblock_t		nfree;
 	xfs_agnumber_t		oagcount;
 	int			pct;
-	xfs_sb_t		*sbp;
 	xfs_trans_t		*tp;
 
 	nb = in->newblocks;
@@ -377,8 +376,7 @@ xfs_growfs_data_private(
 				error, agno);
 			break;
 		}
-		sbp = XFS_BUF_TO_SBP(bp);
-		xfs_xlatesb(sbp, &mp->m_sb, -1, XFS_SB_ALL_BITS);
+		xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb, XFS_SB_ALL_BITS);
 		/*
 		 * If we get an error writing out the alternate superblocks,
 		 * just issue a warning and continue.  The real work is
fs/xfs/xfs_mount.c +88 -46

216 lines not on this page · raw message

fs/xfs/xfs_sb.h +65 -3

86 lines not on this page · raw message

fs/xfs/xfs_trans.c +34 -40

112 lines not on this page · raw message

fs/xfs/xfsidbg.c +6 -6
Index: linux-2.6-xfs/fs/xfs/xfsidbg.c
===================================================================
@@ -170,7 +170,7 @@ static void	xfsidbg_xqm_mplist(xfs_mount
 static void	xfsidbg_xqm_qinfo(xfs_mount_t *mp);
 static void	xfsidbg_xqm_tpdqinfo(xfs_trans_t *tp);
 static void	xfsidbg_xsb(xfs_sb_t *);
-static void	xfsidbg_xsb_convert(xfs_sb_t *);
+static void	xfsidbg_xsb_convert(xfs_dsb_t *);
 static void	xfsidbg_xtp(xfs_trans_t *);
 static void	xfsidbg_xtrans_res(xfs_mount_t *);
 #ifdef CONFIG_XFS_QUOTA
@@ -1719,7 +1719,7 @@ static int	kdbm_xfs_xsb(
 	}
 
 	if (convert)
-		xfsidbg_xsb_convert((xfs_sb_t *) addr);
+		xfsidbg_xsb_convert((xfs_dsb_t *) addr);
 	else
 		xfsidbg_xsb((xfs_sb_t *) addr);
 	return 0;
@@ -4980,7 +4980,7 @@ xfsidbg_xbuf_real(xfs_buf_t *bp, int sum
 	void *d;
 	xfs_agf_t *agf;
 	xfs_agi_t *agi;
-	xfs_sb_t *sb;
+	xfs_dsb_t *sb;
 	xfs_alloc_block_t *bta;
 	xfs_bmbt_block_t *btb;
 	xfs_inobt_block_t *bti;
@@ -5065,7 +5065,7 @@ xfsidbg_xbuf_real(xfs_buf_t *bp, int sum
 			kdb_printf("buf 0x%p dinode 0x%p\n", bp, di);
 			xfs_inodebuf(bp);
 		}
-	} else if (INT_GET((sb = d)->sb_magicnum, ARCH_CONVERT) == XFS_SB_MAGIC) {
+	} else if (be32_to_cpu((sb = d)->sb_magicnum) == XFS_SB_MAGIC) {
 		if (summary) {
 			kdb_printf("Superblock (at 0x%p)\n", sb);
 		} else {
@@ -7359,11 +7359,11 @@ xfsidbg_xsb(xfs_sb_t *sbp)
 }
 
 static void
-xfsidbg_xsb_convert(xfs_sb_t *sbp)
+xfsidbg_xsb_convert(xfs_dsb_t *sbp)
 {
 	xfs_sb_t sb;
 
-	xfs_xlatesb(sbp, &sb, 1, XFS_SB_ALL_BITS);
+	xfs_sb_from_disk(&sb, sbp);
 
 	kdb_printf("<converted>\n");
 	xfsidbg_xsb(&sb);
fs/xfs/xfs_log_recover.c +2 -2
Index: linux-2.6-xfs/fs/xfs/xfs_log_recover.c
===================================================================
@@ -3846,7 +3846,7 @@ xlog_do_recover(
 
 	/* Convert superblock from on-disk format */
 	sbp = &log->l_mp->m_sb;
-	xfs_xlatesb(XFS_BUF_TO_SBP(bp), sbp, 1, XFS_SB_ALL_BITS);
+	xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
 	ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC);
 	ASSERT(XFS_SB_GOOD_VERSION(sbp));
 	xfs_buf_relse(bp);
@@ -4024,7 +4024,7 @@ xlog_recover_check_summary(
 	sbbp = xfs_getsb(mp, 0);
 #ifdef XFS_LOUD_RECOVERY
 	sbp = &mp->m_sb;
-	xfs_xlatesb(XFS_BUF_TO_SBP(sbbp), sbp, 1, XFS_SB_ALL_BITS);
+	xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(sbbp));
 	cmn_err(CE_NOTE,
 		"xlog_recover_check_summary: sb_icount %Lu itotal %Lu",
 		sbp->sb_icount, itotal);
fs/xfs/xfs_mount.h +2 -1
Index: linux-2.6-xfs/fs/xfs/xfs_mount.h
===================================================================
@@ -631,7 +631,8 @@ extern int	xfs_syncsub(xfs_mount_t *, in
 extern int	xfs_sync_inodes(xfs_mount_t *, int, int *);
 extern xfs_agnumber_t	xfs_initialize_perag(struct bhv_vfs *, xfs_mount_t *,
 						xfs_agnumber_t);
-extern void	xfs_xlatesb(void *, struct xfs_sb *, int, __int64_t);
+extern void	xfs_sb_from_disk(struct xfs_sb *, struct xfs_dsb *);
+extern void	xfs_sb_to_disk(struct xfs_dsb *, struct xfs_sb *, __int64_t);
 extern int	xfs_sb_validate_fsb_count(struct xfs_sb *, __uint64_t);
 
 extern struct xfs_dmops xfs_dmcore_stub;
fs/xfs/linux-2.6/xfs_ksyms.c +1 -1
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ksyms.c
===================================================================
@@ -326,7 +326,7 @@ EXPORT_SYMBOL(xfs_vnodeops);
 EXPORT_SYMBOL(xfs_vtoi);
 EXPORT_SYMBOL(xfs_write_clear_setuid);
 EXPORT_SYMBOL(xfs_dinode_from_disk);
-EXPORT_SYMBOL(xfs_xlatesb);
+EXPORT_SYMBOL(xfs_sb_from_disk);
 EXPORT_SYMBOL(xfs_zero_eof);
 EXPORT_SYMBOL(xlog_recover_process_iunlinks);
 EXPORT_SYMBOL(xfs_ichgtime_fast);
#1 lore raw
Quoted 5 lines · Christoph Hellwig

Creates a new xfs_dsb_t that is __be annotated and keeps xfs_sb_t for the incore one. xfs_xlatesb is renamed to xfs_sb_to_disk and only handles the incore -> disk conversion. A new helper xfs_sb_from_disk handles the other direction and doesn't need the slightly hacky table-driven approach because we only ever read the full sb from disk.

Nice. There's some good cleanups in this patch....

Quoted 3 lines

The handling of shared r/o filesystems has been buggy on little endian system and fixing this required shuffling around of some code in that area.

*nod*

Quoted 6 lines

/*
+ * Superblock - on disk version. Must match the in core version below.
+ */

fs/xfs/xfs_sb.h +2 -0
+typedef struct xfs_dsb {
+	__be32		sb_magicnum;	/* magic number == XFS_SB_MAGIC */

.....

fs/xfs/xfs_sb.h typedef struct xfs_sb · line 208

Quoted 4 lines
fs/xfs/xfs_sb.h +4 -0
+	__be16		sb_logsectsize;	/* sector size for the log, bytes */
+	__be32		sb_logsunit;	/* stripe unit size for the log */
+	__be32		sb_features2;	/* additional feature bits */
+} xfs_dsb_t;

Should this be packed so we don't reintroduce have the problem we currently do with 32-vs-64-bit alignment of the last field(s) in the structure?

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#2 lore raw
Quoted 4 lines · David Chinner
Quoted 1 line

+} xfs_dsb_t;

Should this be packed so we don't reintroduce have the problem we currently do with 32-vs-64-bit alignment of the last field(s) in the structure?

There's no packing for the xfs_sb_t, so there's none in xfs_dsb_t aswell. If you introduce packing for xfs_sb_t make sure to patch xfs_dsb_t aswell.

Should we change names to xfs_sb_t for the ondisk one an xfs_icsb_t here aswell? That would be a quite large change as there are a lot more incore instances of the superblock than ondisk.