Skip to content

Commit 133a48a

Browse files
author
Trond Myklebust
committed
NFS: Fix up commit deadlocks
If O_DIRECT bumps the commit_info rpcs_out field, then that could lead to fsync() hangs. The fix is to ensure that O_DIRECT calls nfs_commit_end(). Fixes: 723c921 ("sched/wait, fs/nfs: Convert wait_on_atomic_t() usage to the new wait_var_event() API") Signed-off-by: Trond Myklebust <[email protected]>
1 parent 64a93db commit 133a48a

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

fs/nfs/direct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
620620
nfs_unlock_and_release_request(req);
621621
}
622622

623-
if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
623+
if (nfs_commit_end(cinfo.mds))
624624
nfs_direct_write_complete(dreq);
625625
}
626626

fs/nfs/pnfs_nfs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ pnfs_bucket_alloc_ds_commits(struct list_head *list,
468468
goto out_error;
469469
data->ds_commit_index = i;
470470
list_add_tail(&data->list, list);
471-
atomic_inc(&cinfo->mds->rpcs_out);
472471
nreq++;
473472
}
474473
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
@@ -520,7 +519,6 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
520519
data->ds_commit_index = -1;
521520
list_splice_init(mds_pages, &data->pages);
522521
list_add_tail(&data->list, &list);
523-
atomic_inc(&cinfo->mds->rpcs_out);
524522
nreq++;
525523
}
526524

fs/nfs/write.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,10 +1673,13 @@ static void nfs_commit_begin(struct nfs_mds_commit_info *cinfo)
16731673
atomic_inc(&cinfo->rpcs_out);
16741674
}
16751675

1676-
static void nfs_commit_end(struct nfs_mds_commit_info *cinfo)
1676+
bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
16771677
{
1678-
if (atomic_dec_and_test(&cinfo->rpcs_out))
1678+
if (atomic_dec_and_test(&cinfo->rpcs_out)) {
16791679
wake_up_var(&cinfo->rpcs_out);
1680+
return true;
1681+
}
1682+
return false;
16801683
}
16811684

16821685
void nfs_commitdata_release(struct nfs_commit_data *data)
@@ -1776,6 +1779,7 @@ void nfs_init_commit(struct nfs_commit_data *data,
17761779
data->res.fattr = &data->fattr;
17771780
data->res.verf = &data->verf;
17781781
nfs_fattr_init(&data->fattr);
1782+
nfs_commit_begin(cinfo->mds);
17791783
}
17801784
EXPORT_SYMBOL_GPL(nfs_init_commit);
17811785

@@ -1822,7 +1826,6 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
18221826

18231827
/* Set up the argument struct */
18241828
nfs_init_commit(data, head, NULL, cinfo);
1825-
atomic_inc(&cinfo->mds->rpcs_out);
18261829
if (NFS_SERVER(inode)->nfs_client->cl_minorversion)
18271830
task_flags = RPC_TASK_MOVEABLE;
18281831
return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),

include/linux/nfs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
568568
extern int nfs_commit_inode(struct inode *, int);
569569
extern struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail);
570570
extern void nfs_commit_free(struct nfs_commit_data *data);
571+
bool nfs_commit_end(struct nfs_mds_commit_info *cinfo);
571572

572573
static inline int
573574
nfs_have_writebacks(struct inode *inode)

0 commit comments

Comments
 (0)