Skip to content

Commit 66f9dac

Browse files
author
Trond Myklebust
committed
Revert "nfs: don't reuse partially completed requests in nfs_lock_and_join_requests"
This reverts commit b571cfc. This patch appears to assume that if one request is complete, then the others will complete too before unlocking. That is not a valid assumption, since other requests could hit a non-fatal error or a short write that would cause them not to complete. Reported-by: Igor Raits <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=219508 Fixes: b571cfc ("nfs: don't reuse partially completed requests in nfs_lock_and_join_requests") Signed-off-by: Trond Myklebust <[email protected]>
1 parent 8f52caf commit 66f9dac

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

fs/nfs/write.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,31 @@ static void nfs_io_completion_put(struct nfs_io_completion *ioc)
144144
kref_put(&ioc->refcount, nfs_io_completion_release);
145145
}
146146

147+
static void
148+
nfs_page_set_inode_ref(struct nfs_page *req, struct inode *inode)
149+
{
150+
if (!test_and_set_bit(PG_INODE_REF, &req->wb_flags)) {
151+
kref_get(&req->wb_kref);
152+
atomic_long_inc(&NFS_I(inode)->nrequests);
153+
}
154+
}
155+
156+
static int
157+
nfs_cancel_remove_inode(struct nfs_page *req, struct inode *inode)
158+
{
159+
int ret;
160+
161+
if (!test_bit(PG_REMOVE, &req->wb_flags))
162+
return 0;
163+
ret = nfs_page_group_lock(req);
164+
if (ret)
165+
return ret;
166+
if (test_and_clear_bit(PG_REMOVE, &req->wb_flags))
167+
nfs_page_set_inode_ref(req, inode);
168+
nfs_page_group_unlock(req);
169+
return 0;
170+
}
171+
147172
/**
148173
* nfs_folio_find_head_request - find head request associated with a folio
149174
* @folio: pointer to folio
@@ -540,7 +565,6 @@ static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
540565
struct inode *inode = folio->mapping->host;
541566
struct nfs_page *head, *subreq;
542567
struct nfs_commit_info cinfo;
543-
bool removed;
544568
int ret;
545569

546570
/*
@@ -565,40 +589,25 @@ static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
565589
goto retry;
566590
}
567591

568-
ret = nfs_page_group_lock(head);
592+
ret = nfs_cancel_remove_inode(head, inode);
569593
if (ret < 0)
570594
goto out_unlock;
571595

572-
removed = test_bit(PG_REMOVE, &head->wb_flags);
596+
ret = nfs_page_group_lock(head);
597+
if (ret < 0)
598+
goto out_unlock;
573599

574600
/* lock each request in the page group */
575601
for (subreq = head->wb_this_page;
576602
subreq != head;
577603
subreq = subreq->wb_this_page) {
578-
if (test_bit(PG_REMOVE, &subreq->wb_flags))
579-
removed = true;
580604
ret = nfs_page_group_lock_subreq(head, subreq);
581605
if (ret < 0)
582606
goto out_unlock;
583607
}
584608

585609
nfs_page_group_unlock(head);
586610

587-
/*
588-
* If PG_REMOVE is set on any request, I/O on that request has
589-
* completed, but some requests were still under I/O at the time
590-
* we locked the head request.
591-
*
592-
* In that case the above wait for all requests means that all I/O
593-
* has now finished, and we can restart from a clean slate. Let the
594-
* old requests go away and start from scratch instead.
595-
*/
596-
if (removed) {
597-
nfs_unroll_locks(head, head);
598-
nfs_unlock_and_release_request(head);
599-
goto retry;
600-
}
601-
602611
nfs_init_cinfo_from_inode(&cinfo, inode);
603612
nfs_join_page_group(head, &cinfo, inode);
604613
return head;

0 commit comments

Comments
 (0)