Introduction
PATCH 1/1 Introduction
Following are 7 patches for md in 2.6.13-rc4
They are all fairly well tested, with the possible exception of '4' - I haven't actually tried throwing BIO_RW_BARRIER requests are any md devices. However the code is very straight forward.
I'm happy (even keen) for these to go into 2.6.13.
If it's getting a bit late, then 2 is probably the most important. The others we can probably live without.
Thanks,
NeilBrown
[PATCH md 001 of 7] Remove a stray debugging printk.
[PATCH md 002 of 7] Make 'md' and alias for 'md-mod'
[PATCH md 003 of 7] Fix minor error in raid10 read-balancing calculation.
[PATCH md 004 of 7] Fail IO requests to md that require a barrier.
[PATCH md 005 of 7] Always honour md bitmap being read from disk
[PATCH md 006 of 7] Yet another attempt to get bitmap-based resync to do the right thing in all cases... [PATCH md 007 of 7] Make sure md bitmap updates are flushed when array is stopped.
PATCH 1/1 Remove a stray debugging printk.
### Diffstat output
./drivers/md/md.c | 1 - 1 files changed, 1 deletion(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +0 -1
@@ -3484,7 +3484,6 @@ static void md_do_sync(mddev_t *mddev) goto skip; } ITERATE_MDDEV(mddev2,tmp) { -printk ("." );if (mddev2 == mddev)continue ; if (mddev2->curr_resync &&
PATCH 1/1 Make 'md' and alias for 'md-mod'
In reply to NeilBrownUntil the bitmap code was added,
modprobe md
would load the md module. But now the md module is called 'md-mod', so we really need an alias for backwards comparability.
### Diffstat output
./drivers/md/md.c | 1 + 1 files changed, 1 insertion(+)
drivers/md/md.c renamed from drivers/md/md.c~current~ +1 -0
@@ -4006,3 +4006,4 @@ EXPORT_SYMBOL(md_wakeup_thread);EXPORT_SYMBOL (md_print_devices);EXPORT_SYMBOL (md_check_recovery);MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("md" );
PATCH 1/1 Fix minor error in raid10 read-balancing calculation.
In reply to NeilBrown'this_sector' is a virtual (array) address while 'head_position' is a physical (device) address, so substraction doesn't make any sense. devs[slot].addr should be used instead of this_sector.
However, this patch doesn't make much practical different to the read balancing due to the effects of later code.
### Diffstat output
./drivers/md/raid10.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-)
drivers/md/raid10.c renamed from drivers/md/raid10.c~current~ +2 -1
@@ -538,7 +538,8 @@ static int read_balance(conf_t *conf, r1 } - current_distance =abs (this_sector - conf->mirrors[disk].head_position); + current_distance =abs (r10_bio->devs[slot].addr - + conf->mirrors[disk].head_position);/* Find the disk whose head is closest */
PATCH 1/1 Fail IO request to md that require a barrier.
In reply to NeilBrownmd does not yet support BIO_RW_BARRIER, so be honest about it and fail (-EOPNOTSUPP) any such requests.
### Diffstat output
./drivers/md/linear.c | 5 +++++ ./drivers/md/multipath.c | 5 +++++ ./drivers/md/raid0.c | 5 +++++ ./drivers/md/raid1.c | 4 ++++ ./drivers/md/raid10.c | 5 +++++ ./drivers/md/raid5.c | 5 +++++ ./drivers/md/raid6main.c | 5 +++++ 7 files changed, 34 insertions(+)
drivers/md/linear.c renamed from drivers/md/linear.c~current~ +5 -0
@@ -238,6 +238,11 @@ static int linear_make_request (request_dev_info_t *tmp_dev;sector_t block; +if (unlikely (bio_barrier (bio))) { +bio_endio (bio, bio->bi_size, -EOPNOTSUPP ); +return 0 ; + } +if (bio_data_dir (bio)==WRITE ) {disk_stat_inc (mddev->gendisk, writes);disk_stat_add (mddev->gendisk, write_sectors,bio_sectors (bio));
drivers/md/multipath.c renamed from drivers/md/multipath.c~current~ +5 -0
@@ -169,6 +169,11 @@ static int multipath_make_request (requestruct multipath_bh * mp_bh;struct multipath_info *multipath; +if (unlikely (bio_barrier (bio))) { +bio_endio (bio, bio->bi_size, -EOPNOTSUPP ); +return 0 ; + } + mp_bh =mempool_alloc (conf->pool,GFP_NOIO ); mp_bh->master_bio = bio;
drivers/md/raid0.c renamed from drivers/md/raid0.c~current~ +5 -0
@@ -404,6 +404,11 @@ static int raid0_make_request (request_qunsigned long chunk;sector_t block, rsect; +if (unlikely (bio_barrier (bio))) { +bio_endio (bio, bio->bi_size, -EOPNOTSUPP ); +return 0 ; + } +if (bio_data_dir (bio)==WRITE ) {disk_stat_inc (mddev->gendisk, writes);disk_stat_add (mddev->gendisk, write_sectors,bio_sectors (bio));
drivers/md/raid1.c renamed from drivers/md/raid1.c~current~ +4 -0
@@ -555,6 +555,10 @@ static int make_request(request_queue_tunsigned long flags;struct bio_list bl; +if (unlikely (bio_barrier (bio))) { +bio_endio (bio, bio->bi_size, -EOPNOTSUPP ); +return 0 ; + }/* * Register the new request and wait if the reconstruction
drivers/md/raid10.c renamed from drivers/md/raid10.c~current~ +5 -0
@@ -669,6 +669,11 @@ static int make_request(request_queue_tint i;int chunk_sects = conf->chunk_mask +1 ; +if (unlikely (bio_barrier (bio))) { +bio_endio (bio, bio->bi_size, -EOPNOTSUPP ); +return 0 ; + } +/* If this request crosses a chunk boundary, we need to * split it. This will only happen for 1 PAGE (or less) requests. */
drivers/md/raid5.c renamed from drivers/md/raid5.c~current~ +5 -0
@@ -1411,6 +1411,11 @@ static int make_request (request_queue_tsector_t logical_sector, last_sector;struct stripe_head *sh; +if (unlikely (bio_barrier (bi))) { +bio_endio (bi, bi->bi_size, -EOPNOTSUPP ); +return 0 ; + } +md_write_start (mddev, bi);if (bio_data_dir (bi)==WRITE ) {
drivers/md/raid6main.c renamed from drivers/md/raid6main.c~current~ +5 -0
@@ -1570,6 +1570,11 @@ static int make_request (request_queue_tsector_t logical_sector, last_sector;struct stripe_head *sh; +if (unlikely (bio_barrier (bi))) { +bio_endio (bi, bi->bi_size, -EOPNOTSUPP ); +return 0 ; + } +md_write_start (mddev, bi);if (bio_data_dir (bi)==WRITE ) {
PATCH 1/1 Always honour md bitmap being read from disk
In reply to NeilBrownThe code currently will ignore the bitmap if the array seem to be in-sync. This is wrong if the array is degraded, and probably wrong anyway. If the bitmap says some chunks are not in in-sync, and the superblock says everything IS in sync, then something is clearly wrong, and it is safer to trust the bitmap.
### Diffstat output
./drivers/md/bitmap.c | 52 ++++++++++++++++++++++---------------------------- 1 files changed, 23 insertions(+), 29 deletions(-)
drivers/md/bitmap.c renamed from drivers/md/bitmap.c~current~ +23 -29
@@ -817,8 +817,7 @@ int bitmap_unplug(struct bitmap *bitmap)return 0 ; } -static void bitmap_set_memory_bits (struct bitmap *bitmap,sector_t offset, -unsigned long sectors,int in_sync); +static void bitmap_set_memory_bits (struct bitmap *bitmap,sector_t offset);/* * bitmap_init_from_disk -- called at bitmap_create time to initialize * the in-memory bitmap from the on-disk bitmap -- also, sets up the * memory mapping of the bitmap file
@@ -827,7 +826,7 @@ static void bitmap_set_memory_bits(struc* previously kicked from the array, we mark all the bits as * 1's in order to cause a full resync. */ -static int bitmap_init_from_disk (struct bitmap *bitmap,int in_sync) +static int bitmap_init_from_disk (struct bitmap *bitmap) {unsigned long i, chunks, index, oldindex, bit;struct page *page =NULL , *oldpage =NULL ;
@@ -928,8 +927,7 @@ static int bitmap_init_from_disk(struct }if (test_bit (bit,page_address (page))) {/* if the disk bit is set, set the memory bit */ -bitmap_set_memory_bits (bitmap, - i <<CHUNK_BLOCK_SHIFT (bitmap),1 , in_sync); +bitmap_set_memory_bits (bitmap, i <<CHUNK_BLOCK_SHIFT (bitmap)); bit_cnt++; } }
@@ -1425,35 +1423,30 @@ void bitmap_close_sync(struct bitmap *bi } } -static void bitmap_set_memory_bits (struct bitmap *bitmap,sector_t offset, -unsigned long sectors,int in_sync) +static void bitmap_set_memory_bits (struct bitmap *bitmap,sector_t offset) {/* For each chunk covered by any of these sectors, set the -* counter to 1 and set resync_needed unless in_sync. They should all +* counter to 1 and set resync_needed. They should all * be 0 at this point */ -while (sectors) { -int secs; -bitmap_counter_t *bmc; -spin_lock_irq (&bitmap->lock); - bmc =bitmap_get_counter (bitmap, offset, &secs,1 ); -if (!bmc) { -spin_unlock_irq (&bitmap->lock); -return ; - } -if (! *bmc) { -struct page *page; - *bmc =1 | (in_sync?0 :NEEDED_MASK ); -bitmap_count_page (bitmap, offset,1 ); - page =filemap_get_page (bitmap, offset >>CHUNK_BLOCK_SHIFT (bitmap)); -set_page_attr (bitmap, page,BITMAP_PAGE_CLEAN ); - } + +int secs; +bitmap_counter_t *bmc; +spin_lock_irq (&bitmap->lock); + bmc =bitmap_get_counter (bitmap, offset, &secs,1 ); +if (!bmc) {spin_unlock_irq (&bitmap->lock); -if (sectors > secs) - sectors -= secs; -else - sectors =0 ; +return ; } +if (! *bmc) { +struct page *page; + *bmc =1 |NEEDED_MASK ; +bitmap_count_page (bitmap, offset,1 ); + page =filemap_get_page (bitmap, offset >>CHUNK_BLOCK_SHIFT (bitmap)); +set_page_attr (bitmap, page,BITMAP_PAGE_CLEAN ); + } +spin_unlock_irq (&bitmap->lock); + }/*
@@ -1564,7 +1557,8 @@ int bitmap_create(mddev_t *mddev)/* now that we have some pages available, initialize the in-memory * bitmap from the on-disk bitmap */ - err =bitmap_init_from_disk (bitmap, mddev->recovery_cp == MaxSector); + err =bitmap_init_from_disk (bitmap); +if (err)return err;
PATCH 1/1 Yet another attempt to get bitmap-based resync to do the right thing in all cases...
In reply to NeilBrownFirstly, R1BIO_Degraded was being set in a number of places in the resync code, but is never used there, so get rid of those settings.
Then: When doing a resync, we want to clear the bit in the bitmap iff the array will be non-degraded when the sync has completed. However the current code would clear the bitmap if the array was non-degraded when the resync *started*, which obviously isn't right (it is for 'resync' but not for 'recovery' - i.e. rebuilding a failed drive).
This patch calculated 'still_degraded' and uses the to tell bitmap_start_sync whether this sync should clear the corresponding bit.
### Diffstat output
./drivers/md/raid1.c | 29 +++++++++++++++-------------- 1 files changed, 15 insertions(+), 14 deletions(-)
drivers/md/raid1.c renamed from drivers/md/raid1.c~current~ +15 -14
@@ -897,7 +897,6 @@ static int end_sync_read(struct bio *bioif (!uptodate) {md_error (r1_bio->mddev, conf->mirrors[r1_bio->read_disk].rdev); -set_bit (R1BIO_Degraded, &r1_bio->state); }else set_bit (R1BIO_Uptodate, &r1_bio->state);rdev_dec_pending (conf->mirrors[r1_bio->read_disk].rdev, conf->mddev);
@@ -922,10 +921,9 @@ static int end_sync_write(struct bio *bi mirror = i;break ; } -if (!uptodate) { +if (!uptodate)md_error (mddev, conf->mirrors[mirror].rdev); -set_bit (R1BIO_Degraded, &r1_bio->state); - } +update_head_pos (mirror, r1_bio);if (atomic_dec_and_test (&r1_bio->remaining)) {
@@ -1113,6 +1111,7 @@ static sector_t sync_request(mddev_t *mdint i;int write_targets =0 ;int sync_blocks; +int still_degraded =0 ;if (!conf->r1buf_pool) {
@@ -1141,7 +1140,10 @@ static sector_t sync_request(mddev_t *mdreturn 0 ; } -if (!bitmap_start_sync (mddev->bitmap, sector_nr, &sync_blocks, mddev->degraded) && +/* before building a request, check if we can skip these blocks.. +* This call the bitmap_start_sync doesn't actually record anything +*/ +if (!bitmap_start_sync (mddev->bitmap, sector_nr, &sync_blocks,1 ) && !conf->fullsync) {/* We can skip this block, and probably several more */ *skipped =1 ;
@@ -1207,24 +1209,23 @@ static sector_t sync_request(mddev_t *mdif (i == disk) { bio->bi_rw =READ ; bio->bi_end_io = end_sync_read; - }else if (conf->mirrors[i].rdev && - !conf->mirrors[i].rdev->faulty && - (!conf->mirrors[i].rdev->in_sync || - sector_nr +RESYNC_SECTORS > mddev->recovery_cp)) { + }else if (conf->mirrors[i].rdev ==NULL || + conf->mirrors[i].rdev->faulty) { + still_degraded =1 ; +continue ; + }else if (!conf->mirrors[i].rdev->in_sync || + sector_nr +RESYNC_SECTORS > mddev->recovery_cp) { bio->bi_rw =WRITE ; bio->bi_end_io = end_sync_write; write_targets ++; }else +/* no need to read or write here */ continue ; bio->bi_sector = sector_nr + conf->mirrors[i].rdev->data_offset; bio->bi_bdev = conf->mirrors[i].rdev->bdev; bio->bi_private = r1_bio; } -if (write_targets +1 < conf->raid_disks) -/* array degraded, can't clear bitmap */ -set_bit (R1BIO_Degraded, &r1_bio->state); -if (write_targets ==0 ) {/* There is nowhere to write, so all non-sync * drives must be failed - so we are finished
@@ -1247,7 +1248,7 @@ static sector_t sync_request(mddev_t *mdbreak ;if (sync_blocks ==0 ) {if (!bitmap_start_sync (mddev->bitmap, sector_nr, - &sync_blocks, mddev->degraded) && + &sync_blocks, still_degraded) && !conf->fullsync)break ;if (sync_blocks < (PAGE_SIZE >>9 ))
PATCH 1/1 Make sure md bitmap updates are flushed when array is stopped.
In reply to NeilBrownThe recent change to never ignore the bitmap, revealed that the bitmap isn't begin flushed properly when an array is stopped.
We call bitmap_daemon_work three times as there is a three-stage pipeline for flushing updates to the bitmap file.
### Diffstat output
./drivers/md/bitmap.c | 23 +++++++++++++++++++++++ ./drivers/md/md.c | 2 ++ ./include/linux/raid/bitmap.h | 1 + 3 files changed, 26 insertions(+)
drivers/md/bitmap.c renamed from drivers/md/bitmap.c~current~ +23 -0
@@ -1450,6 +1450,29 @@ static void bitmap_set_memory_bits(struc }/* +* flush out any pending updates +*/ +void bitmap_flush (mddev_t *mddev) +{ +struct bitmap *bitmap = mddev->bitmap; +int sleep; + +if (!bitmap)/* there was no bitmap */ +return ; + +/* run the daemon_work three time to ensure everything is flushed +* that can be +*/ + sleep = bitmap->daemon_sleep; + bitmap->daemon_sleep =0 ; +bitmap_daemon_work (bitmap); +bitmap_daemon_work (bitmap); +bitmap_daemon_work (bitmap); + bitmap->daemon_sleep = sleep; +bitmap_update_sb (bitmap); +} + +/* * free memory that was allocated */ void bitmap_destroy (mddev_t *mddev)
drivers/md/md.c renamed from drivers/md/md.c~current~ +2 -0
@@ -1798,6 +1798,8 @@ static int do_md_stop(mddev_t * mddev, i goto out; mddev->ro =1 ; }else { +bitmap_flush (mddev); +wait_event (mddev->sb_wait,atomic_read (&mddev->pending_writes)==0 );if (mddev->ro)set_disk_ro (disk,0 );blk_queue_make_request (mddev->queue, md_fail_request);
include/linux/raid/bitmap.h renamed from include/linux/raid/bitmap.h~current~ +1 -0
@@ -248,6 +248,7 @@ struct bitmap {/* these are used only by md/bitmap */ int bitmap_create (mddev_t *mddev); +void bitmap_flush (mddev_t *mddev);void bitmap_destroy (mddev_t *mddev);int bitmap_active (struct bitmap *bitmap);
Quoted 11 lines · NeilBrown
Following are 7 patches for md in 2.6.13-rc4
They are all fairly well tested, with the possible exception of '4' - I haven't actually tried throwingBIO_RW_BARRIERrequests are any md devices. However the code is very straight forward.I'm happy (even keen) for these to go into 2.6.13.
If it's getting a bit late, then 2 is probably the most important. The others we can probably live without.
hm, OK. Merging 1) and 2) seems sane. I must say that I worry about 4) and would prefer to defer things if poss.
If there are others there which you really would prefer to see in 2.6.13 then please let me know.
Quoted 9 lines
[PATCH md 001 of 7] Remove a stray debugging printk.
[PATCH md 002 of 7] Make 'md' and alias for 'md-mod'
[PATCH md 003 of 7] Fix minor error in raid10 read-balancing calculation.
[PATCH md 004 of 7] Fail IO requests to md that require a barrier.
[PATCH md 005 of 7] Always honour md bitmap being read from disk
[PATCH md 006 of 7] Yet another attempt to get bitmap-based resync to do the right thing in all cases... [PATCH md 007 of 7] Make sure md bitmap updates are flushed when array is stopped.
Quoted 8 lines · On Wednesday August 3, [email protected] wrote:
Quoted 7 lines · NeilBrown
Following are 7 patches for md in 2.6.13-rc4
They are all fairly well tested, with the possible exception of '4' - I haven't actually tried throwingBIO_RW_BARRIERrequests are any md devices. However the code is very straight forward.
Quoted 7 lines
Quoted 4 lines
I'm happy (even keen) for these to go into 2.6.13.
If it's getting a bit late, then 2 is probably the most important. The others we can probably live without.hm, OK. Merging 1) and 2) seems sane. I must say that I worry about 4) and would prefer to defer things if poss.
Fair enough. 4 can wait until 2.6.14 (only a couple of months away, right :-)
Quoted 4 lines
If there are others there which you really would prefer to see in 2.6.13 then please let me know.
5, 6, and 7 I would really prefer to be in 2.6.13.
The intent-bitmap stuff is broken (in small but potentially significant ways) without them, and they are complete no-ops if bitmaps aren't enabled:
5 only touches bitmap.c
6 removes the setting for R1BIO_Degraded which is not used and
slightly re-arranges an 'if' statement. All other changes are complete no-ops if bitmaps aren't enabled.
7: if bitmaps aren't enabled, all this does is call "wait_event"
exactly the same way as will very possibly be called a few lines later when md_update_sb is called.
So I'm convinced (and hopefully convincing) that they don't have any significant effect if bitmaps aren't enabled, and fix genuine problems with bitmaps, and so are appropriate for 2.6.13...
Thanks,
NeilBrown
Quoted 10 lines
Quoted 10 lines
[PATCH md 001 of 7] Remove a stray debugging printk.
[PATCH md 002 of 7] Make 'md' and alias for 'md-mod'
[PATCH md 003 of 7] Fix minor error in raid10 read-balancing calculation.
[PATCH md 004 of 7] Fail IO requests to md that require a barrier.
[PATCH md 005 of 7] Always honour md bitmap being read from disk
[PATCH md 006 of 7] Yet another attempt to get bitmap-based resync to do the right thing in all cases... [PATCH md 007 of 7] Make sure md bitmap updates are flushed when array is stopped.
Quoted 15 lines · Neil Brown
Quoted 13 lines · On Wednesday August 3, [email protected] wrote:
Quoted 11 lines · NeilBrown
Following are 7 patches for md in 2.6.13-rc4
They are all fairly well tested, with the possible exception of '4' - I haven't actually tried throwingBIO_RW_BARRIERrequests are any md devices. However the code is very straight forward.I'm happy (even keen) for these to go into 2.6.13.
If it's getting a bit late, then 2 is probably the most important. The others we can probably live without.
Quoted 5 lines
Quoted 2 lines
hm, OK. Merging 1) and 2) seems sane. I must say that I worry about 4) and would prefer to defer things if poss.
Fair enough. 4 can wait until 2.6.14 (only a couple of months away, right :-)
Thereabouts..
Quoted 6 lines
Quoted 4 lines
If there are others there which you really would prefer to see in 2.6.13 then please let me know.
5, 6, and 7 I would really prefer to be in 2.6.13.
OK.
Quoted 11 lines
The intent-bitmap stuff is broken (in small but potentially significant ways) without them, and they are complete no-ops if bitmaps aren't enabled:
5 only touchesbitmap.c
6 removes the setting forR1BIO_Degradedwhich is not used and
slightly re-arranges an 'if' statement. All other changes are complete no-ops if bitmaps aren't enabled.
7: if bitmaps aren't enabled, all this does is call "wait_event"
exactly the same way as will very possibly be called a few lines later whenmd_update_sbis called.
Quoted 3 lines
So I'm convinced (and hopefully convincing) that they don't have any significant effect if bitmaps aren't enabled, and fix genuine problems with bitmaps, and so are appropriate for 2.6.13...
We'll see ;)