public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kevin Corry <kevcorry@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] 3/5: dm-ioctl: replace dm_[add|remove]_wait_queue() with dm_wait_event()
Date: Wed, 26 May 2004 11:58:57 -0500	[thread overview]
Message-ID: <200405261158.57176.kevcorry@us.ibm.com> (raw)
In-Reply-To: <200405261152.33233.kevcorry@us.ibm.com>

Replace dm_[add|remove]_wait_queue() with dm_wait_event().

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().

--- diff/drivers/md/dm-ioctl.c	2004-05-25 10:13:20.000000000 -0500
+++ source/drivers/md/dm-ioctl.c	2004-05-25 10:13:51.000000000 -0500
@@ -850,7 +850,6 @@
 	int r;
 	struct mapped_device *md;
 	struct dm_table *table;
-	DECLARE_WAITQUEUE(wq, current);
 
 	md = find_device(param);
 	if (!md)
@@ -859,12 +858,10 @@
 	/*
 	 * Wait for a notification event
 	 */
-	set_current_state(TASK_INTERRUPTIBLE);
-	if (!dm_add_wait_queue(md, &wq, param->event_nr)) {
-		schedule();
-		dm_remove_wait_queue(md, &wq);
+	if (dm_wait_event(md, param->event_nr)) {
+		r = -ERESTARTSYS;
+		goto out;
 	}
- 	set_current_state(TASK_RUNNING);
 
 	/*
 	 * The userland program is going to want to know what
--- diff/drivers/md/dm.c	2004-05-25 10:13:41.000000000 -0500
+++ source/drivers/md/dm.c	2004-05-25 10:13:51.000000000 -0500
@@ -80,7 +80,7 @@
 	/*
 	 * Event handling.
 	 */
-	uint32_t event_nr;
+	atomic_t event_nr;
 	wait_queue_head_t eventq;
 
 	/*
@@ -685,6 +685,7 @@
 	init_rwsem(&md->lock);
 	rwlock_init(&md->map_lock);
 	atomic_set(&md->holders, 1);
+	atomic_set(&md->event_nr, 0);
 
 	md->queue = blk_alloc_queue(GFP_KERNEL);
 	if (!md->queue)
@@ -754,10 +755,8 @@
 {
 	struct mapped_device *md = (struct mapped_device *) context;
 
-	down_write(&md->lock);
-	md->event_nr++;
+	atomic_inc(&md->event_nr);;
 	wake_up(&md->eventq);
-	up_write(&md->lock);
 }
 
 static void __set_size(struct gendisk *disk, sector_t size)
@@ -1055,35 +1054,13 @@
  *---------------------------------------------------------------*/
 uint32_t dm_get_event_nr(struct mapped_device *md)
 {
-	uint32_t r;
-
-	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;
+	return atomic_read(&md->event_nr);
 }
 
-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);
-	remove_wait_queue(&md->eventq, wq);
-	up_write(&md->lock);
+	return wait_event_interruptible(md->eventq,
+			(event_nr != atomic_read(&md->event_nr)));
 }
 
 /*
--- diff/drivers/md/dm.h	2004-05-09 21:32:29.000000000 -0500
+++ source/drivers/md/dm.h	2004-05-25 10:13:51.000000000 -0500
@@ -81,9 +81,7 @@
  * Event functions.
  */
 uint32_t dm_get_event_nr(struct mapped_device *md);
-int dm_add_wait_queue(struct mapped_device *md, wait_queue_t *wq,
-		      uint32_t event_nr);
-void dm_remove_wait_queue(struct mapped_device *md, wait_queue_t *wq);
+int dm_wait_event(struct mapped_device *md, int event_nr);
 
 /*
  * Info functions.

  parent reply	other threads:[~2004-05-26 17:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-26 16:52 [PATCH] 0/5: Device-Mapper bug-fixes and cleanups Kevin Corry
2004-05-26 16:58 ` [PATCH] 1/5: dm-ioctl.c: fix off-by-one error Kevin Corry
2004-05-26 16:58 ` [PATCH] 2/5: dm.c: free cloned bio on error path Kevin Corry
2004-05-26 16:58 ` Kevin Corry [this message]
2004-05-26 16:59 ` [PATCH] 4/5: dm: add static and __init qualifiers Kevin Corry
2004-05-26 16:59 ` [PATCH] 5/5: dm-table.c: proper usage of dm_vcalloc Kevin Corry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200405261158.57176.kevcorry@us.ibm.com \
    --to=kevcorry@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox