linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write()
@ 2021-11-15 21:58 Bean Huo
  2021-11-15 23:48 ` Damien Le Moal
  2021-11-16  1:30 ` Chaitanya Kulkarni
  0 siblings, 2 replies; 4+ messages in thread
From: Bean Huo @ 2021-11-15 21:58 UTC (permalink / raw)
  To: axboe, linux-block, linux-kernel; +Cc: Bean Huo

From: Bean Huo <beanhuo@micron.com>

Use the enums REQ_OP_WRITE in op_is_write() to make it less maintenance
requirement and more readable

Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 include/linux/blk_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index fe065c394fff..5b5924a7e754 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -463,7 +463,7 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
 
 static inline bool op_is_write(unsigned int op)
 {
-	return (op & 1);
+	return (op & REQ_OP_WRITE);
 }
 
 /*
-- 
2.25.1


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

* Re: [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write()
  2021-11-15 21:58 [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write() Bean Huo
@ 2021-11-15 23:48 ` Damien Le Moal
  2021-11-16  2:38   ` Keith Busch
  2021-11-16  1:30 ` Chaitanya Kulkarni
  1 sibling, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2021-11-15 23:48 UTC (permalink / raw)
  To: Bean Huo, axboe, linux-block; +Cc: Bean Huo

On 2021/11/16 6:58, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> Use the enums REQ_OP_WRITE in op_is_write() to make it less maintenance
> requirement and more readable
> 
> Signed-off-by: Bean Huo <beanhuo@micron.com>
> ---
>  include/linux/blk_types.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index fe065c394fff..5b5924a7e754 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -463,7 +463,7 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
>  
>  static inline bool op_is_write(unsigned int op)
>  {
> -	return (op & 1);
> +	return (op & REQ_OP_WRITE);
>  }

See the comment for "enum req_opf":

/*
 * Operations and flags common to the bio and request structures.
 * We use 8 bits for encoding the operation, and the remaining 24 for flags.
 *
 * The least significant bit of the operation number indicates the data
 * transfer direction:
 *
 *   - if the least significant bit is set transfers are TO the device
 *   - if the least significant bit is not set transfers are FROM the device
 *
 * If a operation does not transfer data the least significant bit has no
 * meaning.
 */

So using "1" is correct. Using REQ_OP_WRITE is confusing as it seem to imply
that op_is_write() tests for "op is REQ_OP_WRITE" instead of the intended "op is
transferring data TO the device". If anything, op_is_write() could be renamed to
clarify that.

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write()
  2021-11-15 21:58 [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write() Bean Huo
  2021-11-15 23:48 ` Damien Le Moal
@ 2021-11-16  1:30 ` Chaitanya Kulkarni
  1 sibling, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2021-11-16  1:30 UTC (permalink / raw)
  To: Bean Huo; +Cc: Bean Huo, axboe, linux-block, linux-kernel

Bean,

>   static inline bool op_is_write(unsigned int op)
>   {
> -       return (op & 1);
> +       return (op & REQ_OP_WRITE);
>   }

As pointed out by Damien it supposed to indicate data out and not
only write request REQ_OP_WRITE.

> 
>   /*
> --
> 2.25.1
> 

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

* Re: [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write()
  2021-11-15 23:48 ` Damien Le Moal
@ 2021-11-16  2:38   ` Keith Busch
  0 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2021-11-16  2:38 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Bean Huo, axboe, linux-block, Bean Huo

On Tue, Nov 16, 2021 at 08:48:56AM +0900, Damien Le Moal wrote:
> On 2021/11/16 6:58, Bean Huo wrote:
> > From: Bean Huo <beanhuo@micron.com>
> > 
> > Use the enums REQ_OP_WRITE in op_is_write() to make it less maintenance
> > requirement and more readable
> > 
> > Signed-off-by: Bean Huo <beanhuo@micron.com>
> > ---
> >  include/linux/blk_types.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> > index fe065c394fff..5b5924a7e754 100644
> > --- a/include/linux/blk_types.h
> > +++ b/include/linux/blk_types.h
> > @@ -463,7 +463,7 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
> >  
> >  static inline bool op_is_write(unsigned int op)
> >  {
> > -	return (op & 1);
> > +	return (op & REQ_OP_WRITE);
> >  }
> 
> See the comment for "enum req_opf":
> 
> /*
>  * Operations and flags common to the bio and request structures.
>  * We use 8 bits for encoding the operation, and the remaining 24 for flags.
>  *
>  * The least significant bit of the operation number indicates the data
>  * transfer direction:
>  *
>  *   - if the least significant bit is set transfers are TO the device
>  *   - if the least significant bit is not set transfers are FROM the device
>  *
>  * If a operation does not transfer data the least significant bit has no
>  * meaning.
>  */
> 
> So using "1" is correct. Using REQ_OP_WRITE is confusing as it seem to imply
> that op_is_write() tests for "op is REQ_OP_WRITE" instead of the intended "op is
> transferring data TO the device". If anything, op_is_write() could be renamed to
> clarify that.

Yeah, REQ_OP_WRITE is a value, not a flag. The op_is_write() tests the data
direction flag, which coincidentally happens to be the same as the current,
somewhat arbitrarily chosen value of REQ_OP_WRITE. The op could just as easily
have been set to 0xff.

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

end of thread, other threads:[~2021-11-16  2:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 21:58 [PATCH] block: Use REQ_OP_WRITE instead of its integer constant 1 in op_is_write() Bean Huo
2021-11-15 23:48 ` Damien Le Moal
2021-11-16  2:38   ` Keith Busch
2021-11-16  1:30 ` Chaitanya Kulkarni

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).