mirror patches - device failure detection/race fix/deadlock fix
The first 4 patches (0000[1234].patch) are the device failure detection patches. They've been cleaned up a bit from the last time they were posted.
The 'race.patch' fixes a couple race conditions that were a result of the __rh_alloc() function releasing and regrabbing a lock when called.
The 'deadlock.patch' switches all spin_lock calls on the region_lock to spin_lock_irqsave. Without this patch you machine will hang.
The patches apply in the order described, and should apply to kernels 2.6.12 - 2.6.13-rc5.
I've made them all attachments to this e-mail. If people don't like it this way, let me know, and I'll do it lkml style.
brassow
drivers/md/dm-log.c +76 -25
@@ -30,7 +30,8 @@spin_lock (&_lock);if (type->use_count) -DMWARN ("Attempt to unregister a log type that is still in use" ); +DMWARN ("Unregister failed: log type '%s' still in use" , + type->name);else list_del (&type->list);
@@ -136,7 +137,7 @@unsigned bitset_uint32_count;uint32_t *clean_bits;uint32_t *sync_bits; -uint32_t *recovering_bits;/* FIXME: this seems excessive */ +uint32_t *recovering_bits;int sync_search;
@@ -150,6 +151,9 @@/* * Disk log fields */ +int log_dev_failed; +atomic_t suspended; +struct completion failure_completion;struct dm_dev *log_dev;struct log_header header;
@@ -360,7 +364,7 @@ lc->recovering_bits =vmalloc (bitset_size);if (!lc->recovering_bits) { -DMWARN ("couldn't allocate sync bitset" ); +DMWARN ("couldn't allocate recovering bitset" );vfree (lc->sync_bits);vfree (lc->clean_bits);kfree (lc);
@@ -412,6 +416,8 @@ lc = (struct log_c *) log->context; lc->log_dev = dev; + lc->log_dev_failed =0 ; +init_completion (&lc->failure_completion);/* setup the disk header fields */ lc->header_location.bdev = lc->log_dev->bdev;
@@ -465,22 +471,35 @@return count; } +static void fail_log_device (struct log_c *lc) +{ + lc->log_dev_failed =1 ; +dm_table_event (lc->ti->table); +} + +static void restore_log_device (struct log_c *lc) +{ + lc->log_dev_failed =0 ; +} +static int disk_resume (struct dirty_log *log) { -int r; +int r =0 ;unsigned i;struct log_c *lc = (struct log_c *) log->context;size_t size = lc->bitset_uint32_count *sizeof (uint32_t ); -/* read the disk header */ - r =read_header (lc); -if (r) -return r; - -/* read the bits */ - r =read_bits (lc); -if (r) -return r; +/* +* Read the disk header, but only if we know it is good. +* Assume the worst in the event of failure. +*/ +if (!lc->log_dev_failed && + ((r =read_header (lc)) ||read_bits (lc))) { +DMWARN ("Read %s failed on mirror log device, %s." , + r ?"header" :"bits" , lc->log_dev->name); +fail_log_device (lc); + lc->header.nr_regions =0 ; + }/* set or clear any new bits */ if (lc->sync ==NOSYNC )
@@ -496,16 +515,20 @@memcpy (lc->sync_bits, lc->clean_bits, size); lc->sync_count =count_bits32 (lc->clean_bits, lc->bitset_uint32_count); -/* write the bits */ - r =write_bits (lc); -if (r) -return r; -/* set the correct number of regions in the header */ lc->header.nr_regions = lc->region_count; -/* write the new header */ -return write_header (lc); +/* write out the log. 'i' tells us which has failed if any */ + i =1 ; +if ((r =write_bits (lc)) || (i =0 ) || (r =write_header (lc))) { +DMWARN ("Write %s failed on mirror log device, %s." , + i ?"bits" :"header" , lc->log_dev->name); +fail_log_device (lc); + }else +restore_log_device (lc); + +atomic_set (&lc->suspended,0 ); +return r; }static uint32_t core_get_region_size (struct dirty_log *log)
@@ -532,6 +555,17 @@return 0 ; } +static int disk_presuspend (struct dirty_log *log) +{ +struct log_c *lc = (struct log_c *) log->context; + +atomic_set (&lc->suspended,1 ); +if (lc->log_dev_failed) +complete (&lc->failure_completion); + +return 0 ; +} +static int disk_flush (struct dirty_log *log) {int r;
@@ -541,9 +575,23 @@if (!lc->touched)return 0 ; +/* +* If a failure occurs, we must wait for a suspension. +* We must not proceed in the event of a failure, +* because if the machine reboots with the log +* incorrect, recovery could be compromised +*/ r =write_bits (lc); -if (!r) +if (!r) { lc->touched =0 ; +restore_log_device (lc); + }else { +DMERR ("Write failure on mirror log device, %s." , + lc->log_dev->name); +fail_log_device (lc); +if (!atomic_read (&lc->suspended)) +wait_for_completion (&lc->failure_completion); + }return r; }
@@ -613,6 +661,7 @@switch (status) {case STATUSTYPE_INFO : +DMEMIT ("1 core" );break ;case STATUSTYPE_TABLE :
@@ -628,17 +677,18 @@ char *result, unsigned int maxlen) { int sz = 0; -char buffer[16 ];struct log_c *lc = log->context;switch (status) {case STATUSTYPE_INFO : +DMEMIT ("3 disk %s %c" , lc->log_dev->name, + lc->log_dev_failed ?'D' :'A' );break ;case STATUSTYPE_TABLE : -format_dev_t (buffer, lc->log_dev->bdev->bd_dev);DMEMIT ("%s %u %s %u " , log->type->name, - lc->sync ==DEFAULTSYNC ?2 :3 , buffer, + lc->sync ==DEFAULTSYNC ?2 :3 , + lc->log_dev->name, lc->region_size);DMEMIT_SYNC ; }
@@ -668,7 +718,8 @@ .module = THIS_MODULE, .ctr = disk_ctr, .dtr = disk_dtr, - .suspend = disk_flush, + .presuspend = disk_presuspend, + .postsuspend = disk_flush, .resume = disk_resume, .get_region_size = core_get_region_size, .is_clean = core_is_clean,
drivers/md/dm-log.h +2 -1
@@ -32,7 +32,8 @@* There are times when we don't want the log to touch * the disk. */ -int (*suspend)(struct dirty_log *log); +int (*presuspend)(struct dirty_log *log); +int (*postsuspend)(struct dirty_log *log);int (*resume)(struct dirty_log *log);/*
drivers/md/dm-raid1.c +12 -2
@@ -1158,15 +1158,25 @@return 0 ; } +static void mirror_presuspend (struct dm_target *ti) +{ +struct mirror_set *ms = (struct mirror_set *) ti->private; +struct dirty_log *log = ms->rh.log; + +if (log->type->presuspend && log->type->presuspend (log)) +/* FIXME: need better error handling */ +DMWARN ("log presuspend failed" ); +} +static void mirror_postsuspend (struct dm_target *ti) {struct mirror_set *ms = (struct mirror_set *) ti->private;struct dirty_log *log = ms->rh.log;rh_stop_recovery (&ms->rh); -if (log->type->suspend && log->type->suspend (log)) +if (log->type->postsuspend && log->type->postsuspend (log))/* FIXME: need better error handling */ -DMWARN ("log suspend failed" ); +DMWARN ("log postsuspend failed" ); }static void mirror_resume (struct dm_target *ti)
drivers/md/dm-raid1.c +209 -33
422 lines not on this page · raw message
drivers/md/dm-raid1.c +195 -53
361 lines not on this page · raw message
drivers/md/dm-log.h +10 -0
@@ -49,6 +49,16 @@int (*is_clean)(struct dirty_log *log,region_t region);/* +* Returns: 0, 1 +* +* This is necessary for cluster mirroring. It provides +* a way to detect recovery on another node, so we +* aren't writing concurrently. This function is likely +* to block (when a cluster log is used). +*/ +int (*is_remote_recovering)(struct dirty_log *log,region_t region); + +/* * Returns: 0, 1, -EWOULDBLOCK, < 0 * * A predicate function to check the area given by
drivers/md/dm-raid1.c +15 -1
@@ -984,6 +984,9 @@int state;struct bio *bio;struct bio_list sync, nosync, recover, *this_list =NULL ; +struct bio_list requeue; +struct dirty_log *log = ms->rh.log; +region_t region;if (!writes->head)return ;
@@ -994,9 +997,18 @@bio_list_init (&sync);bio_list_init (&nosync);bio_list_init (&recover); +bio_list_init (&requeue);while ((bio =bio_list_pop (writes))) { - state =rh_state (&ms->rh,bio_to_region (&ms->rh, bio),1 ); + region =bio_to_region (&ms->rh, bio); + +if (log->type->is_remote_recovering && + log->type->is_remote_recovering (log, region)) { +bio_list_add (&requeue, bio); +continue ; + } + + state =rh_state (&ms->rh, region,1 );switch (state) {case RH_CLEAN :case RH_DIRTY :
@@ -1015,6 +1027,8 @@bio_list_add (this_list, bio); } +bio_list_merge (writes, &requeue); +/* * Increment the pending counts for any regions that will * be written to (writes to recover regions are going to
drivers/md/dm-raid1.c +67 -31
168 lines not on this page · raw message
drivers/md/dm-raid1.c +24 -18
141 lines not on this page · raw message
Alasdair G Kergon
maintainerQuoted 2 lines · Jon Brassow
The 'race.patch' fixes a couple race conditions that were a result of the
__rh_alloc()function releasing and regrabbing a lock when called.
- read_unlock(&rh->hash_lock);
- nreg = mempool_alloc(rh->region_pool, GFP_NOIO);
+ nreg = mempool_alloc(rh->region_pool, GFP_ATOMIC);
nreg->state = rh->log->type->in_sync(rh->log, region, 1) ?So mempool_alloc is now called while holding a spinlock. With GFP_ATOMIC, what happens if it returns NULL?
Doesn't it need to be able to sleep to get the benefit of the mempool?
Quoted 2 lines
The 'deadlock.patch' switches all
spin_lockcalls on theregion_locktospin_lock_irqsave. Without this patch you machine will hang.
I'd prefer it if race.patch used the correct versions (with or without _irq).
Alasdair
Signature · 1 line
[email protected]
Quoted 11 lines · Alasdair G Kergon
Quoted 2 lines · Jon Brassow
The 'race.patch' fixes a couple race conditions that were a result of the
__rh_alloc()function releasing and regrabbing a lock when called.drivers/md/dm-raid1.c +1
-2-read_unlock (&rh->hash_lock); - nreg =mempool_alloc (rh->region_pool,GFP_NOIO ); + nreg =mempool_alloc (rh->region_pool,GFP_ATOMIC ); nreg->state = rh->log->type->in_sync(rh->log, region, 1) ?So
mempool_allocis now called while holding a spinlock. WithGFP_ATOMIC, what happens if it returns NULL?
That's what the mempool is all about. :) I suppose, if you were under memory pressure long enough and the kernel never successfully reclaimed memory, it *might* return NULL -- in which case, the kernel oops's. I think this is so unlikely, that I would be willing to put in a BUG() call if nreg is found to be NULL. BTW, the scenario is exactly the same as if the gfp_flag was GFP_NOIO -- if the kernel can't get us memory, it can't get us memory.
Quoted 1 line
Doesn't it need to be able to sleep to get the benefit of the mempool?
No. mempool will try to allocate memory honoring the flags you have set (in this case GFP_ATOMIC). If unsuccessful, it will tap into the memory reserve you have created when you did a mempool_create. So, when there is no memory left to give us, we have 64 _regions_ left in our repository.
Am I wrong?
Quoted 6 lines
Quoted 3 lines
The 'deadlock.patch' switches all
spin_lockcalls on theregion_locktospin_lock_irqsave. Without this patch you machine will hang.I'd prefer it if race.patch used the correct versions (with or without
_irq).
Are you asking me to "combine" the patches? I can do that.
brassow
Alasdair G Kergon
maintainerQuoted 9 lines · Jon Brassow
That's what the mempool is all about. :) I suppose, if you were under memory pressure long enough and the kernel never successfully reclaimed memory, it *might* return NULL -- in which case, the kernel oops's. I think this is so unlikely, that I would be willing to put in a
BUG()call if nreg is found to be NULL.BTW, the scenario is exactly the
same as if thegfp_flagwasGFP_NOIO-- if the kernel can't get us memory, it can't get us memory.
The two cases are quite different.
With NOIO - how it currently works - it'll sleep if there isn't enough memory and *never* return NULL.
Quoted 6 lines
Quoted 1 line
Doesn't it need to be able to sleep to get the benefit of the mempool?
No. mempool will try to allocate memory honoring the flags you have set (in this case
GFP_ATOMIC). If unsuccessful, it will tap into the memory reserve you have created when you did amempool_create. So, when there is no memory left to give us, we have 64 _regions_ left in our repository.
But that's a finite reserve. Consider what happens if mempool_allocs occur faster than mempool_frees: eventually your reserve drops to 0 and mempool_alloc returns NULL - or have I missed some rate-limiting properties of the code that would prevent this?
Quoted 1 line
Are you asking me to "combine" the patches? I can do that.
I think the irqsaves are only necessary because of locking bugs in race.patch: We know the irq state throughout the code, and there's only a small section that gets used in both states and genuinely needs irqsave.
This one is self-evidently unnecessary, for example:
write_lock_irq(&rh->hash_lock);
- spin_lock(&rh->region_lock);
+ spin_lock_irqsave(&rh->region_lock, flags);
Alasdair
Signature · 1 line
[email protected]
Quoted 8 lines · Jonathan E Brassow
The first 4 patches (0000[1234].patch) are the device failure detection patches. They've been cleaned up a bit from the last time they were posted.
The 'race.patch' fixes a couple race conditions that were a result of the
__rh_alloc()function releasing and regrabbing a lock when called.The 'deadlock.patch' switches all
spin_lockcalls on theregion_locktospin_lock_irqsave. Without this patch you machine will hang.The patches apply in the order described, and should apply to kernels 2.6.12 - 2.6.13-rc5.
Quoted 8 lines
I've made them all attachments to this e-mail. If people don't like it this way, let me know, and I'll do it lkml style.
brassow
<00001.patch><00002.patch><00003.patch><00004.patch><race.patch><deadlock.patch>-- dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
I'm an idiot. :)
The 0000[1234].patch files remain unchanged, but you can forget about the race & deadlock patch files. For fixes to those problems, try this new race patch.
QA has confirmed that this patch has at least taken care of the problems I was trying to address with the other patches...
brassow
drivers/md/dm-raid1.c +2 -2
@@ -1563,7 +1563,7 @@ static int __init dm_mirror_init(void)if (r)return r; - _kmirrord_wq =create_workqueue ("kmirrord" ); + _kmirrord_wq =create_singlethread_workqueue ("kmirrord" );if (!_kmirrord_wq) {DMERR ("couldn't start kmirrord" );dm_dirty_log_exit ();
@@ -1571,7 +1571,7 @@ static int __init dm_mirror_init(void) }INIT_WORK (&_kmirrord_work, do_work,NULL ); - _kmir_mon_wq =create_workqueue ("kmir_mon" ); + _kmir_mon_wq =create_singlethread_workqueue ("kmir_mon" );if (!_kmir_mon_wq) {DMERR ("couldn't start kmir_mon" );dm_dirty_log_exit ();