@@ -6,6 +6,7 @@
* Copyright 2021 Ian Pilcher <arequipeno@gmail.com>
*/
+#include <linux/blkdev.h>
#include <linux/ctype.h>
#include <linux/genhd.h>
#include <linux/leds.h>
@@ -441,3 +442,28 @@ static int __init blk_ledtrig_init(void)
return led_trigger_register(&blk_ledtrig_trigger);
}
device_initcall(blk_ledtrig_init);
+
+
+/*
+ *
+ * Blink the LED associated with a (non-NULL) disk (if set)
+ *
+ */
+
+void __blk_ledtrig_try_blink(struct request *const rq)
+{
+ struct blk_ledtrig_led *bd_led;
+ unsigned long delay_on, delay_off;
+
+ rcu_read_lock();
+
+ bd_led = rcu_dereference(rq->rq_disk->led);
+
+ if (bd_led != NULL) {
+ delay_on = READ_ONCE(bd_led->blink_on);
+ delay_off = READ_ONCE(bd_led->blink_off);
+ led_blink_set_oneshot(bd_led->led, &delay_on, &delay_off, 0);
+ }
+
+ rcu_read_unlock();
+}
@@ -26,10 +26,19 @@ ssize_t blk_ledtrig_dev_led_show(struct device *const dev,
struct device_attribute *const attr,
char *const buf);
+void __blk_ledtrig_try_blink(struct request *const rq);
+
+static inline void blk_ledtrig_try_blink(struct request *const rq)
+{
+ if (rq->rq_disk != NULL)
+ __blk_ledtrig_try_blink(rq);
+}
+
#else // CONFIG_BLK_LED_TRIGGERS
static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {}
static inline void blk_ledtrig_dev_clear(const struct gendisk *disk) {}
+static inline void blk_ledtrig_try_blink(const struct request *rq) {}
#endif // CONFIG_BLK_LED_TRIGGERS
@@ -40,6 +40,7 @@
#include "blk-stat.h"
#include "blk-mq-sched.h"
#include "blk-rq-qos.h"
+#include "blk-ledtrig.h"
static DEFINE_PER_CPU(struct llist_head, blk_cpu_done);
@@ -1381,6 +1382,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
switch (ret) {
case BLK_STS_OK:
queued++;
+ blk_ledtrig_try_blink(rq);
break;
case BLK_STS_RESOURCE:
case BLK_STS_DEV_RESOURCE:
Call led_blink_set_oneshot() in RCU critical section to ensure that LED doesn't disappear. (See synchronize_rcu() call in blk_ledtrig_deactivate()). Signed-off-by: Ian Pilcher <arequipeno@gmail.com> --- block/blk-ledtrig.c | 26 ++++++++++++++++++++++++++ block/blk-ledtrig.h | 9 +++++++++ block/blk-mq.c | 2 ++ 3 files changed, 37 insertions(+)