diff mbox

[19/32] block: add helper to get data dir from op

Message ID 1446674909-5371-20-git-send-email-mchristi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Christie Nov. 4, 2015, 10:08 p.m. UTC
From: Mike Christie <mchristi@redhat.com>

In later patches the op will no longer be a bitmap, so we will
not have REQ_WRITE set for all non reads like discard, flush,
and write same. Drivers will still want to treat them as writes
for accounting reasons, so this patch adds a helper to translate
a op to a data direction.

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 include/linux/blkdev.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Bart Van Assche Nov. 4, 2015, 10:44 p.m. UTC | #1
On 11/04/2015 02:08 PM, mchristi@redhat.com wrote:
> From: Mike Christie <mchristi@redhat.com>
>
> In later patches the op will no longer be a bitmap, so we will
> not have REQ_WRITE set for all non reads like discard, flush,
> and write same. Drivers will still want to treat them as writes
> for accounting reasons, so this patch adds a helper to translate
> a op to a data direction.
>
> Signed-off-by: Mike Christie <mchristi@redhat.com>
> ---
>   include/linux/blkdev.h | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 19c2e94..cf5f518 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -586,6 +586,18 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
>
>   #define list_entry_rq(ptr)	list_entry((ptr), struct request, queuelist)
>
> +/*
> + * Non REQ_OP_WRITE requests like discard, write same, etc, are
> + * considered WRITEs.
> + */
> +static inline int op_to_data_dir(int op)
> +{
> +	if (op == REQ_OP_READ)
> +		return READ;
> +	else
> +		return WRITE;
> +}
> +
>   #define rq_data_dir(rq)		((int)((rq)->cmd_flags & 1))
>
>   /*
>

How about introducing two functions - op_is_write() and op_is_read() ? I 
think that approach will result in shorter and easier to read code in 
the contexts where these functions are used.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Christie Nov. 5, 2015, 5:34 p.m. UTC | #2
On 11/04/2015 04:44 PM, Bart Van Assche wrote:
> On 11/04/2015 02:08 PM, mchristi@redhat.com wrote:
>> From: Mike Christie <mchristi@redhat.com>
>>
>> In later patches the op will no longer be a bitmap, so we will
>> not have REQ_WRITE set for all non reads like discard, flush,
>> and write same. Drivers will still want to treat them as writes
>> for accounting reasons, so this patch adds a helper to translate
>> a op to a data direction.
>>
>> Signed-off-by: Mike Christie <mchristi@redhat.com>
>> ---
>>   include/linux/blkdev.h | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>> index 19c2e94..cf5f518 100644
>> --- a/include/linux/blkdev.h
>> +++ b/include/linux/blkdev.h
>> @@ -586,6 +586,18 @@ static inline void queue_flag_clear(unsigned int
>> flag, struct request_queue *q)
>>
>>   #define list_entry_rq(ptr)    list_entry((ptr), struct request,
>> queuelist)
>>
>> +/*
>> + * Non REQ_OP_WRITE requests like discard, write same, etc, are
>> + * considered WRITEs.
>> + */
>> +static inline int op_to_data_dir(int op)
>> +{
>> +    if (op == REQ_OP_READ)
>> +        return READ;
>> +    else
>> +        return WRITE;
>> +}
>> +
>>   #define rq_data_dir(rq)        ((int)((rq)->cmd_flags & 1))
>>
>>   /*
>>
> 
> How about introducing two functions - op_is_write() and op_is_read() ? I
> think that approach will result in shorter and easier to read code in
> the contexts where these functions are used.
> 

I can do that. You are right in how they are used. I just did the above,
to follow the other *_data_dir calls.

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Hellwig Nov. 7, 2015, 10:19 a.m. UTC | #3
On Thu, Nov 05, 2015 at 11:34:07AM -0600, Mike Christie wrote:
> I can do that. You are right in how they are used. I just did the above,
> to follow the other *_data_dir calls.

I think the *_data_dir calls are horrible interfaces.  But your series
already is huge, so if it makes your life easier I'd say keep it as-is
for now.  But in the long run we should have the interfaces that Bart
suggested, and one that gives you a dma_data_direction from a request,
as that's what a lot of the driver ultimatively want.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 19c2e94..cf5f518 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -586,6 +586,18 @@  static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
 
 #define list_entry_rq(ptr)	list_entry((ptr), struct request, queuelist)
 
+/*
+ * Non REQ_OP_WRITE requests like discard, write same, etc, are
+ * considered WRITEs.
+ */
+static inline int op_to_data_dir(int op)
+{
+	if (op == REQ_OP_READ)
+		return READ;
+	else
+		return WRITE;
+}
+
 #define rq_data_dir(rq)		((int)((rq)->cmd_flags & 1))
 
 /*