public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix dir2 shortform structures on ARM old ABI
@ 2008-03-15  3:24 Eric Sandeen
  2008-03-15  4:17 ` Josef 'Jeff' Sipek
                   ` (3 more replies)
  0 siblings, 4 replies; 51+ messages in thread
From: Eric Sandeen @ 2008-03-15  3:24 UTC (permalink / raw)
  To: xfs-oss; +Cc: patches

This should fix the longstanding issues with xfs and old ABI
arm boxes, which lead to various asserts and xfs shutdowns,
and for which an (incorrect) patch has been floating around
for years.  (Said patch made ARM internally consistent, but
altered the normal xfs on-disk format such that it looked
corrupted on other architectures):
http://lists.arm.linux.org.uk/lurker/message/20040311.002034.5ecf21a2.html

Old ABI ARM has interesting packing & padding; for example
on ARM old abi:

struct xfs_dir2_sf_entry {
	__uint8_t                  namelen;      /*     0     1 */

	/* XXX 3 bytes hole, try to pack */

	xfs_dir2_sf_off_t          offset;       /*     4     4 */
	__uint8_t                  name[1];      /*     8     1 */

	/* XXX 3 bytes hole, try to pack */

	xfs_dir2_inou_t            inumber;      /*    12     8 */

	/* size: 20, cachelines: 1 */
	/* sum members: 14, holes: 2, sum holes: 6 */
	/* last cacheline: 20 bytes */
};

but on x86:

struct xfs_dir2_sf_entry {
	__uint8_t                  namelen;      /*     0     1 */
	xfs_dir2_sf_off_t          offset;       /*     1     2 */
	__uint8_t                  name[1];      /*     3     1 */
	xfs_dir2_inou_t            inumber;      /*     4     8 */

	/* size: 12, cachelines: 1 */
	/* last cacheline: 12 bytes */
};

... this sort of discrepancy leads to problems.

I've verified this patch by comparing the on-disk structure 
layouts using pahole from the dwarves package, as well as 
running through a bit of xfsqa under qemu-arm, modified so 
that the check/repair phase after each test actually executes 
check/repair from the x86 host, on the filesystem populated 
by the arm emulator.  Thus far it all looks good.

There are 2 other structures with extra padding at the end, 
but they don't seem to cause trouble.  I suppose they could 
be packed as well: xfs_dir2_data_unused_t and xfs_dir2_sf_t.

Note that userspace needs a similar treatment, and any
filesystems which were running with the previous rogue
"fix" will now see corruption (either in the kernel, or
during xfs_repair) with this fix properly in place; it 
may be worth teaching xfs_repair to identify and fix that 
specific issue.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>

---

Index: linux-2.6.24/fs/xfs/linux-2.6/xfs_linux.h
===================================================================
--- linux-2.6.24.orig/fs/xfs/linux-2.6/xfs_linux.h
+++ linux-2.6.24/fs/xfs/linux-2.6/xfs_linux.h
@@ -300,4 +300,11 @@ static inline __uint64_t howmany_64(__ui
 	return x;
 }
 
+/* ARM old ABI has some weird alignment/padding */
+#if defined(__arm__) && !defined(__ARM_EABI__)
+#define __arch_pack __attribute__((packed))
+#else
+#define __arch_pack
+#endif
+
 #endif /* __XFS_LINUX__ */
