All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] block: Use enum for blk-mq tagset flags
@ 2025-01-02 14:44 John Garry
  2025-01-03  6:44 ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2025-01-02 14:44 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, hch, John Garry

Use an enum for tagset flags, so that they are automatically
renumbered when modified and we don't potentially leave
unused gaps. Some may find this neater.

This also catches when a new flag is added but a corresponding debugfs
name array member is not added.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
Differences to v1:
- Stop using ilog2 in HCTX_FLAG_NAME
- Reword commit message

Note this outstanding comment on v1:
https://lore.kernel.org/linux-block/20241223192727.GA21363@lst.de/

diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 4b6b20ccdb53..dc976a42ecb2 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -179,7 +179,7 @@ static const char *const alloc_policy_name[] = {
 };
 #undef BLK_TAG_ALLOC_NAME
 
-#define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
+#define HCTX_FLAG_NAME(name) [BLK_MQ_B_##name] = #name
 static const char *const hctx_flag_name[] = {
 	HCTX_FLAG_NAME(TAG_QUEUE_SHARED),
 	HCTX_FLAG_NAME(STACKING),
@@ -196,7 +196,7 @@ static int hctx_flags_show(void *data, struct seq_file *m)
 	const int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx->flags);
 
 	BUILD_BUG_ON(ARRAY_SIZE(hctx_flag_name) !=
-			BLK_MQ_F_ALLOC_POLICY_START_BIT);
+			BLK_MQ_B_ALLOC_POLICY_START_BIT);
 	BUILD_BUG_ON(ARRAY_SIZE(alloc_policy_name) != BLK_TAG_ALLOC_MAX);
 
 	seq_puts(m, "alloc_policy=");
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 7f6c482ebf54..8ef1a2455490 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -666,33 +666,39 @@ struct blk_mq_ops {
 #endif
 };
 
-/* Keep hctx_flag_name[] in sync with the definitions below */
 enum {
-	BLK_MQ_F_TAG_QUEUE_SHARED = 1 << 1,
+	BLK_MQ_B_TAG_QUEUE_SHARED,
 	/*
 	 * Set when this device requires underlying blk-mq device for
 	 * completing IO:
 	 */
-	BLK_MQ_F_STACKING	= 1 << 2,
-	BLK_MQ_F_TAG_HCTX_SHARED = 1 << 3,
-	BLK_MQ_F_BLOCKING	= 1 << 4,
+	BLK_MQ_B_STACKING,
+	BLK_MQ_B_TAG_HCTX_SHARED,
+	BLK_MQ_B_BLOCKING,
 	/* Do not allow an I/O scheduler to be configured. */
-	BLK_MQ_F_NO_SCHED	= 1 << 5,
-
+	BLK_MQ_B_NO_SCHED,
 	/*
 	 * Select 'none' during queue registration in case of a single hwq
 	 * or shared hwqs instead of 'mq-deadline'.
 	 */
-	BLK_MQ_F_NO_SCHED_BY_DEFAULT	= 1 << 6,
-	BLK_MQ_F_ALLOC_POLICY_START_BIT = 7,
-	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
+	BLK_MQ_B_NO_SCHED_BY_DEFAULT,
+	BLK_MQ_B_ALLOC_POLICY_START_BIT,
+	BLK_MQ_B_ALLOC_POLICY_BITS = 1,
 };
+/* Keep hctx_flag_name[] in sync with the definitions below */
+#define BLK_MQ_F_TAG_QUEUE_SHARED	(1 << BLK_MQ_B_TAG_QUEUE_SHARED)
+#define BLK_MQ_F_STACKING		(1 << BLK_MQ_B_STACKING)
+#define BLK_MQ_F_TAG_HCTX_SHARED	(1 << BLK_MQ_B_TAG_HCTX_SHARED)
+#define BLK_MQ_F_BLOCKING		(1 << BLK_MQ_B_BLOCKING)
+#define BLK_MQ_F_NO_SCHED		(1 << BLK_MQ_B_NO_SCHED)
+#define BLK_MQ_F_NO_SCHED_BY_DEFAULT	(1 << BLK_MQ_B_NO_SCHED_BY_DEFAULT)
+
 #define BLK_MQ_FLAG_TO_ALLOC_POLICY(flags) \
-	((flags >> BLK_MQ_F_ALLOC_POLICY_START_BIT) & \
-		((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1))
+	((flags >> BLK_MQ_B_ALLOC_POLICY_START_BIT) & \
+		((1 << BLK_MQ_B_ALLOC_POLICY_BITS) - 1))
 #define BLK_ALLOC_POLICY_TO_MQ_FLAG(policy) \
-	((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
-		<< BLK_MQ_F_ALLOC_POLICY_START_BIT)
+	((policy & ((1 << BLK_MQ_B_ALLOC_POLICY_BITS) - 1)) \
+		<< BLK_MQ_B_ALLOC_POLICY_START_BIT)
 
 #define BLK_MQ_MAX_DEPTH	(10240)
 #define BLK_MQ_NO_HCTX_IDX	(-1U)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-01-03 15:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-02 14:44 [PATCH v2] block: Use enum for blk-mq tagset flags John Garry
2025-01-03  6:44 ` Christoph Hellwig
2025-01-03  8:23   ` John Garry
2025-01-03  8:27     ` Christoph Hellwig
2025-01-03  8:38       ` John Garry
2025-01-03 15:13       ` Jens Axboe

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.