linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: axboe@kernel.dk, damien.lemoal@wdc.com
Cc: kbusch@kernel.org, linux-block@vger.kernel.org,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Subject: [PATCH 1/3] block: add a zone condition debug helper
Date: Fri, 14 Feb 2020 16:57:56 -0800	[thread overview]
Message-ID: <20200215005758.3212-2-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20200215005758.3212-1-chaitanya.kulkarni@wdc.com>

Add a helper to stringify the zone conditions. We use this helper in the
next patch to track zone conditions in tracepoints.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 block/blk-zoned.c             | 14 ++++++++++++++
 include/linux/blkdev.h        | 26 ++++++++++++++++++++++++++
 include/uapi/linux/blkzoned.h |  1 +
 3 files changed, 41 insertions(+)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 05741c6f618b..2c4df98b513c 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -20,6 +20,20 @@
 
 #include "blk.h"
 
+#define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name
+const char *const zone_cond_name[BLK_ZONE_COND_LAST] = {
+	ZONE_COND_NAME(NOT_WP),
+	ZONE_COND_NAME(EMPTY),
+	ZONE_COND_NAME(IMP_OPEN),
+	ZONE_COND_NAME(EXP_OPEN),
+	ZONE_COND_NAME(CLOSED),
+	ZONE_COND_NAME(READONLY),
+	ZONE_COND_NAME(FULL),
+	ZONE_COND_NAME(OFFLINE),
+};
+EXPORT_SYMBOL_GPL(zone_cond_name);
+#undef ZONE_COND_NAME
+
 static inline sector_t blk_zone_start(struct request_queue *q,
 				      sector_t sector)
 {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 053ea4b51988..5204eda6e4c1 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -887,6 +887,32 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
 /* Helper to convert REQ_OP_XXX to its string format XXX */
 extern const char *blk_op_str(unsigned int op);
 
+#ifdef CONFIG_BLK_DEV_ZONED
+extern const char *const zone_cond_name[BLK_ZONE_COND_LAST];
+/**
+ * blk_zone_cond_str - Return string XXX in BLK_ZONE_COND_XXX.
+ * @zone_cond: BLK_ZONE_COND_XXX.
+ *
+ * Description: Centralize block layer function to convert BLK_ZONE_COND_XXX
+ * into string format. Useful in the debugging and tracing zone conditions. For
+ * invalid BLK_ZONE_COND_XXX it returns string "UNKNOWN".
+ */
+static inline const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
+{
+	const char *zone_cond_str = "UNKNOWN";
+
+	if (zone_cond < BLK_ZONE_COND_LAST && zone_cond_name[zone_cond])
+		zone_cond_str = zone_cond_name[zone_cond];
+
+	return zone_cond_str;
+}
+#else
+static inline const char *blk_zone_cond_str(unsigned int zone_cond)
+{
+	return "NOT SUPPORTED";
+}
+#endif /* CONFIG_BLK_DEV_ZONED */
+
 int blk_status_to_errno(blk_status_t status);
 blk_status_t errno_to_blk_status(int errno);
 
diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h
index 0cdef67135f0..28ad29973a45 100644
--- a/include/uapi/linux/blkzoned.h
+++ b/include/uapi/linux/blkzoned.h
@@ -71,6 +71,7 @@ enum blk_zone_cond {
 	BLK_ZONE_COND_READONLY	= 0xD,
 	BLK_ZONE_COND_FULL	= 0xE,
 	BLK_ZONE_COND_OFFLINE	= 0xF,
+	BLK_ZONE_COND_LAST,
 };
 
 /**
-- 
2.22.1


  reply	other threads:[~2020-02-15  0:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-15  0:57 [PATCH 0/3] null_blk: add tracnepoints for zoned mode Chaitanya Kulkarni
2020-02-15  0:57 ` Chaitanya Kulkarni [this message]
2020-02-17  0:54   ` [PATCH 1/3] block: add a zone condition debug helper Damien Le Moal
2020-02-15  0:57 ` [PATCH 2/3] null_blk: add tracepoint helpers for zoned mode Chaitanya Kulkarni
2020-02-17  1:04   ` Damien Le Moal
2020-02-15  0:57 ` [PATCH 3/3] null_blk: add trace in null_blk_zoned.c Chaitanya Kulkarni
2020-02-17  1:05   ` Damien Le Moal

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=20200215005758.3212-2-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@wdc.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).