lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 18 Aug 2021 21:50:37 -0500
From:   Ian Pilcher <arequipeno@...il.com>
To:     linux-block@...r.kernel.org, linux-leds@...r.kernel.org
Cc:     axboe@...nel.dk, pavel@....cz, kabel@...nel.org,
        linux-kernel@...r.kernel.org, kernelnewbies@...nelnewbies.org
Subject: [RFC PATCH v3 02/18] block: Add get_disk_by_name() for use by blkdev LED trigger

Add API that gets a "handle" (pointer & incremented reference count) to a
block device (struct gendisk) by name.  Used by the block device LED
trigger when configuring which device(s) an LED should monitor.

Signed-off-by: Ian Pilcher <arequipeno@...il.com>
---
 block/genhd.c         | 25 +++++++++++++++++++++++++
 include/linux/genhd.h | 10 ++++++++++
 2 files changed, 35 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 298ee78c1bda..e6d7bb709d62 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1362,3 +1362,28 @@ int bdev_read_only(struct block_device *bdev)
 	return bdev->bd_read_only || get_disk_ro(bdev->bd_disk);
 }
 EXPORT_SYMBOL(bdev_read_only);
+
+static int match_disk_name(struct device *const dev, const void *const name)
+{
+	return dev->type == &disk_type
+			&& strcmp(name, dev_to_disk(dev)->disk_name) == 0;
+}
+
+/**
+ * get_disk_by_name - get a gendisk by name
+ * @name:	the name of the disk
+ *
+ * Returns a pointer to the gendisk named @name (if it exists), @NULL if not.
+ * Increments the disk's reference count, so caller must call put_device().
+ */
+struct gendisk *get_disk_by_name(const char *const name)
+{
+	struct device *dev;
+
+	dev = class_find_device(&block_class, NULL, name, match_disk_name);
+	if (dev == NULL)
+		return NULL;
+
+	return dev_to_disk(dev);
+}
+EXPORT_SYMBOL_GPL(get_disk_by_name);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 13b34177cc85..b26bbf2d9048 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -342,4 +342,14 @@ static inline void printk_all_partitions(void)
 }
 #endif /* CONFIG_BLOCK */
 
+/* for blkdev LED trigger (drivers/leds/trigger/ledtrig-blkdev.c) */
+#ifdef CONFIG_BLOCK
+struct gendisk *get_disk_by_name(const char *name);
+#else
+static inline struct gendisk *get_disk_by_name(const char *name)
+{
+	return NULL;
+}
+#endif
+
 #endif /* _LINUX_GENHD_H */
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