endianness of Linux kernel RAID
It turns out that if one uses the kernel (2.4.x-2.6.x) RAID support (RAID5, anyway, since that's all I've tested), the RAID'd disks cannot be moved to another system with a different endianness. I don't know how hard that would be to fix, but it did mean that when my ancient Mac clone I was using as a server died I couldn't bring the RAID over to my spare x86 Linux box; I had to dedicate other hardware (my dual G4 that I had been happily using with OS X) to the task instead.
Unfortunately, I haven't gotten into kernel development and, therefore, do not have the necessary expertise to fix it. Is anyone here interested in this issue?
--Greg
Quoted 7 lines · Gregory Seidman
It turns out that if one uses the kernel (2.4.x-2.6.x) RAID support (RAID5, anyway, since that's all I've tested), the RAID'd disks cannot be moved to another system with a different endianness. I don't know how hard that
Unfortunately, I haven't gotten into kernel development and, therefore, do not have the necessary expertise to fix it. Is anyone here interested in this issue?
Version 1 superblock support, which was recently added to the 2.6 kernel and mdadm tool, fixes this issue. Metadata is always stored in little endian on disk.
--
Paul
On Wed, Aug 03, 2005 at 09:05:27AM -0400, Paul Clements wrote:
} Gregory Seidman wrote:
} >It turns out that if one uses the kernel (2.4.x-2.6.x) RAID support (RAID5, } >anyway, since that's all I've tested), the RAID'd disks cannot be moved to } >another system with a different endianness. I don't know how hard that }
} >Unfortunately, I haven't gotten into kernel development and, therefore, do } >not have the necessary expertise to fix it. Is anyone here interested in } >this issue?
}
} Version 1 superblock support, which was recently added to the 2.6 kernel } and mdadm tool, fixes this issue. Metadata is always stored in little } endian on disk.
Great! A few questions:
1) Does this mean that the fix will be in 2.6.13?
2) Does the version 1 you refer to have to do with pre-2.6 RAID support?
3) My existing RAID was original set up under 2.4.18 on PPC, but I'm running 2.6.11 now and it works fine... for now. If metadata was previously stored in host endian, does that mean that my existing RAID that was set up on PPC is going to break, or be upgraded, or what?
} Paul
--Greg
Quoted 1 line · Gregory Seidman
1) Does this mean that the fix will be in 2.6.13?
Yes, version 1 superblock support is in 2.6.13. You need the latest mdadm as well.
Quoted 1 line
2) Does the version 1 you refer to have to do with pre-2.6 RAID support?
No. 2.4 kernels do not understand version 1 superblocks. They only support 0.90 superblocks (which is what you've got).
Quoted 4 lines
3) My existing RAID was original set up under 2.4.18 on PPC, but I'm running 2.6.11 now and it works fine... for now. If metadata was previously stored in host endian, does that mean that my existing RAID that was set up on PPC is going to break, or be upgraded, or what?
You'll have to re-create the array using the version 1 superblock format. The existing 0.90 superblocks will continue to be used until you've done that.
--
Paul
I don't have time to fix this by a long stretch, but I do have a web page that talks about endianness issues, including ways of avoiding painting yourself into a corner with them:
http://dcs.nac.uci.edu/~strombrg/converting-binary.html
The section at the top about architecture-neutral formats is probably most relevant to this discussion - more so than the conversion programs.
As far as fixing up the mess, it'd probably be best to have some sort of RAID usage option that would allow:
1) byte swap all endian-dependent integers on reads and writes - EG little to big, or big to little (the operation is typically its own inverse)
2) use a canonical format (best for use at creation time) that will always store byte-sex dependent integers the same way, irrespective of what sort of platform one is on
It might also not hurt to, at the same time, make sure that integer size (say, 32 bits vs 64 bits) isn't an issue.
I'm actually a bit discouraged that more projects aren't just using some sort of canonical, arbitrary-precision integer format, to eliminate these issues for good. Granted, disk space isn't growing fast enough at current speed to exceed a 128 bit integer anytime soon, but you never know if there's going to be a big leap in disk capacity someday. IMO, this is the ideal long-term solution to this sort of problem.
Quoted 19 lines · Gregory Seidman
It turns out that if one uses the kernel (2.4.x-2.6.x) RAID support (RAID5, anyway, since that's all I've tested), the RAID'd disks cannot be moved to another system with a different endianness. I don't know how hard that would be to fix, but it did mean that when my ancient Mac clone I was using as a server died I couldn't bring the RAID over to my spare x86 Linux box; I had to dedicate other hardware (my dual G4 that I had been happily using with OS X) to the task instead.
Unfortunately, I haven't gotten into kernel development and, therefore, do not have the necessary expertise to fix it. Is anyone here interested in this issue?
--Greg
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Oopps....
I meant to send the following in reply to a recent message from Gregory Seidman, but inadvertently send it in reply to an earlier message from Aaron Botsis (which I must have missed..)
Still, the offer is open to either, or anyone else.
NeilBrown
Quoted 8 lines · On Sunday June 19, [email protected] wrote:
Hello,
I'm attempting to move a raid5 array from a big endian ppc machine to a little endian x86.
Upon trying to import the array, I get:
mdadm: No super block found on/dev/hde1(Expected magica92b4efc, gotfc4e2ba9)
Quoted 5 lines
I assume this to be an endianess issue...
Is this a bug? Is just the magic number whacked? or are the superblock data structures too?what's the best way to fix this?
As has been said, the original raid superblock (still the default) uses host-endian data and so cannot be moved between machines. The new version uses little-endian, but isn't in wide use yet.
It would not be too hard to get mdadm to re-write the superblocks when assembling an array on a different machine. However I am not in a position to test it very well.
If you would be willing to help test some changes over the next several days, I'd be happy to add this functionality to mdadm. The risk of data-loss for you would be very remote. However there would be some risk of extended down-time while you wait for me to fix some silly bug.
The change would involve:
1/ Teaching "mdadm --examine" to recognise a wrong-endian superblock
and display it with suitable swaps.
2/ Teaching "mdadm --assemble" to accept "--update=endian" which
would byte-swap all the superblocks and write them out again.
NeilBrown
Quoted 7 lines · On Thursday August 4, [email protected] wrote:
Oopps....
I meant to send the following in reply to a recent message from Gregory Seidman, but inadvertently send it in reply to an earlier message from Aaron Botsis (which I must have missed..)Still, the offer is open to either, or anyone else.
I decided to try it anyway...
The following patch, when applied to mdadm-2.0-devel-3 (Recently released) should allow:
mdadm --examine --metadata=0.swap /dev/sda1
which will show the superblock with bytes swapped. If that looks right for all devices, then
mdadm --assemble /dev/mdX --update=byteorder /dev/sda1 /dev/sdb1 ...
will assemble the array after swapping the byte order on all devices. Once it has been assembled this way, the superblocks will have the correct byte order, and in future the array can be assembled in the normal way.
Feedback would be very welcome.
Thanks,
NeilBrown
### Diffstat output
./Assemble.c | 3 +++ ./mdadm.c | 14 ++++++++++++++ ./super0.c | 40 +++++++++++++++++++++++++++++++++++++++-
Assemble.c renamed from Assemble.c~current~ +3 -0
@@ -334,6 +334,9 @@ int Assemble(struct supertype *st, charfree (super); super =NULL ; +if (update &&strcmp (update,"byteorder" )==0 ) + st->minor_version =90 ; +if (devcnt ==0 ) {fprintf (stderr, Name": no devices found for %s\n" , mddev);
mdadm.c renamed from mdadm.c~current~ +14 -0
@@ -547,6 +547,20 @@ int main(int argc, char *argv[])continue ;if (strcmp (update,"resync" )==0 )continue ; +if (strcmp (update,"byteorder" )==0 ) { +if (ss) { +fprintf (stderr, Name": must not set metadata type with --update=byteorder.\n" ); +exit (2 ); + } +for (i=0 ; !ss && superlist[i]; i++) + ss = superlist[i]->match_metadata_desc ("0.swap" ); +if (!ss) { +fprintf (stderr, Name": INTERNAL ERROR cannot find 0.swap\n" ); +exit (2 ); + } + +continue ; + }fprintf (stderr, Name": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n" ,update);exit (2 );
super0.c renamed from super0.c~current~ +39 -1
@@ -52,7 +52,39 @@ static unsigned long calc_sb0_csum(mdp_sreturn newcsum; } + +void super0_swap_endian (struct mdp_superblock_s *sb) +{ +/* as super0 superblocks are host-endian, it is sometimes +* useful to be able to swap the endianness +* as (almost) everything is u32's we byte-swap every 4byte +* number. +* We then also have to swap the events_hi and events_lo +*/ +char *sbc = (char *)sb; +__u32 t32; +int i; + +for (i=0 ; i <MD_SB_BYTES ; i+=4 ) { +char t = sbc[i]; + sbc[i] = sbc[i+3 ]; + sbc[i+3 ] = t; + t=sbc[i+1 ]; + sbc[i+1 ]=sbc[i+2 ]; + sbc[i+2 ]=t; + } + t32 = sb->events_hi; + sb->events_hi = sb->events_lo; + sb->events_lo = t32; + + t32 = sb->cp_events_hi; + sb->cp_events_hi = sb->cp_events_lo; + sb->cp_events_lo = t32; + +} +#ifndef MDASSEMBLE +static void examine_super0 (void *sbv) {mdp_super_t *sb = sbv;
@@ -572,6 +604,9 @@ static int load_super0(struct supertypereturn 1 ; } +if (st->ss && st->minor_version ==9 ) +super0_swap_endian (super); +if (super->md_magic !=MD_SB_MAGIC ) {if (devname) fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n",
@@ -611,6 +646,10 @@ static struct supertype *match_metadata_ )return st; + st->minor_version =9 ;/* flag for 'byte-swapped' */ +if (strcmp (arg,"0.swap" )==0 ) +return st; +free (st);return NULL ; }
@@ -742,7 +781,6 @@ int write_bitmap0(struct supertype *st,return rv; } - struct superswitch super0 = {#ifndef MDASSEMBLE
Quoted 19 lines · Neil Brown
Quoted 7 lines · On Thursday August 4, [email protected] wrote:
Oopps....
I meant to send the following in reply to a recent message from Gregory Seidman, but inadvertently send it in reply to an earlier message from Aaron Botsis (which I must have missed..)Still, the offer is open to either, or anyone else.
I decided to try it anyway...
The following patch, when applied to mdadm-2.0-devel-3 (Recently released) should allow:
mdadm --examine --metadata=0.swap /dev/sda1which will show the superblock with bytes swapped. If that looks right for all devices, then
Quoted 8 lines
mdadm --assemble
/dev/mdX--update=byteorder/dev/sda1/dev/sdb1...will assemble the array after swapping the byte order on all devices. Once it has been assembled this way, the superblocks will have the correct byte order, and in future the array can be assembled in the normal way.
Feedback would be very welcome.
If I read your notes correctly, it should be possible to determine that this is (or isn't) a byte-swapped v0 superblock by checking for the byte-swapped magic number, right?
In that case, I think it would be good to have --update=byteorder refuse to work if that magic number check either wasn't the byte-swapped variant.
Adding a 'force' or something to bypass the check if you *really* want to seems reasonable-ish.
That would make it just that little bit harder to accidentally byte-swap a superblock when you shouldn't have done so.
Daniel
On Thu, Aug 04, 2005 at 03:14:07PM +1000, Neil Brown wrote:
[...]
} If you would be willing to help test some changes over the next } several days, I'd be happy to add this functionality to mdadm. } The risk of data-loss for you would be very remote. However there } would be some risk of extended down-time while you wait for me to fix } some silly bug.
[...]
I am planning on building a new RAID soon (from external FW/USB2 drives), and I'll be happy to test on that. Unfortunately, the timeframe for that is before the end of the year, and I can't risk downtime on my current RAID due to the imminent threat of murder by my wife if her email and music are not available.
I greatly appreciate that this is progressing, however.
} NeilBrown
--Greg