From: Ian Pilcher <arequipeno@gmail.com>
To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org
Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org,
kernelnewbies@kernelnewbies.org
Subject: [RFC PATCH v2 09/10] block: Blink device LED (if any) when request is sent to its driver
Date: Sun, 8 Aug 2021 22:32:16 -0500 [thread overview]
Message-ID: <20210809033217.1113444-10-arequipeno@gmail.com> (raw)
In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com>
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(+)
diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c
index 14b1d33a2953..10588f3dea15 100644
--- a/block/blk-ledtrig.c
+++ b/block/blk-ledtrig.c
@@ -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();
+}
diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h
index 771000d43647..7eb1d88e2b3c 100644
--- a/block/blk-ledtrig.h
+++ b/block/blk-ledtrig.h
@@ -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
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 2c4ac51e54eb..7732e31f3ca8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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:
--
2.31.1
next prev parent reply other threads:[~2021-08-09 3:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 3:32 [RFC PATCH v2 00/10] Add configurable block device LED triggers Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 01/10] docs: Add block device LED trigger documentation Ian Pilcher
2021-08-10 13:49 ` Pavel Machek
2021-08-09 3:32 ` [RFC PATCH v2 02/10] block: Add file (blk-ledtrig.c) for block device LED trigger implementation Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 03/10] block: Add block device LED trigger fields to gendisk structure Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 04/10] block: Add functions to set & clear block device LEDs Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 05/10] block: Add block device sysfs attribute to set/clear/show LED Ian Pilcher
2021-08-09 4:21 ` Jackie Liu
2021-08-09 15:44 ` Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 06/10] block: Add activate and deactivate functions for block device LED trigger Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 07/10] block: Add sysfs attributes to LEDs associated with blkdev trigger Ian Pilcher
2021-08-09 3:32 ` [RFC PATCH v2 08/10] block: Add init function for block device LED trigger Ian Pilcher
2021-08-09 3:32 ` Ian Pilcher [this message]
2021-08-09 3:32 ` [RFC PATCH v2 10/10] block: Add config option to enable block device LED triggers Ian Pilcher
2021-08-09 18:56 ` [RFC PATCH v2 00/10] Add configurable " Marek Behún
2021-08-09 19:07 ` Pali Rohár
2021-08-09 19:54 ` Ian Pilcher
2021-08-09 22:43 ` Marek Behún
2021-08-09 23:50 ` Ian Pilcher
2021-08-10 6:35 ` Greg KH
2021-08-10 13:38 ` Marek Behún
2021-08-10 14:48 ` Greg KH
2021-08-10 15:55 ` Ian Pilcher
2021-08-10 16:24 ` Greg KH
2021-08-10 16:39 ` Marek Behún
2021-08-10 16:43 ` Ian Pilcher
2021-08-11 6:26 ` Christoph Hellwig
2021-08-11 10:50 ` Marek Behún
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210809033217.1113444-10-arequipeno@gmail.com \
--to=arequipeno@gmail.com \
--cc=axboe@kernel.dk \
--cc=kernelnewbies@kernelnewbies.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®