From 25affb56b921041794abfb0774b615476d6ddb11 Mon Sep 17 00:00:00 2001 From: Paul Clements Date: Wed, 11 Feb 2009 13:49:26 -0500 Subject: mdadm: allow build to use --size This patch enables the --size parameter for build operations. Without this, if you have a raid1, for instance, where the 2 disks are not the exact same size, and you need to build the array but one of the disks is not available right at the moment (maybe it's USB and it's unplugged, or maybe it's a network disk and it's unavailable), then you have to play some weird games to get the array to size correctly (that is, to the size of the smaller of the two components or less). There may be other uses for this too... -- Paul Signed-off-by: NeilBrown --- Build.c | 8 ++++---- mdadm.c | 6 ++++-- mdadm.h | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Build.c b/Build.c index 1e213ce..21fe2a5 100644 --- a/Build.c +++ b/Build.c @@ -36,7 +36,8 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout, int raiddisks, mddev_dev_t devlist, int assume_clean, - char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int verbose) + char *bitmap_file, int bitmap_chunk, int write_behind, int delay, + int verbose, unsigned long long size) { /* Build a linear or raid0 arrays without superblocks * We cannot really do any checks, we just do it. @@ -57,7 +58,6 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout, int subdevs = 0, missing_disks = 0; mddev_dev_t dv; int bitmap_fd; - unsigned long long size = ~0ULL; unsigned long long bitmapsize; /* scan all devices, make sure they really are block devices */ @@ -119,7 +119,7 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout, if (vers >= 9000) { mdu_array_info_t array; array.level = level; - array.size = 0; + array.size = size; array.nr_disks = raiddisks; array.raid_disks = raiddisks; array.md_minor = 0; @@ -178,7 +178,7 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout, (size == 0 || dsize < size)) size = dsize; close(fd); - if (vers>= 9000) { + if (vers >= 9000) { mdu_disk_info_t disk; disk.number = i; disk.raid_disk = i; diff --git a/mdadm.c b/mdadm.c index 6609bf2..e889b9c 100644 --- a/mdadm.c +++ b/mdadm.c @@ -367,7 +367,8 @@ int main(int argc, char *argv[]) case O(GROW,'z'): - case O(CREATE,'z'): /* size */ + case O(CREATE,'z'): + case O(BUILD,'z'): /* size */ if (size >= 0) { fprintf(stderr, Name ": size may only be specified once. " "Second value is %s.\n", optarg); @@ -1161,7 +1162,8 @@ int main(int argc, char *argv[]) } rv = Build(devlist->devname, mdfd, chunk, level, layout, raiddisks, devlist->next, assume_clean, - bitmap_file, bitmap_chunk, write_behind, delay, verbose-quiet); + bitmap_file, bitmap_chunk, write_behind, delay, + verbose-quiet, size); break; case CREATE: if (delay == 0) delay = DEFAULT_BITMAP_DELAY; diff --git a/mdadm.h b/mdadm.h index 0d5c721..0eb8f39 100644 --- a/mdadm.h +++ b/mdadm.h @@ -443,7 +443,8 @@ extern int Assemble(struct supertype *st, char *mddev, int mdfd, extern int Build(char *mddev, int mdfd, int chunk, int level, int layout, int raiddisks, mddev_dev_t devlist, int assume_clean, - char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int verbose); + char *bitmap_file, int bitmap_chunk, int write_behind, + int delay, int verbose, unsigned long long size); extern int Create(struct supertype *st, char *mddev, int mdfd, -- cgit From 667e66d329168f205f0f67674910287fed982d87 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 29 Apr 2009 11:21:08 +1000 Subject: Makefile: use $(CC) more consistently. Explicitly calling 'gcc' in some rules makes it hard to test with other compilers. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 24ad694..b89cd6f 100644 --- a/Makefile +++ b/Makefile @@ -111,13 +111,13 @@ mdadm.tcc : $(SRCS) mdadm.h mdadm.klibc : $(SRCS) mdadm.h rm -f $(OBJS) - gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS) + $(CC) -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS) mdadm.Os : $(SRCS) mdadm.h - gcc -o mdadm.Os $(CFLAGS) -DHAVE_STDINT_H -Os $(SRCS) + $(CC) -o mdadm.Os $(CFLAGS) -DHAVE_STDINT_H -Os $(SRCS) mdadm.O2 : $(SRCS) mdadm.h - gcc -o mdadm.O2 $(CFLAGS) -DHAVE_STDINT_H -O2 $(SRCS) + $(CC) -o mdadm.O2 $(CFLAGS) -DHAVE_STDINT_H -O2 $(SRCS) test_stripe : restripe.c mdadm.h $(CC) $(CXFLAGS) $(LDFLAGS) -o test_stripe -DMAIN restripe.c -- cgit From caa0f6c623214231380c5ef0de91b53cc43d1e0b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 29 Apr 2009 11:44:02 +1000 Subject: Fix gcc-4.4 compiler warning. Apparently the dereferencing of a type-punned pointer breaks strict aliasing rules. And we wouldn't want to do that. So just make a different array of the appropriate type and use memcpy. Resolves-Debian-bug: 505375 Signed-off-by: NeilBrown --- bitmap.c | 28 +++++++++++++++------------- super1.c | 19 +++++++------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/bitmap.c b/bitmap.c index 352be5d..5618087 100644 --- a/bitmap.c +++ b/bitmap.c @@ -270,6 +270,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st) int rv = 1; char buf[64]; int swap; + __u32 uuid32[4]; info = bitmap_file_read(filename, brief, &st); if (!info) @@ -297,19 +298,20 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st) #else swap = 1; #endif - if (swap) { - printf(" UUID : %08x:%08x:%08x:%08x\n", - swapl(*(__u32 *)(sb->uuid+0)), - swapl(*(__u32 *)(sb->uuid+4)), - swapl(*(__u32 *)(sb->uuid+8)), - swapl(*(__u32 *)(sb->uuid+12))); - } else { - printf(" UUID : %08x:%08x:%08x:%08x\n", - *(__u32 *)(sb->uuid+0), - *(__u32 *)(sb->uuid+4), - *(__u32 *)(sb->uuid+8), - *(__u32 *)(sb->uuid+12)); - } + memcpy(uuid32, sb->uuid, 16); + if (swap) + printf(" UUID : %08x:%08x:%08x:%08x\n", + swapl(uuid32[0]), + swapl(uuid32[1]), + swapl(uuid32[2]), + swapl(uuid32[3])); + else + printf(" UUID : %08x:%08x:%08x:%08x\n", + uuid32[0], + uuid32[1], + uuid32[2], + uuid32[3]); + printf(" Events : %llu\n", (unsigned long long)sb->events); printf(" Events Cleared : %llu\n", (unsigned long long)sb->events_cleared); printf(" State : %s\n", bitmap_state(sb->state)); diff --git a/super1.c b/super1.c index 1342412..037c5eb 100644 --- a/super1.c +++ b/super1.c @@ -612,10 +612,8 @@ static int update_super1(struct supertype *st, struct mdinfo *info, if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || read(rfd, sb->device_uuid, 16) != 16) { - *(__u32*)(sb->device_uuid) = random(); - *(__u32*)(sb->device_uuid+4) = random(); - *(__u32*)(sb->device_uuid+8) = random(); - *(__u32*)(sb->device_uuid+12) = random(); + __u32 r[4] = {random(), random(), random(), random()}; + memcpy(sb->device_uuid, r, 16); } sb->dev_roles[i] = @@ -735,10 +733,8 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info, else { if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || read(rfd, sb->set_uuid, 16) != 16) { - *(__u32*)(sb->set_uuid) = random(); - *(__u32*)(sb->set_uuid+4) = random(); - *(__u32*)(sb->set_uuid+8) = random(); - *(__u32*)(sb->set_uuid+12) = random(); + __u32 r[4] = {random(), random(), random(), random()}; + memcpy(sb->set_uuid, r, 16); } if (rfd >= 0) close(rfd); } @@ -912,11 +908,10 @@ static int write_init_super1(struct supertype *st, if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || read(rfd, sb->device_uuid, 16) != 16) { - *(__u32*)(sb->device_uuid) = random(); - *(__u32*)(sb->device_uuid+4) = random(); - *(__u32*)(sb->device_uuid+8) = random(); - *(__u32*)(sb->device_uuid+12) = random(); + __u32 r[4] = {random(), random(), random(), random()}; + memcpy(sb->device_uuid, r, 16); } + if (rfd >= 0) close(rfd); sb->events = 0; -- cgit From c9f39c1b9bafbd18ce3831c8da6865b21827fef3 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 5 May 2009 21:13:29 +1000 Subject: re-add error check --- Manage.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Manage.c b/Manage.c index 160778e..33a0bc7 100644 --- a/Manage.c +++ b/Manage.c @@ -422,6 +422,11 @@ int Manage_subdevs(char *devname, int fd, fprintf(stderr, Name ": re-added %s\n", dv->devname); continue; } + if (errno == ENOMEM || errno == EROFS) { + fprintf(stderr, Name ": add new device failed for %s: %s\n", + dv->devname, strerror(errno)); + return 1; + } /* fall back on normal-add */ } } -- cgit