summaryrefslogtreecommitdiff
path: root/sys/scsi/sd.c
AgeCommit message (Collapse)Author
2017-12-30Don't pull in <sys/file.h> just to get fcntl.hPhilip Guenther
ok deraadt@ krw@
2017-09-08If you use sys/param.h, you don't need sys/types.hTheo de Raadt
2017-05-29sd: flush cache when closing writable FDStefan Fritsch
Don't skip the cache flush until the last opening of the device is closed. Otherwise, when umounting a writable partition while a different partition is still mounted read-only, the necessary disk flush may be delayed for a very long time. ok krw@ deraadt@
2017-05-29Add an ioctl to tell storage devices to flush their internal cachesStefan Fritsch
Currently implemented for wd and sd. Initially ported from netbsd by pedro@ ok deraadt@
2017-05-29To prevent anyone else from stumbling on this (now) archaic bit ofKenneth R Westerback
history, nuke all mentions of XS_NO_CCB and the #define. 2006 - 2017. R.I.P. ok kettenis@ inferred ok dlg@
2017-05-04Also pass the blk offset to disk_unbusy(), so that it can pass it toTheo de Raadt
the random subsystem as entropy. This value is pretty much unknown, and anyways our entropy input ring does not saturate from knowns. ok mikeb djm
2016-03-19Do not run into sdgetdisklabel() when scsi disk is dying. AddAlexander Bluhm
special error handling in sdopen() as temporary hack. OK krw@
2016-03-18After sleeping and before accessing sc_link, check that scsi diskAlexander Bluhm
is not dying. OK krw@
2016-03-17Do not access the scsi link structure in sdclose() if the diskAlexander Bluhm
device is already dying. Delete the sc_timeout when setting the SDF_DYING flag as the timeout delete in sdclose() may not be reached. OK krw@
2016-03-16Add SDF_DYING checks to more functions in scsi disk, to prevent anAlexander Bluhm
use after free of the scsi link structure during detach. OK krw@
2016-03-12Standardize on calling local scsi_link variables 'link' instead ofKenneth R Westerback
'sc_link'. 'sc_link' is a field in the various device *_softc structures, where the sc_ prefix was for 'softc'. Reduces potential mental confusion. Newer code from down under was already using 'link'. No functional change. Prompted by bluhm@'s adventures in scsi. ok dlg@ jmatthew@
2016-03-12When unplugging an USB umass stick, the kernel could panic becauseAlexander Bluhm
of a use after free. In sdopen() the scsi link pointer is taken from the scsi disk struct. While the scsi disk memory is refcounted by autoconf, the scsi link may be detached and freed during sleep. The solution is to check wether the disk is dying after every sleep. The SDF_DYING flag is set before scsi bus and scsi disk are detached, so without this flag the link must be valid. input and OK krw@
2016-02-03Do not access the scsi link of the disk at the beginning of sdopen()Alexander Bluhm
and sdminphys() if the scsi disk is dying. The memory of the link may have been freed already. OK krw@
2016-02-03When accessing the scsi link of a scsi disk, use a variable "sc_link"Alexander Bluhm
everywhere. This is the first step to fix a use after free of the sc_link when the disk detaches. If a function gets a scsi transfer, the scsi link is always valid. Call this variable "link" consistently. OK krw@
2015-06-07More damned eye searing whitespace.Kenneth R Westerback
2015-04-02use correct capitalization of 'BlackBerry'Jasper Lievisse Adriaanse
"sure" deraadt@
2015-03-08Fix some format specifiers in debug code.Kenneth R Westerback
Pointed out by Kor son of Rynar (sic) when trying to test some debug code. ok matthew@
2014-12-15convert bcopy to memcpy. ok dlg krwTed Unangst
2014-09-18Some disks, such as the Seagate Cheetah 73LP FC with Sun firmwareMark Kettenis
(ST373405FSUN72G) respond to a START STOP UNIT command that spins down the disk with a "Logical Unit Not Ready, Initialization Command Required". Besides causing some dmesg spam, our sd(4) driver responds to such a response by spinning the disk back up. Prevent this from happening by respecting the SCSI_IGNORE_NOT_READY flag and using that flag when spinning down the disk. ok miod@
2014-09-14remove uneeded proc.h includesJonathan Gray
ok mpi@ kspillner@
2014-07-12add a size argument to free. will be used soon, but for now default to 0.Ted Unangst
after discussions with beck deraadt kettenis.
2014-07-10Now that sd(4) drives under softraid0 have their cache flushed whenMartin Pieuchot
DVACT_POWERDOWN is propagated in this subtree, there is no need for this shutdown hook anymore. RIP. ok kettenis@
2014-02-19If a disk returns a size of 0, treat it as an error to let theMartin Pieuchot
driver re-probe for its capacity. Allow to fully recognized Lexar JumpDrive S33 USB 3.0 sticks. ok krw@, dlg@
2014-02-13if an attached sd(4) is readonly, make sure it's noticable in theAlexander Hall
dmesg, or write operations just fail with EACCES for no obvious reason ok krw@ tedu@
2013-11-01Sprinkle (long long) casts where %lld is being used to print daddr_tKenneth R Westerback
variables. Some random whitespace/knf repairs encountered on the way. ok miod@ on inspection, feedback & more suggestions from millert@
2013-10-03Print daddr_t variables with %lld, u_int64_t variables with %llu.Kenneth R Westerback
2013-10-02Use u_int64_t instead of daddr_t parameters to sd_cmd_rw*() functions.Kenneth R Westerback
Ditto disksize field of sd_softc and a couple of local calculation variables. scsi/* now daddr_t clean except where they really are 512-byte blocks.
2013-09-19Tweak types to keep daddr_t address and sector address separate.Kenneth R Westerback
Prefer DL_ macros over handrolling. Fix the loop to allow for bigger (highly unlikely) bunches of bits to be broken up into rw_10 sized (<= UINT32_MAX sectors) chunks. Add check to make sure i/o request starts at a sector address.
2013-09-15Use DL_SECTOBLK() and DL_BLKTOSEC() to clarify code and removeKenneth R Westerback
repeated handrolling of same code. Use daddr_t variable to calculate daddr_t return values, and u_int64_t variables to calculate disk sector values. No functional change.
2013-06-11final removal of daddr64_t. daddr_t has been 64 bit for a long enoughTheo de Raadt
test period; i think 3 years ago the last bugs fell out. ok otto beck others
2012-12-19Temporarily bring back the shutdown hook, but only use it to flush the diskMark Kettenis
cache. This shouldn't interfere with the hibernate code and makes sure we still flush the cache for controller that don't pass DVACT_POWRDOWN down to their children yet. This will be removed when the autoconf subsystem gets changed to do that for us by default. ok deraadt@
2012-10-15In DVACT_SUSPEND, do a flush of the disk. We do this in DVACT_POWERDOWNTheo de Raadt
as well, but it might be wise to flush before a hibernate operation, in case hiberate looks at blocks which are in the buffer cache. ok krw
2012-10-08Revamp the sequences for suspend/hibernate -> resume so that the codeTheo de Raadt
paths are reflexive. It is now possible to fail part-way through a suspend sequence, and recover along the resume code path. Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used after hibernate (and suspend too) to finish the job. Some drivers must be converted at the same time to use this instead of shutdown hooks (the others will follow at a later time) ok kettenis mlarkin
2012-07-09Revert previous.Kenneth R Westerback
The standards gpds are jealous gods. kettenis@ and beck@ have shown EROFS is the wrong thing to return. So revert to EACCES until a better error code is decided on.
2012-07-08Return EROFS when a read-write mount of a read-only sd(4) deviceKenneth R Westerback
is attempted. This is instead of the current EACCES and is intended to result in better error messages from mount(8). Tweak default EROFS error text to mention fsck'ing in mount_ext2fs and mount_msdos since they both have fsck's like ffs. ok deraadt@ aja@ ian@ phessler@
2012-06-10Do NOT make all check condition results report EIO. Only use EIOKenneth R Westerback
when b_error has not already been set to something more informative, e.g. EROFS. DO check the result of ffs_sbupdate() and error out of a mount() call when ffs_sbupdate() reports EROFS while attempting a rw mount. Letting RW mounts proceed regardless of EROFS led to crashes and usb problems for Oliver Seufer while using the RW/RO switches on some usb devices. Fix developed using devices kindly supplied by Oliver & Co. ok miod@
2011-10-10Put the drive in standby mode when we're powering down the machine.Mark Kettenis
tested by dcoppa@, ok krw@, miod@
2011-07-18Fix an off-by-1 error and a 32-bit integer arithmetic overflow bugMatthew Dempsky
that caused large disks to appear offline. Discovered and tested by mlarkin@; ok dlg@
2011-07-12fix some notyet codeDavid Gwynne
2011-07-12now that we know if a disk is thin provisioned (or an ssd), we can chooseDavid Gwynne
to use the fifo bufq sorting on such disks. there's no point ordering io if the real blocks arent in the order we think they are. ok krw@ tedu@ miod@
2011-07-11ask the disk about unmap (read trim) parameters. check if we have theDavid Gwynne
required vpd pages, then read them for the values we want. we look for the max blocks per unmap, the max descriptors per unmap, and which scsi command to use for unmapping (unmap will be preferred). two fixes and ok matthew@
2011-07-11disks report trim^Wunmap^Wif theyre thin provisioned via a bit inDavid Gwynne
the read cap 16 data. move the read cap code into sd.c so i can get at this bit without much contorting, and to make it trivial to get at the other interesting things in there later. thin disks report themselves as "thin" in dmesg along with their size now. ok matthew@
2011-07-06Eliminate redundant buf validation checks in xxstrategy() methods nowMatthew Dempsky
that they're implemented consistently in bounds_check_with_label(). Also, per krw's request, change bounds_check_with_label() to return 0 if the checks succeed, and change the drivers to test == -1 instead of <= 0. (Man page update to follow; intentionally omitting arch/vax/mba/hp.c from this commit because it doesn't even build currently and miod@ promises to kill it soon.) ok krw@
2011-07-03Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thingMatthew Dempsky
that's ever used it, and it's long since been changed to use DVACT_{QUIESCE,SUSPEND,RESUME} instead. ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it up a few weeks ago
2011-06-30Refactor some common open/close/detach disk driver code intoMatthew Dempsky
subr_disk.c. For now just the MI disk drivers. ok deraadt@, krw@; jsing@ liked the approach too
2011-06-19Use disk_lock_nointr() in the xxclose() routines so that they cannotTheo de Raadt
be interrupted. ok matthew
2011-06-19Use disk_lock/disk_unlock directly and in the same way in these drivers,Theo de Raadt
rather than using various wrappings. Convert vnd to using the sc_dk rwlock instead of using one of its own. ok matthew
2011-06-05Drop kernel support for the useless DIOCWLABEL ioctl and prune a lotMatthew Dempsky
of silly flag twiddling code in various disk drivers. ok deraadt@, miod@ N.B., users will need a -current disklabel(8) to be able to write new disklabels to disk now.
2011-06-03Get rid of the wlabel argument to bounds_check_with_label(). It'sMatthew Dempsky
never done anything in OpenBSD and just clutters disk drivers with silly flag handling. More cleanup to follow. ok deraadt@, millert@; no objections krw@
2011-05-31Change a few of the more common disk drivers (sd, cd, wd, rd, and vnd)Matthew Dempsky
to return EBUSY if the user tries to modify an open partition's offset or size. Only sadness can result if a user tries this, and rejecting it prevents a race between sdstart() and sdstrategy(). Curiously, there was already code in the kernel and in disklabel(8) to detect/handle this, but it was effectively disabled because the disk drivers always used something like "/* sc->sc_dk.dk_openmask */ 0", and this commented out code has existed since even r1.1 in NetBSD. I had no problems building a release and messing around with disklabel(8) for a bit with this diff. Canarying the more common MI disk drivers until we gain confidence that there aren't any regressions, then we can switch the remaining drivers. "I am surprised you got me convinced that this stuff is safe" deraadt@ ok krw@