[RFC PATCH v2 02/10] block: Add file (blk-ledtrig.c) for block device LED trigger implementation
Ian Pilcher
arequipeno at gmail.com
Sun Aug 8 23:32:09 EDT 2021
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 at 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 at 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
More information about the Kernelnewbies
mailing list