aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/write.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r--fs/nfs/write.c812
1 files changed, 437 insertions, 375 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index c07462320f6b..4d6861c0dc14 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -39,20 +39,20 @@
39/* 39/*
40 * Local function declarations 40 * Local function declarations
41 */ 41 */
42static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc,
43 struct inode *inode, int ioflags);
44static void nfs_redirty_request(struct nfs_page *req); 42static void nfs_redirty_request(struct nfs_page *req);
45static const struct rpc_call_ops nfs_write_partial_ops; 43static const struct rpc_call_ops nfs_write_common_ops;
46static const struct rpc_call_ops nfs_write_full_ops;
47static const struct rpc_call_ops nfs_commit_ops; 44static const struct rpc_call_ops nfs_commit_ops;
45static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops;
46static const struct nfs_commit_completion_ops nfs_commit_completion_ops;
48 47
49static struct kmem_cache *nfs_wdata_cachep; 48static struct kmem_cache *nfs_wdata_cachep;
50static mempool_t *nfs_wdata_mempool; 49static mempool_t *nfs_wdata_mempool;
50static struct kmem_cache *nfs_cdata_cachep;
51static mempool_t *nfs_commit_mempool; 51static mempool_t *nfs_commit_mempool;
52 52
53struct nfs_write_data *nfs_commitdata_alloc(void) 53struct nfs_commit_data *nfs_commitdata_alloc(void)
54{ 54{
55 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); 55 struct nfs_commit_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS);
56 56
57 if (p) { 57 if (p) {
58 memset(p, 0, sizeof(*p)); 58 memset(p, 0, sizeof(*p));
@@ -62,46 +62,74 @@ struct nfs_write_data *nfs_commitdata_alloc(void)
62} 62}
63EXPORT_SYMBOL_GPL(nfs_commitdata_alloc); 63EXPORT_SYMBOL_GPL(nfs_commitdata_alloc);
64 64
65void nfs_commit_free(struct nfs_write_data *p) 65void nfs_commit_free(struct nfs_commit_data *p)
66{ 66{
67 if (p && (p->pagevec != &p->page_array[0]))
68 kfree(p->pagevec);
69 mempool_free(p, nfs_commit_mempool); 67 mempool_free(p, nfs_commit_mempool);
70} 68}
71EXPORT_SYMBOL_GPL(nfs_commit_free); 69EXPORT_SYMBOL_GPL(nfs_commit_free);
72 70
73struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount) 71struct nfs_write_header *nfs_writehdr_alloc(void)
74{ 72{
75 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); 73 struct nfs_write_header *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS);
76 74
77 if (p) { 75 if (p) {
76 struct nfs_pgio_header *hdr = &p->header;
77
78 memset(p, 0, sizeof(*p)); 78 memset(p, 0, sizeof(*p));
79 INIT_LIST_HEAD(&p->pages); 79 INIT_LIST_HEAD(&hdr->pages);
80 p->npages = pagecount; 80 INIT_LIST_HEAD(&hdr->rpc_list);
81 if (pagecount <= ARRAY_SIZE(p->page_array)) 81 spin_lock_init(&hdr->lock);
82 p->pagevec = p->page_array; 82 atomic_set(&hdr->refcnt, 0);
83 else { 83 hdr->verf = &p->verf;
84 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
85 if (!p->pagevec) {
86 mempool_free(p, nfs_wdata_mempool);
87 p = NULL;
88 }
89 }
90 } 84 }
91 return p; 85 return p;
92} 86}
93 87
94void nfs_writedata_free(struct nfs_write_data *p) 88static struct nfs_write_data *nfs_writedata_alloc(struct nfs_pgio_header *hdr,
89 unsigned int pagecount)
90{
91 struct nfs_write_data *data, *prealloc;
92
93 prealloc = &container_of(hdr, struct nfs_write_header, header)->rpc_data;
94 if (prealloc->header == NULL)
95 data = prealloc;
96 else
97 data = kzalloc(sizeof(*data), GFP_KERNEL);
98 if (!data)
99 goto out;
100
101 if (nfs_pgarray_set(&data->pages, pagecount)) {
102 data->header = hdr;
103 atomic_inc(&hdr->refcnt);
104 } else {
105 if (data != prealloc)
106 kfree(data);
107 data = NULL;
108 }
109out:
110 return data;
111}
112
113void nfs_writehdr_free(struct nfs_pgio_header *hdr)
95{ 114{
96 if (p && (p->pagevec != &p->page_array[0])) 115 struct nfs_write_header *whdr = container_of(hdr, struct nfs_write_header, header);
97 kfree(p->pagevec); 116 mempool_free(whdr, nfs_wdata_mempool);
98 mempool_free(p, nfs_wdata_mempool);
99} 117}
100 118
101void nfs_writedata_release(struct nfs_write_data *wdata) 119void nfs_writedata_release(struct nfs_write_data *wdata)
102{ 120{
121 struct nfs_pgio_header *hdr = wdata->header;
122 struct nfs_write_header *write_header = container_of(hdr, struct nfs_write_header, header);
123
103 put_nfs_open_context(wdata->args.context); 124 put_nfs_open_context(wdata->args.context);
104 nfs_writedata_free(wdata); 125 if (wdata->pages.pagevec != wdata->pages.page_array)
126 kfree(wdata->pages.pagevec);
127 if (wdata != &write_header->rpc_data)
128 kfree(wdata);
129 else
130 wdata->header = NULL;
131 if (atomic_dec_and_test(&hdr->refcnt))
132 hdr->completion_ops->completion(hdr);
105} 133}
106 134
107static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error) 135static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
@@ -203,7 +231,6 @@ static int nfs_set_page_writeback(struct page *page)
203 struct inode *inode = page->mapping->host; 231 struct inode *inode = page->mapping->host;
204 struct nfs_server *nfss = NFS_SERVER(inode); 232 struct nfs_server *nfss = NFS_SERVER(inode);
205 233
206 page_cache_get(page);
207 if (atomic_long_inc_return(&nfss->writeback) > 234 if (atomic_long_inc_return(&nfss->writeback) >
208 NFS_CONGESTION_ON_THRESH) { 235 NFS_CONGESTION_ON_THRESH) {
209 set_bdi_congested(&nfss->backing_dev_info, 236 set_bdi_congested(&nfss->backing_dev_info,
@@ -219,7 +246,6 @@ static void nfs_end_page_writeback(struct page *page)
219 struct nfs_server *nfss = NFS_SERVER(inode); 246 struct nfs_server *nfss = NFS_SERVER(inode);
220 247
221 end_page_writeback(page); 248 end_page_writeback(page);
222 page_cache_release(page);
223 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) 249 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
224 clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC); 250 clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC);
225} 251}
@@ -235,10 +261,10 @@ static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblo
235 req = nfs_page_find_request_locked(page); 261 req = nfs_page_find_request_locked(page);
236 if (req == NULL) 262 if (req == NULL)
237 break; 263 break;
238 if (nfs_lock_request_dontget(req)) 264 if (nfs_lock_request(req))
239 break; 265 break;
240 /* Note: If we hold the page lock, as is the case in nfs_writepage, 266 /* Note: If we hold the page lock, as is the case in nfs_writepage,
241 * then the call to nfs_lock_request_dontget() will always 267 * then the call to nfs_lock_request() will always
242 * succeed provided that someone hasn't already marked the 268 * succeed provided that someone hasn't already marked the
243 * request as dirty (in which case we don't care). 269 * request as dirty (in which case we don't care).
244 */ 270 */
@@ -310,7 +336,8 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc
310 struct nfs_pageio_descriptor pgio; 336 struct nfs_pageio_descriptor pgio;
311 int err; 337 int err;
312 338
313 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc)); 339 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc),
340 &nfs_async_write_completion_ops);
314 err = nfs_do_writepage(page, wbc, &pgio); 341 err = nfs_do_writepage(page, wbc, &pgio);
315 nfs_pageio_complete(&pgio); 342 nfs_pageio_complete(&pgio);
316 if (err < 0) 343 if (err < 0)
@@ -353,7 +380,8 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
353 380
354 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); 381 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
355 382
356 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc)); 383 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc),
384 &nfs_async_write_completion_ops);
357 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio); 385 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
358 nfs_pageio_complete(&pgio); 386 nfs_pageio_complete(&pgio);
359 387
@@ -379,7 +407,7 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
379 struct nfs_inode *nfsi = NFS_I(inode); 407 struct nfs_inode *nfsi = NFS_I(inode);
380 408
381 /* Lock the request! */ 409 /* Lock the request! */
382 nfs_lock_request_dontget(req); 410 nfs_lock_request(req);
383 411
384 spin_lock(&inode->i_lock); 412 spin_lock(&inode->i_lock);
385 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE)) 413 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE))
@@ -421,65 +449,88 @@ nfs_mark_request_dirty(struct nfs_page *req)
421/** 449/**
422 * nfs_request_add_commit_list - add request to a commit list 450 * nfs_request_add_commit_list - add request to a commit list
423 * @req: pointer to a struct nfs_page 451 * @req: pointer to a struct nfs_page
424 * @head: commit list head 452 * @dst: commit list head
453 * @cinfo: holds list lock and accounting info
425 * 454 *
426 * This sets the PG_CLEAN bit, updates the inode global count of 455 * This sets the PG_CLEAN bit, updates the cinfo count of
427 * number of outstanding requests requiring a commit as well as 456 * number of outstanding requests requiring a commit as well as
428 * the MM page stats. 457 * the MM page stats.
429 * 458 *
430 * The caller must _not_ hold the inode->i_lock, but must be 459 * The caller must _not_ hold the cinfo->lock, but must be
431 * holding the nfs_page lock. 460 * holding the nfs_page lock.
432 */ 461 */
433void 462void
434nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head) 463nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
464 struct nfs_commit_info *cinfo)
435{ 465{
436 struct inode *inode = req->wb_context->dentry->d_inode;
437
438 set_bit(PG_CLEAN, &(req)->wb_flags); 466 set_bit(PG_CLEAN, &(req)->wb_flags);
439 spin_lock(&inode->i_lock); 467 spin_lock(cinfo->lock);
440 nfs_list_add_request(req, head); 468 nfs_list_add_request(req, dst);
441 NFS_I(inode)->ncommit++; 469 cinfo->mds->ncommit++;
442 spin_unlock(&inode->i_lock); 470 spin_unlock(cinfo->lock);
443 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 471 if (!cinfo->dreq) {
444 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE); 472 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
445 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 473 inc_bdi_stat(req->wb_page->mapping->backing_dev_info,
474 BDI_RECLAIMABLE);
475 __mark_inode_dirty(req->wb_context->dentry->d_inode,
476 I_DIRTY_DATASYNC);
477 }
446} 478}
447EXPORT_SYMBOL_GPL(nfs_request_add_commit_list); 479EXPORT_SYMBOL_GPL(nfs_request_add_commit_list);
448 480
449/** 481/**
450 * nfs_request_remove_commit_list - Remove request from a commit list 482 * nfs_request_remove_commit_list - Remove request from a commit list
451 * @req: pointer to a nfs_page 483 * @req: pointer to a nfs_page
484 * @cinfo: holds list lock and accounting info
452 * 485 *
453 * This clears the PG_CLEAN bit, and updates the inode global count of 486 * This clears the PG_CLEAN bit, and updates the cinfo's count of
454 * number of outstanding requests requiring a commit 487 * number of outstanding requests requiring a commit
455 * It does not update the MM page stats. 488 * It does not update the MM page stats.
456 * 489 *
457 * The caller _must_ hold the inode->i_lock and the nfs_page lock. 490 * The caller _must_ hold the cinfo->lock and the nfs_page lock.
458 */ 491 */
459void 492void
460nfs_request_remove_commit_list(struct nfs_page *req) 493nfs_request_remove_commit_list(struct nfs_page *req,
494 struct nfs_commit_info *cinfo)
461{ 495{
462 struct inode *inode = req->wb_context->dentry->d_inode;
463
464 if (!test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) 496 if (!test_and_clear_bit(PG_CLEAN, &(req)->wb_flags))
465 return; 497 return;
466 nfs_list_remove_request(req); 498 nfs_list_remove_request(req);
467 NFS_I(inode)->ncommit--; 499 cinfo->mds->ncommit--;
468} 500}
469EXPORT_SYMBOL_GPL(nfs_request_remove_commit_list); 501EXPORT_SYMBOL_GPL(nfs_request_remove_commit_list);
470 502
503static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
504 struct inode *inode)
505{
506 cinfo->lock = &inode->i_lock;
507 cinfo->mds = &NFS_I(inode)->commit_info;
508 cinfo->ds = pnfs_get_ds_info(inode);
509 cinfo->dreq = NULL;
510 cinfo->completion_ops = &nfs_commit_completion_ops;
511}
512
513void nfs_init_cinfo(struct nfs_commit_info *cinfo,
514 struct inode *inode,
515 struct nfs_direct_req *dreq)
516{
517 if (dreq)
518 nfs_init_cinfo_from_dreq(cinfo, dreq);
519 else
520 nfs_init_cinfo_from_inode(cinfo, inode);
521}
522EXPORT_SYMBOL_GPL(nfs_init_cinfo);
471 523
472/* 524/*
473 * Add a request to the inode's commit list. 525 * Add a request to the inode's commit list.
474 */ 526 */
475static void 527void
476nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 528nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
529 struct nfs_commit_info *cinfo)
477{ 530{
478 struct inode *inode = req->wb_context->dentry->d_inode; 531 if (pnfs_mark_request_commit(req, lseg, cinfo))
479
480 if (pnfs_mark_request_commit(req, lseg))
481 return; 532 return;
482 nfs_request_add_commit_list(req, &NFS_I(inode)->commit_list); 533 nfs_request_add_commit_list(req, &cinfo->mds->list, cinfo);
483} 534}
484 535
485static void 536static void
@@ -494,11 +545,13 @@ nfs_clear_request_commit(struct nfs_page *req)
494{ 545{
495 if (test_bit(PG_CLEAN, &req->wb_flags)) { 546 if (test_bit(PG_CLEAN, &req->wb_flags)) {
496 struct inode *inode = req->wb_context->dentry->d_inode; 547 struct inode *inode = req->wb_context->dentry->d_inode;
548 struct nfs_commit_info cinfo;
497 549
498 if (!pnfs_clear_request_commit(req)) { 550 nfs_init_cinfo_from_inode(&cinfo, inode);
499 spin_lock(&inode->i_lock); 551 if (!pnfs_clear_request_commit(req, &cinfo)) {
500 nfs_request_remove_commit_list(req); 552 spin_lock(cinfo.lock);
501 spin_unlock(&inode->i_lock); 553 nfs_request_remove_commit_list(req, &cinfo);
554 spin_unlock(cinfo.lock);
502 } 555 }
503 nfs_clear_page_commit(req->wb_page); 556 nfs_clear_page_commit(req->wb_page);
504 } 557 }
@@ -508,28 +561,25 @@ static inline
508int nfs_write_need_commit(struct nfs_write_data *data) 561int nfs_write_need_commit(struct nfs_write_data *data)
509{ 562{
510 if (data->verf.committed == NFS_DATA_SYNC) 563 if (data->verf.committed == NFS_DATA_SYNC)
511 return data->lseg == NULL; 564 return data->header->lseg == NULL;
512 else 565 return data->verf.committed != NFS_FILE_SYNC;
513 return data->verf.committed != NFS_FILE_SYNC;
514} 566}
515 567
516static inline 568#else
517int nfs_reschedule_unstable_write(struct nfs_page *req, 569static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
518 struct nfs_write_data *data) 570 struct inode *inode)
519{ 571{
520 if (test_and_clear_bit(PG_NEED_COMMIT, &req->wb_flags)) {
521 nfs_mark_request_commit(req, data->lseg);
522 return 1;
523 }
524 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
525 nfs_mark_request_dirty(req);
526 return 1;
527 }
528 return 0;
529} 572}
530#else 573
531static void 574void nfs_init_cinfo(struct nfs_commit_info *cinfo,
532nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 575 struct inode *inode,
576 struct nfs_direct_req *dreq)
577{
578}
579
580void
581nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
582 struct nfs_commit_info *cinfo)
533{ 583{
534} 584}
535 585
@@ -544,25 +594,58 @@ int nfs_write_need_commit(struct nfs_write_data *data)
544 return 0; 594 return 0;
545} 595}
546 596
547static inline 597#endif
548int nfs_reschedule_unstable_write(struct nfs_page *req, 598
549 struct nfs_write_data *data) 599static void nfs_write_completion(struct nfs_pgio_header *hdr)
550{ 600{
551 return 0; 601 struct nfs_commit_info cinfo;
602 unsigned long bytes = 0;
603
604 if (test_bit(NFS_IOHDR_REDO, &hdr->flags))
605 goto out;
606 nfs_init_cinfo_from_inode(&cinfo, hdr->inode);
607 while (!list_empty(&hdr->pages)) {
608 struct nfs_page *req = nfs_list_entry(hdr->pages.next);
609
610 bytes += req->wb_bytes;
611 nfs_list_remove_request(req);
612 if (test_bit(NFS_IOHDR_ERROR, &hdr->flags) &&
613 (hdr->good_bytes < bytes)) {
614 nfs_set_pageerror(req->wb_page);
615 nfs_context_set_write_error(req->wb_context, hdr->error);
616 goto remove_req;
617 }
618 if (test_bit(NFS_IOHDR_NEED_RESCHED, &hdr->flags)) {
619 nfs_mark_request_dirty(req);
620 goto next;
621 }
622 if (test_bit(NFS_IOHDR_NEED_COMMIT, &hdr->flags)) {
623 memcpy(&req->wb_verf, hdr->verf, sizeof(req->wb_verf));
624 nfs_mark_request_commit(req, hdr->lseg, &cinfo);
625 goto next;
626 }
627remove_req:
628 nfs_inode_remove_request(req);
629next:
630 nfs_unlock_request(req);
631 nfs_end_page_writeback(req->wb_page);
632 nfs_release_request(req);
633 }
634out:
635 hdr->release(hdr);
552} 636}
553#endif
554 637
555#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 638#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
556static int 639static unsigned long
557nfs_need_commit(struct nfs_inode *nfsi) 640nfs_reqs_to_commit(struct nfs_commit_info *cinfo)
558{ 641{
559 return nfsi->ncommit > 0; 642 return cinfo->mds->ncommit;
560} 643}
561 644
562/* i_lock held by caller */ 645/* cinfo->lock held by caller */
563static int 646int
564nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int max, 647nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
565 spinlock_t *lock) 648 struct nfs_commit_info *cinfo, int max)
566{ 649{
567 struct nfs_page *req, *tmp; 650 struct nfs_page *req, *tmp;
568 int ret = 0; 651 int ret = 0;
@@ -570,12 +653,13 @@ nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int max,
570 list_for_each_entry_safe(req, tmp, src, wb_list) { 653 list_for_each_entry_safe(req, tmp, src, wb_list) {
571 if (!nfs_lock_request(req)) 654 if (!nfs_lock_request(req))
572 continue; 655 continue;
573 if (cond_resched_lock(lock)) 656 kref_get(&req->wb_kref);
657 if (cond_resched_lock(cinfo->lock))
574 list_safe_reset_next(req, tmp, wb_list); 658 list_safe_reset_next(req, tmp, wb_list);
575 nfs_request_remove_commit_list(req); 659 nfs_request_remove_commit_list(req, cinfo);
576 nfs_list_add_request(req, dst); 660 nfs_list_add_request(req, dst);
577 ret++; 661 ret++;
578 if (ret == max) 662 if ((ret == max) && !cinfo->dreq)
579 break; 663 break;
580 } 664 }
581 return ret; 665 return ret;
@@ -584,37 +668,38 @@ nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int max,
584/* 668/*
585 * nfs_scan_commit - Scan an inode for commit requests 669 * nfs_scan_commit - Scan an inode for commit requests
586 * @inode: NFS inode to scan 670 * @inode: NFS inode to scan
587 * @dst: destination list 671 * @dst: mds destination list
672 * @cinfo: mds and ds lists of reqs ready to commit
588 * 673 *
589 * Moves requests from the inode's 'commit' request list. 674 * Moves requests from the inode's 'commit' request list.
590 * The requests are *not* checked to ensure that they form a contiguous set. 675 * The requests are *not* checked to ensure that they form a contiguous set.
591 */ 676 */
592static int 677int
593nfs_scan_commit(struct inode *inode, struct list_head *dst) 678nfs_scan_commit(struct inode *inode, struct list_head *dst,
679 struct nfs_commit_info *cinfo)
594{ 680{
595 struct nfs_inode *nfsi = NFS_I(inode);
596 int ret = 0; 681 int ret = 0;
597 682
598 spin_lock(&inode->i_lock); 683 spin_lock(cinfo->lock);
599 if (nfsi->ncommit > 0) { 684 if (cinfo->mds->ncommit > 0) {
600 const int max = INT_MAX; 685 const int max = INT_MAX;
601 686
602 ret = nfs_scan_commit_list(&nfsi->commit_list, dst, max, 687 ret = nfs_scan_commit_list(&cinfo->mds->list, dst,
603 &inode->i_lock); 688 cinfo, max);
604 ret += pnfs_scan_commit_lists(inode, max - ret, 689 ret += pnfs_scan_commit_lists(inode, cinfo, max - ret);
605 &inode->i_lock);
606 } 690 }
607 spin_unlock(&inode->i_lock); 691 spin_unlock(cinfo->lock);
608 return ret; 692 return ret;
609} 693}
610 694
611#else 695#else
612static inline int nfs_need_commit(struct nfs_inode *nfsi) 696static unsigned long nfs_reqs_to_commit(struct nfs_commit_info *cinfo)
613{ 697{
614 return 0; 698 return 0;
615} 699}
616 700
617static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst) 701int nfs_scan_commit(struct inode *inode, struct list_head *dst,
702 struct nfs_commit_info *cinfo)
618{ 703{
619 return 0; 704 return 0;
620} 705}
@@ -659,7 +744,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
659 || end < req->wb_offset) 744 || end < req->wb_offset)
660 goto out_flushme; 745 goto out_flushme;
661 746
662 if (nfs_lock_request_dontget(req)) 747 if (nfs_lock_request(req))
663 break; 748 break;
664 749
665 /* The request is locked, so wait and then retry */ 750 /* The request is locked, so wait and then retry */
@@ -729,7 +814,7 @@ static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
729 nfs_grow_file(page, offset, count); 814 nfs_grow_file(page, offset, count);
730 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes); 815 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
731 nfs_mark_request_dirty(req); 816 nfs_mark_request_dirty(req);
732 nfs_unlock_request(req); 817 nfs_unlock_and_release_request(req);
733 return 0; 818 return 0;
734} 819}
735 820
@@ -766,10 +851,14 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
766 * the PageUptodate() flag. In this case, we will need to turn off 851 * the PageUptodate() flag. In this case, we will need to turn off
767 * write optimisations that depend on the page contents being correct. 852 * write optimisations that depend on the page contents being correct.
768 */ 853 */
769static int nfs_write_pageuptodate(struct page *page, struct inode *inode) 854static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
770{ 855{
771 return PageUptodate(page) && 856 if (nfs_have_delegated_attributes(inode))
772 !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA)); 857 goto out;
858 if (NFS_I(inode)->cache_validity & NFS_INO_REVAL_PAGECACHE)
859 return false;
860out:
861 return PageUptodate(page) != 0;
773} 862}
774 863
775/* 864/*
@@ -815,17 +904,6 @@ int nfs_updatepage(struct file *file, struct page *page,
815 return status; 904 return status;
816} 905}
817 906
818static void nfs_writepage_release(struct nfs_page *req,
819 struct nfs_write_data *data)
820{
821 struct page *page = req->wb_page;
822
823 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req, data))
824 nfs_inode_remove_request(req);
825 nfs_unlock_request(req);
826 nfs_end_page_writeback(page);
827}
828
829static int flush_task_priority(int how) 907static int flush_task_priority(int how)
830{ 908{
831 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) { 909 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
@@ -837,18 +915,18 @@ static int flush_task_priority(int how)
837 return RPC_PRIORITY_NORMAL; 915 return RPC_PRIORITY_NORMAL;
838} 916}
839 917
840int nfs_initiate_write(struct nfs_write_data *data, 918int nfs_initiate_write(struct rpc_clnt *clnt,
841 struct rpc_clnt *clnt, 919 struct nfs_write_data *data,
842 const struct rpc_call_ops *call_ops, 920 const struct rpc_call_ops *call_ops,
843 int how) 921 int how, int flags)
844{ 922{
845 struct inode *inode = data->inode; 923 struct inode *inode = data->header->inode;
846 int priority = flush_task_priority(how); 924 int priority = flush_task_priority(how);
847 struct rpc_task *task; 925 struct rpc_task *task;
848 struct rpc_message msg = { 926 struct rpc_message msg = {
849 .rpc_argp = &data->args, 927 .rpc_argp = &data->args,
850 .rpc_resp = &data->res, 928 .rpc_resp = &data->res,
851 .rpc_cred = data->cred, 929 .rpc_cred = data->header->cred,
852 }; 930 };
853 struct rpc_task_setup task_setup_data = { 931 struct rpc_task_setup task_setup_data = {
854 .rpc_client = clnt, 932 .rpc_client = clnt,
@@ -857,7 +935,7 @@ int nfs_initiate_write(struct nfs_write_data *data,
857 .callback_ops = call_ops, 935 .callback_ops = call_ops,
858 .callback_data = data, 936 .callback_data = data,
859 .workqueue = nfsiod_workqueue, 937 .workqueue = nfsiod_workqueue,
860 .flags = RPC_TASK_ASYNC, 938 .flags = RPC_TASK_ASYNC | flags,
861 .priority = priority, 939 .priority = priority,
862 }; 940 };
863 int ret = 0; 941 int ret = 0;
@@ -892,26 +970,21 @@ EXPORT_SYMBOL_GPL(nfs_initiate_write);
892/* 970/*
893 * Set up the argument/result storage required for the RPC call. 971 * Set up the argument/result storage required for the RPC call.
894 */ 972 */
895static void nfs_write_rpcsetup(struct nfs_page *req, 973static void nfs_write_rpcsetup(struct nfs_write_data *data,
896 struct nfs_write_data *data,
897 unsigned int count, unsigned int offset, 974 unsigned int count, unsigned int offset,
898 int how) 975 int how, struct nfs_commit_info *cinfo)
899{ 976{
900 struct inode *inode = req->wb_context->dentry->d_inode; 977 struct nfs_page *req = data->header->req;
901 978
902 /* Set up the RPC argument and reply structs 979 /* Set up the RPC argument and reply structs
903 * NB: take care not to mess about with data->commit et al. */ 980 * NB: take care not to mess about with data->commit et al. */
904 981
905 data->req = req; 982 data->args.fh = NFS_FH(data->header->inode);
906 data->inode = inode = req->wb_context->dentry->d_inode;
907 data->cred = req->wb_context->cred;
908
909 data->args.fh = NFS_FH(inode);
910 data->args.offset = req_offset(req) + offset; 983 data->args.offset = req_offset(req) + offset;
911 /* pnfs_set_layoutcommit needs this */ 984 /* pnfs_set_layoutcommit needs this */
912 data->mds_offset = data->args.offset; 985 data->mds_offset = data->args.offset;
913 data->args.pgbase = req->wb_pgbase + offset; 986 data->args.pgbase = req->wb_pgbase + offset;
914 data->args.pages = data->pagevec; 987 data->args.pages = data->pages.pagevec;
915 data->args.count = count; 988 data->args.count = count;
916 data->args.context = get_nfs_open_context(req->wb_context); 989 data->args.context = get_nfs_open_context(req->wb_context);
917 data->args.lock_context = req->wb_lock_context; 990 data->args.lock_context = req->wb_lock_context;
@@ -920,7 +993,7 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
920 case 0: 993 case 0:
921 break; 994 break;
922 case FLUSH_COND_STABLE: 995 case FLUSH_COND_STABLE:
923 if (nfs_need_commit(NFS_I(inode))) 996 if (nfs_reqs_to_commit(cinfo))
924 break; 997 break;
925 default: 998 default:
926 data->args.stable = NFS_FILE_SYNC; 999 data->args.stable = NFS_FILE_SYNC;
@@ -936,9 +1009,9 @@ static int nfs_do_write(struct nfs_write_data *data,
936 const struct rpc_call_ops *call_ops, 1009 const struct rpc_call_ops *call_ops,
937 int how) 1010 int how)
938{ 1011{
939 struct inode *inode = data->args.context->dentry->d_inode; 1012 struct inode *inode = data->header->inode;
940 1013
941 return nfs_initiate_write(data, NFS_CLIENT(inode), call_ops, how); 1014 return nfs_initiate_write(NFS_CLIENT(inode), data, call_ops, how, 0);
942} 1015}
943 1016
944static int nfs_do_multiple_writes(struct list_head *head, 1017static int nfs_do_multiple_writes(struct list_head *head,
@@ -951,7 +1024,7 @@ static int nfs_do_multiple_writes(struct list_head *head,
951 while (!list_empty(head)) { 1024 while (!list_empty(head)) {
952 int ret2; 1025 int ret2;
953 1026
954 data = list_entry(head->next, struct nfs_write_data, list); 1027 data = list_first_entry(head, struct nfs_write_data, list);
955 list_del_init(&data->list); 1028 list_del_init(&data->list);
956 1029
957 ret2 = nfs_do_write(data, call_ops, how); 1030 ret2 = nfs_do_write(data, call_ops, how);
@@ -967,31 +1040,60 @@ static int nfs_do_multiple_writes(struct list_head *head,
967 */ 1040 */
968static void nfs_redirty_request(struct nfs_page *req) 1041static void nfs_redirty_request(struct nfs_page *req)
969{ 1042{
970 struct page *page = req->wb_page;
971
972 nfs_mark_request_dirty(req); 1043 nfs_mark_request_dirty(req);
973 nfs_unlock_request(req); 1044 nfs_unlock_request(req);
974 nfs_end_page_writeback(page); 1045 nfs_end_page_writeback(req->wb_page);
1046 nfs_release_request(req);
1047}
1048
1049static void nfs_async_write_error(struct list_head *head)
1050{
1051 struct nfs_page *req;
1052
1053 while (!list_empty(head)) {
1054 req = nfs_list_entry(head->next);
1055 nfs_list_remove_request(req);
1056 nfs_redirty_request(req);
1057 }
1058}
1059
1060static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops = {
1061 .error_cleanup = nfs_async_write_error,
1062 .completion = nfs_write_completion,
1063};
1064
1065static void nfs_flush_error(struct nfs_pageio_descriptor *desc,
1066 struct nfs_pgio_header *hdr)
1067{
1068 set_bit(NFS_IOHDR_REDO, &hdr->flags);
1069 while (!list_empty(&hdr->rpc_list)) {
1070 struct nfs_write_data *data = list_first_entry(&hdr->rpc_list,
1071 struct nfs_write_data, list);
1072 list_del(&data->list);
1073 nfs_writedata_release(data);
1074 }
1075 desc->pg_completion_ops->error_cleanup(&desc->pg_list);
975} 1076}
976 1077
977/* 1078/*
978 * Generate multiple small requests to write out a single 1079 * Generate multiple small requests to write out a single
979 * contiguous dirty area on one page. 1080 * contiguous dirty area on one page.
980 */ 1081 */
981static int nfs_flush_multi(struct nfs_pageio_descriptor *desc, struct list_head *res) 1082static int nfs_flush_multi(struct nfs_pageio_descriptor *desc,
1083 struct nfs_pgio_header *hdr)
982{ 1084{
983 struct nfs_page *req = nfs_list_entry(desc->pg_list.next); 1085 struct nfs_page *req = hdr->req;
984 struct page *page = req->wb_page; 1086 struct page *page = req->wb_page;
985 struct nfs_write_data *data; 1087 struct nfs_write_data *data;
986 size_t wsize = desc->pg_bsize, nbytes; 1088 size_t wsize = desc->pg_bsize, nbytes;
987 unsigned int offset; 1089 unsigned int offset;
988 int requests = 0; 1090 int requests = 0;
989 int ret = 0; 1091 struct nfs_commit_info cinfo;
990 1092
991 nfs_list_remove_request(req); 1093 nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq);
992 1094
993 if ((desc->pg_ioflags & FLUSH_COND_STABLE) && 1095 if ((desc->pg_ioflags & FLUSH_COND_STABLE) &&
994 (desc->pg_moreio || NFS_I(desc->pg_inode)->ncommit || 1096 (desc->pg_moreio || nfs_reqs_to_commit(&cinfo) ||
995 desc->pg_count > wsize)) 1097 desc->pg_count > wsize))
996 desc->pg_ioflags &= ~FLUSH_COND_STABLE; 1098 desc->pg_ioflags &= ~FLUSH_COND_STABLE;
997 1099
@@ -1001,28 +1103,22 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc, struct list_head
1001 do { 1103 do {
1002 size_t len = min(nbytes, wsize); 1104 size_t len = min(nbytes, wsize);
1003 1105
1004 data = nfs_writedata_alloc(1); 1106 data = nfs_writedata_alloc(hdr, 1);
1005 if (!data) 1107 if (!data) {
1006 goto out_bad; 1108 nfs_flush_error(desc, hdr);
1007 data->pagevec[0] = page; 1109 return -ENOMEM;
1008 nfs_write_rpcsetup(req, data, len, offset, desc->pg_ioflags); 1110 }
1009 list_add(&data->list, res); 1111 data->pages.pagevec[0] = page;
1112 nfs_write_rpcsetup(data, len, offset, desc->pg_ioflags, &cinfo);
1113 list_add(&data->list, &hdr->rpc_list);
1010 requests++; 1114 requests++;
1011 nbytes -= len; 1115 nbytes -= len;
1012 offset += len; 1116 offset += len;
1013 } while (nbytes != 0); 1117 } while (nbytes != 0);
1014 atomic_set(&req->wb_complete, requests); 1118 nfs_list_remove_request(req);
1015 desc->pg_rpc_callops = &nfs_write_partial_ops; 1119 nfs_list_add_request(req, &hdr->pages);
1016 return ret; 1120 desc->pg_rpc_callops = &nfs_write_common_ops;
1017 1121 return 0;
1018out_bad:
1019 while (!list_empty(res)) {
1020 data = list_entry(res->next, struct nfs_write_data, list);
1021 list_del(&data->list);
1022 nfs_writedata_release(data);
1023 }
1024 nfs_redirty_request(req);
1025 return -ENOMEM;
1026} 1122}
1027 1123
1028/* 1124/*
@@ -1033,62 +1129,71 @@ out_bad:
1033 * This is the case if nfs_updatepage detects a conflicting request 1129 * This is the case if nfs_updatepage detects a conflicting request
1034 * that has been written but not committed. 1130 * that has been written but not committed.
1035 */ 1131 */
1036static int nfs_flush_one(struct nfs_pageio_descriptor *desc, struct list_head *res) 1132static int nfs_flush_one(struct nfs_pageio_descriptor *desc,
1133 struct nfs_pgio_header *hdr)
1037{ 1134{
1038 struct nfs_page *req; 1135 struct nfs_page *req;
1039 struct page **pages; 1136 struct page **pages;
1040 struct nfs_write_data *data; 1137 struct nfs_write_data *data;
1041 struct list_head *head = &desc->pg_list; 1138 struct list_head *head = &desc->pg_list;
1042 int ret = 0; 1139 struct nfs_commit_info cinfo;
1043 1140
1044 data = nfs_writedata_alloc(nfs_page_array_len(desc->pg_base, 1141 data = nfs_writedata_alloc(hdr, nfs_page_array_len(desc->pg_base,
1045 desc->pg_count)); 1142 desc->pg_count));
1046 if (!data) { 1143 if (!data) {
1047 while (!list_empty(head)) { 1144 nfs_flush_error(desc, hdr);
1048 req = nfs_list_entry(head->next); 1145 return -ENOMEM;
1049 nfs_list_remove_request(req);
1050 nfs_redirty_request(req);
1051 }
1052 ret = -ENOMEM;
1053 goto out;
1054 } 1146 }
1055 pages = data->pagevec; 1147
1148 nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq);
1149 pages = data->pages.pagevec;
1056 while (!list_empty(head)) { 1150 while (!list_empty(head)) {
1057 req = nfs_list_entry(head->next); 1151 req = nfs_list_entry(head->next);
1058 nfs_list_remove_request(req); 1152 nfs_list_remove_request(req);
1059 nfs_list_add_request(req, &data->pages); 1153 nfs_list_add_request(req, &hdr->pages);
1060 *pages++ = req->wb_page; 1154 *pages++ = req->wb_page;
1061 } 1155 }
1062 req = nfs_list_entry(data->pages.next);
1063 1156
1064 if ((desc->pg_ioflags & FLUSH_COND_STABLE) && 1157 if ((desc->pg_ioflags & FLUSH_COND_STABLE) &&
1065 (desc->pg_moreio || NFS_I(desc->pg_inode)->ncommit)) 1158 (desc->pg_moreio || nfs_reqs_to_commit(&cinfo)))
1066 desc->pg_ioflags &= ~FLUSH_COND_STABLE; 1159 desc->pg_ioflags &= ~FLUSH_COND_STABLE;
1067 1160
1068 /* Set up the argument struct */ 1161 /* Set up the argument struct */
1069 nfs_write_rpcsetup(req, data, desc->pg_count, 0, desc->pg_ioflags); 1162 nfs_write_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo);
1070 list_add(&data->list, res); 1163 list_add(&data->list, &hdr->rpc_list);
1071 desc->pg_rpc_callops = &nfs_write_full_ops; 1164 desc->pg_rpc_callops = &nfs_write_common_ops;
1072out: 1165 return 0;
1073 return ret;
1074} 1166}
1075 1167
1076int nfs_generic_flush(struct nfs_pageio_descriptor *desc, struct list_head *head) 1168int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
1169 struct nfs_pgio_header *hdr)
1077{ 1170{
1078 if (desc->pg_bsize < PAGE_CACHE_SIZE) 1171 if (desc->pg_bsize < PAGE_CACHE_SIZE)
1079 return nfs_flush_multi(desc, head); 1172 return nfs_flush_multi(desc, hdr);
1080 return nfs_flush_one(desc, head); 1173 return nfs_flush_one(desc, hdr);
1081} 1174}
1082 1175
1083static int nfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) 1176static int nfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
1084{ 1177{
1085 LIST_HEAD(head); 1178 struct nfs_write_header *whdr;
1179 struct nfs_pgio_header *hdr;
1086 int ret; 1180 int ret;
1087 1181
1088 ret = nfs_generic_flush(desc, &head); 1182 whdr = nfs_writehdr_alloc();
1183 if (!whdr) {
1184 desc->pg_completion_ops->error_cleanup(&desc->pg_list);
1185 return -ENOMEM;
1186 }
1187 hdr = &whdr->header;
1188 nfs_pgheader_init(desc, hdr, nfs_writehdr_free);
1189 atomic_inc(&hdr->refcnt);
1190 ret = nfs_generic_flush(desc, hdr);
1089 if (ret == 0) 1191 if (ret == 0)
1090 ret = nfs_do_multiple_writes(&head, desc->pg_rpc_callops, 1192 ret = nfs_do_multiple_writes(&hdr->rpc_list,
1091 desc->pg_ioflags); 1193 desc->pg_rpc_callops,
1194 desc->pg_ioflags);
1195 if (atomic_dec_and_test(&hdr->refcnt))
1196 hdr->completion_ops->completion(hdr);
1092 return ret; 1197 return ret;
1093} 1198}
1094 1199
@@ -1098,9 +1203,10 @@ static const struct nfs_pageio_ops nfs_pageio_write_ops = {
1098}; 1203};
1099 1204
1100void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio, 1205void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio,
1101 struct inode *inode, int ioflags) 1206 struct inode *inode, int ioflags,
1207 const struct nfs_pgio_completion_ops *compl_ops)
1102{ 1208{
1103 nfs_pageio_init(pgio, inode, &nfs_pageio_write_ops, 1209 nfs_pageio_init(pgio, inode, &nfs_pageio_write_ops, compl_ops,
1104 NFS_SERVER(inode)->wsize, ioflags); 1210 NFS_SERVER(inode)->wsize, ioflags);
1105} 1211}
1106 1212
@@ -1111,80 +1217,27 @@ void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio)
1111} 1217}
1112EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds); 1218EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds);
1113 1219
1114static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 1220void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
1115 struct inode *inode, int ioflags) 1221 struct inode *inode, int ioflags,
1222 const struct nfs_pgio_completion_ops *compl_ops)
1116{ 1223{
1117 if (!pnfs_pageio_init_write(pgio, inode, ioflags)) 1224 if (!pnfs_pageio_init_write(pgio, inode, ioflags, compl_ops))
1118 nfs_pageio_init_write_mds(pgio, inode, ioflags); 1225 nfs_pageio_init_write_mds(pgio, inode, ioflags, compl_ops);
1119} 1226}
1120 1227
1121/* 1228void nfs_write_prepare(struct rpc_task *task, void *calldata)
1122 * Handle a write reply that flushed part of a page.
1123 */
1124static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
1125{ 1229{
1126 struct nfs_write_data *data = calldata; 1230 struct nfs_write_data *data = calldata;
1127 1231 NFS_PROTO(data->header->inode)->write_rpc_prepare(task, data);
1128 dprintk("NFS: %5u write(%s/%lld %d@%lld)",
1129 task->tk_pid,
1130 data->req->wb_context->dentry->d_inode->i_sb->s_id,
1131 (long long)
1132 NFS_FILEID(data->req->wb_context->dentry->d_inode),
1133 data->req->wb_bytes, (long long)req_offset(data->req));
1134
1135 nfs_writeback_done(task, data);
1136} 1232}
1137 1233
1138static void nfs_writeback_release_partial(void *calldata) 1234void nfs_commit_prepare(struct rpc_task *task, void *calldata)
1139{ 1235{
1140 struct nfs_write_data *data = calldata; 1236 struct nfs_commit_data *data = calldata;
1141 struct nfs_page *req = data->req;
1142 struct page *page = req->wb_page;
1143 int status = data->task.tk_status;
1144
1145 if (status < 0) {
1146 nfs_set_pageerror(page);
1147 nfs_context_set_write_error(req->wb_context, status);
1148 dprintk(", error = %d\n", status);
1149 goto out;
1150 }
1151
1152 if (nfs_write_need_commit(data)) {
1153 struct inode *inode = page->mapping->host;
1154 1237
1155 spin_lock(&inode->i_lock); 1238 NFS_PROTO(data->inode)->commit_rpc_prepare(task, data);
1156 if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) {
1157 /* Do nothing we need to resend the writes */
1158 } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1159 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1160 dprintk(" defer commit\n");
1161 } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) {
1162 set_bit(PG_NEED_RESCHED, &req->wb_flags);
1163 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
1164 dprintk(" server reboot detected\n");
1165 }
1166 spin_unlock(&inode->i_lock);
1167 } else
1168 dprintk(" OK\n");
1169
1170out:
1171 if (atomic_dec_and_test(&req->wb_complete))
1172 nfs_writepage_release(req, data);
1173 nfs_writedata_release(calldata);
1174} 1239}
1175 1240
1176void nfs_write_prepare(struct rpc_task *task, void *calldata)
1177{
1178 struct nfs_write_data *data = calldata;
1179 NFS_PROTO(data->inode)->write_rpc_prepare(task, data);
1180}
1181
1182static const struct rpc_call_ops nfs_write_partial_ops = {
1183 .rpc_call_prepare = nfs_write_prepare,
1184 .rpc_call_done = nfs_writeback_done_partial,
1185 .rpc_release = nfs_writeback_release_partial,
1186};
1187
1188/* 1241/*
1189 * Handle a write reply that flushes a whole page. 1242 * Handle a write reply that flushes a whole page.
1190 * 1243 *
@@ -1192,59 +1245,36 @@ static const struct rpc_call_ops nfs_write_partial_ops = {
1192 * writebacks since the page->count is kept > 1 for as long 1245 * writebacks since the page->count is kept > 1 for as long
1193 * as the page has a write request pending. 1246 * as the page has a write request pending.
1194 */ 1247 */
1195static void nfs_writeback_done_full(struct rpc_task *task, void *calldata) 1248static void nfs_writeback_done_common(struct rpc_task *task, void *calldata)
1196{ 1249{
1197 struct nfs_write_data *data = calldata; 1250 struct nfs_write_data *data = calldata;
1198 1251
1199 nfs_writeback_done(task, data); 1252 nfs_writeback_done(task, data);
1200} 1253}
1201 1254
1202static void nfs_writeback_release_full(void *calldata) 1255static void nfs_writeback_release_common(void *calldata)
1203{ 1256{
1204 struct nfs_write_data *data = calldata; 1257 struct nfs_write_data *data = calldata;
1258 struct nfs_pgio_header *hdr = data->header;
1205 int status = data->task.tk_status; 1259 int status = data->task.tk_status;
1206 1260
1207 /* Update attributes as result of writeback. */ 1261 if ((status >= 0) && nfs_write_need_commit(data)) {
1208 while (!list_empty(&data->pages)) { 1262 spin_lock(&hdr->lock);
1209 struct nfs_page *req = nfs_list_entry(data->pages.next); 1263 if (test_bit(NFS_IOHDR_NEED_RESCHED, &hdr->flags))
1210 struct page *page = req->wb_page; 1264 ; /* Do nothing */
1211 1265 else if (!test_and_set_bit(NFS_IOHDR_NEED_COMMIT, &hdr->flags))
1212 nfs_list_remove_request(req); 1266 memcpy(hdr->verf, &data->verf, sizeof(*hdr->verf));
1213 1267 else if (memcmp(hdr->verf, &data->verf, sizeof(*hdr->verf)))
1214 dprintk("NFS: %5u write (%s/%lld %d@%lld)", 1268 set_bit(NFS_IOHDR_NEED_RESCHED, &hdr->flags);
1215 data->task.tk_pid, 1269 spin_unlock(&hdr->lock);
1216 req->wb_context->dentry->d_inode->i_sb->s_id,
1217 (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
1218 req->wb_bytes,
1219 (long long)req_offset(req));
1220
1221 if (status < 0) {
1222 nfs_set_pageerror(page);
1223 nfs_context_set_write_error(req->wb_context, status);
1224 dprintk(", error = %d\n", status);
1225 goto remove_request;
1226 }
1227
1228 if (nfs_write_need_commit(data)) {
1229 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1230 nfs_mark_request_commit(req, data->lseg);
1231 dprintk(" marked for commit\n");
1232 goto next;
1233 }
1234 dprintk(" OK\n");
1235remove_request:
1236 nfs_inode_remove_request(req);
1237 next:
1238 nfs_unlock_request(req);
1239 nfs_end_page_writeback(page);
1240 } 1270 }
1241 nfs_writedata_release(calldata); 1271 nfs_writedata_release(data);
1242} 1272}
1243 1273
1244static const struct rpc_call_ops nfs_write_full_ops = { 1274static const struct rpc_call_ops nfs_write_common_ops = {
1245 .rpc_call_prepare = nfs_write_prepare, 1275 .rpc_call_prepare = nfs_write_prepare,
1246 .rpc_call_done = nfs_writeback_done_full, 1276 .rpc_call_done = nfs_writeback_done_common,
1247 .rpc_release = nfs_writeback_release_full, 1277 .rpc_release = nfs_writeback_release_common,
1248}; 1278};
1249 1279
1250 1280
@@ -1255,6 +1285,7 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1255{ 1285{
1256 struct nfs_writeargs *argp = &data->args; 1286 struct nfs_writeargs *argp = &data->args;
1257 struct nfs_writeres *resp = &data->res; 1287 struct nfs_writeres *resp = &data->res;
1288 struct inode *inode = data->header->inode;
1258 int status; 1289 int status;
1259 1290
1260 dprintk("NFS: %5u nfs_writeback_done (status %d)\n", 1291 dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
@@ -1267,10 +1298,10 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1267 * another writer had changed the file, but some applications 1298 * another writer had changed the file, but some applications
1268 * depend on tighter cache coherency when writing. 1299 * depend on tighter cache coherency when writing.
1269 */ 1300 */
1270 status = NFS_PROTO(data->inode)->write_done(task, data); 1301 status = NFS_PROTO(inode)->write_done(task, data);
1271 if (status != 0) 1302 if (status != 0)
1272 return; 1303 return;
1273 nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count); 1304 nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, resp->count);
1274 1305
1275#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 1306#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1276 if (resp->verf->committed < argp->stable && task->tk_status >= 0) { 1307 if (resp->verf->committed < argp->stable && task->tk_status >= 0) {
@@ -1288,46 +1319,47 @@ void nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1288 if (time_before(complain, jiffies)) { 1319 if (time_before(complain, jiffies)) {
1289 dprintk("NFS: faulty NFS server %s:" 1320 dprintk("NFS: faulty NFS server %s:"
1290 " (committed = %d) != (stable = %d)\n", 1321 " (committed = %d) != (stable = %d)\n",
1291 NFS_SERVER(data->inode)->nfs_client->cl_hostname, 1322 NFS_SERVER(inode)->nfs_client->cl_hostname,
1292 resp->verf->committed, argp->stable); 1323 resp->verf->committed, argp->stable);
1293 complain = jiffies + 300 * HZ; 1324 complain = jiffies + 300 * HZ;
1294 } 1325 }
1295 } 1326 }
1296#endif 1327#endif
1297 /* Is this a short write? */ 1328 if (task->tk_status < 0)
1298 if (task->tk_status >= 0 && resp->count < argp->count) { 1329 nfs_set_pgio_error(data->header, task->tk_status, argp->offset);
1330 else if (resp->count < argp->count) {
1299 static unsigned long complain; 1331 static unsigned long complain;
1300 1332
1301 nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE); 1333 /* This a short write! */
1334 nfs_inc_stats(inode, NFSIOS_SHORTWRITE);
1302 1335
1303 /* Has the server at least made some progress? */ 1336 /* Has the server at least made some progress? */
1304 if (resp->count != 0) { 1337 if (resp->count == 0) {
1305 /* Was this an NFSv2 write or an NFSv3 stable write? */ 1338 if (time_before(complain, jiffies)) {
1306 if (resp->verf->committed != NFS_UNSTABLE) { 1339 printk(KERN_WARNING
1307 /* Resend from where the server left off */ 1340 "NFS: Server wrote zero bytes, expected %u.\n",
1308 data->mds_offset += resp->count; 1341 argp->count);
1309 argp->offset += resp->count; 1342 complain = jiffies + 300 * HZ;
1310 argp->pgbase += resp->count;
1311 argp->count -= resp->count;
1312 } else {
1313 /* Resend as a stable write in order to avoid
1314 * headaches in the case of a server crash.
1315 */
1316 argp->stable = NFS_FILE_SYNC;
1317 } 1343 }
1318 rpc_restart_call_prepare(task); 1344 nfs_set_pgio_error(data->header, -EIO, argp->offset);
1345 task->tk_status = -EIO;
1319 return; 1346 return;
1320 } 1347 }
1321 if (time_before(complain, jiffies)) { 1348 /* Was this an NFSv2 write or an NFSv3 stable write? */
1322 printk(KERN_WARNING 1349 if (resp->verf->committed != NFS_UNSTABLE) {
1323 "NFS: Server wrote zero bytes, expected %u.\n", 1350 /* Resend from where the server left off */
1324 argp->count); 1351 data->mds_offset += resp->count;
1325 complain = jiffies + 300 * HZ; 1352 argp->offset += resp->count;
1353 argp->pgbase += resp->count;
1354 argp->count -= resp->count;
1355 } else {
1356 /* Resend as a stable write in order to avoid
1357 * headaches in the case of a server crash.
1358 */
1359 argp->stable = NFS_FILE_SYNC;
1326 } 1360 }
1327 /* Can't do anything about it except throw an error. */ 1361 rpc_restart_call_prepare(task);
1328 task->tk_status = -EIO;
1329 } 1362 }
1330 return;
1331} 1363}
1332 1364
1333 1365
@@ -1347,26 +1379,23 @@ static int nfs_commit_set_lock(struct nfs_inode *nfsi, int may_wait)
1347 return (ret < 0) ? ret : 1; 1379 return (ret < 0) ? ret : 1;
1348} 1380}
1349 1381
1350void nfs_commit_clear_lock(struct nfs_inode *nfsi) 1382static void nfs_commit_clear_lock(struct nfs_inode *nfsi)
1351{ 1383{
1352 clear_bit(NFS_INO_COMMIT, &nfsi->flags); 1384 clear_bit(NFS_INO_COMMIT, &nfsi->flags);
1353 smp_mb__after_clear_bit(); 1385 smp_mb__after_clear_bit();
1354 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT); 1386 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT);
1355} 1387}
1356EXPORT_SYMBOL_GPL(nfs_commit_clear_lock);
1357 1388
1358void nfs_commitdata_release(void *data) 1389void nfs_commitdata_release(struct nfs_commit_data *data)
1359{ 1390{
1360 struct nfs_write_data *wdata = data; 1391 put_nfs_open_context(data->context);
1361 1392 nfs_commit_free(data);
1362 put_nfs_open_context(wdata->args.context);
1363 nfs_commit_free(wdata);
1364} 1393}
1365EXPORT_SYMBOL_GPL(nfs_commitdata_release); 1394EXPORT_SYMBOL_GPL(nfs_commitdata_release);
1366 1395
1367int nfs_initiate_commit(struct nfs_write_data *data, struct rpc_clnt *clnt, 1396int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
1368 const struct rpc_call_ops *call_ops, 1397 const struct rpc_call_ops *call_ops,
1369 int how) 1398 int how, int flags)
1370{ 1399{
1371 struct rpc_task *task; 1400 struct rpc_task *task;
1372 int priority = flush_task_priority(how); 1401 int priority = flush_task_priority(how);
@@ -1382,7 +1411,7 @@ int nfs_initiate_commit(struct nfs_write_data *data, struct rpc_clnt *clnt,
1382 .callback_ops = call_ops, 1411 .callback_ops = call_ops,
1383 .callback_data = data, 1412 .callback_data = data,
1384 .workqueue = nfsiod_workqueue, 1413 .workqueue = nfsiod_workqueue,
1385 .flags = RPC_TASK_ASYNC, 1414 .flags = RPC_TASK_ASYNC | flags,
1386 .priority = priority, 1415 .priority = priority,
1387 }; 1416 };
1388 /* Set up the initial task struct. */ 1417 /* Set up the initial task struct. */
@@ -1403,9 +1432,10 @@ EXPORT_SYMBOL_GPL(nfs_initiate_commit);
1403/* 1432/*
1404 * Set up the argument/result storage required for the RPC call. 1433 * Set up the argument/result storage required for the RPC call.
1405 */ 1434 */
1406void nfs_init_commit(struct nfs_write_data *data, 1435void nfs_init_commit(struct nfs_commit_data *data,
1407 struct list_head *head, 1436 struct list_head *head,
1408 struct pnfs_layout_segment *lseg) 1437 struct pnfs_layout_segment *lseg,
1438 struct nfs_commit_info *cinfo)
1409{ 1439{
1410 struct nfs_page *first = nfs_list_entry(head->next); 1440 struct nfs_page *first = nfs_list_entry(head->next);
1411 struct inode *inode = first->wb_context->dentry->d_inode; 1441 struct inode *inode = first->wb_context->dentry->d_inode;
@@ -1419,13 +1449,14 @@ void nfs_init_commit(struct nfs_write_data *data,
1419 data->cred = first->wb_context->cred; 1449 data->cred = first->wb_context->cred;
1420 data->lseg = lseg; /* reference transferred */ 1450 data->lseg = lseg; /* reference transferred */
1421 data->mds_ops = &nfs_commit_ops; 1451 data->mds_ops = &nfs_commit_ops;
1452 data->completion_ops = cinfo->completion_ops;
1453 data->dreq = cinfo->dreq;
1422 1454
1423 data->args.fh = NFS_FH(data->inode); 1455 data->args.fh = NFS_FH(data->inode);
1424 /* Note: we always request a commit of the entire inode */ 1456 /* Note: we always request a commit of the entire inode */
1425 data->args.offset = 0; 1457 data->args.offset = 0;
1426 data->args.count = 0; 1458 data->args.count = 0;
1427 data->args.context = get_nfs_open_context(first->wb_context); 1459 data->context = get_nfs_open_context(first->wb_context);
1428 data->res.count = 0;
1429 data->res.fattr = &data->fattr; 1460 data->res.fattr = &data->fattr;
1430 data->res.verf = &data->verf; 1461 data->res.verf = &data->verf;
1431 nfs_fattr_init(&data->fattr); 1462 nfs_fattr_init(&data->fattr);
@@ -1433,18 +1464,21 @@ void nfs_init_commit(struct nfs_write_data *data,
1433EXPORT_SYMBOL_GPL(nfs_init_commit); 1464EXPORT_SYMBOL_GPL(nfs_init_commit);
1434 1465
1435void nfs_retry_commit(struct list_head *page_list, 1466void nfs_retry_commit(struct list_head *page_list,
1436 struct pnfs_layout_segment *lseg) 1467 struct pnfs_layout_segment *lseg,
1468 struct nfs_commit_info *cinfo)
1437{ 1469{
1438 struct nfs_page *req; 1470 struct nfs_page *req;
1439 1471
1440 while (!list_empty(page_list)) { 1472 while (!list_empty(page_list)) {
1441 req = nfs_list_entry(page_list->next); 1473 req = nfs_list_entry(page_list->next);
1442 nfs_list_remove_request(req); 1474 nfs_list_remove_request(req);
1443 nfs_mark_request_commit(req, lseg); 1475 nfs_mark_request_commit(req, lseg, cinfo);
1444 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 1476 if (!cinfo->dreq) {
1445 dec_bdi_stat(req->wb_page->mapping->backing_dev_info, 1477 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
1446 BDI_RECLAIMABLE); 1478 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1447 nfs_unlock_request(req); 1479 BDI_RECLAIMABLE);
1480 }
1481 nfs_unlock_and_release_request(req);
1448 } 1482 }
1449} 1483}
1450EXPORT_SYMBOL_GPL(nfs_retry_commit); 1484EXPORT_SYMBOL_GPL(nfs_retry_commit);
@@ -1453,9 +1487,10 @@ EXPORT_SYMBOL_GPL(nfs_retry_commit);
1453 * Commit dirty pages 1487 * Commit dirty pages
1454 */ 1488 */
1455static int 1489static int
1456nfs_commit_list(struct inode *inode, struct list_head *head, int how) 1490nfs_commit_list(struct inode *inode, struct list_head *head, int how,
1491 struct nfs_commit_info *cinfo)
1457{ 1492{
1458 struct nfs_write_data *data; 1493 struct nfs_commit_data *data;
1459 1494
1460 data = nfs_commitdata_alloc(); 1495 data = nfs_commitdata_alloc();
1461 1496
@@ -1463,11 +1498,13 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1463 goto out_bad; 1498 goto out_bad;
1464 1499
1465 /* Set up the argument struct */ 1500 /* Set up the argument struct */
1466 nfs_init_commit(data, head, NULL); 1501 nfs_init_commit(data, head, NULL, cinfo);
1467 return nfs_initiate_commit(data, NFS_CLIENT(inode), data->mds_ops, how); 1502 atomic_inc(&cinfo->mds->rpcs_out);
1503 return nfs_initiate_commit(NFS_CLIENT(inode), data, data->mds_ops,
1504 how, 0);
1468 out_bad: 1505 out_bad:
1469 nfs_retry_commit(head, NULL); 1506 nfs_retry_commit(head, NULL, cinfo);
1470 nfs_commit_clear_lock(NFS_I(inode)); 1507 cinfo->completion_ops->error_cleanup(NFS_I(inode));
1471 return -ENOMEM; 1508 return -ENOMEM;
1472} 1509}
1473 1510
@@ -1476,7 +1513,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1476 */ 1513 */
1477static void nfs_commit_done(struct rpc_task *task, void *calldata) 1514static void nfs_commit_done(struct rpc_task *task, void *calldata)
1478{ 1515{
1479 struct nfs_write_data *data = calldata; 1516 struct nfs_commit_data *data = calldata;
1480 1517
1481 dprintk("NFS: %5u nfs_commit_done (status %d)\n", 1518 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
1482 task->tk_pid, task->tk_status); 1519 task->tk_pid, task->tk_status);
@@ -1485,10 +1522,11 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
1485 NFS_PROTO(data->inode)->commit_done(task, data); 1522 NFS_PROTO(data->inode)->commit_done(task, data);
1486} 1523}
1487 1524
1488void nfs_commit_release_pages(struct nfs_write_data *data) 1525static void nfs_commit_release_pages(struct nfs_commit_data *data)
1489{ 1526{
1490 struct nfs_page *req; 1527 struct nfs_page *req;
1491 int status = data->task.tk_status; 1528 int status = data->task.tk_status;
1529 struct nfs_commit_info cinfo;
1492 1530
1493 while (!list_empty(&data->pages)) { 1531 while (!list_empty(&data->pages)) {
1494 req = nfs_list_entry(data->pages.next); 1532 req = nfs_list_entry(data->pages.next);
@@ -1519,42 +1557,59 @@ void nfs_commit_release_pages(struct nfs_write_data *data)
1519 dprintk(" mismatch\n"); 1557 dprintk(" mismatch\n");
1520 nfs_mark_request_dirty(req); 1558 nfs_mark_request_dirty(req);
1521 next: 1559 next:
1522 nfs_unlock_request(req); 1560 nfs_unlock_and_release_request(req);
1523 } 1561 }
1562 nfs_init_cinfo(&cinfo, data->inode, data->dreq);
1563 if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
1564 nfs_commit_clear_lock(NFS_I(data->inode));
1524} 1565}
1525EXPORT_SYMBOL_GPL(nfs_commit_release_pages);
1526 1566
1527static void nfs_commit_release(void *calldata) 1567static void nfs_commit_release(void *calldata)
1528{ 1568{
1529 struct nfs_write_data *data = calldata; 1569 struct nfs_commit_data *data = calldata;
1530 1570
1531 nfs_commit_release_pages(data); 1571 data->completion_ops->completion(data);
1532 nfs_commit_clear_lock(NFS_I(data->inode));
1533 nfs_commitdata_release(calldata); 1572 nfs_commitdata_release(calldata);
1534} 1573}
1535 1574
1536static const struct rpc_call_ops nfs_commit_ops = { 1575static const struct rpc_call_ops nfs_commit_ops = {
1537 .rpc_call_prepare = nfs_write_prepare, 1576 .rpc_call_prepare = nfs_commit_prepare,
1538 .rpc_call_done = nfs_commit_done, 1577 .rpc_call_done = nfs_commit_done,
1539 .rpc_release = nfs_commit_release, 1578 .rpc_release = nfs_commit_release,
1540}; 1579};
1541 1580
1581static const struct nfs_commit_completion_ops nfs_commit_completion_ops = {
1582 .completion = nfs_commit_release_pages,
1583 .error_cleanup = nfs_commit_clear_lock,
1584};
1585
1586int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
1587 int how, struct nfs_commit_info *cinfo)
1588{
1589 int status;
1590
1591 status = pnfs_commit_list(inode, head, how, cinfo);
1592 if (status == PNFS_NOT_ATTEMPTED)
1593 status = nfs_commit_list(inode, head, how, cinfo);
1594 return status;
1595}
1596
1542int nfs_commit_inode(struct inode *inode, int how) 1597int nfs_commit_inode(struct inode *inode, int how)
1543{ 1598{
1544 LIST_HEAD(head); 1599 LIST_HEAD(head);
1600 struct nfs_commit_info cinfo;
1545 int may_wait = how & FLUSH_SYNC; 1601 int may_wait = how & FLUSH_SYNC;
1546 int res; 1602 int res;
1547 1603
1548 res = nfs_commit_set_lock(NFS_I(inode), may_wait); 1604 res = nfs_commit_set_lock(NFS_I(inode), may_wait);
1549 if (res <= 0) 1605 if (res <= 0)
1550 goto out_mark_dirty; 1606 goto out_mark_dirty;
1551 res = nfs_scan_commit(inode, &head); 1607 nfs_init_cinfo_from_inode(&cinfo, inode);
1608 res = nfs_scan_commit(inode, &head, &cinfo);
1552 if (res) { 1609 if (res) {
1553 int error; 1610 int error;
1554 1611
1555 error = pnfs_commit_list(inode, &head, how); 1612 error = nfs_generic_commit_list(inode, &head, how, &cinfo);
1556 if (error == PNFS_NOT_ATTEMPTED)
1557 error = nfs_commit_list(inode, &head, how);
1558 if (error < 0) 1613 if (error < 0)
1559 return error; 1614 return error;
1560 if (!may_wait) 1615 if (!may_wait)
@@ -1585,14 +1640,14 @@ static int nfs_commit_unstable_pages(struct inode *inode, struct writeback_contr
1585 int ret = 0; 1640 int ret = 0;
1586 1641
1587 /* no commits means nothing needs to be done */ 1642 /* no commits means nothing needs to be done */
1588 if (!nfsi->ncommit) 1643 if (!nfsi->commit_info.ncommit)
1589 return ret; 1644 return ret;
1590 1645
1591 if (wbc->sync_mode == WB_SYNC_NONE) { 1646 if (wbc->sync_mode == WB_SYNC_NONE) {
1592 /* Don't commit yet if this is a non-blocking flush and there 1647 /* Don't commit yet if this is a non-blocking flush and there
1593 * are a lot of outstanding writes for this mapping. 1648 * are a lot of outstanding writes for this mapping.
1594 */ 1649 */
1595 if (nfsi->ncommit <= (nfsi->npages >> 1)) 1650 if (nfsi->commit_info.ncommit <= (nfsi->npages >> 1))
1596 goto out_mark_dirty; 1651 goto out_mark_dirty;
1597 1652
1598 /* don't wait for the COMMIT response */ 1653 /* don't wait for the COMMIT response */
@@ -1665,7 +1720,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1665 req = nfs_page_find_request(page); 1720 req = nfs_page_find_request(page);
1666 if (req == NULL) 1721 if (req == NULL)
1667 break; 1722 break;
1668 if (nfs_lock_request_dontget(req)) { 1723 if (nfs_lock_request(req)) {
1669 nfs_clear_request_commit(req); 1724 nfs_clear_request_commit(req);
1670 nfs_inode_remove_request(req); 1725 nfs_inode_remove_request(req);
1671 /* 1726 /*
@@ -1673,7 +1728,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1673 * page as being dirty 1728 * page as being dirty
1674 */ 1729 */
1675 cancel_dirty_page(page, PAGE_CACHE_SIZE); 1730 cancel_dirty_page(page, PAGE_CACHE_SIZE);
1676 nfs_unlock_request(req); 1731 nfs_unlock_and_release_request(req);
1677 break; 1732 break;
1678 } 1733 }
1679 ret = nfs_wait_on_request(req); 1734 ret = nfs_wait_on_request(req);
@@ -1742,7 +1797,7 @@ int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
1742int __init nfs_init_writepagecache(void) 1797int __init nfs_init_writepagecache(void)
1743{ 1798{
1744 nfs_wdata_cachep = kmem_cache_create("nfs_write_data", 1799 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1745 sizeof(struct nfs_write_data), 1800 sizeof(struct nfs_write_header),
1746 0, SLAB_HWCACHE_ALIGN, 1801 0, SLAB_HWCACHE_ALIGN,
1747 NULL); 1802 NULL);
1748 if (nfs_wdata_cachep == NULL) 1803 if (nfs_wdata_cachep == NULL)
@@ -1753,6 +1808,13 @@ int __init nfs_init_writepagecache(void)
1753 if (nfs_wdata_mempool == NULL) 1808 if (nfs_wdata_mempool == NULL)
1754 return -ENOMEM; 1809 return -ENOMEM;
1755 1810
1811 nfs_cdata_cachep = kmem_cache_create("nfs_commit_data",
1812 sizeof(struct nfs_commit_data),
1813 0, SLAB_HWCACHE_ALIGN,
1814 NULL);
1815 if (nfs_cdata_cachep == NULL)
1816 return -ENOMEM;
1817
1756 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, 1818 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
1757 nfs_wdata_cachep); 1819 nfs_wdata_cachep);
1758 if (nfs_commit_mempool == NULL) 1820 if (nfs_commit_mempool == NULL)