dm: move wait queue declaration

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Friday, April 3, 2009 - 11:09 am

Gitweb:     http://git.kernel.org/linus/b44ebeb017b8a5fe5439e1259708b68cf83a8921
Commit:     b44ebeb017b8a5fe5439e1259708b68cf83a8921
Parent:     022c261100e15652d720395b17ce76304fb2f97f
Author:     Mikulas Patocka <mpatocka@redhat.com>
AuthorDate: Thu Apr 2 19:55:39 2009 +0100
Committer:  Alasdair G Kergon <agk@redhat.com>
CommitDate: Thu Apr 2 19:55:39 2009 +0100

    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>
---
 drivers/md/dm.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f570372..7867d90 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1377,6 +1377,11 @@ EXPORT_SYMBOL_GPL(dm_put);
 static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
 {
 	int r = 0;
+	DECLARE_WAITQUEUE(wait, current);
+
+	dm_unplug_all(md->queue);
+
+	add_wait_queue(&md->wait, &wait);
 
 	while (1) {
 		set_current_state(interruptible);
@@ -1395,6 +1400,8 @@ static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
 	}
 	set_current_state(TASK_RUNNING);
 
+	remove_wait_queue(&md->wait, &wait);
+
 	return r;
 }
 
@@ -1501,7 +1508,6 @@ static void unlock_fs(struct mapped_device *md)
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
 {
 	struct dm_table *map = NULL;
-	DECLARE_WAITQUEUE(wait, current);
 	int r = 0;
 	int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
 	int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
@@ -1551,20 +1557,14 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
 	down_write(&md->io_lock);
 	set_bit(DMF_BLOCK_IO, &md->flags);
 
-	add_wait_queue(&md->wait, &wait);
 	up_write(&md->io_lock);
 
-	/* unplug */
-	if (map)
-		dm_table_unplug_all(map);
-
 	/*
 	 * Wait for the already-mapped ios to complete.
 	 */
 	r = dm_wait_for_completion(md, TASK_INTERRUPTIBLE);
 
 	down_write(&md->io_lock);
-	remove_wait_queue(&md->wait, &wait);
 
 	if (noflush)
 		clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
dm: move wait queue declaration, Linux Kernel Mailing ..., (Fri Apr 3, 11:09 am)