[RFC PATCH v2 03/10] block: Add block device LED trigger fields to gendisk structure
Ian Pilcher
arequipeno at gmail.com
Sun Aug 8 23:32:10 EDT 2021
Add header (blk-ledtrig.h) for LED trigger-related declarations
Add (inline) function to ensure trigger pointer is initialized
(to NULL) and call it from __device_add_disk()
Signed-off-by: Ian Pilcher <arequipeno at gmail.com>
---
block/blk-ledtrig.h | 25 +++++++++++++++++++++++++
block/genhd.c | 2 ++
include/linux/genhd.h | 4 ++++
3 files changed, 31 insertions(+)
create mode 100644 block/blk-ledtrig.h
diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h
new file mode 100644
index 000000000000..95a79d2fe447
--- /dev/null
+++ b/block/blk-ledtrig.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/*
+ * Block device LED triggers
+ *
+ * Copyright 2021 Ian Pilcher <arequipeno at gmail.com>
+ */
+
+#ifndef _BLOCK_BLK_LEDTRIG_H
+#define _BLOCK_BLK_LEDTRIG_H
+
+#ifdef CONFIG_BLK_LED_TRIGGERS
+
+static inline void blk_ledtrig_disk_init(struct gendisk *const disk)
+{
+ RCU_INIT_POINTER(disk->led, NULL);
+}
+
+#else // CONFIG_BLK_LED_TRIGGERS
+
+static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {}
+
+#endif // CONFIG_BLK_LED_TRIGGERS
+
+#endif // _BLOCK_BLK_LEDTRIG_H
diff --git a/block/genhd.c b/block/genhd.c
index 298ee78c1bda..b168172e664b 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -26,6 +26,7 @@
#include <linux/badblocks.h>
#include "blk.h"
+#include "blk-ledtrig.h"
static struct kobject *block_depr;
@@ -539,6 +540,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
disk_add_events(disk);
blk_integrity_add(disk);
+ blk_ledtrig_disk_init(disk);
}
void device_add_disk(struct device *parent, struct gendisk *disk,
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 13b34177cc85..efcb1ca62f17 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -168,6 +168,10 @@ struct gendisk {
#endif /* CONFIG_BLK_DEV_INTEGRITY */
#if IS_ENABLED(CONFIG_CDROM)
struct cdrom_device_info *cdi;
+#endif
+#ifdef CONFIG_BLK_LED_TRIGGERS
+ struct blk_ledtrig_led __rcu *led;
+ struct list_head led_dev_list_node;
#endif
int node_id;
struct badblocks *bb;
--
2.31.1
More information about the Kernelnewbies
mailing list