brintos

brintos / linux-shallow public Read only

0
0
Text · 6.8 KiB · 22c7ec3 Raw
152 lines · plain
1==========================2Hard disk shock protection3==========================4 5Author: Elias Oltmanns <eo@nebensachen.de>6 7Last modified: 2008-10-038 9 10.. 0. Contents11 12   1. Intro13   2. The interface14   3. References15   4. CREDITS16 17 181. Intro19--------20 21ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.22Issuing this command should cause the drive to switch to idle mode and23unload disk heads. This feature is being used in modern laptops in24conjunction with accelerometers and appropriate software to implement25a shock protection facility. The idea is to stop all I/O operations on26the internal hard drive and park its heads on the ramp when critical27situations are anticipated. The desire to have such a feature28available on GNU/Linux systems has been the original motivation to29implement a generic disk head parking interface in the Linux kernel.30Please note, however, that other components have to be set up on your31system in order to get disk shock protection working (see32section 3. References below for pointers to more information about33that).34 35 362. The interface37----------------38 39For each ATA device, the kernel exports the file40`block/*/device/unload_heads` in sysfs (here assumed to be mounted under41/sys). Access to `/sys/block/*/device/unload_heads` is denied with42-EOPNOTSUPP if the device does not support the unload feature.43Otherwise, writing an integer value to this file will take the heads44of the respective drive off the platter and block all I/O operations45for the specified number of milliseconds. When the timeout expires and46no further disk head park request has been issued in the meantime,47normal operation will be resumed. The maximal value accepted for a48timeout is 30000 milliseconds. Exceeding this limit will return49-EOVERFLOW, but heads will be parked anyway and the timeout will be50set to 30 seconds. However, you can always change a timeout to any51value between 0 and 30000 by issuing a subsequent head park request52before the timeout of the previous one has expired. In particular, the53total timeout can exceed 30 seconds and, more importantly, you can54cancel a previously set timeout and resume normal operation55immediately by specifying a timeout of 0. Values below -2 are rejected56with -EINVAL (see below for the special meaning of -1 and -2). If the57timeout specified for a recent head park request has not yet expired,58reading from `/sys/block/*/device/unload_heads` will report the number59of milliseconds remaining until normal operation will be resumed;60otherwise, reading the unload_heads attribute will return 0.61 62For example, do the following in order to park the heads of drive63/dev/sda and stop all I/O operations for five seconds::64 65	# echo 5000 > /sys/block/sda/device/unload_heads66 67A simple::68 69	# cat /sys/block/sda/device/unload_heads70 71will show you how many milliseconds are left before normal operation72will be resumed.73 74A word of caution: The fact that the interface operates on a basis of75milliseconds may raise expectations that cannot be satisfied in76reality. In fact, the ATA specs clearly state that the time for an77unload operation to complete is vendor specific. The hint in ATA-778that this will typically be within 500 milliseconds apparently has79been dropped in ATA-8.80 81There is a technical detail of this implementation that may cause some82confusion and should be discussed here. When a head park request has83been issued to a device successfully, all I/O operations on the84controller port this device is attached to will be deferred. That is85to say, any other device that may be connected to the same port will86be affected too. The only exception is that a subsequent head unload87request to that other device will be executed immediately. Further88operations on that port will be deferred until the timeout specified89for either device on the port has expired. As far as PATA (old style90IDE) configurations are concerned, there can only be two devices91attached to any single port. In SATA world we have port multipliers92which means that a user-issued head parking request to one device may93actually result in stopping I/O to a whole bunch of devices. However,94since this feature is supposed to be used on laptops and does not seem95to be very useful in any other environment, there will be mostly one96device per port. Even if the CD/DVD writer happens to be connected to97the same port as the hard drive, it generally *should* recover just98fine from the occasional buffer under-run incurred by a head park99request to the HD. Actually, when you are using an ide driver rather100than its libata counterpart (i.e. your disk is called /dev/hda101instead of /dev/sda), then parking the heads of one drive (drive X)102will generally not affect the mode of operation of another drive103(drive Y) on the same port as described above. It is only when a port104reset is required to recover from an exception on drive Y that further105I/O operations on that drive (and the reset itself) will be delayed106until drive X is no longer in the parked state.107 108Finally, there are some hard drives that only comply with an earlier109version of the ATA standard than ATA-7, but do support the unload110feature nonetheless. Unfortunately, there is no safe way Linux can111detect these devices, so you won't be able to write to the112unload_heads attribute. If you know that your device really does113support the unload feature (for instance, because the vendor of your114laptop or the hard drive itself told you so), then you can tell the115kernel to enable the usage of this feature for that drive by writing116the special value -1 to the unload_heads attribute::117 118	# echo -1 > /sys/block/sda/device/unload_heads119 120will enable the feature for /dev/sda, and giving -2 instead of -1 will121disable it again.122 123 1243. References125-------------126 127There are several laptops from different vendors featuring shock128protection capabilities. As manufacturers have refused to support open129source development of the required software components so far, Linux130support for shock protection varies considerably between different131hardware implementations. Ideally, this section should contain a list132of pointers at different projects aiming at an implementation of shock133protection on different systems. Unfortunately, I only know of a134single project which, although still considered experimental, is fit135for use. Please feel free to add projects that have been the victims136of my ignorance.137 138- https://www.thinkwiki.org/wiki/HDAPS139 140  See this page for information about Linux support of the hard disk141  active protection system as implemented in IBM/Lenovo Thinkpads.142 143 1444. CREDITS145----------146 147This implementation of disk head parking has been inspired by a patch148originally published by Jon Escombe <lists@dresco.co.uk>. My efforts149to develop an implementation of this feature that is fit to be merged150into mainline have been aided by various kernel developers, in151particular by Tejun Heo and Bartlomiej Zolnierkiewicz.152