Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp849993ybg; Wed, 23 Oct 2019 06:47:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSfbjY3Z9KB1tqTWvtY8GIyDrWD+1ZBfloO7RWEZX9ypNjKEGE5rJwCE8lhhyVx7BsAbbr X-Received: by 2002:a50:8871:: with SMTP id c46mr19096550edc.24.1571838420886; Wed, 23 Oct 2019 06:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571838420; cv=none; d=google.com; s=arc-20160816; b=x9hiPISlAS5SG7vGjsO6N1ebjlInkHtIRaNXjIijU6VBQq9bXfa6Ma9G2AmMs2tGEx FvifIp1kPUpD08jJW86RJ+9k0+Mb5eLdBKfjdn+UabkdT/rTDHurXT+5vwfE5tP5qxFU fVvtlm3Aqi1BKA71Hb3X5/dpv977agPldlfdBq4+d4qCdL4P0hy2AZVyZuClbnyzXuhV Cwo0JyLVdmyl2rEDzMKAjXeMP2YTNmV/E6XD6uM4/pbgyQqActw5o+851xkyYi7H8H/p cdgegnhfNAAnIl8g/Mt6XGuE3Aurh3pgyzYjyFqbeYZdjYgDXySE2K5j30dk/Y+72ZIK mKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+umbuClURffut67moZnMknYN4AK75iquFxylOSaN3Hw=; b=aeZE/rQ7eQbCo2WH/a2TvyweYufpzi3tYAv6tW1dLj6vynTXnEqIIVcv7vH2ZOBPRo aU9KzcIfLhRHukwWNGqZP8cDcWIp6nUE8ls3B4vrU5dXMtHl8QoJqAfNP+yk0qQKsIsa 81DXP1MaJyMbb+2sUYlyVROPQB1lwqO9ZG1klK87vVb35cDltbgR9l4ZNjP3t3XGMU1R +yjlsGsrJEZXTDmruOzyggnDzlNj1S7EMepHYr7H0UHjDiJan07+A6EZDWh7LduguBri rDdlW5odrXY9LYIjFS5oMRm1bWXNP070gZtEXROcHX0Ayu2Km0yk4/8AjfP66TdKPoLl cLKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c26si15314914edx.353.2019.10.23.06.46.36; Wed, 23 Oct 2019 06:47:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391902AbfJWMxS (ORCPT + 99 others); Wed, 23 Oct 2019 08:53:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:49342 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391871AbfJWMxQ (ORCPT ); Wed, 23 Oct 2019 08:53:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D14C3B676; Wed, 23 Oct 2019 12:53:10 +0000 (UTC) From: Michal Suchanek To: linux-scsi@vger.kernel.org Cc: Michal Suchanek , Jonathan Corbet , Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Mauro Carvalho Chehab , Eric Biggers , "J. Bruce Fields" , Benjamin Coddington , Hannes Reinecke , Omar Sandoval , Ming Lei , Damien Le Moal , Bart Van Assche , Tejun Heo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/8] cdrom: wait for the tray to close Date: Wed, 23 Oct 2019 14:52:42 +0200 Message-Id: <1696675e9998df6eee537908903628abf666e3fd.1571834862.git.msuchanek@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The scsi command to close the tray only starts the motor and does not wait for the tray to close. Wait until the state chages from TRAY_OPEN so users do not race with the tray closing. This looks like inifinte wait but unless the drive is broken it either closes the tray shortly or reports an error when it detects the tray is blocked. At worst the wait can be interrupted by the user. Also wait for the drive to become ready once the tray closes. Signed-off-by: Michal Suchanek --- v2: - check drive_status exists before using it - rename tray_close -> cdrom_tray_close - also wait for drive to become ready after tray closes - do not wait in cdrom_ioctl_closetray --- drivers/cdrom/cdrom.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index f504ca70f93f..c0fc9a02b70c 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -1045,6 +1045,18 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks) tracks->cdi, tracks->xa); } +static int cdrom_tray_close(struct cdrom_device_info *cdi) +{ + int ret; + + ret = cdi->ops->tray_move(cdi, 0); + if (ret || !cdi->ops->drive_status) + return ret; + + return poll_event_interruptible(CDS_TRAY_OPEN != + cdi->ops->drive_status(cdi, CDSL_CURRENT), 500); +} + static int open_for_common(struct cdrom_device_info *cdi, tracktype *tracks) { @@ -1063,7 +1075,9 @@ int open_for_common(struct cdrom_device_info *cdi, tracktype *tracks) 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); + ret = cdrom_tray_close(cdi); + if (ret == -ERESTARTSYS) + return ret; if (ret) { cd_dbg(CD_OPEN, "bummer. tried to close the tray but failed.\n"); /* Ignore the error from the low @@ -1086,6 +1100,15 @@ int open_for_common(struct cdrom_device_info *cdi, tracktype *tracks) } cd_dbg(CD_OPEN, "the tray is now closed\n"); } + /* the door should be closed now, check for the disc */ + if (ret == CDS_DRIVE_NOT_READY) { + int poll_res = poll_event_interruptible( + CDS_DRIVE_NOT_READY != + (ret = cdo->drive_status(cdi, CDSL_CURRENT)), + 500); + if (poll_res == -ERESTARTSYS) + return poll_res; + } if (ret != CDS_DISC_OK) return -ENOMEDIUM; } -- 2.23.0