All of lore.kernel.org
 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, pavel@ucw.cz, linux-kernel@vger.kernel.org,
	kernelnewbies@kernelnewbies.org
Subject: [RFC PATCH v2 02/10] block: Add file (blk-ledtrig.c) for block device LED trigger implementation
Date: Sun,  8 Aug 2021 22:32:09 -0500	[thread overview]
Message-ID: <20210809033217.1113444-3-arequipeno@gmail.com> (raw)
In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com>

Define data structure for all associated LEDs

Add list of associated LEDs and list search helper

Add trigger mutex - must be held when accessing trigger/LED or device/LED
associations

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
---
 block/blk-ledtrig.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 block/blk-ledtrig.c

diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c
new file mode 100644
index 000000000000..c5ad57ed9c3b
--- /dev/null
+++ b/block/blk-ledtrig.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ *	Block device LED triggers
+ *
+ *	Copyright 2021 Ian Pilcher <arequipeno@gmail.com>
+ */
+
+#include <linux/leds.h>
+#include <linux/mutex.h>
+
+/*
+ *
+ *	Trigger mutex and LED list
+ *
+ */
+
+// Must hold when doing anything with LED/trigger/block device
+// associations
+static DEFINE_MUTEX(blk_ledtrig_mutex);
+
+static LIST_HEAD(blk_ledtrig_leds);
+
+// Every LED associated with the blkdev trigger gets one of these
+struct blk_ledtrig_led {
+	struct kobject		*dir;		// block_devices subdirectory
+	struct led_classdev	*led;
+	unsigned int		blink_on;
+	unsigned int		blink_off;
+	struct list_head	leds_list_node;
+	struct list_head	dev_list;
+};
+
+// Caller must hold blk_ledtrig_mutex
+static struct blk_ledtrig_led *blk_ledtrig_find(const char *const led_name,
+						const size_t name_len)
+{
+	struct blk_ledtrig_led *bd_led;
+
+	list_for_each_entry(bd_led, &blk_ledtrig_leds, leds_list_node) {
+		if (strlen(bd_led->led->name) != name_len)
+			continue;
+		if (memcmp(bd_led->led->name, led_name, name_len) == 0)
+			return bd_led;
+	}
+
+	return NULL;
+}
-- 
2.31.1


WARNING: multiple messages have this Message-ID (diff)
From: Ian Pilcher <arequipeno@gmail.com>
To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org
Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org, pavel@ucw.cz,
	kernelnewbies@kernelnewbies.org
Subject: [RFC PATCH v2 02/10] block: Add file (blk-ledtrig.c) for block device LED trigger implementation
Date: Sun,  8 Aug 2021 22:32:09 -0500	[thread overview]
Message-ID: <20210809033217.1113444-3-arequipeno@gmail.com> (raw)
In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com>

Define data structure for all associated LEDs

Add list of associated LEDs and list search helper

Add trigger mutex - must be held when accessing trigger/LED or device/LED
associations

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
---
 block/blk-ledtrig.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 block/blk-ledtrig.c

diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c
new file mode 100644
index 000000000000..c5ad57ed9c3b
--- /dev/null
+++ b/block/blk-ledtrig.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ *	Block device LED triggers
+ *
+ *	Copyright 2021 Ian Pilcher <arequipeno@gmail.com>
+ */
+
+#include <linux/leds.h>
+#include <linux/mutex.h>
+
+/*
+ *
+ *	Trigger mutex and LED list
+ *
+ */
+
+// Must hold when doing anything with LED/trigger/block device
+// associations
+static DEFINE_MUTEX(blk_ledtrig_mutex);
+
+static LIST_HEAD(blk_ledtrig_leds);
+
+// Every LED associated with the blkdev trigger gets one of these
+struct blk_ledtrig_led {
+	struct kobject		*dir;		// block_devices subdirectory
+	struct led_classdev	*led;
+	unsigned int		blink_on;
+	unsigned int		blink_off;
+	struct list_head	leds_list_node;
+	struct list_head	dev_list;
+};
+
+// Caller must hold blk_ledtrig_mutex
+static struct blk_ledtrig_led *blk_ledtrig_find(const char *const led_name,
+						const size_t name_len)
+{
+	struct blk_ledtrig_led *bd_led;
+
+	list_for_each_entry(bd_led, &blk_ledtrig_leds, leds_list_node) {
+		if (strlen(bd_led->led->name) != name_len)
+			continue;
+		if (memcmp(bd_led->led->name, led_name, name_len) == 0)
+			return bd_led;
+	}
+
+	return NULL;
+}
-- 
2.31.1


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

  parent reply	other threads:[~2021-08-09  3:32 UTC|newest]

Thread overview: 56+ 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 ` Ian Pilcher
2021-08-09  3:32 ` [RFC PATCH v2 01/10] docs: Add block device LED trigger documentation Ian Pilcher
2021-08-09  3:32   ` Ian Pilcher
2021-08-10 13:49   ` Pavel Machek
2021-08-10 13:49     ` Pavel Machek
2021-08-09  3:32 ` Ian Pilcher [this message]
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   ` 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   ` 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  3:32   ` Ian Pilcher
2021-08-09  4:21   ` Jackie Liu
2021-08-09  4:21     ` Jackie Liu
2021-08-09 15:44     ` Ian Pilcher
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   ` 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   ` 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
2021-08-09  3:32 ` [RFC PATCH v2 09/10] block: Blink device LED (if any) when request is sent to its driver Ian Pilcher
2021-08-09  3:32   ` Ian Pilcher
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  3:32   ` Ian Pilcher
2021-08-09 18:56 ` [RFC PATCH v2 00/10] Add configurable " Marek Behún
2021-08-09 18:56   ` Marek Behún
2021-08-09 19:07   ` Pali Rohár
2021-08-09 19:07     ` Pali Rohár
2021-08-09 19:54   ` Ian Pilcher
2021-08-09 19:54     ` Ian Pilcher
2021-08-09 22:43     ` Marek Behún
2021-08-09 22:43       ` Marek Behún
2021-08-09 23:50       ` Ian Pilcher
2021-08-09 23:50         ` Ian Pilcher
2021-08-10  6:35         ` Greg KH
2021-08-10  6:35           ` Greg KH
2021-08-10 13:38           ` Marek Behún
2021-08-10 13:38             ` Marek Behún
2021-08-10 14:48             ` Greg KH
2021-08-10 14:48               ` Greg KH
2021-08-10 15:55               ` Ian Pilcher
2021-08-10 15:55                 ` Ian Pilcher
2021-08-10 16:24                 ` Greg KH
2021-08-10 16:24                   ` Greg KH
2021-08-10 16:39                   ` Marek Behún
2021-08-10 16:39                     ` Marek Behún
2021-08-10 16:43                   ` Ian Pilcher
2021-08-10 16:43                     ` Ian Pilcher
2021-08-11  6:26         ` Christoph Hellwig
2021-08-11  6:26           ` Christoph Hellwig
2021-08-11 10:50           ` Marek Behún
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-3-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 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.