From: Elias Oltmanns <eo@nebensachen.de>
To: Tejun Heo <htejun@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
Jeff Garzik <jeff@garzik.org>,
Randy Dunlap <randy.dunlap@oracle.com>,
linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] libata: Implement disk shock protection support
Date: Wed, 17 Sep 2008 17:26:59 +0200 [thread overview]
Message-ID: <874p4eoksc.fsf@denkblock.local> (raw)
In-Reply-To: 87k5diq35g.fsf@denkblock.local
Elias Oltmanns <eo@nebensachen.de> wrote:
> What about the following patch?
>
> From: Elias Oltmanns <eo@nebensachen.de>
> Subject: [PATCH] libata: Implement disk shock protection support
>
> 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). In fact, the whole port stops processing
> commands until the timeout has expired in order to avoid any resets due
> to failed commands on another device.
>
> Signed-off-by: Elias Oltmanns <eo@nebensachen.de>
> ---
Apart from addressing the issue with timeouts exceeding the limit of
30000 msec discussed lately, I have also simplified the crucial
if-clause in ata_scsi_park_show(). Both changes are given below.
Assuming that you don't have any objections, I'll just go ahead and
submit the updated patch series shortly.
Regards,
Elias
> +static ssize_t ata_scsi_park_show(struct device *device,
> + struct device_attribute *attr, char *buf)
> +{
> + struct scsi_device *sdev = to_scsi_device(device);
> + struct ata_port *ap;
> + struct ata_link *link;
> + struct ata_device *dev;
> + unsigned long flags;
> + unsigned int uninitialized_var(msecs);
> + int rc = 0;
> +
> + ap = ata_shost_to_port(sdev->host);
> +
> + spin_lock_irqsave(ap->lock, flags);
> + dev = ata_scsi_find_dev(ap, sdev);
> + if (!dev) {
> + rc = -ENODEV;
> + goto unlock;
> + }
> + if (dev->flags & ATA_DFLAG_NO_UNLOAD) {
> + rc = -EOPNOTSUPP;
> + goto unlock;
> + }
> +
> + link = dev->link;
> + if (((ap->pflags & ATA_PFLAG_EH_IN_PROGRESS &&
> + (link->eh_context.i.dev_action[dev->devno] & ATA_EH_PARK ||
> + link->eh_info.dev_action[dev->devno] & ATA_EH_PARK)) ||
> + (ap->pflags & ATA_PFLAG_EH_PENDING &&
> + link->eh_info.dev_action[dev->devno])) &&
> + time_after(dev->unpark_deadline, jiffies))
Changed to:
if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS &&
link->eh_context.unloaded_mask & (1 << dev->devno) &&
time_after(dev->unpark_deadline, jiffies))
> + msecs = jiffies_to_msecs(dev->unpark_deadline - jiffies);
> + else
> + msecs = 0;
> +
> +unlock:
> + spin_unlock_irq(ap->lock);
> +
> + return rc ? rc : snprintf(buf, 20, "%u\n", msecs);
> +}
> +
> +static ssize_t ata_scsi_park_store(struct device *device,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct scsi_device *sdev = to_scsi_device(device);
> + struct ata_port *ap;
> + struct ata_device *dev;
> + long int input;
> + unsigned long flags;
> + int rc;
> +
> + rc = strict_strtol(buf, 10, &input);
> + if (rc || input < -2 || input > ATA_TMOUT_MAX_PARK)
> + return -EINVAL;
Changed to:
if (rc || input < -2)
return -EINVAL;
if (input > ATA_TMOUT_MAX_PARK) {
rc = -EOVERFLOW;
input = ATA_TMOUT_MAX_PARK;
}
> +
> + ap = ata_shost_to_port(sdev->host);
> +
> + spin_lock_irqsave(ap->lock, flags);
> + dev = ata_scsi_find_dev(ap, sdev);
> + if (unlikely(!dev)) {
> + rc = -ENODEV;
> + goto unlock;
> + }
> + if (dev->class != ATA_DEV_ATA) {
> + rc = -EOPNOTSUPP;
> + goto unlock;
> + }
> +
> + if (input >= 0) {
> + if (dev->flags & ATA_DFLAG_NO_UNLOAD) {
> + rc = -EOPNOTSUPP;
> + goto unlock;
> + }
> +
> + dev->unpark_deadline = ata_deadline(jiffies, input);
> + dev->link->eh_info.dev_action[dev->devno] |= ATA_EH_PARK;
> + ata_port_schedule_eh(ap);
> + wake_up_all(&ata_scsi_park_wq);
> + } else {
> + switch (input) {
> + case -1:
> + dev->flags &= ~ATA_DFLAG_NO_UNLOAD;
> + break;
> + case -2:
> + dev->flags |= ATA_DFLAG_NO_UNLOAD;
> + break;
> + }
> + }
> +unlock:
> + spin_unlock_irqrestore(ap->lock, flags);
> +
> + return rc ? rc : len;
> +}
> +DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR,
> + ata_scsi_park_show, ata_scsi_park_store);
> +EXPORT_SYMBOL_GPL(dev_attr_unload_heads);
> +
> static void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
> {
> cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
next prev parent reply other threads:[~2008-09-17 15:27 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-29 21:11 [RFC] Disk shock protection in GNU/Linux (take 2) Elias Oltmanns
2008-08-29 21:16 ` [PATCH 1/4] Introduce ata_id_has_unload() Elias Oltmanns
2008-08-30 11:56 ` Sergei Shtylyov
2008-08-30 17:29 ` Elias Oltmanns
2008-08-30 18:01 ` Sergei Shtylyov
2008-08-29 21:20 ` [PATCH 2/4] libata: Implement disk shock protection support Elias Oltmanns
2008-08-30 9:33 ` Tejun Heo
2008-08-30 23:38 ` Elias Oltmanns
2008-08-31 9:25 ` Tejun Heo
2008-08-31 12:08 ` Elias Oltmanns
2008-08-31 13:03 ` Tejun Heo
2008-08-31 14:32 ` Bartlomiej Zolnierkiewicz
2008-08-31 17:07 ` Elias Oltmanns
2008-08-31 19:35 ` Bartlomiej Zolnierkiewicz
2008-09-01 15:41 ` Elias Oltmanns
2008-09-01 2:08 ` Henrique de Moraes Holschuh
2008-09-01 9:37 ` Matthew Garrett
2008-08-31 16:14 ` Elias Oltmanns
2008-09-01 8:33 ` Tejun Heo
2008-09-01 14:51 ` Elias Oltmanns
2008-09-01 16:43 ` Tejun Heo
2008-09-03 20:23 ` Elias Oltmanns
2008-09-04 9:06 ` Tejun Heo
2008-09-04 17:32 ` Elias Oltmanns
2008-09-05 8:51 ` Tejun Heo
2008-09-10 13:53 ` Elias Oltmanns
2008-09-10 14:40 ` Tejun Heo
2008-09-10 19:28 ` Elias Oltmanns
2008-09-10 20:23 ` Tejun Heo
2008-09-10 21:04 ` Elias Oltmanns
2008-09-10 22:56 ` Tejun Heo
2008-09-11 12:26 ` Elias Oltmanns
2008-09-11 12:51 ` Tejun Heo
2008-09-11 13:01 ` Tejun Heo
2008-09-11 18:28 ` Valdis.Kletnieks
2008-09-11 23:25 ` Tejun Heo
2008-09-12 10:15 ` Elias Oltmanns
2008-09-12 18:11 ` Valdis.Kletnieks
2008-09-17 15:26 ` Elias Oltmanns [this message]
2008-08-29 21:26 ` [PATCH 3/4] ide: " Elias Oltmanns
2008-09-01 19:29 ` Bartlomiej Zolnierkiewicz
2008-09-03 20:01 ` Elias Oltmanns
2008-09-03 21:33 ` Elias Oltmanns
2008-09-05 17:33 ` Bartlomiej Zolnierkiewicz
2008-09-12 9:55 ` Elias Oltmanns
2008-09-12 11:55 ` Elias Oltmanns
2008-09-15 19:15 ` Elias Oltmanns
2008-09-15 23:22 ` Bartlomiej Zolnierkiewicz
2008-09-17 15:28 ` Elias Oltmanns
2008-08-29 21:28 ` [PATCH 4/4] Add documentation for hard disk shock protection interface Elias Oltmanns
2008-09-08 22:04 ` Randy Dunlap
2008-09-16 16:53 ` Elias Oltmanns
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874p4eoksc.fsf@denkblock.local \
--to=eo@nebensachen.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=bzolnier@gmail.com \
--cc=htejun@gmail.com \
--cc=jeff@garzik.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).