Skip to content

Commit d2ccddf

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
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: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent c04871e commit d2ccddf

5 files changed

Lines changed: 60 additions & 25 deletions

File tree

‎fs/nfs/file.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse
303303

304304
static void nfs_invalidate_page(struct page *page, unsigned long offset)
305305
{
306-
/* FIXME: we really should cancel any unstarted writes on this page */
306+
struct inode *inode = page->mapping->host;
307+
308+
/* Cancel any unstarted writes on this page */
309+
if (offset == 0)
310+
nfs_sync_inode_wait(inode, page->index, 1, FLUSH_INVALIDATE);
307311
}
308312

309313
static int nfs_release_page(struct page *page, gfp_t gfp)

‎fs/nfs/pagelist.c‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
325325

326326
/**
327327
* nfs_scan_list - Scan a list for matching requests
328+
* @nfsi: NFS inode
328329
* @head: One of the NFS inode request lists
329330
* @dst: Destination list
330331
* @idx_start: lower bound of page->index to scan
@@ -336,36 +337,44 @@ nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
336337
* The requests are *not* checked to ensure that they form a contiguous set.
337338
* You must be holding the inode's req_lock when calling this function
338339
*/
339-
int
340-
nfs_scan_list(struct list_head *head, struct list_head *dst,
341-
unsigned long idx_start, unsigned int npages)
340+
int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head,
341+
struct list_head *dst, unsigned long idx_start,
342+
unsigned int npages)
342343
{
343-
struct list_head *pos, *tmp;
344-
struct nfs_page *req;
345-
unsigned long idx_end;
346-
int res;
344+
struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
345+
struct nfs_page *req;
346+
unsigned long idx_end;
347+
int found, i;
348+
int res;
347349

348350
res = 0;
349351
if (npages == 0)
350352
idx_end = ~0;
351353
else
352354
idx_end = idx_start + npages - 1;
353355

354-
list_for_each_safe(pos, tmp, head) {
355-
356-
req = nfs_list_entry(pos);
357-
358-
if (req->wb_index < idx_start)
359-
continue;
360-
if (req->wb_index > idx_end)
356+
for (;;) {
357+
found = radix_tree_gang_lookup(&nfsi->nfs_page_tree,
358+
(void **)&pgvec[0], idx_start,
359+
NFS_SCAN_MAXENTRIES);
360+
if (found <= 0)
361361
break;
362+
for (i = 0; i < found; i++) {
363+
req = pgvec[i];
364+
if (req->wb_index > idx_end)
365+
goto out;
366+
idx_start = req->wb_index + 1;
367+
if (req->wb_list_head != head)
368+
continue;
369+
if (nfs_set_page_writeback_locked(req)) {
370+
nfs_list_remove_request(req);
371+
nfs_list_add_request(req, dst);
372+
res++;
373+
}
374+
}
362375

363-
if (!nfs_set_page_writeback_locked(req))
364-
continue;
365-
nfs_list_remove_request(req);
366-
nfs_list_add_request(req, dst);
367-
res++;
368376
}
377+
out:
369378
return res;
370379
}
371380

‎fs/nfs/write.c‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,17 @@ static int nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, un
579579
return ret;
580580
}
581581

582+
static void nfs_cancel_requests(struct list_head *head)
583+
{
584+
struct nfs_page *req;
585+
while(!list_empty(head)) {
586+
req = nfs_list_entry(head->next);
587+
nfs_list_remove_request(req);
588+
nfs_inode_remove_request(req);
589+
nfs_clear_page_writeback(req);
590+
}
591+
}
592+
582593
/*
583594
* nfs_scan_dirty - Scan an inode for dirty requests
584595
* @inode: NFS inode to scan
@@ -623,7 +634,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_st
623634
int res = 0;
624635

625636
if (nfsi->ncommit != 0) {
626-
res = nfs_scan_list(&nfsi->commit, dst, idx_start, npages);
637+
res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages);
627638
nfsi->ncommit -= res;
628639
if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit))
629640
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,
14911502
pages = nfs_scan_dirty(inode, &head, idx_start, npages);
14921503
if (pages != 0) {
14931504
spin_unlock(&nfsi->req_lock);
1494-
ret = nfs_flush_list(inode, &head, pages, how);
1505+
if (how & FLUSH_INVALIDATE)
1506+
nfs_cancel_requests(&head);
1507+
else
1508+
ret = nfs_flush_list(inode, &head, pages, how);
14951509
spin_lock(&nfsi->req_lock);
14961510
continue;
14971511
}
14981512
if (nocommit)
14991513
break;
1500-
pages = nfs_scan_commit(inode, &head, 0, 0);
1514+
pages = nfs_scan_commit(inode, &head, idx_start, npages);
15011515
if (pages == 0)
15021516
break;
1517+
if (how & FLUSH_INVALIDATE) {
1518+
spin_unlock(&nfsi->req_lock);
1519+
nfs_cancel_requests(&head);
1520+
spin_lock(&nfsi->req_lock);
1521+
continue;
1522+
}
1523+
pages += nfs_scan_commit(inode, &head, 0, 0);
15031524
spin_unlock(&nfsi->req_lock);
15041525
ret = nfs_commit_list(inode, &head, how);
15051526
spin_lock(&nfsi->req_lock);

‎include/linux/nfs_fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define FLUSH_LOWPRI 8 /* low priority background flush */
6262
#define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
6363
#define FLUSH_NOCOMMIT 32 /* Don't send the NFSv3/v4 COMMIT */
64+
#define FLUSH_INVALIDATE 64 /* Invalidate the page cache */
6465

6566
#ifdef __KERNEL__
6667

‎include/linux/nfs_page.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ extern void nfs_release_request(struct nfs_page *req);
6363

6464
extern int nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst,
6565
unsigned long idx_start, unsigned int npages);
66-
extern int nfs_scan_list(struct list_head *, struct list_head *,
67-
unsigned long, unsigned int);
66+
extern int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head, struct list_head *dst,
67+
unsigned long idx_start, unsigned int npages);
6868
extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
6969
unsigned int);
7070
extern int nfs_wait_on_request(struct nfs_page *);

0 commit comments

Comments
 (0)