Received: by 10.223.176.5 with SMTP id f5csp682619wra; Sat, 27 Jan 2018 07:49:16 -0800 (PST) X-Google-Smtp-Source: AH8x2251csej3GUDQu4jW44xJxz9ATYymrN4OjoiPqdBLok5oR2/abma+W5dMziL3ntcLOYdt7WP X-Received: by 10.99.114.30 with SMTP id n30mr17472253pgc.178.1517068156245; Sat, 27 Jan 2018 07:49:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517068156; cv=none; d=google.com; s=arc-20160816; b=yiDBKhUcfQzq/zGMfJE7wJ2HJIWYDoFOpdp+EHPtbzhiPRTFjqglUs7oulQozWIz6m RAH4r+LJgzcqAaJjUwUVCT+XEw1gX8WPcyuZDukDEhnvJ53goxwfPPc98rl+QKkdmsPt Qr2vUfvEGGBZPlGHaNrNWEFUSkDGrDcqrjSvjmesCu8K4pTj+PQ6knD4Wbd+oNRmiuBR Rzhcz6xe5GVBK9xRRMYfguEJcBJV53iJ1wUBBALgxa8PzFRwvY97NFA4PbkBt8hKfbhH lEQ9UK0NvdwXI8WxWJzTNUDTJIzr/gUrbDWYaVqiL9hR0NjjjB/gJ7UiMBw6bRhYkLVc 4LoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from :arc-authentication-results; bh=LsIfwrqoAX/wJHsiWNSocKlYQtw2hRouA6sE3VZJLLY=; b=EKv4Zwo1NNNfScNvdsFmpSt9i6KXaLko1m9qz0PwYBcAMd/AX3hbFEumH9oG3+ByNK hdThcytUdGYrYTWnvCcymJc1mfy7F0nXebblSHOThiAFepCBx2PR03Eqd6/C25clfF8k 5PO49MtIrE4ZXzIVyOeWgH7Tp7gLk91LNbBfQv4H3SO7OEcozEV7imnR+eet9UKlKzKW XaN2DjIiIIRnRI9GiYY9Cykqv8UAYwSguZSnpSlfSgITCjIu4VMsxT7yRBDXU/qEZaPW xAzJrj7FbSn7s+DGB1xMo0/B1gbUBKwaxm86HXpAwosocr8rWx0neZordNvEGBafquMA rLnQ== 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 p3-v6si5481107plk.275.2018.01.27.07.49.02; Sat, 27 Jan 2018 07:49:16 -0800 (PST) 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 S1753036AbeA0Psf (ORCPT + 99 others); Sat, 27 Jan 2018 10:48:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:40816 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750730AbeA0Psd (ORCPT ); Sat, 27 Jan 2018 10:48:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 024E3AE8A; Sat, 27 Jan 2018 15:41:48 +0000 (UTC) From: Michal Suchanek To: Jens Axboe , Jonathan Corbet , Borislav Petkov , Tim Waugh , "David S. Miller" , "James E.J. Bottomley" , "Martin K. Petersen" , Michal Suchanek , Kees Cook , Christophe JAILLET , Thomas Gleixner , Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH resend 3/6] cdrom: wait for tray to close Date: Fri, 26 Jan 2018 17:58:37 +0100 Message-Id: <03915a2e64f50ec04ea6d8e6f80e36ecf16e4f0f.1516985620.git.msuchanek@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The scsi command to close 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 within a few seconds or reports an error when it detects the tray is blocked. At worst the wait can be interrupted by user. Signed-off-by: Michal Suchanek --- v2: - check drive_status exists before using it - rename tray_close -> cdrom_tray_close --- drivers/cdrom/cdrom.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 89746b3d193f..69e85c902373 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -281,7 +281,9 @@ #include #include #include +#include #include +#include #include /* used to tell the module to turn on full debugging messages */ @@ -1030,6 +1032,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) { @@ -1048,7 +1062,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 @@ -2312,7 +2328,8 @@ static int cdrom_ioctl_closetray(struct cdrom_device_info *cdi) if (!CDROM_CAN(CDC_CLOSE_TRAY)) return -ENOSYS; - return cdi->ops->tray_move(cdi, 0); + + return cdrom_tray_close(cdi); } static int cdrom_ioctl_eject_sw(struct cdrom_device_info *cdi, -- 2.13.6