retry mounting with ro when rw fails

Andriy Gapon avg at FreeBSD.org
Thu Apr 7 17:01:46 UTC 2011


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: <Generic> at usbus2
umass0: <Generic Mass Storage Device, class 0/0, rev 2.00/1.26, addr 2> on usbus2
da0 at umass-sim0 bus 0 scbus7 target 0 lun 0
da0: <Generic USB SD Reader 1.00> 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: <Generic USB CF Reader 1.01> 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: <Generic USB SM Reader 1.02> 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: <Generic USB MS Reader 1.03> 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


More information about the freebsd-scsi mailing list