From patchwork Wed Nov 7 16:45:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10672707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20BC113AD for ; Wed, 7 Nov 2018 17:26:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07ACC2BCB0 for ; Wed, 7 Nov 2018 17:26:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECAB82C2DC; Wed, 7 Nov 2018 17:26:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0707E2BCB0 for ; Wed, 7 Nov 2018 17:26:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728053AbeKHC5v (ORCPT ); Wed, 7 Nov 2018 21:57:51 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:58011 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbeKHC5v (ORCPT ); Wed, 7 Nov 2018 21:57:51 -0500 X-Greylist: delayed 2440 seconds by postgrey-1.27 at vger.kernel.org; Wed, 07 Nov 2018 21:57:50 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:reply-to:sender:bcc:in-reply-to:references: content-type; bh=c2LrUyP/YKbMJcw4/K1QFws7xTHYnSE42Fp7Qa28j6k=; b=ixgdYXtiZgoD Pz+GGFTj944Hbeq5foAwmOVCTQOkVSEKCXk63GkgEKvUdKmdEvAACUcYSMsXj5VFEKbCFsDp9hlNG FabwhifMZ36uBlcY9QQS+A3HZhvwlfvJWAKXxrEheCRIDiePg8//GyJtylzei1J6W04aqsDZeFhw8 S+pJPCuPK+/VayDhBi3EzC8x8h4H5h64O4cHy6uNle4FIBxnOqF0e3jnxUei2gYFRRW+PadUE9h3q ytAYejx9e08NlA0xzhRi+6L3PWEASWNLJC1OFXsjN6Qs2wChSmtaW7wZcshg9i0mVCg8AiHwPwEVQ 44wGAZWiAFA95hAhhbkc3A==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gKQxq-000Cy0-2y; Wed, 07 Nov 2018 17:45:58 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id EF681C0750; Wed, 7 Nov 2018 17:45:51 +0100 (CET) From: Bart Van Assche To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Jan Kara Subject: [PATCH] fs/direct-io: Avoid duplicating the check whether or not locking is required Date: Wed, 7 Nov 2018 08:45:41 -0800 Message-Id: <20181107164541.72742-1-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: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Px4yl3FaCWaJ15haTzigeB8TJUdnFr9+mv sSlO+eyolGM4l8rlxuGfhU+3uIRPKdR0oxduMdysLKM5JbAc5fWKJNBCrlD810Vlu7CMrXsdZLpO z5y4DUQ0DsAB X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of repeating the check whether inode locking is required, perform that check once and store the result in a variable. Remove the obsolete comment that refers to direct_io_worker() since that function has been removed. This patch does not change the behavior of the direct I/O code. Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Jan Kara Reviewed-by: Jan Kara --- fs/direct-io.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index d4a218b45383..b5a691ba2271 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -1185,6 +1185,8 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, struct buffer_head map_bh = { 0, }; struct blk_plug plug; unsigned long align = offset | iov_iter_alignment(iter); + const bool lock_inode = flags & DIO_LOCKING && + iov_iter_rw(iter) == READ; /* * Avoid references to bdev if not absolutely needed to give @@ -1215,28 +1217,22 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, memset(dio, 0, offsetof(struct dio, pages)); dio->flags = flags; - if (dio->flags & DIO_LOCKING) { - if (iov_iter_rw(iter) == READ) { - struct address_space *mapping = - iocb->ki_filp->f_mapping; - - /* will be released by direct_io_worker */ - inode_lock(inode); - - retval = filemap_write_and_wait_range(mapping, offset, - end - 1); - if (retval) { - inode_unlock(inode); - kmem_cache_free(dio_cache, dio); - goto out; - } + if (lock_inode) { + struct address_space *mapping = iocb->ki_filp->f_mapping; + + inode_lock(inode); + retval = filemap_write_and_wait_range(mapping, offset, end - 1); + if (retval) { + inode_unlock(inode); + kmem_cache_free(dio_cache, dio); + goto out; } } /* Once we sampled i_size check for reads beyond EOF */ dio->i_size = i_size_read(inode); if (iov_iter_rw(iter) == READ && offset >= dio->i_size) { - if (dio->flags & DIO_LOCKING) + if (lock_inode) inode_unlock(inode); kmem_cache_free(dio_cache, dio); retval = 0; @@ -1370,7 +1366,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, * we can let i_mutex go now that its achieved its purpose * of protecting us from looking up uninitialized blocks. */ - if (iov_iter_rw(iter) == READ && (dio->flags & DIO_LOCKING)) + if (lock_inode) inode_unlock(dio->inode); /*