diff options
author | Elias Oltmanns <eo@nebensachen.de> | 2008-10-13 15:39:50 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-13 15:39:50 -0400 |
commit | 4abdc6ee7c47a1a6e12f95717e461baeebee5df7 (patch) | |
tree | 51cac3d66891d026483838563e35124467a8eb86 /drivers/ide/ide-iops.c | |
parent | 08243ba731ee08ff42cf1589379c81567690218f (diff) |
ide: Implement disk shock protection support (v4)
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD
FEATURE as specified in ATA-7 is issued to the device and processing of
the request queue is stopped thereafter until the specified timeout
expires or user space asks to resume normal operation. This is supposed
to prevent the heads of a hard drive from accidentally crashing onto the
platter when a heavy shock is anticipated (like a falling laptop expected
to hit the floor). Port resets are deferred whenever a device on that
port is in the parked state.
v3:
Elias Oltmanns <eo@nebensachen.de> wrote:
[...]
> >> 1. Make sure that no negative value is being passed to
> >> jiffies_to_msecs() in ide_park_show().
> >> 2. Drop the superfluous variable hwif in ide_special_rq().
> >> 3. Skip initialisation of task and tf in ide_special_rq() if we are not
> >> handling a (un)park request.
> >
> > Well, #3 should have been done differently because we donn't want to
> > check for REQ_(UN)?PARK_HEADS more often than is necessary.
>
> While preparing the backport to 2.6.27, it has just occurred to me that
> we need to clear the IDE_DFLAG_PARKED flag in ide_disk_pre_reset()
> because this flag must not be set after *any* sort of access to the
> device.
v4:
Fix a memory leak due to a missing blk_put_request() in
issue_park_cmd(). Additionally, we should plug the queue when enqueueing
the unpark request because there is no guarantee that the park timeout
has not expired by then. Even though the chance for that to happen is
very slim, the request might end up hanging in the queue until the next
I/O operation is queued up. While at it, clean up the code a little:
- make issue_park_cmd() a function of type void since nobody cares for
the return value anyway;
- use blk_start_queueing() instead of __blk_run_queue() since we don't
have to worry about recursion;
- remove a superfluous pointer deference in task_no_data_intr().
Signed-off-by: Elias Oltmanns <eo@nebensachen.de>
Cc: Jeff Garzik <jeff@garzik.org>,
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Tejun Heo <htejun@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-iops.c')
-rw-r--r-- | drivers/ide/ide-iops.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c index 91182ebed468..b762deb2dacb 100644 --- a/drivers/ide/ide-iops.c +++ b/drivers/ide/ide-iops.c | |||
@@ -1020,6 +1020,7 @@ static void ide_disk_pre_reset(ide_drive_t *drive) | |||
1020 | drive->special.b.recalibrate = legacy; | 1020 | drive->special.b.recalibrate = legacy; |
1021 | 1021 | ||
1022 | drive->mult_count = 0; | 1022 | drive->mult_count = 0; |
1023 | drive->dev_flags &= ~IDE_DFLAG_PARKED; | ||
1023 | 1024 | ||
1024 | if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 && | 1025 | if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 && |
1025 | (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) | 1026 | (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) |
@@ -1079,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive) | |||
1079 | static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | 1080 | static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) |
1080 | { | 1081 | { |
1081 | unsigned int unit; | 1082 | unsigned int unit; |
1082 | unsigned long flags; | 1083 | unsigned long flags, timeout; |
1083 | ide_hwif_t *hwif; | 1084 | ide_hwif_t *hwif; |
1084 | ide_hwgroup_t *hwgroup; | 1085 | ide_hwgroup_t *hwgroup; |
1085 | struct ide_io_ports *io_ports; | 1086 | struct ide_io_ports *io_ports; |
1086 | const struct ide_tp_ops *tp_ops; | 1087 | const struct ide_tp_ops *tp_ops; |
1087 | const struct ide_port_ops *port_ops; | 1088 | const struct ide_port_ops *port_ops; |
1089 | DEFINE_WAIT(wait); | ||
1088 | 1090 | ||
1089 | spin_lock_irqsave(&ide_lock, flags); | 1091 | spin_lock_irqsave(&ide_lock, flags); |
1090 | hwif = HWIF(drive); | 1092 | hwif = HWIF(drive); |
@@ -1111,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | |||
1111 | return ide_started; | 1113 | return ide_started; |
1112 | } | 1114 | } |
1113 | 1115 | ||
1116 | /* We must not disturb devices in the IDE_DFLAG_PARKED state. */ | ||
1117 | do { | ||
1118 | unsigned long now; | ||
1119 | |||
1120 | prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE); | ||
1121 | timeout = jiffies; | ||
1122 | for (unit = 0; unit < MAX_DRIVES; unit++) { | ||
1123 | ide_drive_t *tdrive = &hwif->drives[unit]; | ||
1124 | |||
1125 | if (tdrive->dev_flags & IDE_DFLAG_PRESENT && | ||
1126 | tdrive->dev_flags & IDE_DFLAG_PARKED && | ||
1127 | time_after(tdrive->sleep, timeout)) | ||
1128 | timeout = tdrive->sleep; | ||
1129 | } | ||
1130 | |||
1131 | now = jiffies; | ||
1132 | if (time_before_eq(timeout, now)) | ||
1133 | break; | ||
1134 | |||
1135 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1136 | timeout = schedule_timeout_uninterruptible(timeout - now); | ||
1137 | spin_lock_irqsave(&ide_lock, flags); | ||
1138 | } while (timeout); | ||
1139 | finish_wait(&ide_park_wq, &wait); | ||
1140 | |||
1114 | /* | 1141 | /* |
1115 | * First, reset any device state data we were maintaining | 1142 | * First, reset any device state data we were maintaining |
1116 | * for any of the drives on this interface. | 1143 | * for any of the drives on this interface. |