aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian King <brking@us.ibm.com>2006-06-27 12:10:31 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-06-28 12:39:06 -0400
commita144c5ae0956fb262e6c82624c82b1110a451437 (patch)
tree5ce95ee7f08af2e2da257a8d7039e5c63b08db38
parent3bdad7bd253f17ead00b4af2e82f84e9522c95ac (diff)
[SCSI] scsi: Add allow_restart sysfs class attribute
This is a resend of a patch I generated in response to an email sent by Ruben Faelens <parasietje@gmail.com>. His original email to linux-scsi requested a method in which he could spin down a scsi disk when not in use and have the kernel automatically spin it back up when an I/O was generated to the disk. The infrastructure to automatically spin a disk up has been in the scsi error handler for some time now, but it is not enabled by default. This patch adds an sd sysfs attribute which allows userspace to enable this behavior. Signed-off-by: Brian King <brking@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
-rw-r--r--drivers/scsi/sd.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f899ff0cf005..2e96c3d8f7e2 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -208,6 +208,23 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
208 return count; 208 return count;
209} 209}
210 210
211static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
212 size_t count)
213{
214 struct scsi_disk *sdkp = to_scsi_disk(cdev);
215 struct scsi_device *sdp = sdkp->device;
216
217 if (!capable(CAP_SYS_ADMIN))
218 return -EACCES;
219
220 if (sdp->type != TYPE_DISK)
221 return -EINVAL;
222
223 sdp->allow_restart = simple_strtoul(buf, NULL, 10);
224
225 return count;
226}
227
211static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf) 228static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf)
212{ 229{
213 struct scsi_disk *sdkp = to_scsi_disk(cdev); 230 struct scsi_disk *sdkp = to_scsi_disk(cdev);
@@ -223,10 +240,19 @@ static ssize_t sd_show_fua(struct class_device *cdev, char *buf)
223 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); 240 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
224} 241}
225 242
243static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
244{
245 struct scsi_disk *sdkp = to_scsi_disk(cdev);
246
247 return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart);
248}
249
226static struct class_device_attribute sd_disk_attrs[] = { 250static struct class_device_attribute sd_disk_attrs[] = {
227 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type, 251 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type,
228 sd_store_cache_type), 252 sd_store_cache_type),
229 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), 253 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
254 __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart,
255 sd_store_allow_restart),
230 __ATTR_NULL, 256 __ATTR_NULL,
231}; 257};
232 258