Use posix_memalign() for memory used to write bitmaps
This makes super[01].c properly align buffers used for the bitmap using posix_memalign() to make sure the writes don't fail in case the bitmap is opened using O_DIRECT. This is based on https://bugzilla.redhat.com/show_bug.cgi?id=789898 and an initial patch by Alexander Murashkin. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
9f1b0f0f1e
commit
d669228f29
8
super0.c
8
super0.c
|
@ -1065,13 +1065,11 @@ static int write_bitmap0(struct supertype *st, int fd)
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
int towrite, n;
|
int towrite, n;
|
||||||
char abuf[4096+4096];
|
void *buf;
|
||||||
char *buf = (char*)(((long)(abuf+4096))&~4095L);
|
|
||||||
|
|
||||||
if (!get_dev_size(fd, NULL, &dsize))
|
if (!get_dev_size(fd, NULL, &dsize))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
if (dsize < MD_RESERVED_SECTORS*512)
|
if (dsize < MD_RESERVED_SECTORS*512)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -1082,6 +1080,9 @@ static int write_bitmap0(struct supertype *st, int fd)
|
||||||
if (lseek64(fd, offset + 4096, 0)< 0LL)
|
if (lseek64(fd, offset + 4096, 0)< 0LL)
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
|
if (posix_memalign(&buf, 4096, 4096))
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
memset(buf, 0xff, 4096);
|
memset(buf, 0xff, 4096);
|
||||||
memcpy(buf, ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
|
memcpy(buf, ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
|
||||||
towrite = 60*1024;
|
towrite = 60*1024;
|
||||||
|
@ -1100,6 +1101,7 @@ static int write_bitmap0(struct supertype *st, int fd)
|
||||||
if (towrite)
|
if (towrite)
|
||||||
rv = -2;
|
rv = -2;
|
||||||
|
|
||||||
|
free(buf);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
super1.c
7
super1.c
|
@ -1641,12 +1641,14 @@ static int write_bitmap1(struct supertype *st, int fd)
|
||||||
struct mdp_superblock_1 *sb = st->sb;
|
struct mdp_superblock_1 *sb = st->sb;
|
||||||
bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb)+1024);
|
bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb)+1024);
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
void *buf;
|
||||||
int towrite, n;
|
int towrite, n;
|
||||||
char buf[4096];
|
|
||||||
|
|
||||||
locate_bitmap1(st, fd);
|
locate_bitmap1(st, fd);
|
||||||
|
|
||||||
|
if (posix_memalign(&buf, 4096, 4096))
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
memset(buf, 0xff, 4096);
|
memset(buf, 0xff, 4096);
|
||||||
memcpy(buf, ((char*)sb)+1024, sizeof(bitmap_super_t));
|
memcpy(buf, ((char*)sb)+1024, sizeof(bitmap_super_t));
|
||||||
|
|
||||||
|
@ -1669,6 +1671,7 @@ static int write_bitmap1(struct supertype *st, int fd)
|
||||||
if (towrite)
|
if (towrite)
|
||||||
rv = -2;
|
rv = -2;
|
||||||
|
|
||||||
|
free(buf);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue