From owner-freebsd-hardware@FreeBSD.ORG Thu Apr 7 17:19:52 2011 Return-Path: Delivered-To: freebsd-hardware@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D843106564A for ; Thu, 7 Apr 2011 17:19:52 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id CAABE8FC1F for ; Thu, 7 Apr 2011 17:19:51 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id UAA19790; Thu, 07 Apr 2011 20:01:43 +0300 (EEST) (envelope-from avg@FreeBSD.org) Message-ID: <4D9DEDF7.2070107@FreeBSD.org> Date: Thu, 07 Apr 2011 20:01:43 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.15) Gecko/20110309 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: freebsd-scsi@FreeBSD.org, freebsd-fs@FreeBSD.org, freebsd-hardware@FreeBSD.org X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: Subject: retry mounting with ro when rw fails X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2011 17:19:52 -0000 Guys, could you please review and comment on the following patch? http://people.freebsd.org/~avg/mount-retry-ro.diff Thank you! The patch consists of two parts. The first part is in CAM/SCSI to make sure that ENODEV is consistently returned to signal that an operation is not supported by a device (in accordance to intro(2)) and specifically to return ENODEV on write attempt to a read-only or write-protected media. Making this change in SCSI should cover real SCSI devices, as well as ATAPI through ahci/siis/atapicam or similar, plus majority (all?) of USB Mass Storage devices. The second part is in vfs_mount code. The idea is to re-try a mount call if we get the ENODEV error, and mounting was not already in read-only mode, and there was no explicit rw or noro option; the second try is changed to ro. I did only basic testing with an SD card in write-protected mode and a USB card-reader. Since I am not very familiar with vfs_mount code I might have missed some important details. A sample test log, just in case: ugen2.2: at usbus2 umass0: on usbus2 da0 at umass-sim0 bus 0 scbus7 target 0 lun 0 da0: Removable Direct Access SCSI-0 device da0: 40.000MB/s transfers da0: 488MB (1000448 512 byte sectors: 64H 32S/T 488C) da1 at umass-sim0 bus 0 scbus7 target 0 lun 1 da1: Removable Direct Access SCSI-0 device da1: 40.000MB/s transfers da1: Attempt to query device size failed: NOT READY, Medium not present da2 at umass-sim0 bus 0 scbus7 target 0 lun 2 da2: Removable Direct Access SCSI-0 device da2: 40.000MB/s transfers da2: Attempt to query device size failed: NOT READY, Medium not present da3 at umass-sim0 bus 0 scbus7 target 0 lun 3 da3: Removable Direct Access SCSI-0 device da3: 40.000MB/s transfers da3: Attempt to query device size failed: NOT READY, Medium not present GEOM: da0s1: EBR has non empty bootcode. (da0:umass-sim0:0:0:0): WRITE(10). CDB: 2a 0 0 0 0 ea 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: DATA PROTECT csi:0,aa,55,61 asc:27,0 (Write protected) field replaceable unit: 1 g_vfs_done():da0s1[WRITE(offset=512, length=4096)]error = 19 (da0:umass-sim0:0:0:0): WRITE(10). CDB: 2a 0 0 0 0 ea 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: DATA PROTECT csi:0,aa,55,61 asc:27,0 (Write protected) field replaceable unit: 1 g_vfs_done():da0s1[WRITE(offset=512, length=4096)]error = 19 vfs_donmount: R/W mount failed, possibly R/O media, falling back to R/O mount -- Andriy Gapon