提交 d2ccddf0 编写于 作者: T Trond Myklebust

NFS: Flesh out nfs_invalidate_page()

In the case of a call to truncate_inode_pages(), we should really try to
cancel any pending writes on the page.
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 c04871e6
...@@ -303,7 +303,11 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse ...@@ -303,7 +303,11 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse
static void nfs_invalidate_page(struct page *page, unsigned long offset) static void nfs_invalidate_page(struct page *page, unsigned long offset)
{ {
/* FIXME: we really should cancel any unstarted writes on this page */ struct inode *inode = page->mapping->host;
/* Cancel any unstarted writes on this page */
if (offset == 0)
nfs_sync_inode_wait(inode, page->index, 1, FLUSH_INVALIDATE);
} }
static int nfs_release_page(struct page *page, gfp_t gfp) static int nfs_release_page(struct page *page, gfp_t gfp)
......
...@@ -325,6 +325,7 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst, ...@@ -325,6 +325,7 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
/** /**
* nfs_scan_list - Scan a list for matching requests * nfs_scan_list - Scan a list for matching requests
* @nfsi: NFS inode
* @head: One of the NFS inode request lists * @head: One of the NFS inode request lists
* @dst: Destination list * @dst: Destination list
* @idx_start: lower bound of page->index to scan * @idx_start: lower bound of page->index to scan
...@@ -336,14 +337,15 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst, ...@@ -336,14 +337,15 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
* The requests are *not* checked to ensure that they form a contiguous set. * The requests are *not* checked to ensure that they form a contiguous set.
* You must be holding the inode's req_lock when calling this function * You must be holding the inode's req_lock when calling this function
*/ */
int int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head,
nfs_scan_list(struct list_head *head, struct list_head *dst, struct list_head *dst, unsigned long idx_start,
unsigned long idx_start, unsigned int npages) unsigned int npages)
{ {
struct list_head *pos, *tmp; struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
struct nfs_page *req; struct nfs_page *req;
unsigned long idx_end; unsigned long idx_end;
int res; int found, i;
int res;
res = 0; res = 0;
if (npages == 0) if (npages == 0)
...@@ -351,21 +353,28 @@ nfs_scan_list(struct list_head *head, struct list_head *dst, ...@@ -351,21 +353,28 @@ nfs_scan_list(struct list_head *head, struct list_head *dst,
else else
idx_end = idx_start + npages - 1; idx_end = idx_start + npages - 1;
list_for_each_safe(pos, tmp, head) { for (;;) {
found = radix_tree_gang_lookup(&nfsi->nfs_page_tree,
req = nfs_list_entry(pos); (void **)&pgvec[0], idx_start,
NFS_SCAN_MAXENTRIES);
if (req->wb_index < idx_start) if (found <= 0)
continue;
if (req->wb_index > idx_end)
break; break;
for (i = 0; i < found; i++) {
req = pgvec[i];
if (req->wb_index > idx_end)
goto out;
idx_start = req->wb_index + 1;
if (req->wb_list_head != head)
continue;
if (nfs_set_page_writeback_locked(req)) {
nfs_list_remove_request(req);
nfs_list_add_request(req, dst);
res++;
}
}
if (!nfs_set_page_writeback_locked(req))
continue;
nfs_list_remove_request(req);
nfs_list_add_request(req, dst);
res++;
} }
out:
return res; return res;
} }
......
...@@ -579,6 +579,17 @@ static int nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, un ...@@ -579,6 +579,17 @@ static int nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, un
return ret; return ret;
} }
static void nfs_cancel_requests(struct list_head *head)
{
struct nfs_page *req;
while(!list_empty(head)) {
req = nfs_list_entry(head->next);
nfs_list_remove_request(req);
nfs_inode_remove_request(req);
nfs_clear_page_writeback(req);
}
}
/* /*
* nfs_scan_dirty - Scan an inode for dirty requests * nfs_scan_dirty - Scan an inode for dirty requests
* @inode: NFS inode to scan * @inode: NFS inode to scan
...@@ -623,7 +634,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_st ...@@ -623,7 +634,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_st
int res = 0; int res = 0;
if (nfsi->ncommit != 0) { if (nfsi->ncommit != 0) {
res = nfs_scan_list(&nfsi->commit, dst, idx_start, npages); res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages);
nfsi->ncommit -= res; nfsi->ncommit -= res;
if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit)) if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit))
printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n"); printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n");
...@@ -1491,15 +1502,25 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start, ...@@ -1491,15 +1502,25 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
pages = nfs_scan_dirty(inode, &head, idx_start, npages); pages = nfs_scan_dirty(inode, &head, idx_start, npages);
if (pages != 0) { if (pages != 0) {
spin_unlock(&nfsi->req_lock); spin_unlock(&nfsi->req_lock);
ret = nfs_flush_list(inode, &head, pages, how); if (how & FLUSH_INVALIDATE)
nfs_cancel_requests(&head);
else
ret = nfs_flush_list(inode, &head, pages, how);
spin_lock(&nfsi->req_lock); spin_lock(&nfsi->req_lock);
continue; continue;
} }
if (nocommit) if (nocommit)
break; break;
pages = nfs_scan_commit(inode, &head, 0, 0); pages = nfs_scan_commit(inode, &head, idx_start, npages);
if (pages == 0) if (pages == 0)
break; break;
if (how & FLUSH_INVALIDATE) {
spin_unlock(&nfsi->req_lock);
nfs_cancel_requests(&head);
spin_lock(&nfsi->req_lock);
continue;
}
pages += nfs_scan_commit(inode, &head, 0, 0);
spin_unlock(&nfsi->req_lock); spin_unlock(&nfsi->req_lock);
ret = nfs_commit_list(inode, &head, how); ret = nfs_commit_list(inode, &head, how);
spin_lock(&nfsi->req_lock); spin_lock(&nfsi->req_lock);
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#define FLUSH_LOWPRI 8 /* low priority background flush */ #define FLUSH_LOWPRI 8 /* low priority background flush */
#define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */ #define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
#define FLUSH_NOCOMMIT 32 /* Don't send the NFSv3/v4 COMMIT */ #define FLUSH_NOCOMMIT 32 /* Don't send the NFSv3/v4 COMMIT */
#define FLUSH_INVALIDATE 64 /* Invalidate the page cache */
#ifdef __KERNEL__ #ifdef __KERNEL__
......
...@@ -63,8 +63,8 @@ extern void nfs_release_request(struct nfs_page *req); ...@@ -63,8 +63,8 @@ extern void nfs_release_request(struct nfs_page *req);
extern int nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst, extern int nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
unsigned long idx_start, unsigned int npages); unsigned long idx_start, unsigned int npages);
extern int nfs_scan_list(struct list_head *, struct list_head *, extern int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head, struct list_head *dst,
unsigned long, unsigned int); unsigned long idx_start, unsigned int npages);
extern int nfs_coalesce_requests(struct list_head *, struct list_head *, extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
unsigned int); unsigned int);
extern int nfs_wait_on_request(struct nfs_page *); extern int nfs_wait_on_request(struct nfs_page *);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册