Skip to content

Commit

Permalink
nfs: properly protect nfs_direct_req fields
Browse files Browse the repository at this point in the history
We protect accesses to the nfs_direct_req fields with the dreq->lock
ever where except nfs_direct_commit_complete.  This isn't a huge deal,
but it does lead to confusion, and we could potentially end up setting
NFS_ODIRECT_RESCHED_WRITES in one thread where we've had an error in
another.  Clean this up to properly protect ->error and ->flags in the
commit completion path.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
  • Loading branch information
josefbacik authored and Trond Myklebust committed Mar 9, 2024
1 parent b326df4 commit 0945013
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fs/nfs/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,15 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)

trace_nfs_direct_commit_complete(dreq);

spin_lock(&dreq->lock);
if (status < 0) {
/* Errors in commit are fatal */
dreq->error = status;
dreq->flags = NFS_ODIRECT_DONE;
} else {
status = dreq->error;
}
spin_unlock(&dreq->lock);

nfs_init_cinfo_from_dreq(&cinfo, dreq);

Expand All @@ -625,7 +627,10 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
spin_unlock(&dreq->lock);
nfs_release_request(req);
} else if (!nfs_write_match_verf(verf, req)) {
dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
spin_lock(&dreq->lock);
if (dreq->flags == 0)
dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
spin_unlock(&dreq->lock);
/*
* Despite the reboot, the write was successful,
* so reset wb_nio.
Expand Down

0 comments on commit 0945013

Please sign in to comment.