From patchwork Thu Jul 2 00:30:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 11637619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE3D5618 for ; Thu, 2 Jul 2020 00:30:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD745207E8 for ; Thu, 2 Jul 2020 00:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727812AbgGBAat (ORCPT ); Wed, 1 Jul 2020 20:30:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:38434 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbgGBAas (ORCPT ); Wed, 1 Jul 2020 20:30:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 28BF2AD4A; Thu, 2 Jul 2020 00:30:47 +0000 (UTC) From: NeilBrown To: Olga Kornievskaia , trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Date: Thu, 02 Jul 2020 10:30:40 +1000 Cc: linux-nfs@vger.kernel.org Subject: [PATCH] NFS: simplify inode_dio_begin/end calls. In-Reply-To: <20200624175408.74678-1-olga.kornievskaia@gmail.com> References: <20200624175408.74678-1-olga.kornievskaia@gmail.com> Message-ID: <87366a3gi7.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org As a recent patch highlighted, inode_dio_end() must be called after nfs_direct_req_release() is called. It would make the code more robust if nfs_direct_req_release() did that call itself, placing it after put_nfs_open_context(). To achieve this: - move the inode_dio_begin() calls to the moment when a 'struct nfs_direct_req' is allocated, - move the inode_dio_end() calls to just before the 'struct nfs_direct_req' is freed, - use igrab to make req->inode a counted reference so that it can be used after put_nfs_open_context() (which calls dput(), that releasing the only reference we previously held on the inode). This patch doesn't change behaviour at all, it just simplifies the code a little. Signed-off-by: NeilBrown --- fs/nfs/direct.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 3d113cf8908a..ab32b23639d3 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -221,6 +221,8 @@ static void nfs_direct_req_free(struct kref *kref) nfs_put_lock_context(dreq->l_ctx); if (dreq->ctx != NULL) put_nfs_open_context(dreq->ctx); + inode_dio_end(dreq->inode); + iput(dreq->inode); kmem_cache_free(nfs_direct_cachep, dreq); } @@ -278,10 +280,7 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq) complete(&dreq->completion); - igrab(inode); nfs_direct_req_release(dreq); - inode_dio_end(inode); - iput(inode); } static void nfs_direct_read_completion(struct nfs_pgio_header *hdr) @@ -359,7 +358,6 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, &nfs_direct_read_completion_ops); get_dreq(dreq); desc.pg_dreq = dreq; - inode_dio_begin(inode); while (iov_iter_count(iter)) { struct page **pagevec; @@ -411,10 +409,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, * generic layer handle the completion. */ if (requested_bytes == 0) { - igrab(inode); nfs_direct_req_release(dreq); - inode_dio_end(inode); - iput(inode); return result < 0 ? result : -EIO; } @@ -467,7 +462,8 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter) if (dreq == NULL) goto out; - dreq->inode = inode; + dreq->inode = igrab(inode); + inode_dio_begin(inode); dreq->bytes_left = dreq->max_count = count; dreq->io_start = iocb->ki_pos; dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); @@ -807,7 +803,6 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, &nfs_direct_write_completion_ops); desc.pg_dreq = dreq; get_dreq(dreq); - inode_dio_begin(inode); NFS_I(inode)->write_io += iov_iter_count(iter); while (iov_iter_count(iter)) { @@ -867,10 +862,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, * generic layer handle the completion. */ if (requested_bytes == 0) { - igrab(inode); nfs_direct_req_release(dreq); - inode_dio_end(inode); - iput(inode); return result < 0 ? result : -EIO; } @@ -929,7 +921,8 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter) if (!dreq) goto out; - dreq->inode = inode; + dreq->inode = igrab(inode); + inode_dio_begin(inode); dreq->bytes_left = dreq->max_count = count; dreq->io_start = pos; dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));