kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Ian Pilcher <arequipeno@gmail.com>
To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org
Cc: axboe@kernel.dk, Ian Pilcher <arequipeno@gmail.com>,
	linux-kernel@vger.kernel.org, pavel@ucw.cz,
	kernelnewbies@kernelnewbies.org
Subject: [RFC PATCH 8/8] block: Blink device LED when request is sent to low-level driver
Date: Wed, 28 Jul 2021 20:53:44 -0500	[thread overview]
Message-ID: <20210729015344.3366750-9-arequipeno@gmail.com> (raw)
In-Reply-To: <20210729015344.3366750-1-arequipeno@gmail.com>

* Don't wait to lock the device's LED trigger mutex; just don't
  blink the LED this time if it can't be locked right away, i.e.
  if mutex_trylock() fails.

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
---
 block/blk-ledtrig.c | 24 ++++++++++++++++++++++++
 block/blk-ledtrig.h |  9 +++++++++
 block/blk-mq.c      |  2 ++
 3 files changed, 35 insertions(+)

diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c
index 2d324df45149..1b475530ce6c 100644
--- a/block/blk-ledtrig.c
+++ b/block/blk-ledtrig.c
@@ -544,3 +544,27 @@ ssize_t blk_ledtrig_devattr_show(struct device *const dev,
 
 	return (ssize_t)(name_len + 1);
 }
+
+
+/*
+ *
+ *	Try to blink an LED
+ *
+ */
+
+void __blk_ledtrig_try_blink(struct gendisk *const gd)
+{
+	if (mutex_trylock(&gd->ledtrig_mutex)) {
+
+		if (gd->ledtrig != NULL) {
+
+			unsigned long delay_on = 75;
+			unsigned long delay_off = 25;
+
+			led_trigger_blink_oneshot(&gd->ledtrig->trigger,
+						  &delay_on, &delay_off, 0);
+		}
+
+		mutex_unlock(&gd->ledtrig_mutex);
+	}
+}
diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h
index 5d228905edbf..146deda92a8e 100644
--- a/block/blk-ledtrig.h
+++ b/block/blk-ledtrig.h
@@ -27,10 +27,19 @@ ssize_t blk_ledtrig_devattr_show(struct device *const dev,
 				 struct device_attribute *const attr,
 				 char *const buf);
 
+void __blk_ledtrig_try_blink(struct gendisk *gd);
+
+static inline void blk_ledtrig_try_blink(struct gendisk *const gd)
+{
+	if (gd != NULL)
+		__blk_ledtrig_try_blink(gd);
+}
+
 #else	// CONFIG_BLK_LED_TRIGGERS
 
 static inline void blk_ledtrig_init(void) {}
 static inline void blk_ledtrig_disk_init(const struct gendisk *gd) {}
+static inline void blk_ledtrig_try_blink(const struct gendisk *gd) {}
 
 // Real function (declared in include/linux/blk-ledtrig.h) returns a bool.
 // This is only here for del_gendisk() (in genhd.c), which doesn't check
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 2c4ac51e54eb..5593ece7b676 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->rq_disk);
 			break;
 		case BLK_STS_RESOURCE:
 		case BLK_STS_DEV_RESOURCE:
-- 
2.31.1


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  parent reply	other threads:[~2021-07-29  1:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29  1:53 [RFC PATCH 0/8] Add configurable block device LED triggers Ian Pilcher
2021-07-29  1:53 ` [RFC PATCH 1/8] docs: Add block device LED trigger documentation Ian Pilcher
2021-07-29  3:09   ` Valdis Klētnieks
2021-07-29 15:52     ` Ian Pilcher
2021-07-30  5:22       ` Greg KH
2021-07-29  5:53   ` Greg KH
2021-07-29 11:59   ` Marek Behún
2021-07-29 18:03     ` Ian Pilcher
2021-07-29  1:53 ` [RFC PATCH 2/8] block: Add block device LED trigger list Ian Pilcher
2021-07-29  3:14   ` Valdis Klētnieks
2021-07-29 15:55     ` Ian Pilcher
2021-07-29  1:53 ` [RFC PATCH 3/8] block: Add kernel APIs to create & delete block device LED triggers Ian Pilcher
2021-07-29  3:45   ` Valdis Klētnieks
2021-07-29 16:16     ` Ian Pilcher
2021-07-29  5:52   ` Greg KH
2021-07-29  1:53 ` [RFC PATCH 4/8] block: Add block class attributes to manage LED trigger list Ian Pilcher
2021-07-29  5:54   ` Greg KH
2021-07-29  1:53 ` [RFC PATCH 5/8] block: Add block device LED trigger info to struct genhd Ian Pilcher
2021-07-29  1:53 ` [RFC PATCH 6/8] block: Add kernel APIs to set & clear per-block device LED triggers Ian Pilcher
2021-07-29  1:53 ` [RFC PATCH 7/8] block: Add block device attributes to set & clear " Ian Pilcher
2021-07-29  1:53 ` Ian Pilcher [this message]
2021-07-29  8:54 ` [RFC PATCH 0/8] Add configurable block device " Pavel Machek
2021-07-29 17:03   ` Ian Pilcher
2021-07-29 18:35     ` Pavel Machek
2021-07-29 19:14       ` Ian Pilcher

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=20210729015344.3366750-9-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;
as well as URLs for NNTP newsgroup(s).