From: NeilBrown <neilb@suse.de>
To: Olga Kornievskaia <olga.kornievskaia@gmail.com>,
trond.myklebust@hammerspace.com, anna.schumaker@netapp.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH] NFS: simplify inode_dio_begin/end calls.
Date: Thu, 02 Jul 2020 10:30:40 +1000 [thread overview]
Message-ID: <87366a3gi7.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <20200624175408.74678-1-olga.kornievskaia@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3542 bytes --]
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 <neilb@suse.de>
---
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));
--
2.26.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
prev parent reply other threads:[~2020-07-02 0:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-24 17:54 [PATCH 1/1] NFSv4 fix CLOSE not waiting for direct IO compeletion Olga Kornievskaia
2020-07-02 0:30 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87366a3gi7.fsf@notabene.neil.brown.name \
--to=neilb@suse.de \
--cc=anna.schumaker@netapp.com \
--cc=linux-nfs@vger.kernel.org \
--cc=olga.kornievskaia@gmail.com \
--cc=trond.myklebust@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).