diff mbox series

[V4,3/5] block: use blk_op_str() in blk-mq-debugfs.c

Message ID 20190619171302.10146-4-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series block: improve print_req_error | expand

Commit Message

Chaitanya Kulkarni June 19, 2019, 5:13 p.m. UTC
Now that we've a helper function blk_op_str() to convert the
REQ_OP_XXX to string XXX, adjust the code to use that. Get rid of
the duplicate array op_name which is now present in the blk-core.c
which we renamed it to "blk_op_name" and open coding in the
blk-mq-debugfs.c.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 block/blk-mq-debugfs.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

Comments

Bart Van Assche June 19, 2019, 5:50 p.m. UTC | #1
On 6/19/19 10:13 AM, Chaitanya Kulkarni wrote:
> Now that we've a helper function blk_op_str() to convert the
> REQ_OP_XXX to string XXX, adjust the code to use that. Get rid of
> the duplicate array op_name which is now present in the blk-core.c
> which we renamed it to "blk_op_name" and open coding in the
> blk-mq-debugfs.c.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>   block/blk-mq-debugfs.c | 24 ++++--------------------
>   1 file changed, 4 insertions(+), 20 deletions(-)
> 
> diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
> index f0550be60824..68b602d4d1b8 100644
> --- a/block/blk-mq-debugfs.c
> +++ b/block/blk-mq-debugfs.c
> @@ -261,23 +261,6 @@ static int hctx_flags_show(void *data, struct seq_file *m)
>   	return 0;
>   }
>   
> -#define REQ_OP_NAME(name) [REQ_OP_##name] = #name
> -static const char *const op_name[] = {
> -	REQ_OP_NAME(READ),
> -	REQ_OP_NAME(WRITE),
> -	REQ_OP_NAME(FLUSH),
> -	REQ_OP_NAME(DISCARD),
> -	REQ_OP_NAME(SECURE_ERASE),
> -	REQ_OP_NAME(ZONE_RESET),
> -	REQ_OP_NAME(WRITE_SAME),
> -	REQ_OP_NAME(WRITE_ZEROES),
> -	REQ_OP_NAME(SCSI_IN),
> -	REQ_OP_NAME(SCSI_OUT),
> -	REQ_OP_NAME(DRV_IN),
> -	REQ_OP_NAME(DRV_OUT),
> -};
> -#undef REQ_OP_NAME
> -
>   #define CMD_FLAG_NAME(name) [__REQ_##name] = #name
>   static const char *const cmd_flag_name[] = {
>   	CMD_FLAG_NAME(FAILFAST_DEV),
> @@ -342,12 +325,13 @@ int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
>   {
>   	const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
>   	const unsigned int op = rq->cmd_flags & REQ_OP_MASK;
> +	const char *op_str = blk_op_str(op);
>   
>   	seq_printf(m, "%p {.op=", rq);
> -	if (op < ARRAY_SIZE(op_name) && op_name[op])
> -		seq_printf(m, "%s", op_name[op]);
> -	else
> +	if (strcmp(op_str, "UNKNOWN") == 0)
>   		seq_printf(m, "%d", op);
> +	else
> +		seq_printf(m, "%s", op_str);
>   	seq_puts(m, ", .cmd_flags=");
>   	blk_flags_show(m, rq->cmd_flags & ~REQ_OP_MASK, cmd_flag_name,
>   		       ARRAY_SIZE(cmd_flag_name));

Although I'm still not enthusiast about the strcmp(..., "UNKNOWN"):

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
diff mbox series

Patch

diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index f0550be60824..68b602d4d1b8 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -261,23 +261,6 @@  static int hctx_flags_show(void *data, struct seq_file *m)
 	return 0;
 }
 
-#define REQ_OP_NAME(name) [REQ_OP_##name] = #name
-static const char *const op_name[] = {
-	REQ_OP_NAME(READ),
-	REQ_OP_NAME(WRITE),
-	REQ_OP_NAME(FLUSH),
-	REQ_OP_NAME(DISCARD),
-	REQ_OP_NAME(SECURE_ERASE),
-	REQ_OP_NAME(ZONE_RESET),
-	REQ_OP_NAME(WRITE_SAME),
-	REQ_OP_NAME(WRITE_ZEROES),
-	REQ_OP_NAME(SCSI_IN),
-	REQ_OP_NAME(SCSI_OUT),
-	REQ_OP_NAME(DRV_IN),
-	REQ_OP_NAME(DRV_OUT),
-};
-#undef REQ_OP_NAME
-
 #define CMD_FLAG_NAME(name) [__REQ_##name] = #name
 static const char *const cmd_flag_name[] = {
 	CMD_FLAG_NAME(FAILFAST_DEV),
@@ -342,12 +325,13 @@  int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
 {
 	const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
 	const unsigned int op = rq->cmd_flags & REQ_OP_MASK;
+	const char *op_str = blk_op_str(op);
 
 	seq_printf(m, "%p {.op=", rq);
-	if (op < ARRAY_SIZE(op_name) && op_name[op])
-		seq_printf(m, "%s", op_name[op]);
-	else
+	if (strcmp(op_str, "UNKNOWN") == 0)
 		seq_printf(m, "%d", op);
+	else
+		seq_printf(m, "%s", op_str);
 	seq_puts(m, ", .cmd_flags=");
 	blk_flags_show(m, rq->cmd_flags & ~REQ_OP_MASK, cmd_flag_name,
 		       ARRAY_SIZE(cmd_flag_name));