diff options
author | Tejun Heo <htejun@gmail.com> | 2007-03-20 11:13:59 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2007-03-20 13:06:20 -0400 |
commit | c3c94c5a2fb43a654e777f509d5032b0db8ed09f (patch) | |
tree | cbc9b0adfa0a83fc5859344d6f9911d3010a29ac /drivers | |
parent | 3721050afc6cb6ddf6de0f782e2054ebcc225e9b (diff) |
[SCSI] sd: implement START/STOP management
Implement SBC START/STOP management. sdev->mange_start_stop is added.
When it's set to one, sd STOPs the device on suspend and shutdown and
STARTs it on resume. sdev->manage_start_stop defaults is in sdev
instead of scsi_disk cdev to allow ->slave_config() override the
default configuration but is exported under scsi_disk sysfs node as
sdev->allow_restart is.
When manage_start_stop is zero (the default value), this patch doesn't
introduce any behavior change.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Rejections fixed and
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/scsi_sysfs.c | 31 | ||||
-rw-r--r-- | drivers/scsi/sd.c | 101 |
2 files changed, 128 insertions, 4 deletions
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index c275dcac3f18..96db51c40ef3 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c | |||
@@ -278,6 +278,7 @@ static int scsi_bus_match(struct device *dev, struct device_driver *gendrv) | |||
278 | 278 | ||
279 | static int scsi_bus_suspend(struct device * dev, pm_message_t state) | 279 | static int scsi_bus_suspend(struct device * dev, pm_message_t state) |
280 | { | 280 | { |
281 | struct device_driver *drv = dev->driver; | ||
281 | struct scsi_device *sdev = to_scsi_device(dev); | 282 | struct scsi_device *sdev = to_scsi_device(dev); |
282 | struct scsi_host_template *sht = sdev->host->hostt; | 283 | struct scsi_host_template *sht = sdev->host->hostt; |
283 | int err; | 284 | int err; |
@@ -286,23 +287,45 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state) | |||
286 | if (err) | 287 | if (err) |
287 | return err; | 288 | return err; |
288 | 289 | ||
289 | if (sht->suspend) | 290 | /* call HLD suspend first */ |
291 | if (drv && drv->suspend) { | ||
292 | err = drv->suspend(dev, state); | ||
293 | if (err) | ||
294 | return err; | ||
295 | } | ||
296 | |||
297 | /* then, call host suspend */ | ||
298 | if (sht->suspend) { | ||
290 | err = sht->suspend(sdev, state); | 299 | err = sht->suspend(sdev, state); |
300 | if (err) { | ||
301 | if (drv && drv->resume) | ||
302 | drv->resume(dev); | ||
303 | return err; | ||
304 | } | ||
305 | } | ||
291 | 306 | ||
292 | return err; | 307 | return 0; |
293 | } | 308 | } |
294 | 309 | ||
295 | static int scsi_bus_resume(struct device * dev) | 310 | static int scsi_bus_resume(struct device * dev) |
296 | { | 311 | { |
312 | struct device_driver *drv = dev->driver; | ||
297 | struct scsi_device *sdev = to_scsi_device(dev); | 313 | struct scsi_device *sdev = to_scsi_device(dev); |
298 | struct scsi_host_template *sht = sdev->host->hostt; | 314 | struct scsi_host_template *sht = sdev->host->hostt; |
299 | int err = 0; | 315 | int err = 0, err2 = 0; |
300 | 316 | ||
317 | /* call host resume first */ | ||
301 | if (sht->resume) | 318 | if (sht->resume) |
302 | err = sht->resume(sdev); | 319 | err = sht->resume(sdev); |
303 | 320 | ||
321 | /* then, call HLD resume */ | ||
322 | if (drv && drv->resume) | ||
323 | err2 = drv->resume(dev); | ||
324 | |||
304 | scsi_device_resume(sdev); | 325 | scsi_device_resume(sdev); |
305 | return err; | 326 | |
327 | /* favor LLD failure */ | ||
328 | return err ? err : err2;; | ||
306 | } | 329 | } |
307 | 330 | ||
308 | struct bus_type scsi_bus_type = { | 331 | struct bus_type scsi_bus_type = { |
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3dda77c31f50..49a94ae3225b 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -147,6 +147,20 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf, | |||
147 | return count; | 147 | return count; |
148 | } | 148 | } |
149 | 149 | ||
150 | static ssize_t sd_store_manage_start_stop(struct class_device *cdev, | ||
151 | const char *buf, size_t count) | ||
152 | { | ||
153 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | ||
154 | struct scsi_device *sdp = sdkp->device; | ||
155 | |||
156 | if (!capable(CAP_SYS_ADMIN)) | ||
157 | return -EACCES; | ||
158 | |||
159 | sdp->manage_start_stop = simple_strtoul(buf, NULL, 10); | ||
160 | |||
161 | return count; | ||
162 | } | ||
163 | |||
150 | static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf, | 164 | static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf, |
151 | size_t count) | 165 | size_t count) |
152 | { | 166 | { |
@@ -179,6 +193,14 @@ static ssize_t sd_show_fua(struct class_device *cdev, char *buf) | |||
179 | return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); | 193 | return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); |
180 | } | 194 | } |
181 | 195 | ||
196 | static ssize_t sd_show_manage_start_stop(struct class_device *cdev, char *buf) | ||
197 | { | ||
198 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | ||
199 | struct scsi_device *sdp = sdkp->device; | ||
200 | |||
201 | return snprintf(buf, 20, "%u\n", sdp->manage_start_stop); | ||
202 | } | ||
203 | |||
182 | static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf) | 204 | static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf) |
183 | { | 205 | { |
184 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | 206 | struct scsi_disk *sdkp = to_scsi_disk(cdev); |
@@ -192,6 +214,8 @@ static struct class_device_attribute sd_disk_attrs[] = { | |||
192 | __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), | 214 | __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), |
193 | __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart, | 215 | __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart, |
194 | sd_store_allow_restart), | 216 | sd_store_allow_restart), |
217 | __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop, | ||
218 | sd_store_manage_start_stop), | ||
195 | __ATTR_NULL, | 219 | __ATTR_NULL, |
196 | }; | 220 | }; |
197 | 221 | ||
@@ -208,6 +232,8 @@ static struct scsi_driver sd_template = { | |||
208 | .name = "sd", | 232 | .name = "sd", |
209 | .probe = sd_probe, | 233 | .probe = sd_probe, |
210 | .remove = sd_remove, | 234 | .remove = sd_remove, |
235 | .suspend = sd_suspend, | ||
236 | .resume = sd_resume, | ||
211 | .shutdown = sd_shutdown, | 237 | .shutdown = sd_shutdown, |
212 | }, | 238 | }, |
213 | .rescan = sd_rescan, | 239 | .rescan = sd_rescan, |
@@ -1707,6 +1733,32 @@ static void scsi_disk_release(struct class_device *cdev) | |||
1707 | kfree(sdkp); | 1733 | kfree(sdkp); |
1708 | } | 1734 | } |
1709 | 1735 | ||
1736 | static int sd_start_stop_device(struct scsi_device *sdp, int start) | ||
1737 | { | ||
1738 | unsigned char cmd[6] = { START_STOP }; /* START_VALID */ | ||
1739 | struct scsi_sense_hdr sshdr; | ||
1740 | int res; | ||
1741 | |||
1742 | if (start) | ||
1743 | cmd[4] |= 1; /* START */ | ||
1744 | |||
1745 | if (!scsi_device_online(sdp)) | ||
1746 | return -ENODEV; | ||
1747 | |||
1748 | res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, | ||
1749 | SD_TIMEOUT, SD_MAX_RETRIES); | ||
1750 | if (res) { | ||
1751 | printk(KERN_WARNING "FAILED\n status = %x, message = %02x, " | ||
1752 | "host = %d, driver = %02x\n ", | ||
1753 | status_byte(res), msg_byte(res), | ||
1754 | host_byte(res), driver_byte(res)); | ||
1755 | if (driver_byte(res) & DRIVER_SENSE) | ||
1756 | scsi_print_sense_hdr("sd", &sshdr); | ||
1757 | } | ||
1758 | |||
1759 | return res; | ||
1760 | } | ||
1761 | |||
1710 | /* | 1762 | /* |
1711 | * Send a SYNCHRONIZE CACHE instruction down to the device through | 1763 | * Send a SYNCHRONIZE CACHE instruction down to the device through |
1712 | * the normal SCSI command structure. Wait for the command to | 1764 | * the normal SCSI command structure. Wait for the command to |
@@ -1714,6 +1766,7 @@ static void scsi_disk_release(struct class_device *cdev) | |||
1714 | */ | 1766 | */ |
1715 | static void sd_shutdown(struct device *dev) | 1767 | static void sd_shutdown(struct device *dev) |
1716 | { | 1768 | { |
1769 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1717 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | 1770 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); |
1718 | 1771 | ||
1719 | if (!sdkp) | 1772 | if (!sdkp) |
@@ -1723,9 +1776,57 @@ static void sd_shutdown(struct device *dev) | |||
1723 | sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); | 1776 | sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); |
1724 | sd_sync_cache(sdkp); | 1777 | sd_sync_cache(sdkp); |
1725 | } | 1778 | } |
1779 | |||
1780 | if (system_state != SYSTEM_RESTART && sdp->manage_start_stop) { | ||
1781 | printk(KERN_NOTICE "Stopping disk %s: \n", | ||
1782 | sdkp->disk->disk_name); | ||
1783 | sd_start_stop_device(sdp, 0); | ||
1784 | } | ||
1785 | |||
1726 | scsi_disk_put(sdkp); | 1786 | scsi_disk_put(sdkp); |
1727 | } | 1787 | } |
1728 | 1788 | ||
1789 | static int sd_suspend(struct device *dev, pm_message_t mesg) | ||
1790 | { | ||
1791 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1792 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | ||
1793 | int ret; | ||
1794 | |||
1795 | if (!sdkp) | ||
1796 | return 0; /* this can happen */ | ||
1797 | |||
1798 | if (sdkp->WCE) { | ||
1799 | printk(KERN_NOTICE "Synchronizing SCSI cache for disk %s: \n", | ||
1800 | sdkp->disk->disk_name); | ||
1801 | ret = sd_sync_cache(sdkp); | ||
1802 | if (ret) | ||
1803 | return ret; | ||
1804 | } | ||
1805 | |||
1806 | if (mesg.event == PM_EVENT_SUSPEND && sdp->manage_start_stop) { | ||
1807 | printk(KERN_NOTICE "Stopping disk %s: \n", | ||
1808 | sdkp->disk->disk_name); | ||
1809 | ret = sd_start_stop_device(sdp, 0); | ||
1810 | if (ret) | ||
1811 | return ret; | ||
1812 | } | ||
1813 | |||
1814 | return 0; | ||
1815 | } | ||
1816 | |||
1817 | static int sd_resume(struct device *dev) | ||
1818 | { | ||
1819 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1820 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | ||
1821 | |||
1822 | if (!sdp->manage_start_stop) | ||
1823 | return 0; | ||
1824 | |||
1825 | printk(KERN_NOTICE "Starting disk %s: \n", sdkp->disk->disk_name); | ||
1826 | |||
1827 | return sd_start_stop_device(sdp, 1); | ||
1828 | } | ||
1829 | |||
1729 | /** | 1830 | /** |
1730 | * init_sd - entry point for this driver (both when built in or when | 1831 | * init_sd - entry point for this driver (both when built in or when |
1731 | * a module). | 1832 | * a module). |