All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] scsi: Add allow_restart sysfs class attribute
@ 2006-06-27 16:10 Brian King
  2006-06-27 19:45 ` Stefan Richter
  0 siblings, 1 reply; 3+ messages in thread
From: Brian King @ 2006-06-27 16:10 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, parasietje, brking


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>
---

 linux-2.6-bjking1/drivers/scsi/sd.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+)

diff -puN drivers/scsi/sd.c~sd_allow_restart_sysfs_attr drivers/scsi/sd.c
--- linux-2.6/drivers/scsi/sd.c~sd_allow_restart_sysfs_attr	2006-06-26 14:07:59.000000000 -0500
+++ linux-2.6-bjking1/drivers/scsi/sd.c	2006-06-26 14:07:59.000000000 -0500
@@ -208,6 +208,23 @@ static ssize_t sd_store_cache_type(struc
 	return count;
 }
 
+static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
+				      size_t count)
+{
+	struct scsi_disk *sdkp = to_scsi_disk(cdev);
+	struct scsi_device *sdp = sdkp->device;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EACCES;
+
+	if (sdp->type != TYPE_DISK)
+		return -EINVAL;
+
+	sdp->allow_restart = simple_strtoul(buf, NULL, 10);
+
+	return count;
+}
+
 static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf)
 {
 	struct scsi_disk *sdkp = to_scsi_disk(cdev);
@@ -223,10 +240,19 @@ static ssize_t sd_show_fua(struct class_
 	return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
 }
 
+static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
+{
+	struct scsi_disk *sdkp = to_scsi_disk(cdev);
+
+	return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart);
+}
+
 static struct class_device_attribute sd_disk_attrs[] = {
 	__ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type,
 	       sd_store_cache_type),
 	__ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
+	__ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart,
+	       sd_store_allow_restart),
 	__ATTR_NULL,
 };
 
_

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-27 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27 16:10 [PATCH 1/1] scsi: Add allow_restart sysfs class attribute Brian King
2006-06-27 19:45 ` Stefan Richter
2006-06-27 19:54   ` Brian King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.