Fix alignment for backup of reshape data.

Since we introduced O_DIRECT for device access we need
properly aligned buffers and IO requests.  The reshape code
missed out on the conversion.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2008-08-19 17:55:15 +10:00
parent e9dd159873
commit 94a20f0c80
2 changed files with 9 additions and 8 deletions

12
Grow.c
View File

@ -396,7 +396,8 @@ struct mdp_backup_super {
__u64 arraystart; __u64 arraystart;
__u64 length; __u64 length;
__u32 sb_csum; /* csum of preceeding bytes. */ __u32 sb_csum; /* csum of preceeding bytes. */
}; __u8 pad[512-68];
} __attribute__((aligned(512))) bsb;
int bsb_csum(char *buf, int len) int bsb_csum(char *buf, int len)
{ {
@ -420,7 +421,6 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
struct mdu_array_info_s array; struct mdu_array_info_s array;
char *c; char *c;
struct mdp_backup_super bsb;
struct supertype *st; struct supertype *st;
int nlevel, olevel; int nlevel, olevel;
@ -720,7 +720,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
* a leading superblock 4K earlier. * a leading superblock 4K earlier.
*/ */
for (i=array.raid_disks; i<d; i++) { for (i=array.raid_disks; i<d; i++) {
char buf[4096]; char abuf[4096+512];
char *buf = (char*)(((unsigned long)abuf+511)& ~511);
if (i==d-1 && backup_file) { if (i==d-1 && backup_file) {
/* This is the backup file */ /* This is the backup file */
offsets[i] = 8; offsets[i] = 8;
@ -731,7 +732,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
fprintf(stderr, Name ": could not seek...\n"); fprintf(stderr, Name ": could not seek...\n");
goto abort; goto abort;
} }
memset(buf, 0, sizeof(buf)); memset(buf, 0, 4096);
bsb.devstart = __cpu_to_le64(offsets[i]); bsb.devstart = __cpu_to_le64(offsets[i]);
bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb)); bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
memcpy(buf, &bsb, sizeof(bsb)); memcpy(buf, &bsb, sizeof(bsb));
@ -793,7 +794,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
if (lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0) < 0 || if (lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0) < 0 ||
write(fdlist[i], &bsb, sizeof(bsb)) != sizeof(bsb) || write(fdlist[i], &bsb, sizeof(bsb)) != sizeof(bsb) ||
fsync(fdlist[i]) != 0) { fsync(fdlist[i]) != 0) {
fprintf(stderr, Name ": %s: fail to save metadata for critical region backups.\n", fprintf(stderr, Name ": %s: failed to save metadata for critical region backups.\n",
devname); devname);
goto abort_resume; goto abort_resume;
} }
@ -882,7 +883,6 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
for (i=old_disks-(backup_file?1:0); i<cnt; i++) { for (i=old_disks-(backup_file?1:0); i<cnt; i++) {
struct mdinfo dinfo; struct mdinfo dinfo;
struct mdp_backup_super bsb;
char buf[4096]; char buf[4096];
int fd; int fd;

View File

@ -152,7 +152,8 @@ int save_stripes(int *source, unsigned long long *offsets,
int nwrites, int *dest, int nwrites, int *dest,
unsigned long long start, unsigned long long length) unsigned long long start, unsigned long long length)
{ {
char buf[8192]; char abuf[8192+512];
char *buf = (char*)(((unsigned long)abuf+511)&~511UL);
int cpos = start % chunk_size; /* where in chunk we are up to */ int cpos = start % chunk_size; /* where in chunk we are up to */
int len; int len;
int data_disks = raid_disks - (level == 0 ? 0 : level <=5 ? 1 : 2); int data_disks = raid_disks - (level == 0 ? 0 : level <=5 ? 1 : 2);
@ -162,7 +163,7 @@ int save_stripes(int *source, unsigned long long *offsets,
unsigned long long offset; unsigned long long offset;
int i; int i;
len = chunk_size - cpos; len = chunk_size - cpos;
if (len > sizeof(buf)) len = sizeof(buf); if (len > 8192) len = 8192;
if (len > length) len = length; if (len > length) len = length;
/* len bytes to be moved from one device */ /* len bytes to be moved from one device */