diff mbox series

[1/3] block: add a zone condition debug helper

Message ID 20200215005758.3212-2-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series null_blk: add tracnepoints for zoned mode | expand

Commit Message

Chaitanya Kulkarni Feb. 15, 2020, 12:57 a.m. UTC
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(+)

Comments

Damien Le Moal Feb. 17, 2020, 12:54 a.m. UTC | #1
On 2020/02/15 9:58, Chaitanya Kulkarni wrote:
> 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] = {

Is the BLK_ZONE_COND_LAST really necessary ?

> +	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);

Instead of exporting this, why not keep it static and export the function
blk_zone_cond_str() ? Any particular reason ? Does blk_zone_cond_str() need
to be inline ?

> +#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";

Shouldn't this be "static const char *..." ?

> +
> +	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,

Is this really necessary ?

>  };
>  
>  /**
>
diff mbox series

Patch

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,
 };
 
 /**