aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm.c
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2009-04-02 14:55:39 -0400
committerAlasdair G Kergon <agk@redhat.com>2009-04-02 14:55:39 -0400
commitb44ebeb017b8a5fe5439e1259708b68cf83a8921 (patch)
treeea138d44aa80302002b3e67cd6049a18c2302734 /drivers/md/dm.c
parent022c261100e15652d720395b17ce76304fb2f97f (diff)
dm: move wait queue declaration
Move wait queue declaration and unplug to dm_wait_for_completion. The purpose is to minimize duplicate code in the further patches. The patch reorders functions a little bit. It doesn't change any functionality. For proper non-deadlock operation, add_wait_queue must happen before set_current_state(interruptible) and before the test for !atomic_read(&md->pending). Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r--drivers/md/dm.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f5703727d974..7867d905ff89 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1377,6 +1377,11 @@ EXPORT_SYMBOL_GPL(dm_put);
1377static int dm_wait_for_completion(struct mapped_device *md, int interruptible) 1377static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
1378{ 1378{
1379 int r = 0; 1379 int r = 0;
1380 DECLARE_WAITQUEUE(wait, current);
1381
1382 dm_unplug_all(md->queue);
1383
1384 add_wait_queue(&md->wait, &wait);
1380 1385
1381 while (1) { 1386 while (1) {
1382 set_current_state(interruptible); 1387 set_current_state(interruptible);
@@ -1395,6 +1400,8 @@ static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
1395 } 1400 }
1396 set_current_state(TASK_RUNNING); 1401 set_current_state(TASK_RUNNING);
1397 1402
1403 remove_wait_queue(&md->wait, &wait);
1404
1398 return r; 1405 return r;
1399} 1406}
1400 1407
@@ -1501,7 +1508,6 @@ static void unlock_fs(struct mapped_device *md)
1501int dm_suspend(struct mapped_device *md, unsigned suspend_flags) 1508int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1502{ 1509{
1503 struct dm_table *map = NULL; 1510 struct dm_table *map = NULL;
1504 DECLARE_WAITQUEUE(wait, current);
1505 int r = 0; 1511 int r = 0;
1506 int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0; 1512 int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
1507 int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0; 1513 int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
@@ -1551,20 +1557,14 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1551 down_write(&md->io_lock); 1557 down_write(&md->io_lock);
1552 set_bit(DMF_BLOCK_IO, &md->flags); 1558 set_bit(DMF_BLOCK_IO, &md->flags);
1553 1559
1554 add_wait_queue(&md->wait, &wait);
1555 up_write(&md->io_lock); 1560 up_write(&md->io_lock);
1556 1561
1557 /* unplug */
1558 if (map)
1559 dm_table_unplug_all(map);
1560
1561 /* 1562 /*
1562 * Wait for the already-mapped ios to complete. 1563 * Wait for the already-mapped ios to complete.
1563 */ 1564 */
1564 r = dm_wait_for_completion(md, TASK_INTERRUPTIBLE); 1565 r = dm_wait_for_completion(md, TASK_INTERRUPTIBLE);
1565 1566
1566 down_write(&md->io_lock); 1567 down_write(&md->io_lock);
1567 remove_wait_queue(&md->wait, &wait);
1568 1568
1569 if (noflush) 1569 if (noflush)
1570 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); 1570 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);