Commit 52414318 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] dm-ioctl: replace dm_[add|remove]_wait_queue() with dm_wait_event()

From: Kevin Corry <kevcorry@us.ibm.com>

Some testing of DM multipath has turned up a problem with the DEVICE_WAIT
command.  In the tests, while performing a DEVICE_WAIT on a multipath device,
the command sometimes returns immediately, even though the event-number is
correct and no path-failure has occurred to trigger an event.  The problem was
tracked down to the call to schedule() in dev_wait(), which would return even
though it was not woken up by a DM table event.

This patch moves the responsibility for waiting from the ioctl interface into
the core driver, and uses wait_event_interruptible() instead of relying on
wait-queues and schedule().
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0f76498d
...@@ -850,7 +850,6 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size) ...@@ -850,7 +850,6 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
int r; int r;
struct mapped_device *md; struct mapped_device *md;
struct dm_table *table; struct dm_table *table;
DECLARE_WAITQUEUE(wq, current);
md = find_device(param); md = find_device(param);
if (!md) if (!md)
...@@ -859,12 +858,10 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size) ...@@ -859,12 +858,10 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
/* /*
* Wait for a notification event * Wait for a notification event
*/ */
set_current_state(TASK_INTERRUPTIBLE); if (dm_wait_event(md, param->event_nr)) {
if (!dm_add_wait_queue(md, &wq, param->event_nr)) { r = -ERESTARTSYS;
schedule(); goto out;
dm_remove_wait_queue(md, &wq);
} }
set_current_state(TASK_RUNNING);
/* /*
* The userland program is going to want to know what * The userland program is going to want to know what
......
...@@ -80,7 +80,7 @@ struct mapped_device { ...@@ -80,7 +80,7 @@ struct mapped_device {
/* /*
* Event handling. * Event handling.
*/ */
uint32_t event_nr; atomic_t event_nr;
wait_queue_head_t eventq; wait_queue_head_t eventq;
/* /*
...@@ -685,6 +685,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -685,6 +685,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
init_rwsem(&md->lock); init_rwsem(&md->lock);
rwlock_init(&md->map_lock); rwlock_init(&md->map_lock);
atomic_set(&md->holders, 1); atomic_set(&md->holders, 1);
atomic_set(&md->event_nr, 0);
md->queue = blk_alloc_queue(GFP_KERNEL); md->queue = blk_alloc_queue(GFP_KERNEL);
if (!md->queue) if (!md->queue)
...@@ -754,10 +755,8 @@ static void event_callback(void *context) ...@@ -754,10 +755,8 @@ static void event_callback(void *context)
{ {
struct mapped_device *md = (struct mapped_device *) context; struct mapped_device *md = (struct mapped_device *) context;
down_write(&md->lock); atomic_inc(&md->event_nr);;
md->event_nr++;
wake_up(&md->eventq); wake_up(&md->eventq);
up_write(&md->lock);
} }
static void __set_size(struct gendisk *disk, sector_t size) static void __set_size(struct gendisk *disk, sector_t size)
...@@ -1055,35 +1054,13 @@ int dm_resume(struct mapped_device *md) ...@@ -1055,35 +1054,13 @@ int dm_resume(struct mapped_device *md)
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
uint32_t dm_get_event_nr(struct mapped_device *md) uint32_t dm_get_event_nr(struct mapped_device *md)
{ {
uint32_t r; return atomic_read(&md->event_nr);
down_read(&md->lock);
r = md->event_nr;
up_read(&md->lock);
return r;
}
int dm_add_wait_queue(struct mapped_device *md, wait_queue_t *wq,
uint32_t event_nr)
{
down_write(&md->lock);
if (event_nr != md->event_nr) {
up_write(&md->lock);
return 1;
}
add_wait_queue(&md->eventq, wq);
up_write(&md->lock);
return 0;
} }
void dm_remove_wait_queue(struct mapped_device *md, wait_queue_t *wq) int dm_wait_event(struct mapped_device *md, int event_nr)
{ {
down_write(&md->lock); return wait_event_interruptible(md->eventq,
remove_wait_queue(&md->eventq, wq); (event_nr != atomic_read(&md->event_nr)));
up_write(&md->lock);
} }
/* /*
......
...@@ -81,9 +81,7 @@ struct dm_table *dm_get_table(struct mapped_device *md); ...@@ -81,9 +81,7 @@ struct dm_table *dm_get_table(struct mapped_device *md);
* Event functions. * Event functions.
*/ */
uint32_t dm_get_event_nr(struct mapped_device *md); uint32_t dm_get_event_nr(struct mapped_device *md);
int dm_add_wait_queue(struct mapped_device *md, wait_queue_t *wq, int dm_wait_event(struct mapped_device *md, int event_nr);
uint32_t event_nr);
void dm_remove_wait_queue(struct mapped_device *md, wait_queue_t *wq);
/* /*
* Info functions. * Info functions.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment