Skip to content

Commit 2ce209c

Browse files
committed
NFS: Wait for requests that are locked on the commit list
If a request is on the commit list, but is locked, we will currently skip it, which can lead to livelocking when the commit count doesn't reduce to zero. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 8205b9c commit 2ce209c

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎fs/nfs/pagelist.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ void nfs_release_request(struct nfs_page *req)
434434
{
435435
kref_put(&req->wb_kref, nfs_page_group_destroy);
436436
}
437+
EXPORT_SYMBOL_GPL(nfs_release_request);
437438

438439
/**
439440
* nfs_wait_on_request - Wait for a request to complete.
@@ -452,6 +453,7 @@ nfs_wait_on_request(struct nfs_page *req)
452453
return wait_on_bit_io(&req->wb_flags, PG_BUSY,
453454
TASK_UNINTERRUPTIBLE);
454455
}
456+
EXPORT_SYMBOL_GPL(nfs_wait_on_request);
455457

456458
/*
457459
* nfs_generic_pg_test - determine if requests can be coalesced

‎fs/nfs/pnfs_nfs.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,23 @@ static int
9191
pnfs_generic_transfer_commit_list(struct list_head *src, struct list_head *dst,
9292
struct nfs_commit_info *cinfo, int max)
9393
{
94-
struct nfs_page *req, *tmp;
94+
struct nfs_page *req;
9595
int ret = 0;
9696

97-
list_for_each_entry_safe(req, tmp, src, wb_list) {
98-
if (!nfs_lock_request(req))
99-
continue;
97+
while(!list_empty(src)) {
98+
req = list_first_entry(src, struct nfs_page, wb_list);
99+
100100
kref_get(&req->wb_kref);
101+
if (!nfs_lock_request(req)) {
102+
int status;
103+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
104+
status = nfs_wait_on_request(req);
105+
nfs_release_request(req);
106+
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
107+
if (status < 0)
108+
break;
109+
continue;
110+
}
101111
nfs_request_remove_commit_list(req, cinfo);
102112
clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
103113
nfs_list_add_request(req, dst);

‎fs/nfs/write.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,22 @@ int
10301030
nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
10311031
struct nfs_commit_info *cinfo, int max)
10321032
{
1033-
struct nfs_page *req, *tmp;
1033+
struct nfs_page *req;
10341034
int ret = 0;
10351035

1036-
list_for_each_entry_safe(req, tmp, src, wb_list) {
1037-
if (!nfs_lock_request(req))
1038-
continue;
1036+
while(!list_empty(src)) {
1037+
req = list_first_entry(src, struct nfs_page, wb_list);
10391038
kref_get(&req->wb_kref);
1039+
if (!nfs_lock_request(req)) {
1040+
int status;
1041+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
1042+
status = nfs_wait_on_request(req);
1043+
nfs_release_request(req);
1044+
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
1045+
if (status < 0)
1046+
break;
1047+
continue;
1048+
}
10401049
nfs_request_remove_commit_list(req, cinfo);
10411050
nfs_list_add_request(req, dst);
10421051
ret++;

0 commit comments

Comments
 (0)