From: Tejun Heo <tj@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Amit Shah <amit.shah@redhat.com>,
David Zeuthen <zeuthen@gmail.com>,
Martin Pitt <martin.pitt@ubuntu.com>,
Kay Sievers <kay.sievers@vrfy.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] cdrom: always check_disk_change() on open
Date: Wed, 6 Apr 2011 05:20:09 -0700 [thread overview]
Message-ID: <20110406121920.GC4142@mtj.dyndns.org> (raw)
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) {
next reply other threads:[~2011-04-06 12:20 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-06 12:20 Tejun Heo [this message]
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
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=20110406121920.GC4142@mtj.dyndns.org \
--to=tj@kernel.org \
--cc=amit.shah@redhat.com \
--cc=axboe@kernel.dk \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.pitt@ubuntu.com \
--cc=zeuthen@gmail.com \
/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
Powered by JetHome