From patchwork Tue Oct 6 09:40:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Schmitt X-Patchwork-Id: 11818369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F0B76CB for ; Tue, 6 Oct 2020 09:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE5F4206F7 for ; Tue, 6 Oct 2020 09:43:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=gmx.net header.i=@gmx.net header.b="BLwfFik8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbgJFJnO (ORCPT ); Tue, 6 Oct 2020 05:43:14 -0400 Received: from mout.gmx.net ([212.227.17.22]:36701 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbgJFJnK (ORCPT ); Tue, 6 Oct 2020 05:43:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1601977379; bh=GDqZvLHFHyBlYJw8l9bRGc++uPRpcU3Nor7kkfioIFQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BLwfFik80p5AksROUSKurPLh7IAuAvJ1ZOpl938bd4m0oAhddCOzrcSmBCbVkzsOF mMtdkgRoDazuVewKjm2SCLRialE2dkrwd/NHMoeDQf0MOFhakz+TrhNwobmEsEKKoP 4Iv60QFScDxl9px/kzpWb3ZSfTiCE58+GQvxUF5o= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from ts7.local ([91.8.173.95]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MfHEJ-1ktGtU0Gkt-00gmR3; Tue, 06 Oct 2020 11:42:59 +0200 From: Thomas Schmitt 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 Subject: [PATCH v2 1/2] cdrom: delegate automatic CD tray loading to callers of cdrom_open() Date: Tue, 6 Oct 2020 11:40:25 +0200 Message-Id: <20201006094026.1730-2-scdbackup@gmx.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201006094026.1730-1-scdbackup@gmx.net> References: <20201006094026.1730-1-scdbackup@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:vlHcON2E3P4q3nSfVlLS2ubdHMbDBcNtQxLwnpjBPvu1KgfoOpY /2IvL0qsLthPXmOnUD+oi0nq0p3s/qJk2wosffB+pjxNO7FZl9SsgqxMZtzjKrdWOM7PvG3 9awFscxzBlKE0k8gaXBkst37misIjLWDUqTrL8BAZ/HNh6BQdDuoQgtKem7By6mCjmpNxXI pyE57Orj/8/zuGbFuglkA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:7M6p5R/qggM=:1cGjnQuRlW4kFtIfKci4Wo sjxVrK21VrxkvgWCaSTPsytPyo+78R7fjBNQTPhr9ESMJ2A1HOQpvWAxdBJfY0U8D2JmPky7z eq09b2Pf2SiXHHPrvfGhS1Y0526LrsftH0ksyTtMsBJ6diHGI79SQYzmi4mqESTkyXfGkJtDj VN5BrQGym7hyr8o5zBP7ZrsISVy78XQ3Q1HXI/kehnvw9iyUPzG/kMJob72jANkgm9phf93rb qRJ6AfhPE0uLHHuemGDKkDXekUdCzX5DHipl0GPUyRcpwO/95gt4WQy63GSAyhJ88wY09RBD0 t7cYxszQGDc3XDmy+vDC1ZqX/MevLCtX6qXT+4fjDZCCwGn1b0i1ylnuYXiAMw7S9rppyMEeb R5D9OOWnRbcCEgKIe+b3F+feIdERwWU9p9PUNGJ+oSXQCJo+MOuvufch4C/T4DkzFAOyrFNkS 5bdWCtWpujt02Nv0vfmlPf2if2aZ9jdRoHvlSyM/2iTv/erjk8+bAeQAcxyOW5gJzlzrCA53W 1U2+G2P/KIjeNkM2MvSf5y2KkGMsu141gBQA1b2nLSC1tvGntk9KLnxPUEUxOW6WyuN9D6XWZ cuyHec6iHQKeENadgyv8Oc2as6SVaI0cop7zUPZ4UE9lRswz4axyACW6XaXtbIzKj4l136nj4 Viwy/bcNIqs+W5EKyIo4pJjiVpkOPZ0Voo3eSBFCZhMHvnLLqD5eclv0GCGq2Uu+wlnlHuIw8 dRXe/XILLFv9XTk9D/BjWdGnZYl4wayys7PjjcHPJ85RZxfr47lRnx6zzREa+Afz11k6rzdcy mt7BiYutZzH1AMHZwWThrMa5pQNFMGgofCjsXcMIvflJ2QdE8qkfaLdugXTwB8Yds6V0t8dA9 f3ytILr7gm15lQTwGMtjaLa/QJQv7dxLEd2ZyyjtcR5Nap0lgzhBMPcGemCoReb1LyAgBBpR+ 9vrWdyrkmuId9lTUchhdo9bs8seqELv7D8bUaUV6qhBjyRpSKarwV2dkpB6fJh0o1F+o+PVg5 9R43xAmnJMO0zpOIfVI7zLLpYfnLYZ02yl1tHTbcUb5FsVAGBce/ClFkA03OdzJrFHsmYiSAx b1DRN96byjpf1MogtoVjjWKgPjd+nLwFAk+vbzJ5tVFgHPK5+5Ux8rW322oaOUkIjcx9Y6m2M ur9KCrPXzhYiUc7ALHtRTWEGVnvzdCOCuqHC42yb9+D1Jb/GKmjWH60CYn6QgnOWgGuasRoT4 fzXfa8I6JNaTWdF4EvjLhfGwPL9f2DjqlI7wuPA== Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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. Since commit 210ba1d1724f ("[SCSI] sr: update to follow tray status correctly") of january 2008 the necessary waiting loop after emitting the tray loading command is not performed, because sr_do_ioctl() is not called any more. Commit 2bbea6e11735 ("cdrom: do not call check_disk_change() inside cdrom_open()") of march 2008 moved medium assessment out of cdrom_open() and thus inevitable before automatic tray loading. Factor out a new function cdrom_handle_open_tray() in cdrom.c from open_for_data() and export it, so that callers of cdrom_open() can call it before their call of check_disk_change(). It decides whether it can and should load the tray. If so, it emits the tray loading command and waits for the drive to make its decision. Replace automatic tray loading in cdrom_open() by a mere check whether the drive reports a usable medium in a loaded tray. Unaware callers of cdrom_open() will not cause automatic tray loading any more, but rather will reliably see -ENOMEDIUM if the tray is open. Signed-off-by: Thomas Schmitt --- drivers/cdrom/cdrom.c | 173 +++++++++++++++++++++++++++++++----------- include/linux/cdrom.h | 3 + 2 files changed, 132 insertions(+), 44 deletions(-) -- 2.20.1 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 0c271b9e3c5b..45bfe76129ef 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -286,6 +286,18 @@ #include #include +/* + * For the wait-and-retry loop after possibly having loaded the drive tray. + * 10 retries in 20 seconds are hardcoded in sr_do_ioctl() which was used + * up to 2008. + * But time spans up to 25 seconds were measured by libburn on + * drives connected via SATA or USB-SATA bridges. + * So 20 retries * 2000 ms = 40 seconds seems more appropriate. + */ +#define CD_OPEN_MEDIUM_RETRY_MAX 20 +#define CD_OPEN_MEDIUM_RETRY_MSLEEP 2000 +#include + /* used to tell the module to turn on full debugging messages */ static bool debug; /* default compatibility mode */ @@ -1040,6 +1052,114 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks) tracks->cdi, tracks->xa); } +static +int wait_for_medium_decision(struct cdrom_device_info *cdi) +{ + int retry = 0, ret; + const struct cdrom_device_ops *cdo = cdi->ops; + + /* Wait until the intermediate drive status CDS_DRIVE_NOT_READY ends */ + while (1) { + ret = cdo->drive_status(cdi, CDSL_CURRENT); + if (ret == CDS_DRIVE_NOT_READY && + retry++ < CD_OPEN_MEDIUM_RETRY_MAX) + msleep(CD_OPEN_MEDIUM_RETRY_MSLEEP); + else + break; + } + if (ret != CDS_DISC_OK) + return ret; + /* + * It is hard to test whether very recent readiness can cause race + * conditions with media change events. So wait a while to never + * undercut the average delay between actual readiness and detection + * which was tested without this additional msleep(). + */ + msleep(CD_OPEN_MEDIUM_RETRY_MSLEEP / 2); + + return CDS_DISC_OK; +} + +/* + * To be called by expectant callers of cdrom_open(), before they call + * check_disk_change() and then cdrom_open(). + * + * If the mode is right, the drive capable, the tray out, and autoclose + * enabled, try to move in the tray and wait for the drive's decision about + * the medium. + * Return 0 if cdrom_open() would not want to know the tray status, or the + * drive cannot report its tray status at all, or the decision is CDS_DISC_OK. + * Else return a negative error number. + * Input parameter mode decides whether cdrom_open() will want to know or + * change the tray status at all. + * Input parameter leave_open == 1 suppresses the try to close and the waiting + * for a decision. It rather just assesses the situation. Submit mode == 0 + * to not hamper assessment. + */ +int cdrom_handle_open_tray(struct cdrom_device_info *cdi, fmode_t mode, + int leave_open) +{ + int ret; + const struct cdrom_device_ops *cdo = cdi->ops; + + if ((mode & FMODE_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) + return 0; + if (!cdo->drive_status) + return 0; + + ret = cdo->drive_status(cdi, CDSL_CURRENT); + cd_dbg(CD_OPEN, "drive_status=%d\n", ret); + if (ret == CDS_DRIVE_NOT_READY) { + /* Probably some other entity is loading the tray */ + if (leave_open) + return -ENOMEDIUM; + wait_for_medium_decision(cdi); + goto assess_and_return; + } + if (ret != CDS_TRAY_OPEN) + goto assess_and_return; + + cd_dbg(CD_OPEN, "the tray is open...\n"); + if (leave_open) + return -ENOMEDIUM; + /* can/may i close it? */ + if (CDROM_CAN(CDC_CLOSE_TRAY) && cdi->options & CDO_AUTO_CLOSE) { + cd_dbg(CD_OPEN, "trying to close the tray\n"); + ret = cdo->tray_move(cdi, 0); + if (ret) { + cd_dbg(CD_OPEN, + "bummer. tried to close the tray but failed.\n"); + /* Ignore the error from the low + * level driver. We don't care why it + * couldn't close the tray. We only care + * that there is no disc in the drive, + * since that is the _REAL_ problem here. + */ + return -ENOMEDIUM; + } + } else { + if (!CDROM_CAN(CDC_CLOSE_TRAY)) + cd_dbg(CD_OPEN, + "bummer. this drive can't close the tray.\n"); + return -ENOMEDIUM; + } + + ret = wait_for_medium_decision(cdi); + if (ret == CDS_NO_DISC || ret == CDS_TRAY_OPEN) { + cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n"); + cd_dbg(CD_OPEN, "tray might not contain a medium\n"); + return -ENOMEDIUM; + } + cd_dbg(CD_OPEN, "the tray is now closed\n"); + +assess_and_return: + ret = cdo->drive_status(cdi, CDSL_CURRENT); + if (ret != CDS_DISC_OK) + return -ENOMEDIUM; + return 0; +} +EXPORT_SYMBOL(cdrom_handle_open_tray); + static int open_for_data(struct cdrom_device_info *cdi) { @@ -1047,50 +1167,15 @@ int open_for_data(struct cdrom_device_info *cdi) const struct cdrom_device_ops *cdo = cdi->ops; tracktype tracks; cd_dbg(CD_OPEN, "entering open_for_data\n"); - /* Check if the driver can report drive status. If it can, we - can do clever things. If it can't, well, we at least tried! */ - if (cdo->drive_status != NULL) { - ret = cdo->drive_status(cdi, CDSL_CURRENT); - cd_dbg(CD_OPEN, "drive_status=%d\n", ret); - if (ret == CDS_TRAY_OPEN) { - cd_dbg(CD_OPEN, "the tray is open...\n"); - /* can/may i close it? */ - if (CDROM_CAN(CDC_CLOSE_TRAY) && - cdi->options & CDO_AUTO_CLOSE) { - cd_dbg(CD_OPEN, "trying to close the tray\n"); - ret=cdo->tray_move(cdi,0); - if (ret) { - cd_dbg(CD_OPEN, "bummer. tried to close the tray but failed.\n"); - /* Ignore the error from the low - level driver. We don't care why it - couldn't close the tray. We only care - that there is no disc in the drive, - since that is the _REAL_ problem here.*/ - ret=-ENOMEDIUM; - goto clean_up_and_return; - } - } else { - cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n"); - ret=-ENOMEDIUM; - goto clean_up_and_return; - } - /* Ok, the door should be closed now.. Check again */ - ret = cdo->drive_status(cdi, CDSL_CURRENT); - if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) { - cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n"); - cd_dbg(CD_OPEN, "tray might not contain a medium\n"); - ret=-ENOMEDIUM; - goto clean_up_and_return; - } - cd_dbg(CD_OPEN, "the tray is now closed\n"); - } - /* the door should be closed now, check for the disc */ - ret = cdo->drive_status(cdi, CDSL_CURRENT); - if (ret!=CDS_DISC_OK) { - ret = -ENOMEDIUM; - goto clean_up_and_return; - } - } + + /* + * Check for open tray, but do not close it. The caller should + * have cared to call cdrom_handle_open_tray(,,0) in advance. + */ + ret = cdrom_handle_open_tray(cdi, (fmode_t)0, 1); + if (ret) + goto clean_up_and_return; + cdrom_count_tracks(cdi, &tracks); if (tracks.error == CDS_NO_DISC) { cd_dbg(CD_OPEN, "bummer. no disc.\n"); diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h index f48d0a31deae..cf2b5fc9c6fd 100644 --- a/include/linux/cdrom.h +++ b/include/linux/cdrom.h @@ -98,6 +98,9 @@ int cdrom_multisession(struct cdrom_device_info *cdi, int cdrom_read_tocentry(struct cdrom_device_info *cdi, struct cdrom_tocentry *entry); +int cdrom_handle_open_tray(struct cdrom_device_info *cdi, fmode_t mode, + int leave_open); + /* the general block_device operations structure: */ extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, fmode_t mode); From patchwork Tue Oct 6 09:40:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Schmitt X-Patchwork-Id: 11818367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5846C6CA for ; Tue, 6 Oct 2020 09:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22640206B5 for ; Tue, 6 Oct 2020 09:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=gmx.net header.i=@gmx.net header.b="RJNbDXt2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726064AbgJFJnJ (ORCPT ); Tue, 6 Oct 2020 05:43:09 -0400 Received: from mout.gmx.net ([212.227.17.20]:51189 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbgJFJnJ (ORCPT ); Tue, 6 Oct 2020 05:43:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1601977381; bh=MRG/DidZTMAP3s/IKygvp2ugxJn5R6bJa+RqDMprr3A=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=RJNbDXt2g4hh29Zl7x8j5rFscE1YFwWtvw53aiaHjw7P+lC/cmJu0Kc1/SMgBg5ie WLLlspcuHC6fTZhryPL1rpJuRZq+axnMm9qizK+6dW6boXvYV9rtvl/UjaOxXODjIY 3d3lgrk5l9p8T0Ze5g5YGDuz7lZNru34hbUoHPIc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from ts7.local ([91.8.173.95]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MbAci-1kwrOO3hzk-00bXEk; Tue, 06 Oct 2020 11:43:00 +0200 From: Thomas Schmitt 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 Subject: [PATCH v2 2/2] sr: fix automatic tray loading for data reading Date: Tue, 6 Oct 2020 11:40:26 +0200 Message-Id: <20201006094026.1730-3-scdbackup@gmx.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201006094026.1730-1-scdbackup@gmx.net> References: <20201006094026.1730-1-scdbackup@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:l6ieuFgGsYKG0hE/t+kPEvA27KMQa7HUegLkrn6XgsyAYX3WwjC DhexRajTu/N89hanWQRi0GRynj8P0alW0hVBwrdWS+AMITo8iAu7tj1gVvYHz/UyqN+uBTi sYUYJsakyq2l2yzOSZX3kBku7+CrTzrxHh0iElUNUJHzSshBIvTII6X6uyX5d+Me6i/90ww 3m5qmAs6TmvMplmrGe8Mw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:RYa96kB+0ww=:w/pmmUVibN6OGtyT+mpzkK uML4P15EonK3MCzgl5GcAgkiP98lMqCcchlxNSZVlOv5d0byxJqlLRTHoV5Ej0fMsPooNistW b1w9wCTQKAvD+lfzwz5ZbszjbVe+HRI2Ant1ao2EqsS0Lvjv4f1Y2Zzb8Rqbqsg9TSROWweDS gUGP4iMBuJ1rI3Y6CAVjtj+8cp5NgXC/L3ptNqtFOc8yz36gikT0roI0jLq8qnnyZ3cOi6mFx Y8k39ipnyLSiyyDsZny1BpMaOyKkL7GhiR2naU9qbWmZMPLjRcfApAA2GkHswNHkk7mN5IQ9G 0ePgjx9mIUZA/GquUUvRABd4w9MvVHGBhg8IB9iblbu+vaEruOE2bOVcp5L8xsOYHuf+3hjxY 2RkcOTjjE/4rKOYcC7xFj81n31gRo5O8DEkEa8iVxOXWfVJDr++pw/D/t2s3zQiH+LcPyc5S2 99QoX/kDc7D7uyIJF8FmhgGaswDiix4UY8jSqoyiDZUU49VXalDWXnux4BcynYQ1cF4biNKFx Q68vffQ7aW/6i0gN5muXfMsUcDVDoAJ4J8PyBThZnzuPdRaoJiahF5g2i43OjMkI8IbHdhTP3 N7+mRlv/1sJ2Tk4NOa9i6y1Ao2kdK/tHK+CYo/vtiHdjZI13K6BaB72JXT2b/r97IcExDS8oc Z8ajzlTaIbVspRwyKizK7mdGOzsP2FLYCkd33iLWWJljun7NKmLR09A18KVbGUDzT3QIR7HtN MMP1MjIpPwOyUzYF7dF6BCO8eXHaWOjmPWvHD4V5FJWGB9H0rHTDckI4BwOKn75oD24IkVx5h HdByxZH/1IRtIaZi7q2aMIY1uWCfWZp2/662YSJgW+3xE1yggtHqkmzUcZ1rjB59+y8eeKr48 SuGS6mN1h9qsBf+p9rXDodUZo6G3VJMrUv0RddpAW74YW4HxVuaLBVfQBSKsDBt2mgZX/LKJ/ vAx3sHz2Z9Mvg+YS+g0+HLj5Ap8DB02UjoajrkbeVvLruKMDedLGeLMdWIdq9bzRhlPQuUskQ uJyYXflWjuQ0jk5JNq88cSmdIcERD9ljOedQx8YOGh1sIUavmz0KoJMAsrFlwXYmEdgmlbvDI JNeeYQa+QEaDtISWUCIjr1zy0hcVfNvxcgVgrs/ojxQC+8B8CdXezFhwFTNMjjuZu65JbO0a7 YOqhQIt5sTzSoVcmYKXQG1j9wHf6zs2CNPxspZyoQfxn7Ih6JuJjcDlX82fQs465HSxIhiqrt b9js8tcDChVQGh0d49H/H5oAgBhJeiz0Mp/mcvw== Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 --- drivers/scsi/sr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 2b43c0f97442..1c3806f59865 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -540,12 +540,18 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode) sdev = cd->device; scsi_autopm_get_device(sdev); - if (bdev_check_media_change(bdev)) - sr_revalidate_disk(cd); 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) { + if (bdev_check_media_change(bdev)) + sr_revalidate_disk(cd); + + mutex_lock(&cd->lock); + ret = cdrom_open(&cd->cdi, bdev, mode); + mutex_unlock(&cd->lock); + } scsi_autopm_put_device(sdev); if (ret)