Skip to content

Commit 0945013

Browse files
josefbacikTrond Myklebust
authored andcommitted
nfs: properly protect nfs_direct_req fields
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>
1 parent b326df4 commit 0945013

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/nfs/direct.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,15 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
606606

607607
trace_nfs_direct_commit_complete(dreq);
608608

609+
spin_lock(&dreq->lock);
609610
if (status < 0) {
610611
/* Errors in commit are fatal */
611612
dreq->error = status;
612613
dreq->flags = NFS_ODIRECT_DONE;
613614
} else {
614615
status = dreq->error;
615616
}
617+
spin_unlock(&dreq->lock);
616618

617619
nfs_init_cinfo_from_dreq(&cinfo, dreq);
618620

@@ -625,7 +627,10 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
625627
spin_unlock(&dreq->lock);
626628
nfs_release_request(req);
627629
} else if (!nfs_write_match_verf(verf, req)) {
628-
dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
630+
spin_lock(&dreq->lock);
631+
if (dreq->flags == 0)
632+
dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
633+
spin_unlock(&dreq->lock);
629634
/*
630635
* Despite the reboot, the write was successful,
631636
* so reset wb_nio.

0 commit comments

Comments
 (0)