]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix alignment for backup of reshape data.
authorNeilBrown <neilb@suse.de>
Tue, 19 Aug 2008 07:55:15 +0000 (17:55 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 19 Aug 2008 07:55:15 +0000 (17:55 +1000)
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>
Grow.c
restripe.c

diff --git a/Grow.c b/Grow.c
index 3a31ea547cc9317a1564beaf3d0caed4d5583268..14e48f5696cb0c93fb35eb843a4a5fbd99e40b3e 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -396,7 +396,8 @@ struct mdp_backup_super {
        __u64   arraystart;
        __u64   length;
        __u32   sb_csum;        /* csum of preceeding bytes. */
-};
+       __u8 pad[512-68];
+} __attribute__((aligned(512))) bsb;
 
 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;
        char *c;
 
-       struct mdp_backup_super bsb;
        struct supertype *st;
 
        int nlevel, olevel;
@@ -720,7 +720,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                 * a leading superblock 4K earlier.
                 */
                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) {
                                /* This is the backup file */
                                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");
                                goto abort;
                        }
-                       memset(buf, 0, sizeof(buf));
+                       memset(buf, 0, 4096);
                        bsb.devstart = __cpu_to_le64(offsets[i]);
                        bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&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 ||
                            write(fdlist[i], &bsb, sizeof(bsb)) != sizeof(bsb) ||
                            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);
                                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++) {
                struct mdinfo dinfo;
-               struct mdp_backup_super bsb;
                char buf[4096];
                int fd;
 
index afde8363529c5bc48cebc1a108bf2505d074e8d0..509b45087bed453b6f76aa23e4a2d4639a6d1405 100644 (file)
@@ -152,7 +152,8 @@ int save_stripes(int *source, unsigned long long *offsets,
                 int nwrites, int *dest,
                 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 len;
        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;
                int i;
                len = chunk_size - cpos;
-               if (len > sizeof(buf)) len = sizeof(buf);
+               if (len > 8192) len = 8192;
                if (len > length) len = length;
                /* len bytes to be moved from one device */