linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Schmitt <scdbackup@gmx.net>
To: linux-scsi@vger.kernel.org
Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org,
	jejb@linux.ibm.com, martin.petersen@oracle.com,
	Thomas Schmitt <scdbackup@gmx.net>
Subject: [PATCH 2/2] sr: fix automatic tray loading for data reading
Date: Tue,  8 Sep 2020 14:02:07 +0200	[thread overview]
Message-ID: <20200908120207.5014-3-scdbackup@gmx.net> (raw)
In-Reply-To: <20200908120207.5014-1-scdbackup@gmx.net>

If
  open("/dev/sr0", O_RDONLY);
pulls in the tray of an optical drive, it immediately returns -1 with
errno ENOMEDIUM or the first read(2) fails with EIO. Later, when the drive
has stopped blinking, another open() yields success and read() works.
This affects not only userland reading of the device file but also
mounting the device.
The reason is that medium assessment happens before automatic tray
loading.

Use the new function cdrom_handle_open_tray() for deciding and performing
tray loading before doing medium assessment.

Signed-off-by: Thomas Schmitt <scdbackup@gmx.net>
---
 drivers/scsi/sr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 3b3a53c6a0de..cf06afffcb56 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -529,11 +529,16 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)

 	sdev = cd->device;
 	scsi_autopm_get_device(sdev);
-	check_disk_change(bdev);

 	mutex_lock(&cd->lock);
-	ret = cdrom_open(&cd->cdi, bdev, mode);
+	ret = cdrom_handle_open_tray(&cd->cdi, mode, 0);
 	mutex_unlock(&cd->lock);
+	if (!ret) {
+		check_disk_change(bdev);
+		mutex_lock(&cd->lock);
+		ret = cdrom_open(&cd->cdi, bdev, mode);
+		mutex_unlock(&cd->lock);
+	}

 	scsi_autopm_put_device(sdev);
 	if (ret)
--
2.20.1


      parent reply	other threads:[~2020-09-08 18:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 12:02 [PATCH 0/2] Fix automatic CD tray loading for data reading via sr Thomas Schmitt
2020-09-08 12:02 ` [PATCH 1/2] cdrom: delegate automatic CD tray loading to callers of cdrom_open() Thomas Schmitt
2020-09-08 12:02 ` Thomas Schmitt [this message]

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=20200908120207.5014-3-scdbackup@gmx.net \
    --to=scdbackup@gmx.net \
    --cc=axboe@kernel.dk \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).