Fix failure of devices refusing to add to raids using bitmaps

This fixes an issue with devices failing to be added to a raid using
bitmaps, due to trying to write the bitmap with mis-aligned buffers
using O_DIRECT

Resolves bz789898 (f16) bz791189 (f15)

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
This commit is contained in:
Jes Sorensen 2012-02-16 12:14:26 +01:00
parent c68d736ff4
commit 15adacde4b
2 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,88 @@
From 6ef89052d85b8137b8a7100f761d896ae6f61001 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Tue, 7 Feb 2012 11:55:18 +1100
Subject: [PATCH] super1: make aread/awrite always use an aligned buffer.
A recently change to write_bitmap1 meant awrite would sometimes
write from a non-aligned buffer which of course break.
So change awrite (and aread) to always use their own aligned
buffer to ensure safety.
Reported-by: Alexander Lyakas <alex.bolshoy@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
---
super1.c | 39 +++++++++++++++++++++++----------------
1 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/super1.c b/super1.c
index d23d6e8..cfa237a 100644
--- a/super1.c
+++ b/super1.c
@@ -143,17 +143,19 @@ static int aread(int fd, void *buf, int len)
* the full sector and copy relevant bits into
* the buffer
*/
- int bsize;
+ int bsize, iosize;
char *b;
int n;
- if (ioctl(fd, BLKSSZGET, &bsize) != 0 ||
- bsize <= len)
- return read(fd, buf, len);
- if (bsize > 4096)
+ if (ioctl(fd, BLKSSZGET, &bsize) != 0)
+ bsize = 512;
+
+ if (bsize > 4096 || len > 4096)
return -1;
b = (char*)(((long)(abuf+4096))&~4095UL);
- n = read(fd, b, bsize);
+ for (iosize = 0; iosize < len; iosize += bsize)
+ ;
+ n = read(fd, b, iosize);
if (n <= 0)
return n;
lseek(fd, len - n, 1);
@@ -171,22 +173,27 @@ static int awrite(int fd, void *buf, int len)
* than the write.
* The address must be sector-aligned.
*/
- int bsize;
+ int bsize, iosize;
char *b;
int n;
- if (ioctl(fd, BLKSSZGET, &bsize) != 0 ||
- bsize <= len)
- return write(fd, buf, len);
- if (bsize > 4096)
+ if (ioctl(fd, BLKSSZGET, &bsize) != 0)
+ bsize = 512;
+ if (bsize > 4096 || len > 4096)
return -1;
b = (char*)(((long)(abuf+4096))&~4095UL);
- n = read(fd, b, bsize);
- if (n <= 0)
- return n;
- lseek(fd, -n, 1);
+ for (iosize = 0; iosize < len ; iosize += bsize)
+ ;
+
+ if (len != iosize) {
+ n = read(fd, b, iosize);
+ if (n <= 0)
+ return n;
+ lseek(fd, -n, 1);
+ }
+
memcpy(b, buf, len);
- n = write(fd, b, bsize);
+ n = write(fd, b, iosize);
if (n <= 0)
return n;
lseek(fd, len - n, 1);
--
1.7.7.6

View File

@ -1,7 +1,7 @@
Summary: The mdadm program controls Linux md devices (software RAID arrays)
Name: mdadm
Version: 3.2.3
Release: 4%{?dist}
Release: 5%{?dist}
Source: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}.tar.bz2
Source1: mdmonitor.init
Source2: raid-check
@ -18,6 +18,7 @@ Patch4: mdadm-3.2.3-mdmon-Use-getopt_long-to-parse-command-line-options.pat
Patch5: mdadm-3.2.3-Add-offroot-argument-to-mdadm.patch
Patch6: mdadm-3.2.3-Add-offroot-argument-to-mdmon.patch
Patch7: mdadm-3.2.3-Spawn-mdmon-with-offroot-if-mdadm-was-launched-with-.patch
Patch8: mdadm-3.2.3-super1-make-aread-awrite-always-use-an-aligned-buffe.patch
Patch19: mdadm-3.2.3-udev.patch
Patch20: mdadm-2.5.2-static.patch
URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/
@ -59,6 +60,7 @@ is not used as the system init process.
%patch5 -p1 -b .offroot-mdadm
%patch6 -p1 -b .offroot-mdmon
%patch7 -p1 -b .offroot-spawn
%patch8 -p1 -b .bitmap
%patch19 -p1 -b .udev
%patch20 -p1 -b .static
@ -133,6 +135,12 @@ fi
%{_initrddir}/*
%changelog
* Thu Feb 16 2012 Jes Sorensen <Jes.Sorensen@redhat.com> - 3.2.3-5
- Fix issue with devices failing to be added to a raid using bitmaps,
due to trying to write the bitmap with mis-aligned buffers using
O_DIRECT
- Resolves: bz789898 (f16) bz791189 (f15)
* Mon Jan 30 2012 Jes Sorensen <Jes.Sorensen@redhat.com> - 3.2.3-4
- Add support for --offroot to mdadm/mdmon
- Resolves: bz785739 (rawhide) bz785737 (f16) bz771405 (f15)