Skip to contentSkip to conversation

endianness of Linux kernel RAID

DISCUSSION Brent Walsh 2 participants 4 messages Aug 9, 2005 – Aug 18, 2005 MD RAID

lore
Share & tools
lore
#0 lore raw
Quoted 15 lines · Neil Brown

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 ...

Quoted 5 lines

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.

I have a PowerPC based NAS device that was damaged by a recent a brownout. The drives in the array are fine, but the device's firmware was corrupted. My first attempt to assemble the array on my x86 system failed due to the endian differences. After applying this patch, the mdadm examine command worked perfectly. As of yet, I have not attempted to update the superblocks. I would like to leave the original superblocks intact so that I can reinstall the drives in my NAS device when it is repaired. Is it possible to assemble the array without overwriting the superblocks?

-Brent

____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

#1 lore raw
Quoted 13 lines · On Monday August 8, [email protected] wrote:

I have a PowerPC based NAS device that was damaged by a recent a brownout. The drives in the array are fine, but the device's firmware was corrupted. My first attempt to assemble the array on my x86 system failed due to the endian differences. After applying this patch, the mdadm examine command worked perfectly. As of yet, I have not attempted to update the superblocks. I would like to leave the original superblocks intact so that I can reinstall the drives in my NAS device when it is repaired. Is it possible to assemble the array without overwriting the superblocks?

Not really.... The kernel reads the superblocks to find out the details of the array. If it cannot read them, it won't assemble the array.

Depending on the type of array, you could --build the array instead. This allows for arrays that deliberately don't have superblocks. It should work for raid0, might work for linear, could work for raid1, but no for anything else.

If you want to try it, send me the --examine output. and I'll suggest a command.

NeilBrown

#2 lore raw
Quoted 14 lines · --- Neil Brown

Not really.... The kernel reads the superblocks to find out the
details of the array. If it cannot read them, it won't assemble the
array.

Depending on the type of array, you could --build the array instead.
This allows for arrays that deliberately don't have superblocks.
It should work for raid0, might work for linear, could work for raid1,
but no for anything else.

Quoted 4 lines

If you want to try it, send me the --examine output. and I'll suggest
a command.

My array is raid5, so I decided to overwrite the big-endian superblocks and assemble the array. Your patch worked as expected and the array is functioning properly. Thanks for the help.

Is there a simple way convert the superblocks back to big-endian while the drives are connected to the little-endian machine?

-Brent

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#3 lore raw
Quoted 9 lines · On Thursday August 11, [email protected] wrote:

My array is raid5, so I decided to overwrite the big-endian superblocks and assemble the array. Your patch worked as expected and the array is functioning properly. Thanks for the help.

Is there a simple way convert the superblocks back to big-endian while the drives are connected to the little-endian machine?

Not with mdadm... I could but I don't think I really want to.

However I wrote the following little program to test the byteswapping code in mdadm. It does a full byteswap of the superblock on the device that you pass as an argument.

NeilBrown

-----------cut--here--------
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mount.h>
/*
* This is a tiny test program to endian-swap
* the superblock on a given device.
* We simply read 4k from where the superblock should be
* do the swap, and write it back
* Don't use this on a real array, use mdadm. */

#define MD_RESERVED_BYTES (64 * 1024)
#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)

#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)

main(int argc, char *argv[])

{
	int fd, i;
	unsigned long size;
	unsigned long long offset;
	char super[4096];
	if (argc != 2) {
		fprintf(stderr, "Usage: swap_super device\n");
		exit(1);
	}
	fd = open(argv[1], O_RDWR);
	if (fd<0) {
		perror(argv[1]);
		exit(1);
	}
	if (ioctl(fd, BLKGETSIZE, &size)) {
		perror("BLKGETSIZE");
		exit(1);
	}
	offset = MD_NEW_SIZE_SECTORS(size) * 512LL;
	if (lseek64(fd, offset, 0) < 0LL) {
		perror("lseek64");
		exit(1);
	}
	if (read(fd, super, 4096) != 4096) {
		perror("read");
		exit(1);
	}


	for (i=0; i < 4096 ; i+=4) {
		char t = super[i];
		super[i] = super[i+3];
		super[i+3] = t;
		t=super[i+1];
		super[i+1]=super[i+2];
		super[i+2]=t;
	}
	/* swap the u64 events counters */
	for (i=0; i<4; i++) {
		/* events_hi and events_lo */
		char t=super[32*4+7*4 +i];
		super[32*4+7*4 +i] = super[32*4+8*4 +i];
		super[32*4+8*4 +i] = t;

		/* cp_events_hi and cp_events_lo */
		t=super[32*4+9*4 +i];
		super[32*4+9*4 +i] = super[32*4+10*4 +i];
		super[32*4+10*4 +i] = t;
	}


	if (lseek64(fd, offset, 0) < 0LL) {
		perror("lseek64");
		exit(1);
	}
	if (write(fd, super, 4096) != 4096) {
		perror("write");
		exit(1);
	}
	exit(0);

}