diff mbox series

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

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

Commit Message

Chaitanya Kulkarni March 25, 2020, 2:16 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      | 32 ++++++++++++++++++++++++++++++++
 include/linux/blkdev.h |  3 +++
 2 files changed, 35 insertions(+)

Comments

Damien Le Moal March 25, 2020, 3:27 a.m. UTC | #1
On 2020/03/25 12:21, 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      | 32 ++++++++++++++++++++++++++++++++
>  include/linux/blkdev.h |  3 +++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
> index 6b442ae96499..f87956e0dcaf 100644
> --- a/block/blk-zoned.c
> +++ b/block/blk-zoned.c
> @@ -20,6 +20,38 @@
>  
>  #include "blk.h"
>  
> +#define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name
> +static const char *const zone_cond_name[] = {
> +	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),
> +};
> +#undef ZONE_COND_NAME
> +
> +/**
> + * 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".
> + */
> +const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
> +{
> +	static const char *zone_cond_str = "UNKNOWN";
> +
> +	if (zone_cond < ARRAY_SIZE(zone_cond_name) && zone_cond_name[zone_cond])
> +		zone_cond_str = zone_cond_name[zone_cond];
> +
> +	return zone_cond_str;
> +}
> +EXPORT_SYMBOL_GPL(blk_zone_cond_str);
> +
>  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 53a1325efbc3..0070f26b9579 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -887,6 +887,9 @@ 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);
>  
> +/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
> +extern const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
> +

I do not think that the extern is needed here. And I think that this declaration
should go under #ifdef CONFIG_BLK_DEV_ZONED since its code is compiled only if
that config option is enabled.

>  int blk_status_to_errno(blk_status_t status);
>  blk_status_t errno_to_blk_status(int errno);
>  
>
Chaitanya Kulkarni March 25, 2020, 4:31 a.m. UTC | #2
On 03/24/2020 08:27 PM, Damien Le Moal wrote:
>>   {
>> >diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>> >index 53a1325efbc3..0070f26b9579 100644
>> >--- a/include/linux/blkdev.h
>> >+++ b/include/linux/blkdev.h
>> >@@ -887,6 +887,9 @@ 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);
>> >
>> >+/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
>> >+extern const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
>> >+
> I do not think that the extern is needed here. And I think that this declaration
> should go under #ifdef CONFIG_BLK_DEV_ZONED since its code is compiled only if
> that config option is enabled.
>

Are you suggesting like following ?

+#ifdef CONFIG_BLK_DEV_ZONED
+/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
+const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
+#endif /* CONFIG_BLK_DEV_ZONED */
+
Damien Le Moal March 25, 2020, 5:20 a.m. UTC | #3
On 2020/03/25 13:31, Chaitanya Kulkarni wrote:
> On 03/24/2020 08:27 PM, Damien Le Moal wrote:
>>>   {
>>>> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>>>> index 53a1325efbc3..0070f26b9579 100644
>>>> --- a/include/linux/blkdev.h
>>>> +++ b/include/linux/blkdev.h
>>>> @@ -887,6 +887,9 @@ 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);
>>>>
>>>> +/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
>>>> +extern const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
>>>> +
>> I do not think that the extern is needed here. And I think that this declaration
>> should go under #ifdef CONFIG_BLK_DEV_ZONED since its code is compiled only if
>> that config option is enabled.
>>
> 
> Are you suggesting like following ?
> 
> +#ifdef CONFIG_BLK_DEV_ZONED
> +/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
> +const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
> +#endif /* CONFIG_BLK_DEV_ZONED */

Yes, That is what I meant. But may be do not add another #ifdef and simply move
the declaration within one of the existing #ifdef CONFIG_BLK_DEV_ZONED in
blkdev.h ? Less #ifdef is always better :)
diff mbox series

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 6b442ae96499..f87956e0dcaf 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -20,6 +20,38 @@ 
 
 #include "blk.h"
 
+#define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name
+static const char *const zone_cond_name[] = {
+	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),
+};
+#undef ZONE_COND_NAME
+
+/**
+ * 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".
+ */
+const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
+{
+	static const char *zone_cond_str = "UNKNOWN";
+
+	if (zone_cond < ARRAY_SIZE(zone_cond_name) && zone_cond_name[zone_cond])
+		zone_cond_str = zone_cond_name[zone_cond];
+
+	return zone_cond_str;
+}
+EXPORT_SYMBOL_GPL(blk_zone_cond_str);
+
 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 53a1325efbc3..0070f26b9579 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -887,6 +887,9 @@  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);
 
+/* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */
+extern const char *blk_zone_cond_str(enum blk_zone_cond zone_cond);
+
 int blk_status_to_errno(blk_status_t status);
 blk_status_t errno_to_blk_status(int errno);