Fix and extend raid6check repair
PATCH RESEND 1/1 Fix and extend raid6check repair
Hello,
this is a resend of my patches dated Jul 20th in the "Find mismatch in data blocks during raid6 repair" thread.
Currently, the raid6check tool does not compile (due to the xmalloc changes) and my initial set of repair patches are faulty. Please merge and see my original emails for extended comments
http://thread.gmane.org/gmane.linux.raid/38922/focus=39454
http://thread.gmane.org/gmane.linux.raid/38922/focus=39460
Cheers
Robert
From 30e1c452d39e3c2d95eb22e2cdd23feb1a8e2914 Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Mon, 16 Jul 2012 23:56:54 +0200
Subject: [PATCH 1/5] Move xmalloc et al into their own file
This avoid code duplication for utilities that do not link to util.c and everything that comes with it, such as test_restripe and raid6check
--- Makefile | 12 +++++----- restripe.c | 22 ------------------ util.c | 40 --------------------------------- xmalloc.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 68 deletions(-) create mode 100644 xmalloc.c
Makefile +6 -6
@@ -109,10 +109,10 @@ OBJS = mdadm.o config.o policy.o mdstat.o ReadMe.o util.o maps.o lib.o \ Incremental.o \ mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \ super-mbr.o super-gpt.o \ - restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o \ + restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \ platform-intel.o probe_roms.o -CHECK_OBJS = restripe.o sysfs.o maps.o lib.o +CHECK_OBJS = restripe.o sysfs.o maps.o lib.o xmalloc.o SRCS = $(patsubst %.o,%.c,$(OBJS))
@@ -122,7 +122,7 @@ MON_OBJS = mdmon.o monitor.o managemon.o util.o maps.o mdstat.o sysfs.o \ config.o policy.o lib.o \ Kill.o sg_io.o dlink.o ReadMe.o super0.o super1.o super-intel.o \ super-mbr.o super-gpt.o \ - super-ddf.o sha1.o crc32.o msg.o bitmap.o \ + super-ddf.o sha1.o crc32.o msg.o bitmap.o xmalloc.o \ platform-intel.o probe_roms.o MON_SRCS = $(patsubst %.o,%.c,$(MON_OBJS))
@@ -131,7 +131,7 @@ STATICSRC = pwgr.c STATICOBJS = pwgr.o ASSEMBLE_SRCS := mdassemble.c Assemble.c Manage.c config.c policy.c dlink.c util.c \ - maps.c lib.c \ + maps.c lib.c xmalloc.c \ super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c mdstat.c \ platform-intel.c probe_roms.c sysfs.c super-mbr.c super-gpt.c ASSEMBLE_AUTO_SRCS := mdopen.c
@@ -180,8 +180,8 @@ mdmon : $(MON_OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -Wl,-z,now -o mdmon $(MON_OBJS) $(LDLIBS) msg.o: msg.c msg.h -test_stripe : restripe.c mdadm.h - $(CC) $(CXFLAGS) $(LDFLAGS) -o test_stripe -DMAIN restripe.c +test_stripe : restripe.c xmalloc.o mdadm.h + $(CC) $(CXFLAGS) $(LDFLAGS) -o test_stripe xmalloc.o -DMAIN restripe.c raid6check : raid6check.o mdadm.h $(CHECK_OBJS) $(CC) $(CXFLAGS) $(LDFLAGS) -o raid6check raid6check.o $(CHECK_OBJS)
restripe.c +0 -22
@@ -998,26 +998,4 @@ main(int argc, char *argv[]) exit(0); } - -void *xmalloc (size_t len) -{ -void *rv =malloc (len); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -write (2 , msg,strlen (msg)); -exit (4 ); -} - -void *xcalloc (size_t num,size_t size) -{ -void *rv =calloc (num, size); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -write (2 , msg,strlen (msg)); -exit (4 ); -}#endif /* MAIN */
util.c +0 -40
@@ -1803,43 +1803,3 @@ struct mdinfo *container_choose_spares(struct supertype *st, }return disks; } - -void *xmalloc (size_t len) -{ -void *rv =malloc (len); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -exit (4 +!!write (2 , msg,strlen (msg))); -} - -void *xrealloc (void *ptr,size_t len) -{ -void *rv =realloc (ptr, len); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -exit (4 +!!write (2 , msg,strlen (msg))); -} - -void *xcalloc (size_t num,size_t size) -{ -void *rv =calloc (num, size); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -exit (4 +!!write (2 , msg,strlen (msg))); -} - -char *xstrdup (const char *str) -{ -char *rv =strdup (str); -char *msg; -if (rv) -return rv; - msg = Name": memory allocation failure - aborting\n" ; -exit (4 +!!write (2 , msg,strlen (msg))); -}
xmalloc.c new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
1.7.3.4
From e89053ac2f7bf025ff2ae4eb9e4f742c439cd88b Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Thu, 19 Jul 2012 17:14:47 +0200
Subject: [PATCH 2/5] raid6check: Fix off-by-one in argument check
In repair mode, specifying a failed slot that is equal to the number of devices in the raid could cause a segfault.
--- raid6check.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
raid6check.c +2 -2
@@ -416,12 +416,12 @@ int main(int argc, char *argv[]) failed_disk1 =getnum (argv[4 ], &err); failed_disk2 =getnum (argv[5 ], &err); -if (failed_disk1 > info->array.raid_disks) { +if (failed_disk1 >= info->array.raid_disks) {fprintf (stderr,"%s: failed_slot_1 index is higher than number of devices in raid\n" , prg); exit_err =4 ; goto exitHere; } -if (failed_disk2 > info->array.raid_disks) { +if (failed_disk2 >= info->array.raid_disks) {fprintf (stderr,"%s: failed_slot_2 index is higher than number of devices in raid\n" , prg); exit_err =4 ; goto exitHere;
Signature · 1 line
1.7.3.4
From 84f06a6c216ed41e008ef94b8adbcb3b028f77b8 Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Thu, 19 Jul 2012 19:33:22 +0200
Subject: [PATCH 3/5] raid6check: Repair mode used geo_map incorrectly
In repair mode, the data block indices to be repaired were calculated using geo_map() which returns the disk slot for a data block index and not the reverse. Now we simply store the reverse of that calculation when we do it anyway.
--- raid6check.c | 24 +++++++++++++----------- tests/19repair-does-not-destroy | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 tests/19repair-does-not-destroy
raid6check.c +13 -11
@@ -116,6 +116,7 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,char *stripe_buf =xmalloc (raid_disks * chunk_size);char **stripes =xmalloc (raid_disks *sizeof (char *));char **blocks =xmalloc (raid_disks *sizeof (char *)); +int *block_index_for_slot =xmalloc (raid_disks *sizeof (int ));uint8_t *p =xmalloc (chunk_size);uint8_t *q =xmalloc (chunk_size);int *results =xmalloc (chunk_size *sizeof (int ));
@@ -172,6 +173,7 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,for (i =0 ; i < data_disks ; i++) {int disk =geo_map (i, start, raid_disks, level, layout); blocks[i] = stripes[disk]; + block_index_for_slot[disk] = i;printf ("%d->%d\n" , i, disk); }
@@ -179,7 +181,9 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, diskP =geo_map (-1 , start, raid_disks, level, layout); diskQ =geo_map (-2 , start, raid_disks, level, layout); blocks[data_disks] = stripes[diskP]; + block_index_for_slot[diskP] = data_disks; blocks[data_disks+1 ] = stripes[diskQ]; + block_index_for_slot[diskQ] = data_disks+1 ;if (memcmp (p, stripes[diskP], chunk_size) !=0 ) {printf ("P(%d) wrong at %llu\n" , diskP, start);
@@ -208,23 +212,21 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,if (failed_disk1 == diskQ || failed_disk2 == diskQ) {char *all_but_failed_blocks[data_disks]; -int failed_data; +int failed_data_or_p;int failed_block_index;if (failed_disk1 == diskQ) - failed_data = failed_disk2; + failed_data_or_p = failed_disk2;else - failed_data = failed_disk1; -printf ("Repairing D/P(%d) and Q\n" , failed_data); - failed_block_index =geo_map ( - failed_data, start, raid_disks, - level, layout); + failed_data_or_p = failed_disk1; +printf ("Repairing D/P(%d) and Q\n" , failed_data_or_p); + failed_block_index = block_index_for_slot[failed_data_or_p];for (i=0 ; i < data_disks; i++)if (failed_block_index == i) all_but_failed_blocks[i] = stripes[diskP];else all_but_failed_blocks[i] = blocks[i]; -xor_blocks (stripes[failed_data], +xor_blocks (stripes[failed_data_or_p], all_but_failed_blocks, data_disks, chunk_size);qsyndrome (p, (uint8_t *)stripes[diskQ], (uint8_t **)blocks, data_disks, chunk_size); }else {
@@ -235,13 +237,13 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, failed_data = failed_disk2; else failed_data = failed_disk1; - failed_block_index =geo_map (failed_data, start, raid_disks, level, layout); + failed_block_index = block_index_for_slot[failed_data];printf ("Repairing D(%d) and P\n" , failed_data);raid6_datap_recov (raid_disks, chunk_size, failed_block_index, (uint8_t **)blocks); }else {printf ("Repairing D and D\n" ); -int failed_block_index1 =geo_map (failed_disk1, start, raid_disks, level, layout); -int failed_block_index2 =geo_map (failed_disk2, start, raid_disks, level, layout); +int failed_block_index1 = block_index_for_slot[failed_disk1]; +int failed_block_index2 = block_index_for_slot[failed_disk2];if (failed_block_index1 > failed_block_index2) {int t = failed_block_index1; failed_block_index1 = failed_block_index2;
tests/19repair-does-not-destroy new file +30 -0
@@ -0,0 +1,30 @@ +number_of_disks=7 +chunksize_in_kib=512 +array_data_size_in_kib=$[chunksize_in_kib*(number_of_disks-2)*number_of_disks] +array_data_size_in_b=$[array_data_size_in_kib*1024] +devs="$dev0 $dev1 $dev2 $dev3 $dev4 $dev5 $dev6" + +dd if=/dev/urandom of=/tmp/RandFile bs=1024 count=$array_data_size_in_kib +mdadm -CR $md0 -l6 -n$number_of_disks -c $chunksize_in_kib $devs +dd if=/tmp/RandFile of=$md0 bs=1024 count=$array_data_size_in_kib +blockdev --flushbufs $md0; sync +check wait +blockdev --flushbufs $devs; sync +echo 3 > /proc/sys/vm/drop_caches +$dir/raid6check $md0 repair 1 2 3 > /dev/null # D D +$dir/raid6check $md0 repair 8 2 5 > /dev/null # D P +$dir/raid6check $md0 repair 15 4 6 > /dev/null # D Q +$dir/raid6check $md0 repair 22 5 6 > /dev/null # P Q +$dir/raid6check $md0 repair 3 4 0 > /dev/null # Q D +$dir/raid6check $md0 repair 3 3 1 > /dev/null # P D +$dir/raid6check $md0 repair 6 4 5 > /dev/null # D<D +$dir/raid6check $md0 repair 13 5 4 > /dev/null # D>D +blockdev --flushbufs $devs; sync +echo 3 > /proc/sys/vm/drop_caches +$dir/raid6check $md0 0 0 2>&1 | grep -qs "Error" && { echo errors detected; exit 2; } +cmp -s -n $array_data_size_in_b $md0 /tmp/RandFile || { echo should not mess up correct stripe ; exit 2; } + +mdadm -S $md0 +udevadm settle +blockdev --flushbufs $md0 $devs; sync +
Signature · 1 line
1.7.3.4
From b5f457753f2888444f5cd40690d2bd250e53f0dd Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Fri, 20 Jul 2012 16:00:14 +0200
Subject: [PATCH 4/5] raid6check: Extract (un)locking into functions
--- raid6check.c | 90 ++++++++++++++++++++++++++++++--------------------------- 1 files changed, 47 insertions(+), 43 deletions(-)
raid6check.c +47 -43
134 lines not on this page · raw message
Signature · 1 line
1.7.3.4
From f49a80c54716114375511fdc3609209275269afa Mon Sep 17 00:00:00 2001
From: Robert Buchholz <[email protected]>
Date: Fri, 20 Jul 2012 16:01:53 +0200
Subject: [PATCH 5/5] raid6check: Auto-repair mode
When calling raid6check in regular scanning mode, specifiying "autorepair" as the last positional parameter will cause it to automatically repair any single slot failes it identifies.
--- raid6check.c | 33 ++++++++++++++++++++++++++++++++- tests/19raid6auto-repair | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletions(-) create mode 100644 tests/19raid6auto-repair
raid6check.c +32 -1
@@ -284,6 +284,35 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, err =unlock_all_stripes (info, sig);if (err !=0 ) goto exitCheck; + }else if (disk >=0 && repair ==2 ) { +printf ("Auto-repairing slot %d (%s)\n" , disk, name[disk]); +if (disk == diskQ) { +qsyndrome (p, (uint8_t *)stripes[diskQ], (uint8_t **)blocks, data_disks, chunk_size); + }else { +char *all_but_failed_blocks[data_disks]; +int failed_block_index = block_index_for_slot[disk]; +for (i=0 ; i < data_disks; i++) +if (failed_block_index == i) + all_but_failed_blocks[i] = stripes[diskP]; +else + all_but_failed_blocks[i] = blocks[i]; +xor_blocks (stripes[disk], + all_but_failed_blocks, data_disks, chunk_size); + } + + err =lock_stripe (info, start, chunk_size, data_disks, sig); +if (err !=0 ) { +if (err !=2 ) +unlock_all_stripes (info, sig); + goto exitCheck; + } + +lseek64 (source[disk], offsets[disk] + start * chunk_size,0 ); +write (source[disk], stripes[disk], chunk_size); + + err =unlock_all_stripes (info, sig); +if (err !=0 ) + goto exitCheck; }
@@ -343,7 +372,7 @@ int main(int argc, char *argv[]) prg++;if (argc <4 ) { -fprintf (stderr,"Usage: %s md_device start_stripe length_stripes\n" , prg); +fprintf (stderr,"Usage: %s md_device start_stripe length_stripes [autorepair]\n" , prg);fprintf (stderr," or: %s md_device repair stripe failed_slot_1 failed_slot_2\n" , prg); exit_err =1 ; goto exitHere;
@@ -441,6 +470,8 @@ int main(int argc, char *argv[])else { start =getnum (argv[2 ], &err); length =getnum (argv[3 ], &err); +if (argc >=5 &&strcmp (argv[4 ],"autorepair" )==0 ) + repair =2 ; }if (err) {
tests/19raid6auto-repair new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
1.7.3.4
NeilBrown
AppliedQuoted 13 lines · On Wed, 15 Aug 2012 14:55:43 +0200 Robert Buchholz…
Hello,
this is a resend of my patches dated Jul 20th in the "Find mismatch in data blocks during raid6 repair" thread.
Currently, the raid6check tool does not compile (due to the xmalloc changes) and my initial set of repair patches are faulty. Please merge and see my original emails for extended comments
http://thread.gmane.org/gmane.linux.raid/38922/focus=39454
http://thread.gmane.org/gmane.linux.raid/38922/focus=39460
Quoted 3 lines
Cheers
Robert
Hi,
sorry for the long delay in getting to these.
They mostly look OK. However:
1/ They way you added 'autorepair' as a new, final positional parameter is not good. I understand why you did it (it was easy) but I think we really need to bite the bullet and introduce proper "getopt" parameter parsing.
2/ your new test scripts (thanks for including them!!) call
blockdev --flushbufs $md0
after
mdadm -S $md0
This is pointless. Once $md0 is stopped, there can be no bufs to flush. I don't think there is any point in the 'udevadm settle' 'flushbufs' and 'drop_caches' at the end.
I've applied your patches but if you could send updates to address those issues, I'd appreciate it.
Also: please send one patch per email, preferably in-line (not an attachment). It makes it easier to reply to and also easier to apply.
Thanks,
NeilBrown