Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4119ybg; Fri, 25 Oct 2019 15:34:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+Wx3uV9xd08LVhmQNNfvJN6Y+Dva57z3BfwfeYWrwlFloaL4RA+zn7TsSqAPeDukoAXAi X-Received: by 2002:a17:907:104c:: with SMTP id oy12mr5886177ejb.269.1572042893280; Fri, 25 Oct 2019 15:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572042893; cv=none; d=google.com; s=arc-20160816; b=bd0uPWj4BcOIsxvVizQCaaW13CDlQv37SN5B3sI8TUINv8a0eucihsWnDty0soRAvY xui+LeUElSZdOVghOKNDW2lKF78HEn21GCh+9UobhLIWhOWVkIscP1BbDJjLyCbhY4so X0NcniD8B04GSlv3tfMoAujob2jd4B6ZktJoNSpzx2NU581rRi8MZ9eKEwJG5AVUxWWQ FAcpi+yIQE6Dhg7KaaVI8cSUgJydEdILDz9UAMICIKyd5eHCh9CEClMBFkhtFNsSwsb4 pPpcwP2Cmjk6yYrAB8WT/qaVkpyLEiotKVy+5dvwMzL7GUcKMPgtFowBC96y0XMFSjnh QFiw== 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=7hbt2LDReUsIHmE82iN9xxFLVlsK9Ee4hB6Tgrw/9ww=; b=AipfZkaqgnedUdREYzcUjYMS6Kgg59nHR+mXH+4DZ23dXHATMhRRM3oHi7xjM2GqQq P/zeOBXVXmKytJZ3RQ2RthkPh5B3EbKv3mwO2T+4tyzRq3glxxsdNg6iQ3M06PRTWCx+ kbrqvsquU6nxlilA1jhWhXN4Y4wC2dbencDuExJRKRtE04BWRSCNlRDFQq+q83U0wUT/ ycIRlXLCyAIFWfHpJ1EIR9P7ok1a8DeyVeZlYFlUU9uYt15fv8IslOGiaPYrgBR2k3jR 3jR2V+HQ2pWm51WdwPSkiTO/EssSp9zFMK7dya9b0ae6houYs0/LoK0xGK3XZUThKMOa 77YA== 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 r5si2866906edi.349.2019.10.25.15.34.29; Fri, 25 Oct 2019 15:34:53 -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 S2410277AbfJYLVy (ORCPT + 99 others); Fri, 25 Oct 2019 07:21:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:56864 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726352AbfJYLVx (ORCPT ); Fri, 25 Oct 2019 07:21:53 -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 02277B286; Fri, 25 Oct 2019 11:21:51 +0000 (UTC) From: Michal Suchanek To: linux-scsi@vger.kernel.org Cc: Michal Suchanek , Christoph Hellwig , Matthew Wilcox , "Ewan D. Milne" , Jonathan Corbet , Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , "J. Bruce Fields" , Mauro Carvalho Chehab , Eric Biggers , 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 v3 3/7] cdrom: wait for the tray to close Date: Fri, 25 Oct 2019 13:21:40 +0200 Message-Id: <08202208cb9876d2d96454e6fdd89b022a0be978.1572002144.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 87db82489bf8..27f4fce22781 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) { int ret; @@ -1062,7 +1074,9 @@ static 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 @@ -1085,6 +1099,15 @@ static 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