linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cdrom: always check_disk_change() on open
@ 2011-04-06 12:20 Tejun Heo
  2011-04-06 12:22 ` [PATCH 2/2] block: rescan partitions on invalidated devices on -ENOMEDIA too Tejun Heo
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Tejun Heo @ 2011-04-06 12:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Amit Shah, David Zeuthen, Martin Pitt, Kay Sievers, linux-kernel

cdrom_open() called check_disk_change() after the rest of open path
succeeded which leads to the following bizarre behavior.

* After media change, if the device opened without O_NONBLOCK,
  open_for_data() naturally fails with -ENOMEDIA and
  check_disk_change() is never called.  The media is known to be gone
  and the open failure makes it obvious to the userland but device
  invalidation never happens.

* But if the device is opened with O_NONBLOCK, all the checks are
  bypassed and cdrom_open() doesn't notice that the media is not there
  and check_disk_change() is called and invalidation happens.

There's nothing to be gained by avoiding calling check_disk_change()
on open failure.  Common cases end up calling check_disk_change()
anyway.  All we get is inconsistent behavior.

Fix it by moving check_disk_change() invocation to the top of
cdrom_open() so that it always gets called regardless of how the rest
of open proceeds.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Amit Shah <amit.shah@redhat.com>
Tested-by: Amit Shah <amit.shah@redhat.com>
---
 drivers/cdrom/cdrom.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index e2c48a7..5ade78a 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -986,6 +986,9 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, fmode_t
 
 	cdinfo(CD_OPEN, "entering cdrom_open\n"); 
 
+	/* open is event synchronization point, check events first */
+	check_disk_change(bdev);
+
 	/* if this was a O_NONBLOCK open and we should honor the flags,
 	 * do a quick open without drive/disc integrity checks. */
 	cdi->use_count++;
@@ -1012,9 +1015,6 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, fmode_t
 
 	cdinfo(CD_OPEN, "Use count for \"/dev/%s\" now %d\n",
 			cdi->name, cdi->use_count);
-	/* Do this on open.  Don't wait for mount, because they might
-	    not be mounting, but opening with O_NONBLOCK */
-	check_disk_change(bdev);
 	return 0;
 err_release:
 	if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2011-12-19 16:44 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-06 12:20 [PATCH 1/2] cdrom: always check_disk_change() on open Tejun Heo
2011-04-06 12:22 ` [PATCH 2/2] block: rescan partitions on invalidated devices on -ENOMEDIA too Tejun Heo
2011-04-29  6:57 ` [PATCH 1/2] cdrom: always check_disk_change() on open Amit Shah
2011-04-29  8:15   ` Tejun Heo
2011-04-29  8:15   ` Jens Axboe
2011-04-29  8:16     ` Tejun Heo
2011-04-29  8:28       ` Jens Axboe
2011-05-10  6:42     ` Amit Shah
2011-05-10  7:44       ` Jens Axboe
2011-05-10  8:13         ` Amit Shah
2011-09-03 22:14 ` [regression] CD-ROM polling blocks suspend on some machines (Re: [PATCH 1/2] cdrom: always check_disk_change() on open) Jonathan Nieder
2011-09-04  2:42   ` Tejun Heo
2011-09-04 15:05     ` [regression] CD-ROM polling blocks suspend on some machines Jonathan Nieder
2011-09-05  1:49     ` [regression] CD-ROM polling blocks suspend on some machines (Re: [PATCH 1/2] cdrom: always check_disk_change() on open) Jameson Graef Rollins
2011-09-06 17:45       ` Tejun Heo
2011-09-07  8:50         ` Matthijs Kooijman
2011-09-11  4:08           ` Tejun Heo
2011-10-24 20:25             ` Gaudenz Steinlin
2011-10-26 18:26               ` Matthijs Kooijman - Brevidius
2011-10-26 22:25                 ` Tejun Heo
2011-10-28 13:47                   ` Matthijs Kooijman
2011-10-30 20:35                     ` Tejun Heo
2011-10-31  9:28                       ` Matthijs Kooijman
2011-10-31 15:26                         ` Tejun Heo
2011-12-19 11:12                           ` Matthijs Kooijman
2011-12-19 16:44                             ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).