@@ -479,3 +479,68 @@ bool blk_ledtrig_clear(struct gendisk *const gd)
return changed;
}
EXPORT_SYMBOL_GPL(blk_ledtrig_clear);
+
+
+/*
+ *
+ * Set, clear & show LED triggers via sysfs device attributes
+ *
+ * (See dev_attr_led_trigger and disk_attrs in genhd.c)
+ *
+ */
+
+ssize_t blk_ledtrig_devattr_store(struct device *const dev,
+ struct device_attribute *const attr,
+ const char *const buf, const size_t count)
+{
+ struct gendisk *const gd = dev_to_disk(dev);
+ const char *const name = blk_ledtrig_skip_whitespace(buf);
+ const char *const endp = blk_ledtrig_find_whitespace(name);
+ const ptrdiff_t name_len = endp - name; // always >= 0
+ int ret;
+
+ if (name_len == 0)
+ ret = blk_ledtrig_clear(gd);
+ else
+ ret = __blk_ledtrig_set(gd, name, name_len);
+
+ if (ret < 0)
+ return ret;
+
+ return blk_ledtrig_skip_whitespace(endp) - buf;
+}
+
+ssize_t blk_ledtrig_devattr_show(struct device *const dev,
+ struct device_attribute *const attr,
+ char *const buf)
+{
+ struct gendisk *const gd = dev_to_disk(dev);
+ const struct blk_ledtrig *t;
+ size_t name_len;
+ int ret;
+
+ ret = mutex_lock_interruptible(&gd->ledtrig_mutex);
+ if (unlikely(ret != 0))
+ return ret;
+
+ t = gd->ledtrig;
+
+ if (t != NULL) {
+ name_len = strlen(t->name);
+ if (likely(name_len < PAGE_SIZE - 1))
+ memcpy(buf, t->name, name_len);
+ }
+
+ mutex_unlock(&gd->ledtrig_mutex);
+
+ if (t == NULL)
+ return sprintf(buf, "(none)\n");
+
+ if (unlikely(name_len >= PAGE_SIZE - 1))
+ return -EOVERFLOW;
+
+ buf[name_len] = '\n';
+ buf[name_len + 1] = 0;
+
+ return (ssize_t)(name_len + 1);
+}
@@ -19,6 +19,14 @@ static inline void blk_ledtrig_disk_init(struct gendisk *const gd)
mutex_init(&gd->ledtrig_mutex);
}
+ssize_t blk_ledtrig_devattr_store(struct device *const dev,
+ struct device_attribute *const attr,
+ const char *const buf, const size_t count);
+
+ssize_t blk_ledtrig_devattr_show(struct device *const dev,
+ struct device_attribute *const attr,
+ char *const buf);
+
#else // CONFIG_BLK_LED_TRIGGERS
static inline void blk_ledtrig_init(void) {}
@@ -1014,6 +1014,12 @@ static struct device_attribute dev_attr_fail_timeout =
__ATTR(io-timeout-fail, 0644, part_timeout_show, part_timeout_store);
#endif
+#ifdef CONFIG_BLK_LED_TRIGGERS
+static struct device_attribute dev_attr_led_trigger =
+ __ATTR(led_trigger, 0644,
+ blk_ledtrig_devattr_show, blk_ledtrig_devattr_store);
+#endif
+
static struct attribute *disk_attrs[] = {
&dev_attr_range.attr,
&dev_attr_ext_range.attr,
@@ -1035,6 +1041,9 @@ static struct attribute *disk_attrs[] = {
#endif
#ifdef CONFIG_FAIL_IO_TIMEOUT
&dev_attr_fail_timeout.attr,
+#endif
+#ifdef CONFIG_BLK_LED_TRIGGERS
+ &dev_attr_led_trigger.attr,
#endif
NULL
};
* Set/store functions in block/blk-ledtrig.c * Add device attributes to disk_attrs in block/genhd.c Signed-off-by: Ian Pilcher <arequipeno@gmail.com> --- block/blk-ledtrig.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ block/blk-ledtrig.h | 8 ++++++ block/genhd.c | 9 +++++++ 3 files changed, 82 insertions(+)