From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162235AbbKEReP (ORCPT ); Thu, 5 Nov 2015 12:34:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57882 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932824AbbKEReL (ORCPT ); Thu, 5 Nov 2015 12:34:11 -0500 Subject: Re: [dm-devel] [PATCH 19/32] block: add helper to get data dir from op To: Bart Van Assche , device-mapper development , linux-fsdevel@vger.kernel.org, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, drbd-dev@lists.linbit.com References: <1446674909-5371-1-git-send-email-mchristi@redhat.com> <1446674909-5371-20-git-send-email-mchristi@redhat.com> <563A8A33.3000002@sandisk.com> From: Mike Christie Message-ID: <563B930F.7040705@redhat.com> Date: Thu, 5 Nov 2015 11:34:07 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <563A8A33.3000002@sandisk.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> >> 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 >> --- >> 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.