Hard disk protection
====================


Intro
-----
ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with UNLOAD FEATURE.
Issuing this command should cause the drive to switch to idle mode and
unload disk heads. This feature is being used in modern laptops in
conjunction with accelerometers and appropriate software to implement
a shock protection facility. The idea is to stop all I/O operations on
the internal hard drive and park its heads on the ramp when critical
situations are anticipated. The desire to have such a feature
available on GNU/Linux systems has been the original motivation to
implement a generic disk parking interface in the Linux kernel.


The interface
-------------
The interface works as follows: Writing an integer value to
/sys/block/*/queue/protect will park the respective drive and freeze
the block layer queue for the specified number of seconds. When the
timeout expires and no further disk park request has been issued in
the meantime, the queue is unfrozen and accumulated I/O operations are
performed.

IMPORTANT NOTE:
Not all ATA drives implement IDLE IMMEDIATE with UNLOAD FEATURE and
quite a few of those that do so, don't report this capability as
described in the specs. When a disk park has been requested through
sysfs as described above, the kernel will try to determine if the
drive supports the UNLOAD FEATURE by default. The kernel will only
rely on the IDLE IMMEDIATE with UNLOAD FEATURE command if it is
convinced that this command is actually supported by the disk drive;
otherwise, it will fall back to STANDBY IMMEDIATE. Resuming from the
latter will take much longer and it is generally more likely to have a
negative impact on the drive's lifetime due to the inclease of spin
down and up cycles. If you want to use this interface in a shock
protection framework and you know that your drive does indeed support
the IDLE IMMEDIATE with UNLOAD FEATURE command despite not saying so,
you can force the kernel to issue that command by doing the following
on the command line:
# echo -n unload > /sys/block/sda/queue/protect_method
(replace sda by the drive identifier as appropriate).

/sys/block/*/queue/protect_method accepts auto, unload and standby
respectively. Reading from protect_method shows the available options
surrounding the active one with brackets. When auto is active, this
will change to whatever the kernel sees fit after the next disk park
command has been issued.


References
----------

There are several laptops from different brands featuring shock
protection capabilities. As manufacturers have refused to support open
source development of the required software components so far, Linux
support for shock protection varies considerably between different
hardware implementations. Ideally, this section should contain a list
of poiters at different projects aiming at an implementation of shock
protection on different systeems. Unfortunately, I only know of a
single project which, although still considered experimental, is fit
for use. Please feel free to add projects that have been the victims
of my ignorance.

- http://www.thinkwiki.org/wiki/HDAPS
  See this page for information about Linux support of the hard disk
  active protection syystem as implemented in IBM/Lenovo Thinkpads.


CREDITS
-------

The patch to implement the interface described in this file has
originally been published by Jon Escombe <lists@dresco.co.uk>.


05 Dec 2006, Elias Oltmanns <eo@nebensachen.de>