Index: linux-2.6.24/fs/xfs/xfs_dir2_sf.h
===================================================================
--- linux-2.6.24.orig/fs/xfs/xfs_dir2_sf.h
+++ linux-2.6.24/fs/xfs/xfs_dir2_sf.h
@@ -62,7 +62,7 @@ typedef union {
  * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
  * Only need 16 bits, this is the byte offset into the single block form.
  */
-typedef struct { __uint8_t i[2]; } xfs_dir2_sf_off_t;
+typedef struct { __uint8_t i[2]; } __arch_pack xfs_dir2_sf_off_t;
 
 /*
  * The parent directory has a dedicated field, and the self-pointer must
@@ -76,14 +76,14 @@ typedef struct xfs_dir2_sf_hdr {
 	__uint8_t		count;		/* count of entries */
 	__uint8_t		i8count;	/* count of 8-byte inode #s */
 	xfs_dir2_inou_t		parent;		/* parent dir inode number */
-} xfs_dir2_sf_hdr_t;
+} __arch_pack xfs_dir2_sf_hdr_t;
 
 typedef struct xfs_dir2_sf_entry {
 	__uint8_t		namelen;	/* actual name length */
 	xfs_dir2_sf_off_t	offset;		/* saved offset */
 	__uint8_t		name[1];	/* name, variable size */
 	xfs_dir2_inou_t		inumber;	/* inode number, var. offset */
-} xfs_dir2_sf_entry_t;
+} __arch_pack xfs_dir2_sf_entry_t; 
 
 typedef struct xfs_dir2_sf {
 	xfs_dir2_sf_hdr_t	hdr;		/* shortform header */

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [PATCH] fix dir2 shortform structures on ARM old ABI
@ 2008-03-18 23:31 Andre Draszik
  2008-03-19  3:18 ` Eric Sandeen
  0 siblings, 1 reply; 51+ messages in thread
From: Andre Draszik @ 2008-03-18 23:31 UTC (permalink / raw)
  To: xfs

Hi,

(I just subscribed, so I can't reply correctly :-(

In fact,, the last two evenings I spent making XFS work on arm eabi,
where things are much better than with the old API, but still XFS
won't work out of the box.

So, Eric, if you go for the #if defined(__arm__) &&
!defined(__ARM_EABI__) approach, arm eabi will still be broken.

EABI basically behaves like other 'normal' arches/abis, but sometimes
structures get padded to have a size of a multiple of 8, i.e. padding
is added at the end of the struct, which as far as I can see for now
affects 5 structs: xfs_dir2_data_entry_t, xfs_dinode_t, xfs_sb_t,
xfs_dsb_t, and xfs_log_item_t

I must say, I like Jeff's approach of explicitly telling gcc about
alignment much better :-) It makes it a) much easier to find structs
that are in fact representations of on-disk data and thus might need
tweaking, and b) as somebody already said you fix such problems once
and forever.
E.g. for me as an absolute outsider, it was quite time consuming
finding out which structs are actually on-disk.


That said, Jeff, you mentioned that your changes don't work yet
completely - could this be because (at least from the comments) struct
xfs_sb needs to match struct xfs_dsb and you only change xfs_dsb?


Cheers,
Andre'

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [PATCH] fix dir2 shortform structures on ARM old ABI
@ 2008-03-18 23:49 Andre Draszik
  2008-03-19  0:23 ` Josef 'Jeff' Sipek
  0 siblings, 1 reply; 51+ messages in thread
From: Andre Draszik @ 2008-03-18 23:49 UTC (permalink / raw)
  To: xfs

Hi,

(I just subscribed, so I can't reply correctly :-(

In fact,, the last two evenings I spent making XFS work on arm eabi,
where things are much better than with the old API, but still XFS
won't work out of the box.

So, Eric, if you go for the #if defined(__arm__) &&
!defined(__ARM_EABI__) approach, arm eabi will still be broken.

EABI basically behaves like other 'normal' arches/abis, but sometimes
structures get padded to have a size of a multiple of 8, i.e. padding
is added at the end of the struct, which as far as I can see for now
affects 5 structs: xfs_dir2_data_entry_t, xfs_dinode_t, xfs_sb_t,
xfs_dsb_t, and xlog_rec_header_t

I must say, I like Jeff's approach of explicitly telling gcc about
alignment much better :-) It makes it a) much easier to find structs
that are in fact representations of on-disk data and thus might need
tweaking, and b) as somebody already said you fix such problems once
and forever.
E.g. for me as an absolute outsider, it was quite time consuming
finding out which structs are actually on-disk.


