Commit 2df485a7 authored by Trond Myklebust's avatar Trond Myklebust

nfs: remove extraneous and problematic calls to nfs_clear_request

When a nfs_page is freed, nfs_free_request is called which also calls
nfs_clear_request to clean out the lock and open contexts and free the
pagecache page.

However, a couple of places in the nfs code call nfs_clear_request
themselves. What happens here if the refcount on the request is still high?
We'll be releasing contexts and freeing pointers while the request is
possibly still in use.

Remove those bare calls to nfs_clear_context. That should only be done when
the request is being freed.

Note that when doing this, we need to watch out for tests of req->wb_page.
Previously, nfs_set_page_tag_locked() and nfs_clear_page_tag_locked()
would check the value of req->wb_page to figure out if the page is mapped
into the nfsi->nfs_page_tree. We now indicate the page is mapped using
the new bit PG_MAPPED in req->wb_flags .
Reported-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 0de1b7e8
...@@ -115,7 +115,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req) ...@@ -115,7 +115,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req)
{ {
if (!nfs_lock_request_dontget(req)) if (!nfs_lock_request_dontget(req))
return 0; return 0;
if (req->wb_page != NULL) if (test_bit(PG_MAPPED, &req->wb_flags))
radix_tree_tag_set(&NFS_I(req->wb_context->path.dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED); radix_tree_tag_set(&NFS_I(req->wb_context->path.dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
return 1; return 1;
} }
...@@ -125,7 +125,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req) ...@@ -125,7 +125,7 @@ int nfs_set_page_tag_locked(struct nfs_page *req)
*/ */
void nfs_clear_page_tag_locked(struct nfs_page *req) void nfs_clear_page_tag_locked(struct nfs_page *req)
{ {
if (req->wb_page != NULL) { if (test_bit(PG_MAPPED, &req->wb_flags)) {
struct inode *inode = req->wb_context->path.dentry->d_inode; struct inode *inode = req->wb_context->path.dentry->d_inode;
struct nfs_inode *nfsi = NFS_I(inode); struct nfs_inode *nfsi = NFS_I(inode);
......
...@@ -152,7 +152,6 @@ static void nfs_readpage_release(struct nfs_page *req) ...@@ -152,7 +152,6 @@ static void nfs_readpage_release(struct nfs_page *req)
(long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
req->wb_bytes, req->wb_bytes,
(long long)req_offset(req)); (long long)req_offset(req));
nfs_clear_request(req);
nfs_release_request(req); nfs_release_request(req);
} }
......
...@@ -390,6 +390,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) ...@@ -390,6 +390,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
if (nfs_have_delegation(inode, FMODE_WRITE)) if (nfs_have_delegation(inode, FMODE_WRITE))
nfsi->change_attr++; nfsi->change_attr++;
} }
set_bit(PG_MAPPED, &req->wb_flags);
SetPagePrivate(req->wb_page); SetPagePrivate(req->wb_page);
set_page_private(req->wb_page, (unsigned long)req); set_page_private(req->wb_page, (unsigned long)req);
nfsi->npages++; nfsi->npages++;
...@@ -415,6 +416,7 @@ static void nfs_inode_remove_request(struct nfs_page *req) ...@@ -415,6 +416,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
set_page_private(req->wb_page, 0); set_page_private(req->wb_page, 0);
ClearPagePrivate(req->wb_page); ClearPagePrivate(req->wb_page);
clear_bit(PG_MAPPED, &req->wb_flags);
radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index); radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
nfsi->npages--; nfsi->npages--;
if (!nfsi->npages) { if (!nfsi->npages) {
...@@ -422,7 +424,6 @@ static void nfs_inode_remove_request(struct nfs_page *req) ...@@ -422,7 +424,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
iput(inode); iput(inode);
} else } else
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
nfs_clear_request(req);
nfs_release_request(req); nfs_release_request(req);
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
*/ */
enum { enum {
PG_BUSY = 0, PG_BUSY = 0,
PG_MAPPED,
PG_CLEAN, PG_CLEAN,
PG_NEED_COMMIT, PG_NEED_COMMIT,
PG_NEED_RESCHED, PG_NEED_RESCHED,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment