Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4068064ybg; Fri, 25 Oct 2019 12:51:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvMYbTwXf3eyYKSPCStcPM8d7KZWRXMELIaxlbgwkPzCzLSkRkoBDqrECmd46E77/QvHDT X-Received: by 2002:a17:906:694e:: with SMTP id c14mr2558528ejs.122.1572033107033; Fri, 25 Oct 2019 12:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572033107; cv=none; d=google.com; s=arc-20160816; b=gYFgKfocQvZ8OU2u+DUe+z/Fvt32sT0u3KBPlimzUWpQSI+Yn7L5O2kDpM5e6o5Lu8 UyfIpuxwDlT//6f0OdkyMQ3tS4ZFP+D7D2y/dcUMpuqJ0UFHiEVR5e4ZHX1T5HV0BeW8 4RqBaNZGnamTGMp+2EjC11QcWjFp8Q/+nR6HTeJPRmQUsEigdTost1LggGowfjuRwe2o /d4csdkrwxpAEMgzgCtQLa1Ci5P86TwdrncPuu3+GqIcgLSmNxuDO7MXXoYUMMQNDLlu X1uKYwSQsJAZKKJJo5WVjpFgq9llQ5d9f83xjLpunV5ZJ3k8d9N8qZASTnnN1XglQlRN UaOA== 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=qUIWL6khirHbqMWB6lrZiqktpTQ1bh4xv/Ni2ijW5fA=; b=X3lvXU3/W/fNBczDlhkF/Kxc88bCipk2Q2p5xYyVQ8dKWYHZaZ6AoySZgFSvck8duX I6ZRARoiU9wp98tnnJ9PT+349QlAMu1jUAeUbYOGkk2mbPY8LOkhygwkBYSzvWhEO+x1 r/Qcji5dpDELA0RaIicq0cpaTXIaayk1HEdToWUTj8MoSk4yPphPAElCb4TQbvHoBPTp X6Mm5anN3FPv32GTjjZQyLu04iQ9k2N1Hoct83/LWFJxwUnPCFsDklBUMay4B9M26LbK Rogk7kg0tpa5wDljHmGJtrS4LHUUWjEQT3D5KkGplH81xohuC5UoR9mLfoxuGPEIgAPa HnxA== 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 h43si1861169edb.89.2019.10.25.12.51.23; Fri, 25 Oct 2019 12:51:47 -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 S2410288AbfJYLVz (ORCPT + 99 others); Fri, 25 Oct 2019 07:21:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:56914 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2410162AbfJYLVx (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 D4E01B294; 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 4/7] cdrom: export autoclose logic as a separate function Date: Fri, 25 Oct 2019 13:21:41 +0200 Message-Id: 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 This allows the sr driver to call it without blocking other processes accessing the device. This solves a issue with process waiting in open() on broken drive to close the tray blocking out all access to the device, including nonblocking access to determine drive status. Signed-off-by: Michal Suchanek --- v2: new patch v3: - change IOCTL to export - fix the logic about reporting cdroms inability to close tray --- drivers/cdrom/cdrom.c | 87 +++++++++++++++++++++++++------------------ include/linux/cdrom.h | 1 + 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 27f4fce22781..a494f44fcf1f 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -1070,46 +1070,16 @@ static int open_for_common(struct cdrom_device_info *cdi, tracktype *tracks) 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 = 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 - 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 { - cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n"); - return -ENOMEDIUM; - } - /* 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"); - return -ENOMEDIUM; - } - cd_dbg(CD_OPEN, "the tray is now closed\n"); + return -ENOMEDIUM; } - /* 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; + cd_dbg(CD_OPEN, "the drive is not ready...\n"); + return -ENOMEDIUM; } - if (ret != CDS_DISC_OK) + if (ret != CDS_DISC_OK) { + cd_dbg(CD_OPEN, "drive returned status %i...\n", ret); return -ENOMEDIUM; + } } cdrom_count_tracks(cdi, tracks); if (tracks->error == CDS_NO_DISC) { @@ -2351,6 +2321,51 @@ static int cdrom_ioctl_closetray(struct cdrom_device_info *cdi) return cdi->ops->tray_move(cdi, 0); } +int cdrom_autoclose(struct cdrom_device_info *cdi) +{ + const struct cdrom_device_ops *cdo = cdi->ops; + int ret; + + cd_dbg(CD_OPEN, "entering cdrom_autoclose\n"); + if (!cdo->drive_status) + return -ENXIO; + + ret = cdo->drive_status(cdi, CDSL_CURRENT); + cd_dbg(CD_OPEN, "drive_status=%d\n", ret); + + if (ret == CDS_TRAY_OPEN) + if(CDROM_CAN(CDC_CLOSE_TRAY)) { + if (!(cdi->options & CDO_AUTO_CLOSE)) + return -ENOMEDIUM; + cd_dbg(CD_OPEN, "trying to close the tray...\n"); + 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"); + return -ENOMEDIUM; + } + ret = cdo->drive_status(cdi, CDSL_CURRENT); + } else { + cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n"); + return -ENOMEDIUM; + } + if (ret == CDS_DRIVE_NOT_READY) { + int poll_res; + + cd_dbg(CD_OPEN, "waiting for drive to become ready...\n"); + poll_res = poll_event_interruptible(CDS_DRIVE_NOT_READY != + (ret = cdo->drive_status(cdi, CDSL_CURRENT)), 50); + if (poll_res == -ERESTARTSYS) + return poll_res; + } + if (ret != CDS_DISC_OK) + return -ENOMEDIUM; + + return 0; +} +EXPORT_SYMBOL_GPL(cdrom_autoclose); + static int cdrom_ioctl_eject_sw(struct cdrom_device_info *cdi, unsigned long arg) { diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h index 528271c60018..ea0415ba9f9d 100644 --- a/include/linux/cdrom.h +++ b/include/linux/cdrom.h @@ -126,6 +126,7 @@ extern void init_cdrom_command(struct packet_command *cgc, void *buffer, int len, int type); extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi, struct packet_command *cgc); +int cdrom_autoclose(struct cdrom_device_info *cdi); /* The SCSI spec says there could be 256 slots. */ #define CDROM_MAX_SLOTS 256 -- 2.23.0