Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1130097ybg; Wed, 23 Oct 2019 10:47:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjZI/aMUjAUgkg4WjF+nYiZXdu7O7yRtuy4o4JhcvJazspnEaZxc6guERxdYT1pTBbhH09 X-Received: by 2002:a50:ac3c:: with SMTP id v57mr9420665edc.300.1571852877725; Wed, 23 Oct 2019 10:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571852877; cv=none; d=google.com; s=arc-20160816; b=pGxZCcKIimKmkzli93BTRSJ6z0tIdSnKToh1eIozBCdEi0Io/SZ4G4Y0WWOO3N54Xu fUgFSzh8VYh2n0R11AelXHCwGBI3pSQ/Slr6p/O+zBuspWUY1s9RGS+0Xajpk0VIQqim DoNS/323aQKRArJOvJy7gc9D2T95/M2YbyQ2VIjDLsbcmAXK7rPSveI7/1Z2bxpwUmTw zTjzwJRjkzl7fEnUvmf9LUsAoFGE4+AoN/yZXsUKsbAbpqXbaEyI5ySIBBRAQamjfg9o huftZciy2DyRwxohlGB56qMGyFU4k71nqpZo2E+N7Qrju8SGoN94DfCHv3n+TXEsl7yF GPuQ== 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=BR7JB9GwvX1Eah3wRByyhOPWNSwkmudRd5blpBU5hOA=; b=CV+knNXd9YUo0yoogefIp/3QT4mvrbpJv9CAWIhm4G3xqx7LqncZ2gUQ/8CYyEZF3f KNG4PIED5L++yiZ6+LArl33BVqr+MY2bRJhUb6l3PyzPo1cPa3vMJ9bFYUz8Y5vjs7/4 Lc5HsbVsq20c5UdiuRry9KYH5CgQKr0MXzfNpHEr82AiHShwESUsFg0dNIHcylAgsRHl L2jSn4D+3xjWqKUaOfNkoqHQBvhyXvEmjSbPQzHxcfVd3+Bg6/73hw2oBOG3wn/bzqAr kf87bxzL2I1k7Z8G+K/6UwtoR/mPfj05i9FcBRjbqUd9SLzcYQLJT6Ps2pf2xWxGr3yV m6FQ== 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 r5si14202591edo.14.2019.10.23.10.47.33; Wed, 23 Oct 2019 10:47:57 -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 S2391926AbfJWMx1 (ORCPT + 99 others); Wed, 23 Oct 2019 08:53:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:49442 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391046AbfJWMxQ (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 0BE11B67D; Wed, 23 Oct 2019 12:53:14 +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 7/8] scsi: sr: workaround VMware ESXi cdrom emulation bug Date: Wed, 23 Oct 2019 14:52:46 +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 The WMware ESXi cdrom identifies itself as: sr 0:0:0:0: [sr0] scsi3-mmc drive: vendor: "NECVMWarVMware SATA CD001.00" model: "VMware SATA CD001.00" with the following get_capabilities print in sr.c: sr_printk(KERN_INFO, cd, "scsi3-mmc drive: vendor: \"%s\" model: \"%s\"\n", cd->device->vendor, cd->device->model); So the model looks like reliable identification while vendor does not. The drive claims to have a tray and claims to be able to close it. However, the UI has no notion of a tray - when medium is ejected it is dropped in the floor and the user must select a medium again before the drive can be re-loaded. On the kernel side the tray_move call to close the tray succeeds but the drive state does not change as a result of the call. The drive does not in fact emulate the tray state. There are two ways to get the medium state. One is the SCSI status: Physical drive: Fixed format, current; Sense key: Not Ready Additional sense: Medium not present - tray open Raw sense data (in hex): 70 00 02 00 00 00 00 0a 00 00 00 00 3a 02 00 00 00 00 Fixed format, current; Sense key: Not Ready Additional sense: Medium not present - tray closed Raw sense data (in hex): 70 00 02 00 00 00 00 0a 00 00 00 00 3a 01 00 00 00 00 VMware ESXi: Fixed format, current; Sense key: Not Ready Additional sense: Medium not present Info fld=0x0 [0] Raw sense data (in hex): f0 00 02 00 00 00 00 0a 00 00 00 00 3a 00 00 00 00 00 So the tray state is not reported here. Other is medium status which the kernel prefers if available. Adding a print here gives: cdrom: get_media_event success: code = 0, door_open = 1, medium_present = 0 door_open is interpreted as open tray. This is fine so long as tray_move would close the tray when requested or report an error which never happens on VMware ESXi servers (5.5 and 6.5 tested). This is a popular virtualization platform so a workaround is worthwhile. Signed-off-by: Michal Suchanek --- drivers/scsi/sr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 4664fdf75c0f..8090c5bdec09 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -867,6 +867,7 @@ static void get_capabilities(struct scsi_cd *cd) unsigned int ms_len = 128; int rc, n; + static const char *model_vmware = "VMware"; static const char *loadmech[] = { "caddy", @@ -922,6 +923,11 @@ static void get_capabilities(struct scsi_cd *cd) buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */ buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */ loadmech[buffer[n + 6] >> 5]); + if (!strncmp(cd->device->model, model_vmware, strlen(model_vmware))) { + buffer[n + 6] &= ~(0xff << 5); + sr_printk(KERN_INFO, cd, + "VMware ESXi bug workaround: tray -> caddy\n"); + } if ((buffer[n + 6] >> 5) == 0) /* caddy drives can't close tray... */ cd->cdi.mask |= CDC_CLOSE_TRAY; -- 2.23.0