That said, Jeff, you mentioned that your changes don't work yet
completely - could this be because (at least from the comments) struct
xfs_sb needs to match struct xfs_dsb and you only change xfs_dsb?


Cheers,
Andre'

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

end of thread, other threads:[~2008-06-06 14:15 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-15  3:24 [PATCH] fix dir2 shortform structures on ARM old ABI Eric Sandeen
2008-03-15  4:17 ` Josef 'Jeff' Sipek
2008-03-15  4:23   ` Eric Sandeen
2008-03-15  4:27     ` Josef 'Jeff' Sipek
2008-03-15  4:33       ` Eric Sandeen
2008-03-15  4:51         ` Josef 'Jeff' Sipek
2008-03-17 18:32           ` Eric Sandeen
2008-03-17 19:53             ` Josef 'Jeff' Sipek
2008-03-17 20:04               ` Eric Sandeen
2008-03-17 20:28                 ` Josef 'Jeff' Sipek
2008-03-18  0:39                   ` [RFC][PATCH 1/1] XFS: annotate all on-disk structures with __ondisk Josef 'Jeff' Sipek
2008-03-18  3:34                     ` Eric Sandeen
2008-03-18  4:09                       ` David Chinner
2008-03-18  5:28                         ` Josef 'Jeff' Sipek
2008-03-17 23:35             ` [PATCH] fix dir2 shortform structures on ARM old ABI Timothy Shimmin
2008-03-17 23:42               ` Josef 'Jeff' Sipek
2008-03-18  4:31                 ` Timothy Shimmin
     [not found]     ` <20080315043622.GA11547@puku.stupidest.org>
2008-03-15  4:45       ` Eric Sandeen
2008-03-20  3:02 ` Eric Sandeen
2008-05-05  7:38   ` Barry Naujok
2008-06-06 14:15   ` Eric Sandeen
2008-04-09 19:53 ` Eric Sandeen
2008-04-23  0:58 ` Eric Sandeen
2008-05-02 20:55   ` Eric Sandeen
2008-05-05  7:08     ` David Chinner
2008-05-05 13:07       ` Eric Sandeen
2008-05-06  4:21       ` Timothy Shimmin
2008-05-06 13:43         ` Eric Sandeen
2008-06-05  5:38           ` Eric Sandeen
2008-06-05  5:46             ` Mark Goodwin
2008-06-05  5:49               ` Eric Sandeen
2008-06-05  6:02                 ` Mark Goodwin
2008-06-05  6:04                   ` Mark Goodwin
2008-06-05  6:06                   ` Eric Sandeen
2008-06-05  5:49             ` Chris Wedgwood
2008-06-05  5:52               ` Eric Sandeen
2008-06-05  6:34               ` Eric Sandeen
  -- strict thread matches above, loose matches on Subject: below --
2008-03-18 23:31 Andre Draszik
2008-03-19  3:18 ` Eric Sandeen
2008-03-19  3:40   ` Eric Sandeen
2008-03-19  5:11   ` Eric Sandeen
2008-03-19  5:31     ` Eric Sandeen
2008-03-20  0:35     ` Timothy Shimmin
2008-03-18 23:49 Andre Draszik
2008-03-19  0:23 ` Josef 'Jeff' Sipek
2008-03-19 11:21   ` Luca Olivetti
2008-03-19 12:53     ` Eric Sandeen
2008-03-19 14:11       ` Luca Olivetti
     [not found]       ` <47E11F4A.3090205@ventoso.org>
     [not found]         ` <47E12D20.4010901@sandeen.net>
2008-03-19 15:34           ` Luca Olivetti
2008-03-19 15:40             ` Eric Sandeen
     [not found]             ` <47E14FF1.2020100@sandeen.net>
2008-03-19 18:24               ` Luca Olivetti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox