4 * Writing file data over NFS.
6 * We do it like this: When a (user) process wishes to write data to an
7 * NFS file, a write request is allocated that contains the RPC task data
8 * plus some info on the page to be written, and added to the inode's
9 * write chain. If the process writes past the end of the page, an async
10 * RPC call to write the page is scheduled immediately; otherwise, the call
11 * is delayed for a few seconds.
13 * Just like readahead, no async I/O is performed if wsize < PAGE_SIZE.
15 * Write requests are kept on the inode's writeback list. Each entry in
16 * that list references the page (portion) to be written. When the
17 * cache timeout has expired, the RPC task is woken up, and tries to
18 * lock the page. As soon as it manages to do so, the request is moved
19 * from the writeback list to the writelock list.
21 * Note: we must make sure never to confuse the inode passed in the
22 * write_page request with the one in page->inode. As far as I understand
23 * it, these are different when doing a swap-out.
25 * To understand everything that goes on here and in the NFS read code,
26 * one should be aware that a page is locked in exactly one of the following
29 * - A write request is in progress.
30 * - A user process is in generic_file_write/nfs_update_page
31 * - A user process is in generic_file_read
33 * Also note that because of the way pages are invalidated in
34 * nfs_revalidate_inode, the following assertions hold:
36 * - If a page is dirty, there will be no read requests (a page will
37 * not be re-read unless invalidated by nfs_revalidate_inode).
38 * - If the page is not uptodate, there will be no pending write
39 * requests, and no process will be in nfs_update_page.
41 * FIXME: Interaction with the vmscan routines is not optimal yet.
42 * Either vmscan must be made nfs-savvy, or we need a different page
43 * reclaim concept that supports something like FS-independent
44 * buffer_heads with a b_ops-> field.
46 * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de>
49 #include <linux/types.h>
50 #include <linux/slab.h>
52 #include <linux/pagemap.h>
53 #include <linux/file.h>
54 #include <linux/writeback.h>
56 #include <linux/sunrpc/clnt.h>
57 #include <linux/nfs_fs.h>
58 #include <linux/nfs_mount.h>
59 #include <linux/nfs_page.h>
60 #include <linux/backing-dev.h>
62 #include <asm/uaccess.h>
63 #include <linux/smp_lock.h>
65 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_PAGECACHE
70 #define MIN_POOL_WRITE (32)
71 #define MIN_POOL_COMMIT (4)
74 * Local function declarations
76 static struct nfs_page
* nfs_update_request(struct nfs_open_context
*,
79 unsigned int, unsigned int);
80 static int nfs_wait_on_write_congestion(struct address_space
*, int);
81 static int nfs_wait_on_requests(struct inode
*, unsigned long, unsigned int);
82 static long nfs_flush_mapping(struct address_space
*mapping
, struct writeback_control
*wbc
, int how
);
83 static int nfs_wb_page_priority(struct inode
*inode
, struct page
*page
, int how
);
84 static const struct rpc_call_ops nfs_write_partial_ops
;
85 static const struct rpc_call_ops nfs_write_full_ops
;
86 static const struct rpc_call_ops nfs_commit_ops
;
88 static kmem_cache_t
*nfs_wdata_cachep
;
89 static mempool_t
*nfs_wdata_mempool
;
90 static mempool_t
*nfs_commit_mempool
;
92 static DECLARE_WAIT_QUEUE_HEAD(nfs_write_congestion
);
94 struct nfs_write_data
*nfs_commit_alloc(void)
96 struct nfs_write_data
*p
= mempool_alloc(nfs_commit_mempool
, SLAB_NOFS
);
99 memset(p
, 0, sizeof(*p
));
100 INIT_LIST_HEAD(&p
->pages
);
105 void nfs_commit_rcu_free(struct rcu_head
*head
)
107 struct nfs_write_data
*p
= container_of(head
, struct nfs_write_data
, task
.u
.tk_rcu
);
108 if (p
&& (p
->pagevec
!= &p
->page_array
[0]))
110 mempool_free(p
, nfs_commit_mempool
);
113 void nfs_commit_free(struct nfs_write_data
*wdata
)
115 call_rcu_bh(&wdata
->task
.u
.tk_rcu
, nfs_commit_rcu_free
);
118 struct nfs_write_data
*nfs_writedata_alloc(size_t len
)
120 unsigned int pagecount
= (len
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
121 struct nfs_write_data
*p
= mempool_alloc(nfs_wdata_mempool
, SLAB_NOFS
);
124 memset(p
, 0, sizeof(*p
));
125 INIT_LIST_HEAD(&p
->pages
);
126 p
->npages
= pagecount
;
127 if (pagecount
<= ARRAY_SIZE(p
->page_array
))
128 p
->pagevec
= p
->page_array
;
130 p
->pagevec
= kcalloc(pagecount
, sizeof(struct page
*), GFP_NOFS
);
132 mempool_free(p
, nfs_wdata_mempool
);
140 static void nfs_writedata_rcu_free(struct rcu_head
*head
)
142 struct nfs_write_data
*p
= container_of(head
, struct nfs_write_data
, task
.u
.tk_rcu
);
143 if (p
&& (p
->pagevec
!= &p
->page_array
[0]))
145 mempool_free(p
, nfs_wdata_mempool
);
148 static void nfs_writedata_free(struct nfs_write_data
*wdata
)
150 call_rcu_bh(&wdata
->task
.u
.tk_rcu
, nfs_writedata_rcu_free
);
153 void nfs_writedata_release(void *wdata
)
155 nfs_writedata_free(wdata
);
158 static struct nfs_page
*nfs_page_find_request_locked(struct page
*page
)
160 struct nfs_page
*req
= NULL
;
162 if (PagePrivate(page
)) {
163 req
= (struct nfs_page
*)page_private(page
);
165 atomic_inc(&req
->wb_count
);
170 static struct nfs_page
*nfs_page_find_request(struct page
*page
)
172 struct nfs_page
*req
= NULL
;
173 spinlock_t
*req_lock
= &NFS_I(page
->mapping
->host
)->req_lock
;
176 req
= nfs_page_find_request_locked(page
);
177 spin_unlock(req_lock
);
181 /* Adjust the file length if we're writing beyond the end */
182 static void nfs_grow_file(struct page
*page
, unsigned int offset
, unsigned int count
)
184 struct inode
*inode
= page
->mapping
->host
;
185 loff_t end
, i_size
= i_size_read(inode
);
186 unsigned long end_index
= (i_size
- 1) >> PAGE_CACHE_SHIFT
;
188 if (i_size
> 0 && page
->index
< end_index
)
190 end
= ((loff_t
)page
->index
<< PAGE_CACHE_SHIFT
) + ((loff_t
)offset
+count
);
193 nfs_inc_stats(inode
, NFSIOS_EXTENDWRITE
);
194 i_size_write(inode
, end
);
197 /* We can set the PG_uptodate flag if we see that a write request
198 * covers the full page.
200 static void nfs_mark_uptodate(struct page
*page
, unsigned int base
, unsigned int count
)
204 if (PageUptodate(page
))
208 if (count
== PAGE_CACHE_SIZE
) {
209 SetPageUptodate(page
);
213 end_offs
= i_size_read(page
->mapping
->host
) - 1;
216 /* Is this the last page? */
217 if (page
->index
!= (unsigned long)(end_offs
>> PAGE_CACHE_SHIFT
))
219 /* This is the last page: set PG_uptodate if we cover the entire
220 * extent of the data, then zero the rest of the page.
222 if (count
== (unsigned int)(end_offs
& (PAGE_CACHE_SIZE
- 1)) + 1) {
223 memclear_highpage_flush(page
, count
, PAGE_CACHE_SIZE
- count
);
224 SetPageUptodate(page
);
229 * Write a page synchronously.
230 * Offset is the data offset within the page.
232 static int nfs_writepage_sync(struct nfs_open_context
*ctx
, struct inode
*inode
,
233 struct page
*page
, unsigned int offset
, unsigned int count
,
236 unsigned int wsize
= NFS_SERVER(inode
)->wsize
;
237 int result
, written
= 0;
238 struct nfs_write_data
*wdata
;
240 wdata
= nfs_writedata_alloc(wsize
);
245 wdata
->cred
= ctx
->cred
;
246 wdata
->inode
= inode
;
247 wdata
->args
.fh
= NFS_FH(inode
);
248 wdata
->args
.context
= ctx
;
249 wdata
->args
.pages
= &page
;
250 wdata
->args
.stable
= NFS_FILE_SYNC
;
251 wdata
->args
.pgbase
= offset
;
252 wdata
->args
.count
= wsize
;
253 wdata
->res
.fattr
= &wdata
->fattr
;
254 wdata
->res
.verf
= &wdata
->verf
;
256 dprintk("NFS: nfs_writepage_sync(%s/%Ld %d@%Ld)\n",
258 (long long)NFS_FILEID(inode
),
259 count
, (long long)(page_offset(page
) + offset
));
261 set_page_writeback(page
);
262 nfs_begin_data_update(inode
);
265 wdata
->args
.count
= count
;
266 wdata
->args
.offset
= page_offset(page
) + wdata
->args
.pgbase
;
268 result
= NFS_PROTO(inode
)->write(wdata
);
271 /* Must mark the page invalid after I/O error */
272 ClearPageUptodate(page
);
275 if (result
< wdata
->args
.count
)
276 printk(KERN_WARNING
"NFS: short write, count=%u, result=%d\n",
277 wdata
->args
.count
, result
);
279 wdata
->args
.offset
+= result
;
280 wdata
->args
.pgbase
+= result
;
283 nfs_add_stats(inode
, NFSIOS_SERVERWRITTENBYTES
, result
);
285 /* Update file length */
286 nfs_grow_file(page
, offset
, written
);
287 /* Set the PG_uptodate flag? */
288 nfs_mark_uptodate(page
, offset
, written
);
291 ClearPageError(page
);
294 nfs_end_data_update(inode
);
295 end_page_writeback(page
);
296 nfs_writedata_release(wdata
);
297 return written
? written
: result
;
300 static int nfs_writepage_async(struct nfs_open_context
*ctx
,
301 struct inode
*inode
, struct page
*page
,
302 unsigned int offset
, unsigned int count
)
304 struct nfs_page
*req
;
306 req
= nfs_update_request(ctx
, inode
, page
, offset
, count
);
309 /* Update file length */
310 nfs_grow_file(page
, offset
, count
);
311 /* Set the PG_uptodate flag? */
312 nfs_mark_uptodate(page
, offset
, count
);
313 nfs_unlock_request(req
);
317 static int wb_priority(struct writeback_control
*wbc
)
319 if (wbc
->for_reclaim
)
320 return FLUSH_HIGHPRI
;
321 if (wbc
->for_kupdate
)
327 * Write an mmapped page to the server.
329 int nfs_writepage(struct page
*page
, struct writeback_control
*wbc
)
331 struct nfs_open_context
*ctx
;
332 struct inode
*inode
= page
->mapping
->host
;
333 unsigned long end_index
;
334 unsigned offset
= PAGE_CACHE_SIZE
;
335 loff_t i_size
= i_size_read(inode
);
336 int inode_referenced
= 0;
337 int priority
= wb_priority(wbc
);
340 nfs_inc_stats(inode
, NFSIOS_VFSWRITEPAGE
);
341 nfs_add_stats(inode
, NFSIOS_WRITEPAGES
, 1);
344 * Note: We need to ensure that we have a reference to the inode
345 * if we are to do asynchronous writes. If not, waiting
346 * in nfs_wait_on_request() may deadlock with clear_inode().
348 * If igrab() fails here, then it is in any case safe to
349 * call nfs_wb_page(), since there will be no pending writes.
351 if (igrab(inode
) != 0)
352 inode_referenced
= 1;
353 end_index
= i_size
>> PAGE_CACHE_SHIFT
;
355 /* Ensure we've flushed out any previous writes */
356 nfs_wb_page_priority(inode
, page
, priority
);
359 if (page
->index
< end_index
)
361 /* things got complicated... */
362 offset
= i_size
& (PAGE_CACHE_SIZE
-1);
364 /* OK, are we completely out? */
365 err
= 0; /* potential race with truncate - ignore */
366 if (page
->index
>= end_index
+1 || !offset
)
369 ctx
= nfs_find_open_context(inode
, NULL
, FMODE_WRITE
);
375 if (!IS_SYNC(inode
) && inode_referenced
) {
376 err
= nfs_writepage_async(ctx
, inode
, page
, 0, offset
);
377 if (!wbc
->for_writepages
)
378 nfs_flush_mapping(page
->mapping
, wbc
, wb_priority(wbc
));
380 err
= nfs_writepage_sync(ctx
, inode
, page
, 0,
384 redirty_page_for_writepage(wbc
, page
);
389 put_nfs_open_context(ctx
);
392 if (inode_referenced
)
398 * Note: causes nfs_update_request() to block on the assumption
399 * that the writeback is generated due to memory pressure.
401 int nfs_writepages(struct address_space
*mapping
, struct writeback_control
*wbc
)
403 struct backing_dev_info
*bdi
= mapping
->backing_dev_info
;
404 struct inode
*inode
= mapping
->host
;
407 nfs_inc_stats(inode
, NFSIOS_VFSWRITEPAGES
);
409 err
= generic_writepages(mapping
, wbc
);
412 while (test_and_set_bit(BDI_write_congested
, &bdi
->state
) != 0) {
413 if (wbc
->nonblocking
)
415 nfs_wait_on_write_congestion(mapping
, 0);
417 err
= nfs_flush_mapping(mapping
, wbc
, wb_priority(wbc
));
420 nfs_add_stats(inode
, NFSIOS_WRITEPAGES
, err
);
421 if (!wbc
->nonblocking
&& wbc
->sync_mode
== WB_SYNC_ALL
) {
422 err
= nfs_wait_on_requests(inode
, 0, 0);
426 err
= nfs_commit_inode(inode
, wb_priority(wbc
));
430 clear_bit(BDI_write_congested
, &bdi
->state
);
431 wake_up_all(&nfs_write_congestion
);
432 congestion_end(WRITE
);
437 * Insert a write request into an inode
439 static int nfs_inode_add_request(struct inode
*inode
, struct nfs_page
*req
)
441 struct nfs_inode
*nfsi
= NFS_I(inode
);
444 error
= radix_tree_insert(&nfsi
->nfs_page_tree
, req
->wb_index
, req
);
445 BUG_ON(error
== -EEXIST
);
450 nfs_begin_data_update(inode
);
451 if (nfs_have_delegation(inode
, FMODE_WRITE
))
454 SetPagePrivate(req
->wb_page
);
455 set_page_private(req
->wb_page
, (unsigned long)req
);
457 atomic_inc(&req
->wb_count
);
462 * Insert a write request into an inode
464 static void nfs_inode_remove_request(struct nfs_page
*req
)
466 struct inode
*inode
= req
->wb_context
->dentry
->d_inode
;
467 struct nfs_inode
*nfsi
= NFS_I(inode
);
469 BUG_ON (!NFS_WBACK_BUSY(req
));
471 spin_lock(&nfsi
->req_lock
);
472 set_page_private(req
->wb_page
, 0);
473 ClearPagePrivate(req
->wb_page
);
474 radix_tree_delete(&nfsi
->nfs_page_tree
, req
->wb_index
);
477 spin_unlock(&nfsi
->req_lock
);
478 nfs_end_data_update(inode
);
481 spin_unlock(&nfsi
->req_lock
);
482 nfs_clear_request(req
);
483 nfs_release_request(req
);
487 * Add a request to the inode's dirty list.
490 nfs_mark_request_dirty(struct nfs_page
*req
)
492 struct inode
*inode
= req
->wb_context
->dentry
->d_inode
;
493 struct nfs_inode
*nfsi
= NFS_I(inode
);
495 spin_lock(&nfsi
->req_lock
);
496 radix_tree_tag_set(&nfsi
->nfs_page_tree
,
497 req
->wb_index
, NFS_PAGE_TAG_DIRTY
);
498 nfs_list_add_request(req
, &nfsi
->dirty
);
500 spin_unlock(&nfsi
->req_lock
);
501 inc_zone_page_state(req
->wb_page
, NR_FILE_DIRTY
);
502 mark_inode_dirty(inode
);
506 * Check if a request is dirty
509 nfs_dirty_request(struct nfs_page
*req
)
511 struct nfs_inode
*nfsi
= NFS_I(req
->wb_context
->dentry
->d_inode
);
512 return !list_empty(&req
->wb_list
) && req
->wb_list_head
== &nfsi
->dirty
;
515 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
517 * Add a request to the inode's commit list.
520 nfs_mark_request_commit(struct nfs_page
*req
)
522 struct inode
*inode
= req
->wb_context
->dentry
->d_inode
;
523 struct nfs_inode
*nfsi
= NFS_I(inode
);
525 spin_lock(&nfsi
->req_lock
);
526 nfs_list_add_request(req
, &nfsi
->commit
);
528 spin_unlock(&nfsi
->req_lock
);
529 inc_zone_page_state(req
->wb_page
, NR_UNSTABLE_NFS
);
530 mark_inode_dirty(inode
);
535 * Wait for a request to complete.
537 * Interruptible by signals only if mounted with intr flag.
539 static int nfs_wait_on_requests_locked(struct inode
*inode
, unsigned long idx_start
, unsigned int npages
)
541 struct nfs_inode
*nfsi
= NFS_I(inode
);
542 struct nfs_page
*req
;
543 unsigned long idx_end
, next
;
544 unsigned int res
= 0;
550 idx_end
= idx_start
+ npages
- 1;
553 while (radix_tree_gang_lookup_tag(&nfsi
->nfs_page_tree
, (void **)&req
, next
, 1, NFS_PAGE_TAG_WRITEBACK
)) {
554 if (req
->wb_index
> idx_end
)
557 next
= req
->wb_index
+ 1;
558 BUG_ON(!NFS_WBACK_BUSY(req
));
560 atomic_inc(&req
->wb_count
);
561 spin_unlock(&nfsi
->req_lock
);
562 error
= nfs_wait_on_request(req
);
563 nfs_release_request(req
);
564 spin_lock(&nfsi
->req_lock
);
572 static int nfs_wait_on_requests(struct inode
*inode
, unsigned long idx_start
, unsigned int npages
)
574 struct nfs_inode
*nfsi
= NFS_I(inode
);
577 spin_lock(&nfsi
->req_lock
);
578 ret
= nfs_wait_on_requests_locked(inode
, idx_start
, npages
);
579 spin_unlock(&nfsi
->req_lock
);
583 static void nfs_cancel_dirty_list(struct list_head
*head
)
585 struct nfs_page
*req
;
586 while(!list_empty(head
)) {
587 req
= nfs_list_entry(head
->next
);
588 nfs_list_remove_request(req
);
589 nfs_inode_remove_request(req
);
590 nfs_clear_page_writeback(req
);
594 static void nfs_cancel_commit_list(struct list_head
*head
)
596 struct nfs_page
*req
;
598 while(!list_empty(head
)) {
599 req
= nfs_list_entry(head
->next
);
600 dec_zone_page_state(req
->wb_page
, NR_UNSTABLE_NFS
);
601 nfs_list_remove_request(req
);
602 nfs_inode_remove_request(req
);
603 nfs_unlock_request(req
);
607 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
609 * nfs_scan_commit - Scan an inode for commit requests
610 * @inode: NFS inode to scan
611 * @dst: destination list
612 * @idx_start: lower bound of page->index to scan.
613 * @npages: idx_start + npages sets the upper bound to scan.
615 * Moves requests from the inode's 'commit' request list.
616 * The requests are *not* checked to ensure that they form a contiguous set.
619 nfs_scan_commit(struct inode
*inode
, struct list_head
*dst
, unsigned long idx_start
, unsigned int npages
)
621 struct nfs_inode
*nfsi
= NFS_I(inode
);
624 if (nfsi
->ncommit
!= 0) {
625 res
= nfs_scan_list(nfsi
, &nfsi
->commit
, dst
, idx_start
, npages
);
626 nfsi
->ncommit
-= res
;
627 if ((nfsi
->ncommit
== 0) != list_empty(&nfsi
->commit
))
628 printk(KERN_ERR
"NFS: desynchronized value of nfs_i.ncommit.\n");
633 static inline int nfs_scan_commit(struct inode
*inode
, struct list_head
*dst
, unsigned long idx_start
, unsigned int npages
)
639 static int nfs_wait_on_write_congestion(struct address_space
*mapping
, int intr
)
641 struct backing_dev_info
*bdi
= mapping
->backing_dev_info
;
647 if (!bdi_write_congested(bdi
))
650 nfs_inc_stats(mapping
->host
, NFSIOS_CONGESTIONWAIT
);
653 struct rpc_clnt
*clnt
= NFS_CLIENT(mapping
->host
);
656 rpc_clnt_sigmask(clnt
, &oldset
);
657 prepare_to_wait(&nfs_write_congestion
, &wait
, TASK_INTERRUPTIBLE
);
658 if (bdi_write_congested(bdi
)) {
664 rpc_clnt_sigunmask(clnt
, &oldset
);
666 prepare_to_wait(&nfs_write_congestion
, &wait
, TASK_UNINTERRUPTIBLE
);
667 if (bdi_write_congested(bdi
))
670 finish_wait(&nfs_write_congestion
, &wait
);
676 * Try to update any existing write request, or create one if there is none.
677 * In order to match, the request's credentials must match those of
678 * the calling process.
680 * Note: Should always be called with the Page Lock held!
682 static struct nfs_page
* nfs_update_request(struct nfs_open_context
* ctx
,
683 struct inode
*inode
, struct page
*page
,
684 unsigned int offset
, unsigned int bytes
)
686 struct nfs_server
*server
= NFS_SERVER(inode
);
687 struct nfs_inode
*nfsi
= NFS_I(inode
);
688 struct nfs_page
*req
, *new = NULL
;
689 unsigned long rqend
, end
;
691 end
= offset
+ bytes
;
693 if (nfs_wait_on_write_congestion(page
->mapping
, server
->flags
& NFS_MOUNT_INTR
))
694 return ERR_PTR(-ERESTARTSYS
);
696 /* Loop over all inode entries and see if we find
697 * A request for the page we wish to update
699 spin_lock(&nfsi
->req_lock
);
700 req
= nfs_page_find_request_locked(page
);
702 if (!nfs_lock_request_dontget(req
)) {
705 spin_unlock(&nfsi
->req_lock
);
706 error
= nfs_wait_on_request(req
);
707 nfs_release_request(req
);
710 nfs_release_request(new);
711 return ERR_PTR(error
);
715 spin_unlock(&nfsi
->req_lock
);
717 nfs_release_request(new);
723 nfs_lock_request_dontget(new);
724 error
= nfs_inode_add_request(inode
, new);
726 spin_unlock(&nfsi
->req_lock
);
727 nfs_unlock_request(new);
728 return ERR_PTR(error
);
730 spin_unlock(&nfsi
->req_lock
);
731 nfs_mark_request_dirty(new);
734 spin_unlock(&nfsi
->req_lock
);
736 new = nfs_create_request(ctx
, inode
, page
, offset
, bytes
);
741 /* We have a request for our page.
742 * If the creds don't match, or the
743 * page addresses don't match,
744 * tell the caller to wait on the conflicting
747 rqend
= req
->wb_offset
+ req
->wb_bytes
;
748 if (req
->wb_context
!= ctx
749 || req
->wb_page
!= page
750 || !nfs_dirty_request(req
)
751 || offset
> rqend
|| end
< req
->wb_offset
) {
752 nfs_unlock_request(req
);
753 return ERR_PTR(-EBUSY
);
756 /* Okay, the request matches. Update the region */
757 if (offset
< req
->wb_offset
) {
758 req
->wb_offset
= offset
;
759 req
->wb_pgbase
= offset
;
760 req
->wb_bytes
= rqend
- req
->wb_offset
;
764 req
->wb_bytes
= end
- req
->wb_offset
;
769 int nfs_flush_incompatible(struct file
*file
, struct page
*page
)
771 struct nfs_open_context
*ctx
= (struct nfs_open_context
*)file
->private_data
;
772 struct nfs_page
*req
;
775 * Look for a request corresponding to this page. If there
776 * is one, and it belongs to another file, we flush it out
777 * before we try to copy anything into the page. Do this
778 * due to the lack of an ACCESS-type call in NFSv2.
779 * Also do the same if we find a request from an existing
782 req
= nfs_page_find_request(page
);
784 int do_flush
= req
->wb_page
!= page
|| req
->wb_context
!= ctx
;
786 nfs_release_request(req
);
788 status
= nfs_wb_page(page
->mapping
->host
, page
);
790 return (status
< 0) ? status
: 0;
794 * Update and possibly write a cached page of an NFS file.
796 * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
797 * things with a page scheduled for an RPC call (e.g. invalidate it).
799 int nfs_updatepage(struct file
*file
, struct page
*page
,
800 unsigned int offset
, unsigned int count
)
802 struct nfs_open_context
*ctx
= (struct nfs_open_context
*)file
->private_data
;
803 struct inode
*inode
= page
->mapping
->host
;
804 struct nfs_page
*req
;
807 nfs_inc_stats(inode
, NFSIOS_VFSUPDATEPAGE
);
809 dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n",
810 file
->f_dentry
->d_parent
->d_name
.name
,
811 file
->f_dentry
->d_name
.name
, count
,
812 (long long)(page_offset(page
) +offset
));
814 if (IS_SYNC(inode
)) {
815 status
= nfs_writepage_sync(ctx
, inode
, page
, offset
, count
, 0);
817 if (offset
== 0 && status
== PAGE_CACHE_SIZE
)
818 SetPageUptodate(page
);
824 /* If we're not using byte range locks, and we know the page
825 * is entirely in cache, it may be more efficient to avoid
826 * fragmenting write requests.
828 if (PageUptodate(page
) && inode
->i_flock
== NULL
&& !(file
->f_mode
& O_SYNC
)) {
829 loff_t end_offs
= i_size_read(inode
) - 1;
830 unsigned long end_index
= end_offs
>> PAGE_CACHE_SHIFT
;
834 if (unlikely(end_offs
< 0)) {
836 } else if (page
->index
== end_index
) {
838 pglen
= (unsigned int)(end_offs
& (PAGE_CACHE_SIZE
-1)) + 1;
841 } else if (page
->index
< end_index
)
842 count
= PAGE_CACHE_SIZE
;
846 * Try to find an NFS request corresponding to this page
848 * If the existing request cannot be updated, we must flush
852 req
= nfs_update_request(ctx
, inode
, page
, offset
, count
);
853 status
= (IS_ERR(req
)) ? PTR_ERR(req
) : 0;
854 if (status
!= -EBUSY
)
856 /* Request could not be updated. Flush it out and try again */
857 status
= nfs_wb_page(inode
, page
);
858 } while (status
>= 0);
864 /* Update file length */
865 nfs_grow_file(page
, offset
, count
);
866 /* Set the PG_uptodate flag? */
867 nfs_mark_uptodate(page
, req
->wb_pgbase
, req
->wb_bytes
);
868 nfs_unlock_request(req
);
870 dprintk("NFS: nfs_updatepage returns %d (isize %Ld)\n",
871 status
, (long long)i_size_read(inode
));
873 ClearPageUptodate(page
);
877 static void nfs_writepage_release(struct nfs_page
*req
)
879 end_page_writeback(req
->wb_page
);
881 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
882 if (!PageError(req
->wb_page
)) {
883 if (NFS_NEED_RESCHED(req
)) {
884 nfs_mark_request_dirty(req
);
886 } else if (NFS_NEED_COMMIT(req
)) {
887 nfs_mark_request_commit(req
);
891 nfs_inode_remove_request(req
);
894 nfs_clear_commit(req
);
895 nfs_clear_reschedule(req
);
897 nfs_inode_remove_request(req
);
899 nfs_clear_page_writeback(req
);
902 static inline int flush_task_priority(int how
)
904 switch (how
& (FLUSH_HIGHPRI
|FLUSH_LOWPRI
)) {
906 return RPC_PRIORITY_HIGH
;
908 return RPC_PRIORITY_LOW
;
910 return RPC_PRIORITY_NORMAL
;
914 * Set up the argument/result storage required for the RPC call.
916 static void nfs_write_rpcsetup(struct nfs_page
*req
,
917 struct nfs_write_data
*data
,
918 const struct rpc_call_ops
*call_ops
,
919 unsigned int count
, unsigned int offset
,
925 /* Set up the RPC argument and reply structs
926 * NB: take care not to mess about with data->commit et al. */
929 data
->inode
= inode
= req
->wb_context
->dentry
->d_inode
;
930 data
->cred
= req
->wb_context
->cred
;
932 data
->args
.fh
= NFS_FH(inode
);
933 data
->args
.offset
= req_offset(req
) + offset
;
934 data
->args
.pgbase
= req
->wb_pgbase
+ offset
;
935 data
->args
.pages
= data
->pagevec
;
936 data
->args
.count
= count
;
937 data
->args
.context
= req
->wb_context
;
939 data
->res
.fattr
= &data
->fattr
;
940 data
->res
.count
= count
;
941 data
->res
.verf
= &data
->verf
;
942 nfs_fattr_init(&data
->fattr
);
944 /* Set up the initial task struct. */
945 flags
= (how
& FLUSH_SYNC
) ? 0 : RPC_TASK_ASYNC
;
946 rpc_init_task(&data
->task
, NFS_CLIENT(inode
), flags
, call_ops
, data
);
947 NFS_PROTO(inode
)->write_setup(data
, how
);
949 data
->task
.tk_priority
= flush_task_priority(how
);
950 data
->task
.tk_cookie
= (unsigned long)inode
;
952 dprintk("NFS: %4d initiated write call (req %s/%Ld, %u bytes @ offset %Lu)\n",
955 (long long)NFS_FILEID(inode
),
957 (unsigned long long)data
->args
.offset
);
960 static void nfs_execute_write(struct nfs_write_data
*data
)
962 struct rpc_clnt
*clnt
= NFS_CLIENT(data
->inode
);
965 rpc_clnt_sigmask(clnt
, &oldset
);
966 rpc_execute(&data
->task
);
967 rpc_clnt_sigunmask(clnt
, &oldset
);
971 * Generate multiple small requests to write out a single
972 * contiguous dirty area on one page.
974 static int nfs_flush_multi(struct inode
*inode
, struct list_head
*head
, int how
)
976 struct nfs_page
*req
= nfs_list_entry(head
->next
);
977 struct page
*page
= req
->wb_page
;
978 struct nfs_write_data
*data
;
979 size_t wsize
= NFS_SERVER(inode
)->wsize
, nbytes
;
984 nfs_list_remove_request(req
);
986 nbytes
= req
->wb_bytes
;
988 size_t len
= min(nbytes
, wsize
);
990 data
= nfs_writedata_alloc(len
);
993 list_add(&data
->pages
, &list
);
996 } while (nbytes
!= 0);
997 atomic_set(&req
->wb_complete
, requests
);
999 ClearPageError(page
);
1000 set_page_writeback(page
);
1002 nbytes
= req
->wb_bytes
;
1004 data
= list_entry(list
.next
, struct nfs_write_data
, pages
);
1005 list_del_init(&data
->pages
);
1007 data
->pagevec
[0] = page
;
1009 if (nbytes
> wsize
) {
1010 nfs_write_rpcsetup(req
, data
, &nfs_write_partial_ops
,
1011 wsize
, offset
, how
);
1015 nfs_write_rpcsetup(req
, data
, &nfs_write_partial_ops
,
1016 nbytes
, offset
, how
);
1019 nfs_execute_write(data
);
1020 } while (nbytes
!= 0);
1025 while (!list_empty(&list
)) {
1026 data
= list_entry(list
.next
, struct nfs_write_data
, pages
);
1027 list_del(&data
->pages
);
1028 nfs_writedata_release(data
);
1030 nfs_mark_request_dirty(req
);
1031 nfs_clear_page_writeback(req
);
1036 * Create an RPC task for the given write request and kick it.
1037 * The page must have been locked by the caller.
1039 * It may happen that the page we're passed is not marked dirty.
1040 * This is the case if nfs_updatepage detects a conflicting request
1041 * that has been written but not committed.
1043 static int nfs_flush_one(struct inode
*inode
, struct list_head
*head
, int how
)
1045 struct nfs_page
*req
;
1046 struct page
**pages
;
1047 struct nfs_write_data
*data
;
1050 data
= nfs_writedata_alloc(NFS_SERVER(inode
)->wsize
);
1054 pages
= data
->pagevec
;
1056 while (!list_empty(head
)) {
1057 req
= nfs_list_entry(head
->next
);
1058 nfs_list_remove_request(req
);
1059 nfs_list_add_request(req
, &data
->pages
);
1060 ClearPageError(req
->wb_page
);
1061 set_page_writeback(req
->wb_page
);
1062 *pages
++ = req
->wb_page
;
1063 count
+= req
->wb_bytes
;
1065 req
= nfs_list_entry(data
->pages
.next
);
1067 /* Set up the argument struct */
1068 nfs_write_rpcsetup(req
, data
, &nfs_write_full_ops
, count
, 0, how
);
1070 nfs_execute_write(data
);
1073 while (!list_empty(head
)) {
1074 struct nfs_page
*req
= nfs_list_entry(head
->next
);
1075 nfs_list_remove_request(req
);
1076 nfs_mark_request_dirty(req
);
1077 nfs_clear_page_writeback(req
);
1082 static int nfs_flush_list(struct inode
*inode
, struct list_head
*head
, int npages
, int how
)
1084 LIST_HEAD(one_request
);
1085 int (*flush_one
)(struct inode
*, struct list_head
*, int);
1086 struct nfs_page
*req
;
1087 int wpages
= NFS_SERVER(inode
)->wpages
;
1088 int wsize
= NFS_SERVER(inode
)->wsize
;
1091 flush_one
= nfs_flush_one
;
1092 if (wsize
< PAGE_CACHE_SIZE
)
1093 flush_one
= nfs_flush_multi
;
1094 /* For single writes, FLUSH_STABLE is more efficient */
1095 if (npages
<= wpages
&& npages
== NFS_I(inode
)->npages
1096 && nfs_list_entry(head
->next
)->wb_bytes
<= wsize
)
1097 how
|= FLUSH_STABLE
;
1100 nfs_coalesce_requests(head
, &one_request
, wpages
);
1101 req
= nfs_list_entry(one_request
.next
);
1102 error
= flush_one(inode
, &one_request
, how
);
1105 } while (!list_empty(head
));
1108 while (!list_empty(head
)) {
1109 req
= nfs_list_entry(head
->next
);
1110 nfs_list_remove_request(req
);
1111 nfs_mark_request_dirty(req
);
1112 nfs_clear_page_writeback(req
);
1118 * Handle a write reply that flushed part of a page.
1120 static void nfs_writeback_done_partial(struct rpc_task
*task
, void *calldata
)
1122 struct nfs_write_data
*data
= calldata
;
1123 struct nfs_page
*req
= data
->req
;
1124 struct page
*page
= req
->wb_page
;
1126 dprintk("NFS: write (%s/%Ld %d@%Ld)",
1127 req
->wb_context
->dentry
->d_inode
->i_sb
->s_id
,
1128 (long long)NFS_FILEID(req
->wb_context
->dentry
->d_inode
),
1130 (long long)req_offset(req
));
1132 if (nfs_writeback_done(task
, data
) != 0)
1135 if (task
->tk_status
< 0) {
1136 ClearPageUptodate(page
);
1138 req
->wb_context
->error
= task
->tk_status
;
1139 dprintk(", error = %d\n", task
->tk_status
);
1141 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1142 if (data
->verf
.committed
< NFS_FILE_SYNC
) {
1143 if (!NFS_NEED_COMMIT(req
)) {
1144 nfs_defer_commit(req
);
1145 memcpy(&req
->wb_verf
, &data
->verf
, sizeof(req
->wb_verf
));
1146 dprintk(" defer commit\n");
1147 } else if (memcmp(&req
->wb_verf
, &data
->verf
, sizeof(req
->wb_verf
))) {
1148 nfs_defer_reschedule(req
);
1149 dprintk(" server reboot detected\n");
1156 if (atomic_dec_and_test(&req
->wb_complete
))
1157 nfs_writepage_release(req
);
1160 static const struct rpc_call_ops nfs_write_partial_ops
= {
1161 .rpc_call_done
= nfs_writeback_done_partial
,
1162 .rpc_release
= nfs_writedata_release
,
1166 * Handle a write reply that flushes a whole page.
1168 * FIXME: There is an inherent race with invalidate_inode_pages and
1169 * writebacks since the page->count is kept > 1 for as long
1170 * as the page has a write request pending.
1172 static void nfs_writeback_done_full(struct rpc_task
*task
, void *calldata
)
1174 struct nfs_write_data
*data
= calldata
;
1175 struct nfs_page
*req
;
1178 if (nfs_writeback_done(task
, data
) != 0)
1181 /* Update attributes as result of writeback. */
1182 while (!list_empty(&data
->pages
)) {
1183 req
= nfs_list_entry(data
->pages
.next
);
1184 nfs_list_remove_request(req
);
1185 page
= req
->wb_page
;
1187 dprintk("NFS: write (%s/%Ld %d@%Ld)",
1188 req
->wb_context
->dentry
->d_inode
->i_sb
->s_id
,
1189 (long long)NFS_FILEID(req
->wb_context
->dentry
->d_inode
),
1191 (long long)req_offset(req
));
1193 if (task
->tk_status
< 0) {
1194 ClearPageUptodate(page
);
1196 req
->wb_context
->error
= task
->tk_status
;
1197 end_page_writeback(page
);
1198 nfs_inode_remove_request(req
);
1199 dprintk(", error = %d\n", task
->tk_status
);
1202 end_page_writeback(page
);
1204 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1205 if (data
->args
.stable
!= NFS_UNSTABLE
|| data
->verf
.committed
== NFS_FILE_SYNC
) {
1206 nfs_inode_remove_request(req
);
1210 memcpy(&req
->wb_verf
, &data
->verf
, sizeof(req
->wb_verf
));
1211 nfs_mark_request_commit(req
);
1212 dprintk(" marked for commit\n");
1214 nfs_inode_remove_request(req
);
1217 nfs_clear_page_writeback(req
);
1221 static const struct rpc_call_ops nfs_write_full_ops
= {
1222 .rpc_call_done
= nfs_writeback_done_full
,
1223 .rpc_release
= nfs_writedata_release
,
1228 * This function is called when the WRITE call is complete.
1230 int nfs_writeback_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
1232 struct nfs_writeargs
*argp
= &data
->args
;
1233 struct nfs_writeres
*resp
= &data
->res
;
1236 dprintk("NFS: %4d nfs_writeback_done (status %d)\n",
1237 task
->tk_pid
, task
->tk_status
);
1240 * ->write_done will attempt to use post-op attributes to detect
1241 * conflicting writes by other clients. A strict interpretation
1242 * of close-to-open would allow us to continue caching even if
1243 * another writer had changed the file, but some applications
1244 * depend on tighter cache coherency when writing.
1246 status
= NFS_PROTO(data
->inode
)->write_done(task
, data
);
1249 nfs_add_stats(data
->inode
, NFSIOS_SERVERWRITTENBYTES
, resp
->count
);
1251 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1252 if (resp
->verf
->committed
< argp
->stable
&& task
->tk_status
>= 0) {
1253 /* We tried a write call, but the server did not
1254 * commit data to stable storage even though we
1256 * Note: There is a known bug in Tru64 < 5.0 in which
1257 * the server reports NFS_DATA_SYNC, but performs
1258 * NFS_FILE_SYNC. We therefore implement this checking
1259 * as a dprintk() in order to avoid filling syslog.
1261 static unsigned long complain
;
1263 if (time_before(complain
, jiffies
)) {
1264 dprintk("NFS: faulty NFS server %s:"
1265 " (committed = %d) != (stable = %d)\n",
1266 NFS_SERVER(data
->inode
)->nfs_client
->cl_hostname
,
1267 resp
->verf
->committed
, argp
->stable
);
1268 complain
= jiffies
+ 300 * HZ
;
1272 /* Is this a short write? */
1273 if (task
->tk_status
>= 0 && resp
->count
< argp
->count
) {
1274 static unsigned long complain
;
1276 nfs_inc_stats(data
->inode
, NFSIOS_SHORTWRITE
);
1278 /* Has the server at least made some progress? */
1279 if (resp
->count
!= 0) {
1280 /* Was this an NFSv2 write or an NFSv3 stable write? */
1281 if (resp
->verf
->committed
!= NFS_UNSTABLE
) {
1282 /* Resend from where the server left off */
1283 argp
->offset
+= resp
->count
;
1284 argp
->pgbase
+= resp
->count
;
1285 argp
->count
-= resp
->count
;
1287 /* Resend as a stable write in order to avoid
1288 * headaches in the case of a server crash.
1290 argp
->stable
= NFS_FILE_SYNC
;
1292 rpc_restart_call(task
);
1295 if (time_before(complain
, jiffies
)) {
1297 "NFS: Server wrote zero bytes, expected %u.\n",
1299 complain
= jiffies
+ 300 * HZ
;
1301 /* Can't do anything about it except throw an error. */
1302 task
->tk_status
= -EIO
;
1308 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1309 void nfs_commit_release(void *wdata
)
1311 nfs_commit_free(wdata
);
1315 * Set up the argument/result storage required for the RPC call.
1317 static void nfs_commit_rpcsetup(struct list_head
*head
,
1318 struct nfs_write_data
*data
,
1321 struct nfs_page
*first
;
1322 struct inode
*inode
;
1325 /* Set up the RPC argument and reply structs
1326 * NB: take care not to mess about with data->commit et al. */
1328 list_splice_init(head
, &data
->pages
);
1329 first
= nfs_list_entry(data
->pages
.next
);
1330 inode
= first
->wb_context
->dentry
->d_inode
;
1332 data
->inode
= inode
;
1333 data
->cred
= first
->wb_context
->cred
;
1335 data
->args
.fh
= NFS_FH(data
->inode
);
1336 /* Note: we always request a commit of the entire inode */
1337 data
->args
.offset
= 0;
1338 data
->args
.count
= 0;
1339 data
->res
.count
= 0;
1340 data
->res
.fattr
= &data
->fattr
;
1341 data
->res
.verf
= &data
->verf
;
1342 nfs_fattr_init(&data
->fattr
);
1344 /* Set up the initial task struct. */
1345 flags
= (how
& FLUSH_SYNC
) ? 0 : RPC_TASK_ASYNC
;
1346 rpc_init_task(&data
->task
, NFS_CLIENT(inode
), flags
, &nfs_commit_ops
, data
);
1347 NFS_PROTO(inode
)->commit_setup(data
, how
);
1349 data
->task
.tk_priority
= flush_task_priority(how
);
1350 data
->task
.tk_cookie
= (unsigned long)inode
;
1352 dprintk("NFS: %4d initiated commit call\n", data
->task
.tk_pid
);
1356 * Commit dirty pages
1359 nfs_commit_list(struct inode
*inode
, struct list_head
*head
, int how
)
1361 struct nfs_write_data
*data
;
1362 struct nfs_page
*req
;
1364 data
= nfs_commit_alloc();
1369 /* Set up the argument struct */
1370 nfs_commit_rpcsetup(head
, data
, how
);
1372 nfs_execute_write(data
);
1375 while (!list_empty(head
)) {
1376 req
= nfs_list_entry(head
->next
);
1377 nfs_list_remove_request(req
);
1378 nfs_mark_request_commit(req
);
1379 dec_zone_page_state(req
->wb_page
, NR_UNSTABLE_NFS
);
1380 nfs_clear_page_writeback(req
);
1386 * COMMIT call returned
1388 static void nfs_commit_done(struct rpc_task
*task
, void *calldata
)
1390 struct nfs_write_data
*data
= calldata
;
1391 struct nfs_page
*req
;
1393 dprintk("NFS: %4d nfs_commit_done (status %d)\n",
1394 task
->tk_pid
, task
->tk_status
);
1396 /* Call the NFS version-specific code */
1397 if (NFS_PROTO(data
->inode
)->commit_done(task
, data
) != 0)
1400 while (!list_empty(&data
->pages
)) {
1401 req
= nfs_list_entry(data
->pages
.next
);
1402 nfs_list_remove_request(req
);
1403 dec_zone_page_state(req
->wb_page
, NR_UNSTABLE_NFS
);
1405 dprintk("NFS: commit (%s/%Ld %d@%Ld)",
1406 req
->wb_context
->dentry
->d_inode
->i_sb
->s_id
,
1407 (long long)NFS_FILEID(req
->wb_context
->dentry
->d_inode
),
1409 (long long)req_offset(req
));
1410 if (task
->tk_status
< 0) {
1411 req
->wb_context
->error
= task
->tk_status
;
1412 nfs_inode_remove_request(req
);
1413 dprintk(", error = %d\n", task
->tk_status
);
1417 /* Okay, COMMIT succeeded, apparently. Check the verifier
1418 * returned by the server against all stored verfs. */
1419 if (!memcmp(req
->wb_verf
.verifier
, data
->verf
.verifier
, sizeof(data
->verf
.verifier
))) {
1420 /* We have a match */
1421 nfs_inode_remove_request(req
);
1425 /* We have a mismatch. Write the page again */
1426 dprintk(" mismatch\n");
1427 nfs_mark_request_dirty(req
);
1429 nfs_clear_page_writeback(req
);
1433 static const struct rpc_call_ops nfs_commit_ops
= {
1434 .rpc_call_done
= nfs_commit_done
,
1435 .rpc_release
= nfs_commit_release
,
1438 static inline int nfs_commit_list(struct inode
*inode
, struct list_head
*head
, int how
)
1444 static long nfs_flush_mapping(struct address_space
*mapping
, struct writeback_control
*wbc
, int how
)
1446 struct nfs_inode
*nfsi
= NFS_I(mapping
->host
);
1450 spin_lock(&nfsi
->req_lock
);
1451 res
= nfs_scan_dirty(mapping
, wbc
, &head
);
1452 spin_unlock(&nfsi
->req_lock
);
1454 int error
= nfs_flush_list(mapping
->host
, &head
, res
, how
);
1461 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1462 int nfs_commit_inode(struct inode
*inode
, int how
)
1464 struct nfs_inode
*nfsi
= NFS_I(inode
);
1468 spin_lock(&nfsi
->req_lock
);
1469 res
= nfs_scan_commit(inode
, &head
, 0, 0);
1470 spin_unlock(&nfsi
->req_lock
);
1472 int error
= nfs_commit_list(inode
, &head
, how
);
1480 long nfs_sync_mapping_wait(struct address_space
*mapping
, struct writeback_control
*wbc
, int how
)
1482 struct inode
*inode
= mapping
->host
;
1483 struct nfs_inode
*nfsi
= NFS_I(inode
);
1484 unsigned long idx_start
, idx_end
;
1485 unsigned int npages
= 0;
1487 int nocommit
= how
& FLUSH_NOCOMMIT
;
1491 if (wbc
->range_cyclic
)
1494 idx_start
= wbc
->range_start
>> PAGE_CACHE_SHIFT
;
1495 idx_end
= wbc
->range_end
>> PAGE_CACHE_SHIFT
;
1496 if (idx_end
> idx_start
) {
1497 unsigned long l_npages
= 1 + idx_end
- idx_start
;
1499 if (sizeof(npages
) != sizeof(l_npages
) &&
1500 (unsigned long)npages
!= l_npages
)
1504 how
&= ~FLUSH_NOCOMMIT
;
1505 spin_lock(&nfsi
->req_lock
);
1507 wbc
->pages_skipped
= 0;
1508 ret
= nfs_wait_on_requests_locked(inode
, idx_start
, npages
);
1511 pages
= nfs_scan_dirty(mapping
, wbc
, &head
);
1513 spin_unlock(&nfsi
->req_lock
);
1514 if (how
& FLUSH_INVALIDATE
) {
1515 nfs_cancel_dirty_list(&head
);
1518 ret
= nfs_flush_list(inode
, &head
, pages
, how
);
1519 spin_lock(&nfsi
->req_lock
);
1522 if (wbc
->pages_skipped
!= 0)
1526 pages
= nfs_scan_commit(inode
, &head
, idx_start
, npages
);
1528 if (wbc
->pages_skipped
!= 0)
1532 if (how
& FLUSH_INVALIDATE
) {
1533 spin_unlock(&nfsi
->req_lock
);
1534 nfs_cancel_commit_list(&head
);
1536 spin_lock(&nfsi
->req_lock
);
1539 pages
+= nfs_scan_commit(inode
, &head
, 0, 0);
1540 spin_unlock(&nfsi
->req_lock
);
1541 ret
= nfs_commit_list(inode
, &head
, how
);
1542 spin_lock(&nfsi
->req_lock
);
1544 spin_unlock(&nfsi
->req_lock
);
1549 * flush the inode to disk.
1551 int nfs_wb_all(struct inode
*inode
)
1553 struct address_space
*mapping
= inode
->i_mapping
;
1554 struct writeback_control wbc
= {
1555 .bdi
= mapping
->backing_dev_info
,
1556 .sync_mode
= WB_SYNC_ALL
,
1557 .nr_to_write
= LONG_MAX
,
1562 ret
= nfs_sync_mapping_wait(mapping
, &wbc
, 0);
1568 int nfs_sync_mapping_range(struct address_space
*mapping
, loff_t range_start
, loff_t range_end
, int how
)
1570 struct writeback_control wbc
= {
1571 .bdi
= mapping
->backing_dev_info
,
1572 .sync_mode
= WB_SYNC_ALL
,
1573 .nr_to_write
= LONG_MAX
,
1574 .range_start
= range_start
,
1575 .range_end
= range_end
,
1579 ret
= nfs_sync_mapping_wait(mapping
, &wbc
, how
);
1585 static int nfs_wb_page_priority(struct inode
*inode
, struct page
*page
, int how
)
1587 loff_t range_start
= page_offset(page
);
1588 loff_t range_end
= range_start
+ (loff_t
)(PAGE_CACHE_SIZE
- 1);
1590 return nfs_sync_mapping_range(inode
->i_mapping
, range_start
, range_end
, how
| FLUSH_STABLE
);
1594 * Write back all requests on one page - we do this before reading it.
1596 int nfs_wb_page(struct inode
*inode
, struct page
* page
)
1598 return nfs_wb_page_priority(inode
, page
, 0);
1602 int __init
nfs_init_writepagecache(void)
1604 nfs_wdata_cachep
= kmem_cache_create("nfs_write_data",
1605 sizeof(struct nfs_write_data
),
1606 0, SLAB_HWCACHE_ALIGN
,
1608 if (nfs_wdata_cachep
== NULL
)
1611 nfs_wdata_mempool
= mempool_create_slab_pool(MIN_POOL_WRITE
,
1613 if (nfs_wdata_mempool
== NULL
)
1616 nfs_commit_mempool
= mempool_create_slab_pool(MIN_POOL_COMMIT
,
1618 if (nfs_commit_mempool
== NULL
)
1624 void nfs_destroy_writepagecache(void)
1626 mempool_destroy(nfs_commit_mempool
);
1627 mempool_destroy(nfs_wdata_mempool
);
1628 kmem_cache_destroy(nfs_wdata_cachep
);