blob: e560a78995a3cf5027a01df5168060183ef49547 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/write.c
3 *
Trond Myklebust7c85d902006-12-13 15:23:48 -05004 * Write file data over NFS.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de>
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/types.h>
10#include <linux/slab.h>
11#include <linux/mm.h>
12#include <linux/pagemap.h>
13#include <linux/file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/writeback.h>
Peter Zijlstra89a09142007-03-16 13:38:26 -080015#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <linux/sunrpc/clnt.h>
18#include <linux/nfs_fs.h>
19#include <linux/nfs_mount.h>
20#include <linux/nfs_page.h>
Andrew Morton3fcfab12006-10-19 23:28:16 -070021#include <linux/backing-dev.h>
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "delegation.h"
Trond Myklebust49a70f22006-12-05 00:35:38 -050026#include "internal.h"
Chuck Lever91d5b472006-03-20 13:44:14 -050027#include "iostat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#define NFSDBG_FACILITY NFSDBG_PAGECACHE
30
31#define MIN_POOL_WRITE (32)
32#define MIN_POOL_COMMIT (4)
33
34/*
35 * Local function declarations
36 */
Trond Myklebustc63c7b02007-04-02 19:29:52 -040037static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc,
38 struct inode *inode, int ioflags);
Fred Isamanf8512ad2008-03-19 11:24:39 -040039static void nfs_redirty_request(struct nfs_page *req);
Trond Myklebust788e7a82006-03-20 13:44:27 -050040static const struct rpc_call_ops nfs_write_partial_ops;
41static const struct rpc_call_ops nfs_write_full_ops;
42static const struct rpc_call_ops nfs_commit_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Christoph Lametere18b8902006-12-06 20:33:20 -080044static struct kmem_cache *nfs_wdata_cachep;
Trond Myklebust3feb2d42006-03-20 13:44:37 -050045static mempool_t *nfs_wdata_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static mempool_t *nfs_commit_mempool;
47
Trond Myklebustc9d8f892008-04-15 16:56:39 -040048struct nfs_write_data *nfs_commitdata_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Christoph Lametere6b4f8d2006-12-06 20:33:14 -080050 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS);
Chuck Lever40859d72005-11-30 18:09:02 -050051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if (p) {
53 memset(p, 0, sizeof(*p));
54 INIT_LIST_HEAD(&p->pages);
55 }
56 return p;
57}
58
Trond Myklebust5e4424a2008-02-25 21:53:49 -080059void nfs_commit_free(struct nfs_write_data *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Chuck Lever40859d72005-11-30 18:09:02 -050061 if (p && (p->pagevec != &p->page_array[0]))
62 kfree(p->pagevec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 mempool_free(p, nfs_commit_mempool);
64}
65
Trond Myklebust8d5658c2007-04-10 09:26:35 -040066struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050067{
Christoph Lametere6b4f8d2006-12-06 20:33:14 -080068 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS);
Trond Myklebust3feb2d42006-03-20 13:44:37 -050069
70 if (p) {
71 memset(p, 0, sizeof(*p));
72 INIT_LIST_HEAD(&p->pages);
Trond Myklebuste9f7bee2006-09-08 09:48:54 -070073 p->npages = pagecount;
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040074 if (pagecount <= ARRAY_SIZE(p->page_array))
75 p->pagevec = p->page_array;
Trond Myklebust3feb2d42006-03-20 13:44:37 -050076 else {
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040077 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
78 if (!p->pagevec) {
Trond Myklebust3feb2d42006-03-20 13:44:37 -050079 mempool_free(p, nfs_wdata_mempool);
80 p = NULL;
81 }
82 }
83 }
84 return p;
85}
86
Trond Myklebust5e4424a2008-02-25 21:53:49 -080087static void nfs_writedata_free(struct nfs_write_data *p)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050088{
89 if (p && (p->pagevec != &p->page_array[0]))
90 kfree(p->pagevec);
91 mempool_free(p, nfs_wdata_mempool);
92}
93
Trond Myklebust383ba712008-02-19 20:04:20 -050094void nfs_writedata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Trond Myklebust383ba712008-02-19 20:04:20 -050096 struct nfs_write_data *wdata = data;
97
98 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 nfs_writedata_free(wdata);
100}
101
Trond Myklebust7b159fc2007-07-25 14:09:54 -0400102static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
103{
104 ctx->error = error;
105 smp_wmb();
106 set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
107}
108
Trond Myklebust277459d2006-12-05 00:35:35 -0500109static struct nfs_page *nfs_page_find_request_locked(struct page *page)
110{
111 struct nfs_page *req = NULL;
112
113 if (PagePrivate(page)) {
114 req = (struct nfs_page *)page_private(page);
115 if (req != NULL)
Trond Myklebustc03b4022007-06-17 13:26:38 -0400116 kref_get(&req->wb_kref);
Trond Myklebust277459d2006-12-05 00:35:35 -0500117 }
118 return req;
119}
120
121static struct nfs_page *nfs_page_find_request(struct page *page)
122{
Trond Myklebust587142f2007-07-02 09:57:54 -0400123 struct inode *inode = page->mapping->host;
Trond Myklebust277459d2006-12-05 00:35:35 -0500124 struct nfs_page *req = NULL;
Trond Myklebust277459d2006-12-05 00:35:35 -0500125
Trond Myklebust587142f2007-07-02 09:57:54 -0400126 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500127 req = nfs_page_find_request_locked(page);
Trond Myklebust587142f2007-07-02 09:57:54 -0400128 spin_unlock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500129 return req;
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* Adjust the file length if we're writing beyond the end */
133static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
134{
135 struct inode *inode = page->mapping->host;
Trond Myklebusta3d01452008-06-11 12:21:19 -0400136 loff_t end, i_size;
137 pgoff_t end_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Trond Myklebusta3d01452008-06-11 12:21:19 -0400139 spin_lock(&inode->i_lock);
140 i_size = i_size_read(inode);
141 end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (i_size > 0 && page->index < end_index)
Trond Myklebusta3d01452008-06-11 12:21:19 -0400143 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count);
145 if (i_size >= end)
Trond Myklebusta3d01452008-06-11 12:21:19 -0400146 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 i_size_write(inode, end);
Trond Myklebusta3d01452008-06-11 12:21:19 -0400148 nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
149out:
150 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Trond Myklebusta301b772007-02-06 11:07:15 -0800153/* A writeback failed: mark the page as bad, and invalidate the page cache */
154static void nfs_set_pageerror(struct page *page)
155{
156 SetPageError(page);
157 nfs_zap_mapping(page->mapping->host, page->mapping);
158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/* We can set the PG_uptodate flag if we see that a write request
161 * covers the full page.
162 */
163static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int count)
164{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 if (PageUptodate(page))
166 return;
167 if (base != 0)
168 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500169 if (count != nfs_page_length(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500171 SetPageUptodate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174static int wb_priority(struct writeback_control *wbc)
175{
176 if (wbc->for_reclaim)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400177 return FLUSH_HIGHPRI | FLUSH_STABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 if (wbc->for_kupdate)
179 return FLUSH_LOWPRI;
180 return 0;
181}
182
183/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800184 * NFS congestion control
185 */
186
187int nfs_congestion_kb;
188
189#define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10))
190#define NFS_CONGESTION_OFF_THRESH \
191 (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2))
192
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400193static int nfs_set_page_writeback(struct page *page)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800194{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400195 int ret = test_set_page_writeback(page);
196
197 if (!ret) {
Peter Zijlstra89a09142007-03-16 13:38:26 -0800198 struct inode *inode = page->mapping->host;
199 struct nfs_server *nfss = NFS_SERVER(inode);
200
Peter Zijlstra277866a2007-05-08 00:35:12 -0700201 if (atomic_long_inc_return(&nfss->writeback) >
Peter Zijlstra89a09142007-03-16 13:38:26 -0800202 NFS_CONGESTION_ON_THRESH)
203 set_bdi_congested(&nfss->backing_dev_info, WRITE);
204 }
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400205 return ret;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800206}
207
208static void nfs_end_page_writeback(struct page *page)
209{
210 struct inode *inode = page->mapping->host;
211 struct nfs_server *nfss = NFS_SERVER(inode);
212
213 end_page_writeback(page);
Peter Zijlstrac4dc4be2007-10-16 23:25:41 -0700214 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800215 clear_bdi_congested(&nfss->backing_dev_info, WRITE);
Peter Zijlstra89a09142007-03-16 13:38:26 -0800216}
217
218/*
Trond Myklebuste261f512006-12-05 00:35:41 -0500219 * Find an associated nfs write request, and prepare to flush it out
Trond Myklebust9cccef92007-07-22 17:09:05 -0400220 * May return an error if the user signalled nfs_wait_on_request().
Trond Myklebuste261f512006-12-05 00:35:41 -0500221 */
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400222static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
223 struct page *page)
Trond Myklebuste261f512006-12-05 00:35:41 -0500224{
Trond Myklebust587142f2007-07-02 09:57:54 -0400225 struct inode *inode = page->mapping->host;
Trond Myklebuste261f512006-12-05 00:35:41 -0500226 struct nfs_page *req;
Trond Myklebuste261f512006-12-05 00:35:41 -0500227 int ret;
228
Trond Myklebust587142f2007-07-02 09:57:54 -0400229 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500230 for(;;) {
231 req = nfs_page_find_request_locked(page);
232 if (req == NULL) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400233 spin_unlock(&inode->i_lock);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400234 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500235 }
Trond Myklebustacee4782008-01-22 17:13:07 -0500236 if (nfs_set_page_tag_locked(req))
Trond Myklebuste261f512006-12-05 00:35:41 -0500237 break;
238 /* Note: If we hold the page lock, as is the case in nfs_writepage,
Trond Myklebustacee4782008-01-22 17:13:07 -0500239 * then the call to nfs_set_page_tag_locked() will always
Trond Myklebuste261f512006-12-05 00:35:41 -0500240 * succeed provided that someone hasn't already marked the
241 * request as dirty (in which case we don't care).
242 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400243 spin_unlock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500244 ret = nfs_wait_on_request(req);
245 nfs_release_request(req);
246 if (ret != 0)
247 return ret;
Trond Myklebust587142f2007-07-02 09:57:54 -0400248 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500249 }
Trond Myklebuste468bae2008-06-13 13:25:22 -0400250 if (test_bit(PG_CLEAN, &req->wb_flags)) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400251 spin_unlock(&inode->i_lock);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400252 BUG();
Trond Myklebust612c9382007-04-20 16:12:45 -0400253 }
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400254 if (nfs_set_page_writeback(page) != 0) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400255 spin_unlock(&inode->i_lock);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400256 BUG();
257 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400258 spin_unlock(&inode->i_lock);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400259 if (!nfs_pageio_add_request(pgio, req)) {
260 nfs_redirty_request(req);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400261 return pgio->pg_error;
262 }
Trond Myklebust9cccef92007-07-22 17:09:05 -0400263 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500264}
265
Trond Myklebustf758c8852007-07-22 19:27:32 -0400266static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
267{
268 struct inode *inode = page->mapping->host;
269
270 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
271 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
272
273 nfs_pageio_cond_complete(pgio, page->index);
274 return nfs_page_async_flush(pgio, page);
275}
276
Trond Myklebuste261f512006-12-05 00:35:41 -0500277/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 * Write an mmapped page to the server.
279 */
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500280static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400282 struct nfs_pageio_descriptor pgio;
Trond Myklebuste261f512006-12-05 00:35:41 -0500283 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Trond Myklebustf758c8852007-07-22 19:27:32 -0400285 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc));
286 err = nfs_do_writepage(page, wbc, &pgio);
287 nfs_pageio_complete(&pgio);
288 if (err < 0)
289 return err;
290 if (pgio.pg_error < 0)
291 return pgio.pg_error;
292 return 0;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500293}
294
295int nfs_writepage(struct page *page, struct writeback_control *wbc)
296{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400297 int ret;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500298
Trond Myklebustf758c8852007-07-22 19:27:32 -0400299 ret = nfs_writepage_locked(page, wbc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 unlock_page(page);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400301 return ret;
302}
303
304static int nfs_writepages_callback(struct page *page, struct writeback_control *wbc, void *data)
305{
306 int ret;
307
308 ret = nfs_do_writepage(page, wbc, data);
309 unlock_page(page);
310 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
314{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 struct inode *inode = mapping->host;
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400316 unsigned long *bitlock = &NFS_I(inode)->flags;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400317 struct nfs_pageio_descriptor pgio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 int err;
319
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400320 /* Stop dirtying of new pages while we sync */
321 err = wait_on_bit_lock(bitlock, NFS_INO_FLUSHING,
322 nfs_wait_bit_killable, TASK_KILLABLE);
323 if (err)
324 goto out_err;
325
Chuck Lever91d5b472006-03-20 13:44:14 -0500326 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
327
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400328 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc));
Trond Myklebustf758c8852007-07-22 19:27:32 -0400329 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400330 nfs_pageio_complete(&pgio);
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400331
332 clear_bit_unlock(NFS_INO_FLUSHING, bitlock);
333 smp_mb__after_clear_bit();
334 wake_up_bit(bitlock, NFS_INO_FLUSHING);
335
Trond Myklebustf758c8852007-07-22 19:27:32 -0400336 if (err < 0)
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400337 goto out_err;
338 err = pgio.pg_error;
339 if (err < 0)
340 goto out_err;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400341 return 0;
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400342out_err:
343 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
346/*
347 * Insert a write request into an inode
348 */
Trond Myklebuste7d39062008-06-13 12:12:32 -0400349static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
351 struct nfs_inode *nfsi = NFS_I(inode);
352 int error;
353
Trond Myklebuste7d39062008-06-13 12:12:32 -0400354 error = radix_tree_preload(GFP_NOFS);
355 if (error != 0)
356 goto out;
357
358 /* Lock the request! */
359 nfs_lock_request_dontget(req);
360
361 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
Nick Piggin27852592008-02-04 23:48:37 -0800363 BUG_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (!nfsi->npages) {
365 igrab(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (nfs_have_delegation(inode, FMODE_WRITE))
367 nfsi->change_attr++;
368 }
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500369 SetPagePrivate(req->wb_page);
Trond Myklebust277459d2006-12-05 00:35:35 -0500370 set_page_private(req->wb_page, (unsigned long)req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 nfsi->npages++;
Trond Myklebustc03b4022007-06-17 13:26:38 -0400372 kref_get(&req->wb_kref);
Nick Piggin27852592008-02-04 23:48:37 -0800373 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
374 NFS_PAGE_TAG_LOCKED);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400375 spin_unlock(&inode->i_lock);
376 radix_tree_preload_end();
377out:
378 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800382 * Remove a write request from an inode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 */
384static void nfs_inode_remove_request(struct nfs_page *req)
385{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400386 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 struct nfs_inode *nfsi = NFS_I(inode);
388
389 BUG_ON (!NFS_WBACK_BUSY(req));
390
Trond Myklebust587142f2007-07-02 09:57:54 -0400391 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500392 set_page_private(req->wb_page, 0);
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500393 ClearPagePrivate(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
395 nfsi->npages--;
396 if (!nfsi->npages) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400397 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 iput(inode);
399 } else
Trond Myklebust587142f2007-07-02 09:57:54 -0400400 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 nfs_clear_request(req);
402 nfs_release_request(req);
403}
404
Trond Myklebust61822ab2006-12-05 00:35:42 -0500405static void
Fred6d884e82008-03-19 11:24:38 -0400406nfs_mark_request_dirty(struct nfs_page *req)
Trond Myklebust61822ab2006-12-05 00:35:42 -0500407{
Trond Myklebust61822ab2006-12-05 00:35:42 -0500408 __set_page_dirty_nobuffers(req->wb_page);
409}
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
412/*
413 * Add a request to the inode's commit list.
414 */
415static void
416nfs_mark_request_commit(struct nfs_page *req)
417{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400418 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 struct nfs_inode *nfsi = NFS_I(inode);
420
Trond Myklebust587142f2007-07-02 09:57:54 -0400421 spin_lock(&inode->i_lock);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400422 set_bit(PG_CLEAN, &(req)->wb_flags);
Trond Myklebust5c369682007-06-17 15:27:42 -0400423 radix_tree_tag_set(&nfsi->nfs_page_tree,
424 req->wb_index,
425 NFS_PAGE_TAG_COMMIT);
Trond Myklebust587142f2007-07-02 09:57:54 -0400426 spin_unlock(&inode->i_lock);
Christoph Lameterfd39fc82006-06-30 01:55:40 -0700427 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700428 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
Trond Myklebusta1803042006-12-05 00:45:19 -0500429 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400431
Trond Myklebuste468bae2008-06-13 13:25:22 -0400432static int
433nfs_clear_request_commit(struct nfs_page *req)
434{
435 struct page *page = req->wb_page;
436
437 if (test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) {
438 dec_zone_page_state(page, NR_UNSTABLE_NFS);
439 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE);
440 return 1;
441 }
442 return 0;
443}
444
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400445static inline
446int nfs_write_need_commit(struct nfs_write_data *data)
447{
448 return data->verf.committed != NFS_FILE_SYNC;
449}
450
451static inline
452int nfs_reschedule_unstable_write(struct nfs_page *req)
453{
Trond Myklebuste468bae2008-06-13 13:25:22 -0400454 if (test_and_clear_bit(PG_NEED_COMMIT, &req->wb_flags)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400455 nfs_mark_request_commit(req);
456 return 1;
457 }
458 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
Fred6d884e82008-03-19 11:24:38 -0400459 nfs_mark_request_dirty(req);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400460 return 1;
461 }
462 return 0;
463}
464#else
465static inline void
466nfs_mark_request_commit(struct nfs_page *req)
467{
468}
469
Trond Myklebuste468bae2008-06-13 13:25:22 -0400470static inline int
471nfs_clear_request_commit(struct nfs_page *req)
472{
473 return 0;
474}
475
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400476static inline
477int nfs_write_need_commit(struct nfs_write_data *data)
478{
479 return 0;
480}
481
482static inline
483int nfs_reschedule_unstable_write(struct nfs_page *req)
484{
485 return 0;
486}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#endif
488
489/*
490 * Wait for a request to complete.
491 *
Matthew Wilcox150030b2007-12-06 16:24:39 -0500492 * Interruptible by fatal signals only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 */
Trond Myklebustca52fec2007-04-17 17:22:13 -0400494static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 struct nfs_inode *nfsi = NFS_I(inode);
497 struct nfs_page *req;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400498 pgoff_t idx_end, next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 unsigned int res = 0;
500 int error;
501
502 if (npages == 0)
503 idx_end = ~0;
504 else
505 idx_end = idx_start + npages - 1;
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 next = idx_start;
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400508 while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_LOCKED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (req->wb_index > idx_end)
510 break;
511
512 next = req->wb_index + 1;
Trond Myklebustc6a556b2005-06-22 17:16:30 +0000513 BUG_ON(!NFS_WBACK_BUSY(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Trond Myklebustc03b4022007-06-17 13:26:38 -0400515 kref_get(&req->wb_kref);
Trond Myklebust587142f2007-07-02 09:57:54 -0400516 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 error = nfs_wait_on_request(req);
518 nfs_release_request(req);
Trond Myklebust587142f2007-07-02 09:57:54 -0400519 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (error < 0)
521 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 res++;
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return res;
525}
526
Trond Myklebust83715ad2006-07-05 13:17:12 -0400527static void nfs_cancel_commit_list(struct list_head *head)
528{
529 struct nfs_page *req;
530
531 while(!list_empty(head)) {
532 req = nfs_list_entry(head->next);
533 nfs_list_remove_request(req);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400534 nfs_clear_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400535 nfs_inode_remove_request(req);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700536 nfs_unlock_request(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400537 }
538}
539
Trond Myklebust47c62562009-03-16 08:13:41 -0400540#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400541static int
542nfs_need_commit(struct nfs_inode *nfsi)
543{
544 return radix_tree_tagged(&nfsi->nfs_page_tree, NFS_PAGE_TAG_COMMIT);
545}
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547/*
548 * nfs_scan_commit - Scan an inode for commit requests
549 * @inode: NFS inode to scan
550 * @dst: destination list
551 * @idx_start: lower bound of page->index to scan.
552 * @npages: idx_start + npages sets the upper bound to scan.
553 *
554 * Moves requests from the inode's 'commit' request list.
555 * The requests are *not* checked to ensure that they form a contiguous set.
556 */
557static int
Trond Myklebustca52fec2007-04-17 17:22:13 -0400558nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
560 struct nfs_inode *nfsi = NFS_I(inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000561
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400562 if (!nfs_need_commit(nfsi))
563 return 0;
564
565 return nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
Trond Myklebustc42de9d2006-03-20 13:44:51 -0500567#else
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400568static inline int nfs_need_commit(struct nfs_inode *nfsi)
569{
570 return 0;
571}
572
Trond Myklebustca52fec2007-04-17 17:22:13 -0400573static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
Trond Myklebustc42de9d2006-03-20 13:44:51 -0500574{
575 return 0;
576}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#endif
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579/*
Trond Myklebuste7d39062008-06-13 12:12:32 -0400580 * Search for an existing write request, and attempt to update
581 * it to reflect a new dirty region on a given page.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 *
Trond Myklebuste7d39062008-06-13 12:12:32 -0400583 * If the attempt fails, then the existing request is flushed out
584 * to disk.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 */
Trond Myklebuste7d39062008-06-13 12:12:32 -0400586static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
587 struct page *page,
588 unsigned int offset,
589 unsigned int bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
Trond Myklebuste7d39062008-06-13 12:12:32 -0400591 struct nfs_page *req;
592 unsigned int rqend;
593 unsigned int end;
594 int error;
595
596 if (!PagePrivate(page))
597 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 end = offset + bytes;
Trond Myklebuste7d39062008-06-13 12:12:32 -0400600 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 for (;;) {
Trond Myklebust277459d2006-12-05 00:35:35 -0500603 req = nfs_page_find_request_locked(page);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400604 if (req == NULL)
605 goto out_unlock;
Trond Myklebust277459d2006-12-05 00:35:35 -0500606
Trond Myklebuste7d39062008-06-13 12:12:32 -0400607 rqend = req->wb_offset + req->wb_bytes;
608 /*
609 * Tell the caller to flush out the request if
610 * the offsets are non-contiguous.
611 * Note: nfs_flush_incompatible() will already
612 * have flushed out requests having wrong owners.
613 */
Trond Myklebuste468bae2008-06-13 13:25:22 -0400614 if (offset > rqend
Trond Myklebuste7d39062008-06-13 12:12:32 -0400615 || end < req->wb_offset)
616 goto out_flushme;
617
618 if (nfs_set_page_tag_locked(req))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Trond Myklebuste7d39062008-06-13 12:12:32 -0400621 /* The request is locked, so wait and then retry */
Trond Myklebust587142f2007-07-02 09:57:54 -0400622 spin_unlock(&inode->i_lock);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400623 error = nfs_wait_on_request(req);
624 nfs_release_request(req);
625 if (error != 0)
626 goto out_err;
627 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
Trond Myklebuste468bae2008-06-13 13:25:22 -0400630 if (nfs_clear_request_commit(req))
631 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
632 req->wb_index, NFS_PAGE_TAG_COMMIT);
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 /* Okay, the request matches. Update the region */
635 if (offset < req->wb_offset) {
636 req->wb_offset = offset;
637 req->wb_pgbase = offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (end > rqend)
640 req->wb_bytes = end - req->wb_offset;
Trond Myklebuste7d39062008-06-13 12:12:32 -0400641 else
642 req->wb_bytes = rqend - req->wb_offset;
643out_unlock:
644 spin_unlock(&inode->i_lock);
645 return req;
646out_flushme:
647 spin_unlock(&inode->i_lock);
648 nfs_release_request(req);
649 error = nfs_wb_page(inode, page);
650out_err:
651 return ERR_PTR(error);
652}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Trond Myklebuste7d39062008-06-13 12:12:32 -0400654/*
655 * Try to update an existing write request, or create one if there is none.
656 *
657 * Note: Should always be called with the Page Lock held to prevent races
658 * if we have to add a new request. Also assumes that the caller has
659 * already called nfs_flush_incompatible() if necessary.
660 */
661static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
662 struct page *page, unsigned int offset, unsigned int bytes)
663{
664 struct inode *inode = page->mapping->host;
665 struct nfs_page *req;
666 int error;
667
668 req = nfs_try_to_update_request(inode, page, offset, bytes);
669 if (req != NULL)
670 goto out;
671 req = nfs_create_request(ctx, inode, page, offset, bytes);
672 if (IS_ERR(req))
673 goto out;
674 error = nfs_inode_add_request(inode, req);
675 if (error != 0) {
676 nfs_release_request(req);
677 req = ERR_PTR(error);
678 }
Trond Myklebustefc91ed2008-06-10 18:31:00 -0400679out:
Trond Myklebust61e930a2007-10-18 17:08:05 -0400680 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Trond Myklebuste7d39062008-06-13 12:12:32 -0400683static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
684 unsigned int offset, unsigned int count)
685{
686 struct nfs_page *req;
687
688 req = nfs_setup_write_request(ctx, page, offset, count);
689 if (IS_ERR(req))
690 return PTR_ERR(req);
691 /* Update file length */
692 nfs_grow_file(page, offset, count);
693 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
694 nfs_clear_page_tag_locked(req);
695 return 0;
696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698int nfs_flush_incompatible(struct file *file, struct page *page)
699{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400700 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 struct nfs_page *req;
Trond Myklebust1a545332006-12-05 00:35:40 -0500702 int do_flush, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 /*
704 * Look for a request corresponding to this page. If there
705 * is one, and it belongs to another file, we flush it out
706 * before we try to copy anything into the page. Do this
707 * due to the lack of an ACCESS-type call in NFSv2.
708 * Also do the same if we find a request from an existing
709 * dropped page.
710 */
Trond Myklebust1a545332006-12-05 00:35:40 -0500711 do {
712 req = nfs_page_find_request(page);
713 if (req == NULL)
714 return 0;
Trond Myklebuste468bae2008-06-13 13:25:22 -0400715 do_flush = req->wb_page != page || req->wb_context != ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 nfs_release_request(req);
Trond Myklebust1a545332006-12-05 00:35:40 -0500717 if (!do_flush)
718 return 0;
719 status = nfs_wb_page(page->mapping->host, page);
720 } while (status == 0);
721 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722}
723
724/*
Trond Myklebust5d47a352008-02-07 17:24:07 -0500725 * If the page cache is marked as unsafe or invalid, then we can't rely on
726 * the PageUptodate() flag. In this case, we will need to turn off
727 * write optimisations that depend on the page contents being correct.
728 */
729static int nfs_write_pageuptodate(struct page *page, struct inode *inode)
730{
731 return PageUptodate(page) &&
732 !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA));
733}
734
735/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * Update and possibly write a cached page of an NFS file.
737 *
738 * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
739 * things with a page scheduled for an RPC call (e.g. invalidate it).
740 */
741int nfs_updatepage(struct file *file, struct page *page,
742 unsigned int offset, unsigned int count)
743{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400744 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 struct inode *inode = page->mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 int status = 0;
747
Chuck Lever91d5b472006-03-20 13:44:14 -0500748 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
749
Chuck Lever48186c72008-06-11 17:56:05 -0400750 dprintk("NFS: nfs_updatepage(%s/%s %d@%lld)\n",
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800751 file->f_path.dentry->d_parent->d_name.name,
752 file->f_path.dentry->d_name.name, count,
Chuck Lever48186c72008-06-11 17:56:05 -0400753 (long long)(page_offset(page) + offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 /* If we're not using byte range locks, and we know the page
Trond Myklebust5d47a352008-02-07 17:24:07 -0500756 * is up to date, it may be more efficient to extend the write
757 * to cover the entire page in order to avoid fragmentation
758 * inefficiencies.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 */
Trond Myklebust5d47a352008-02-07 17:24:07 -0500760 if (nfs_write_pageuptodate(page, inode) &&
761 inode->i_flock == NULL &&
Trond Myklebust4b5621f2008-02-25 15:56:29 -0800762 !(file->f_flags & O_SYNC)) {
Trond Myklebust49a70f22006-12-05 00:35:38 -0500763 count = max(count + offset, nfs_page_length(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
766
Trond Myklebuste21195a2006-12-05 00:35:39 -0500767 status = nfs_writepage_setup(ctx, page, offset, count);
Trond Myklebust03fa9e82008-06-05 16:02:35 -0400768 if (status < 0)
769 nfs_set_pageerror(page);
770 else
771 __set_page_dirty_nobuffers(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Chuck Lever48186c72008-06-11 17:56:05 -0400773 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 status, (long long)i_size_read(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return status;
776}
777
778static void nfs_writepage_release(struct nfs_page *req)
779{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Trond Myklebust7e5f6142008-05-25 12:59:19 -0400781 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400782 nfs_end_page_writeback(req->wb_page);
783 nfs_inode_remove_request(req);
784 } else
785 nfs_end_page_writeback(req->wb_page);
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400786 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
Trond Myklebust3ff75762007-07-14 15:40:00 -0400789static int flush_task_priority(int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
792 case FLUSH_HIGHPRI:
793 return RPC_PRIORITY_HIGH;
794 case FLUSH_LOWPRI:
795 return RPC_PRIORITY_LOW;
796 }
797 return RPC_PRIORITY_NORMAL;
798}
799
800/*
801 * Set up the argument/result storage required for the RPC call.
802 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400803static int nfs_write_rpcsetup(struct nfs_page *req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 struct nfs_write_data *data,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500805 const struct rpc_call_ops *call_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 unsigned int count, unsigned int offset,
807 int how)
808{
Trond Myklebust84115e12007-07-14 15:39:59 -0400809 struct inode *inode = req->wb_context->path.dentry->d_inode;
810 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -0400811 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -0400812 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400813 struct rpc_message msg = {
814 .rpc_argp = &data->args,
815 .rpc_resp = &data->res,
816 .rpc_cred = req->wb_context->cred,
817 };
Trond Myklebust84115e12007-07-14 15:39:59 -0400818 struct rpc_task_setup task_setup_data = {
819 .rpc_client = NFS_CLIENT(inode),
Trond Myklebust07737692007-10-25 18:42:54 -0400820 .task = &data->task,
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400821 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -0400822 .callback_ops = call_ops,
823 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -0500824 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -0400825 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -0400826 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -0400827 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* Set up the RPC argument and reply structs
830 * NB: take care not to mess about with data->commit et al. */
831
832 data->req = req;
Trond Myklebust88be9f92007-06-05 10:42:27 -0400833 data->inode = inode = req->wb_context->path.dentry->d_inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400834 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 data->args.fh = NFS_FH(inode);
837 data->args.offset = req_offset(req) + offset;
838 data->args.pgbase = req->wb_pgbase + offset;
839 data->args.pages = data->pagevec;
840 data->args.count = count;
Trond Myklebust383ba712008-02-19 20:04:20 -0500841 data->args.context = get_nfs_open_context(req->wb_context);
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400842 data->args.stable = NFS_UNSTABLE;
843 if (how & FLUSH_STABLE) {
844 data->args.stable = NFS_DATA_SYNC;
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400845 if (!nfs_need_commit(NFS_I(inode)))
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400846 data->args.stable = NFS_FILE_SYNC;
847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 data->res.fattr = &data->fattr;
850 data->res.count = count;
851 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400852 nfs_fattr_init(&data->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Trond Myklebust788e7a82006-03-20 13:44:27 -0500854 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400855 NFS_PROTO(inode)->write_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Chuck Levera3f565b2007-01-31 12:14:01 -0500857 dprintk("NFS: %5u initiated write call "
Chuck Lever48186c72008-06-11 17:56:05 -0400858 "(req %s/%lld, %u bytes @ offset %llu)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500859 data->task.tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 inode->i_sb->s_id,
861 (long long)NFS_FILEID(inode),
862 count,
863 (unsigned long long)data->args.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Trond Myklebust07737692007-10-25 18:42:54 -0400865 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400866 if (IS_ERR(task))
867 return PTR_ERR(task);
868 rpc_put_task(task);
869 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
871
Fred6d884e82008-03-19 11:24:38 -0400872/* If a nfs_flush_* function fails, it should remove reqs from @head and
873 * call this on each, which will prepare them to be retried on next
874 * writeback using standard nfs.
875 */
876static void nfs_redirty_request(struct nfs_page *req)
877{
878 nfs_mark_request_dirty(req);
879 nfs_end_page_writeback(req->wb_page);
880 nfs_clear_page_tag_locked(req);
881}
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883/*
884 * Generate multiple small requests to write out a single
885 * contiguous dirty area on one page.
886 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400887static int nfs_flush_multi(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
889 struct nfs_page *req = nfs_list_entry(head->next);
890 struct page *page = req->wb_page;
891 struct nfs_write_data *data;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700892 size_t wsize = NFS_SERVER(inode)->wsize, nbytes;
893 unsigned int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 int requests = 0;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400895 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 LIST_HEAD(list);
897
898 nfs_list_remove_request(req);
899
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400900 nbytes = count;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700901 do {
902 size_t len = min(nbytes, wsize);
903
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400904 data = nfs_writedata_alloc(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (!data)
906 goto out_bad;
907 list_add(&data->pages, &list);
908 requests++;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700909 nbytes -= len;
910 } while (nbytes != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 atomic_set(&req->wb_complete, requests);
912
913 ClearPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 offset = 0;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400915 nbytes = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 do {
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400917 int ret2;
918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 data = list_entry(list.next, struct nfs_write_data, pages);
920 list_del_init(&data->pages);
921
922 data->pagevec[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400924 if (nbytes < wsize)
925 wsize = nbytes;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400926 ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops,
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400927 wsize, offset, how);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400928 if (ret == 0)
929 ret = ret2;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400930 offset += wsize;
931 nbytes -= wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 } while (nbytes != 0);
933
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400934 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936out_bad:
937 while (!list_empty(&list)) {
938 data = list_entry(list.next, struct nfs_write_data, pages);
939 list_del(&data->pages);
Trond Myklebust8aca67f2006-11-13 16:23:44 -0500940 nfs_writedata_release(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
Trond Myklebust61822ab2006-12-05 00:35:42 -0500942 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return -ENOMEM;
944}
945
946/*
947 * Create an RPC task for the given write request and kick it.
948 * The page must have been locked by the caller.
949 *
950 * It may happen that the page we're passed is not marked dirty.
951 * This is the case if nfs_updatepage detects a conflicting request
952 * that has been written but not committed.
953 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400954static int nfs_flush_one(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 struct nfs_page *req;
957 struct page **pages;
958 struct nfs_write_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400960 data = nfs_writedata_alloc(npages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (!data)
962 goto out_bad;
963
964 pages = data->pagevec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 while (!list_empty(head)) {
966 req = nfs_list_entry(head->next);
967 nfs_list_remove_request(req);
968 nfs_list_add_request(req, &data->pages);
969 ClearPageError(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 *pages++ = req->wb_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 }
972 req = nfs_list_entry(data->pages.next);
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400975 return nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 out_bad:
977 while (!list_empty(head)) {
Trond Myklebust10afec92007-05-14 17:16:04 -0400978 req = nfs_list_entry(head->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 nfs_list_remove_request(req);
Trond Myklebust61822ab2006-12-05 00:35:42 -0500980 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
982 return -ENOMEM;
983}
984
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400985static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
986 struct inode *inode, int ioflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
Chuck Leverbf4285e2007-12-20 14:54:57 -0500988 size_t wsize = NFS_SERVER(inode)->wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400990 if (wsize < PAGE_CACHE_SIZE)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400991 nfs_pageio_init(pgio, inode, nfs_flush_multi, wsize, ioflags);
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400992 else
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400993 nfs_pageio_init(pgio, inode, nfs_flush_one, wsize, ioflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
996/*
997 * Handle a write reply that flushed part of a page.
998 */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500999static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001001 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Chuck Lever48186c72008-06-11 17:56:05 -04001003 dprintk("NFS: %5u write(%s/%lld %d@%lld)",
1004 task->tk_pid,
1005 data->req->wb_context->path.dentry->d_inode->i_sb->s_id,
1006 (long long)
1007 NFS_FILEID(data->req->wb_context->path.dentry->d_inode),
1008 data->req->wb_bytes, (long long)req_offset(data->req));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001010 nfs_writeback_done(task, data);
1011}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001012
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001013static void nfs_writeback_release_partial(void *calldata)
1014{
1015 struct nfs_write_data *data = calldata;
1016 struct nfs_page *req = data->req;
1017 struct page *page = req->wb_page;
1018 int status = data->task.tk_status;
1019
1020 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001021 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001022 nfs_context_set_write_error(req->wb_context, status);
1023 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001024 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001027 if (nfs_write_need_commit(data)) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001028 struct inode *inode = page->mapping->host;
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001029
Trond Myklebust587142f2007-07-02 09:57:54 -04001030 spin_lock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001031 if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) {
1032 /* Do nothing we need to resend the writes */
1033 } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1034 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1035 dprintk(" defer commit\n");
1036 } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) {
1037 set_bit(PG_NEED_RESCHED, &req->wb_flags);
1038 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
1039 dprintk(" server reboot detected\n");
1040 }
Trond Myklebust587142f2007-07-02 09:57:54 -04001041 spin_unlock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001042 } else
1043 dprintk(" OK\n");
1044
1045out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (atomic_dec_and_test(&req->wb_complete))
1047 nfs_writepage_release(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001048 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Trond Myklebust788e7a82006-03-20 13:44:27 -05001051static const struct rpc_call_ops nfs_write_partial_ops = {
1052 .rpc_call_done = nfs_writeback_done_partial,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001053 .rpc_release = nfs_writeback_release_partial,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001054};
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056/*
1057 * Handle a write reply that flushes a whole page.
1058 *
1059 * FIXME: There is an inherent race with invalidate_inode_pages and
1060 * writebacks since the page->count is kept > 1 for as long
1061 * as the page has a write request pending.
1062 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001063static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001065 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001067 nfs_writeback_done(task, data);
1068}
1069
1070static void nfs_writeback_release_full(void *calldata)
1071{
1072 struct nfs_write_data *data = calldata;
1073 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001074
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 /* Update attributes as result of writeback. */
1076 while (!list_empty(&data->pages)) {
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001077 struct nfs_page *req = nfs_list_entry(data->pages.next);
1078 struct page *page = req->wb_page;
1079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 nfs_list_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Chuck Lever48186c72008-06-11 17:56:05 -04001082 dprintk("NFS: %5u write (%s/%lld %d@%lld)",
1083 data->task.tk_pid,
Trond Myklebust88be9f92007-06-05 10:42:27 -04001084 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1085 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 req->wb_bytes,
1087 (long long)req_offset(req));
1088
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001089 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001090 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001091 nfs_context_set_write_error(req->wb_context, status);
1092 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001093 goto remove_request;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001096 if (nfs_write_need_commit(data)) {
1097 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1098 nfs_mark_request_commit(req);
1099 nfs_end_page_writeback(page);
1100 dprintk(" marked for commit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 goto next;
1102 }
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001103 dprintk(" OK\n");
1104remove_request:
1105 nfs_end_page_writeback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 nfs_inode_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001108 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001110 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Trond Myklebust788e7a82006-03-20 13:44:27 -05001113static const struct rpc_call_ops nfs_write_full_ops = {
1114 .rpc_call_done = nfs_writeback_done_full,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001115 .rpc_release = nfs_writeback_release_full,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001116};
1117
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119/*
1120 * This function is called when the WRITE call is complete.
1121 */
Chuck Lever462d5b32006-03-20 13:44:32 -05001122int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 struct nfs_writeargs *argp = &data->args;
1125 struct nfs_writeres *resp = &data->res;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001126 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Chuck Levera3f565b2007-01-31 12:14:01 -05001128 dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 task->tk_pid, task->tk_status);
1130
Chuck Leverf551e442006-09-20 14:33:04 -04001131 /*
1132 * ->write_done will attempt to use post-op attributes to detect
1133 * conflicting writes by other clients. A strict interpretation
1134 * of close-to-open would allow us to continue caching even if
1135 * another writer had changed the file, but some applications
1136 * depend on tighter cache coherency when writing.
1137 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001138 status = NFS_PROTO(data->inode)->write_done(task, data);
1139 if (status != 0)
1140 return status;
Chuck Lever91d5b472006-03-20 13:44:14 -05001141 nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count);
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1144 if (resp->verf->committed < argp->stable && task->tk_status >= 0) {
1145 /* We tried a write call, but the server did not
1146 * commit data to stable storage even though we
1147 * requested it.
1148 * Note: There is a known bug in Tru64 < 5.0 in which
1149 * the server reports NFS_DATA_SYNC, but performs
1150 * NFS_FILE_SYNC. We therefore implement this checking
1151 * as a dprintk() in order to avoid filling syslog.
1152 */
1153 static unsigned long complain;
1154
1155 if (time_before(complain, jiffies)) {
Chuck Lever48186c72008-06-11 17:56:05 -04001156 dprintk("NFS: faulty NFS server %s:"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 " (committed = %d) != (stable = %d)\n",
David Howells54ceac42006-08-22 20:06:13 -04001158 NFS_SERVER(data->inode)->nfs_client->cl_hostname,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 resp->verf->committed, argp->stable);
1160 complain = jiffies + 300 * HZ;
1161 }
1162 }
1163#endif
1164 /* Is this a short write? */
1165 if (task->tk_status >= 0 && resp->count < argp->count) {
1166 static unsigned long complain;
1167
Chuck Lever91d5b472006-03-20 13:44:14 -05001168 nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE);
1169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 /* Has the server at least made some progress? */
1171 if (resp->count != 0) {
1172 /* Was this an NFSv2 write or an NFSv3 stable write? */
1173 if (resp->verf->committed != NFS_UNSTABLE) {
1174 /* Resend from where the server left off */
1175 argp->offset += resp->count;
1176 argp->pgbase += resp->count;
1177 argp->count -= resp->count;
1178 } else {
1179 /* Resend as a stable write in order to avoid
1180 * headaches in the case of a server crash.
1181 */
1182 argp->stable = NFS_FILE_SYNC;
1183 }
1184 rpc_restart_call(task);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001185 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
1187 if (time_before(complain, jiffies)) {
1188 printk(KERN_WARNING
1189 "NFS: Server wrote zero bytes, expected %u.\n",
1190 argp->count);
1191 complain = jiffies + 300 * HZ;
1192 }
1193 /* Can't do anything about it except throw an error. */
1194 task->tk_status = -EIO;
1195 }
Trond Myklebust788e7a82006-03-20 13:44:27 -05001196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
1199
1200#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001201void nfs_commitdata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Trond Myklebust383ba712008-02-19 20:04:20 -05001203 struct nfs_write_data *wdata = data;
1204
1205 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 nfs_commit_free(wdata);
1207}
1208
1209/*
1210 * Set up the argument/result storage required for the RPC call.
1211 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001212static int nfs_commit_rpcsetup(struct list_head *head,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001213 struct nfs_write_data *data,
1214 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
Trond Myklebust84115e12007-07-14 15:39:59 -04001216 struct nfs_page *first = nfs_list_entry(head->next);
1217 struct inode *inode = first->wb_context->path.dentry->d_inode;
1218 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -04001219 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -04001220 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001221 struct rpc_message msg = {
1222 .rpc_argp = &data->args,
1223 .rpc_resp = &data->res,
1224 .rpc_cred = first->wb_context->cred,
1225 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001226 struct rpc_task_setup task_setup_data = {
Trond Myklebust07737692007-10-25 18:42:54 -04001227 .task = &data->task,
Trond Myklebust84115e12007-07-14 15:39:59 -04001228 .rpc_client = NFS_CLIENT(inode),
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001229 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -04001230 .callback_ops = &nfs_commit_ops,
1231 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -05001232 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -04001233 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -04001234 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -04001235 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 /* Set up the RPC argument and reply structs
1238 * NB: take care not to mess about with data->commit et al. */
1239
1240 list_splice_init(head, &data->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 data->inode = inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001243 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 data->args.fh = NFS_FH(data->inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001246 /* Note: we always request a commit of the entire inode */
1247 data->args.offset = 0;
1248 data->args.count = 0;
Trond Myklebust383ba712008-02-19 20:04:20 -05001249 data->args.context = get_nfs_open_context(first->wb_context);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001250 data->res.count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 data->res.fattr = &data->fattr;
1252 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001253 nfs_fattr_init(&data->fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001254
1255 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001256 NFS_PROTO(inode)->commit_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Chuck Levera3f565b2007-01-31 12:14:01 -05001258 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001259
Trond Myklebust07737692007-10-25 18:42:54 -04001260 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001261 if (IS_ERR(task))
1262 return PTR_ERR(task);
1263 rpc_put_task(task);
1264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267/*
1268 * Commit dirty pages
1269 */
1270static int
Chuck Lever40859d72005-11-30 18:09:02 -05001271nfs_commit_list(struct inode *inode, struct list_head *head, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
1273 struct nfs_write_data *data;
1274 struct nfs_page *req;
1275
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001276 data = nfs_commitdata_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
1278 if (!data)
1279 goto out_bad;
1280
1281 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001282 return nfs_commit_rpcsetup(head, data, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 out_bad:
1284 while (!list_empty(head)) {
1285 req = nfs_list_entry(head->next);
1286 nfs_list_remove_request(req);
1287 nfs_mark_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001288 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001289 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1290 BDI_RECLAIMABLE);
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001291 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 }
1293 return -ENOMEM;
1294}
1295
1296/*
1297 * COMMIT call returned
1298 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001299static void nfs_commit_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001301 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Chuck Levera3f565b2007-01-31 12:14:01 -05001303 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 task->tk_pid, task->tk_status);
1305
Trond Myklebust788e7a82006-03-20 13:44:27 -05001306 /* Call the NFS version-specific code */
1307 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
1308 return;
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001309}
1310
1311static void nfs_commit_release(void *calldata)
1312{
1313 struct nfs_write_data *data = calldata;
1314 struct nfs_page *req;
1315 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 while (!list_empty(&data->pages)) {
1318 req = nfs_list_entry(data->pages.next);
1319 nfs_list_remove_request(req);
Trond Myklebuste468bae2008-06-13 13:25:22 -04001320 nfs_clear_request_commit(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Chuck Lever48186c72008-06-11 17:56:05 -04001322 dprintk("NFS: commit (%s/%lld %d@%lld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -04001323 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1324 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 req->wb_bytes,
1326 (long long)req_offset(req));
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001327 if (status < 0) {
1328 nfs_context_set_write_error(req->wb_context, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 nfs_inode_remove_request(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001330 dprintk(", error = %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 goto next;
1332 }
1333
1334 /* Okay, COMMIT succeeded, apparently. Check the verifier
1335 * returned by the server against all stored verfs. */
1336 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
1337 /* We have a match */
1338 nfs_inode_remove_request(req);
1339 dprintk(" OK\n");
1340 goto next;
1341 }
1342 /* We have a mismatch. Write the page again */
1343 dprintk(" mismatch\n");
Fred6d884e82008-03-19 11:24:38 -04001344 nfs_mark_request_dirty(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001346 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001348 nfs_commitdata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001350
1351static const struct rpc_call_ops nfs_commit_ops = {
1352 .rpc_call_done = nfs_commit_done,
1353 .rpc_release = nfs_commit_release,
1354};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001356int nfs_commit_inode(struct inode *inode, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 LIST_HEAD(head);
Trond Myklebust7d46a492006-03-20 13:44:50 -05001359 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Trond Myklebust587142f2007-07-02 09:57:54 -04001361 spin_lock(&inode->i_lock);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001362 res = nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001363 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 if (res) {
Trond Myklebust7d46a492006-03-20 13:44:50 -05001365 int error = nfs_commit_list(inode, &head, how);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001366 if (error < 0)
1367 return error;
1368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 return res;
1370}
Trond Myklebustc63c7b02007-04-02 19:29:52 -04001371#else
1372static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1373{
1374 return 0;
1375}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376#endif
1377
Trond Myklebust1c759502006-10-09 16:18:38 -04001378long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Trond Myklebust1c759502006-10-09 16:18:38 -04001380 struct inode *inode = mapping->host;
Trond Myklebustca52fec2007-04-17 17:22:13 -04001381 pgoff_t idx_start, idx_end;
Trond Myklebust1c759502006-10-09 16:18:38 -04001382 unsigned int npages = 0;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001383 LIST_HEAD(head);
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001384 int nocommit = how & FLUSH_NOCOMMIT;
Trond Myklebust3f442542006-09-17 14:46:44 -04001385 long pages, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Trond Myklebust1c759502006-10-09 16:18:38 -04001387 /* FIXME */
1388 if (wbc->range_cyclic)
1389 idx_start = 0;
1390 else {
1391 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
1392 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
1393 if (idx_end > idx_start) {
Trond Myklebustca52fec2007-04-17 17:22:13 -04001394 pgoff_t l_npages = 1 + idx_end - idx_start;
Trond Myklebust1c759502006-10-09 16:18:38 -04001395 npages = l_npages;
1396 if (sizeof(npages) != sizeof(l_npages) &&
Trond Myklebustca52fec2007-04-17 17:22:13 -04001397 (pgoff_t)npages != l_npages)
Trond Myklebust1c759502006-10-09 16:18:38 -04001398 npages = 0;
1399 }
1400 }
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001401 how &= ~FLUSH_NOCOMMIT;
Trond Myklebust587142f2007-07-02 09:57:54 -04001402 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 do {
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001404 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1405 if (ret != 0)
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001406 continue;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001407 if (nocommit)
1408 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001409 pages = nfs_scan_commit(inode, &head, idx_start, npages);
Trond Myklebust724c4392007-04-17 17:22:13 -04001410 if (pages == 0)
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001411 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001412 if (how & FLUSH_INVALIDATE) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001413 spin_unlock(&inode->i_lock);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001414 nfs_cancel_commit_list(&head);
Trond Myklebuste8e058e2006-11-15 17:31:56 -05001415 ret = pages;
Trond Myklebust587142f2007-07-02 09:57:54 -04001416 spin_lock(&inode->i_lock);
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001417 continue;
1418 }
1419 pages += nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001420 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001421 ret = nfs_commit_list(inode, &head, how);
Trond Myklebust587142f2007-07-02 09:57:54 -04001422 spin_lock(&inode->i_lock);
1423
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001424 } while (ret >= 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001425 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001426 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427}
1428
Trond Myklebust34901f72007-07-25 14:09:54 -04001429static int __nfs_write_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001430{
Trond Myklebust1c759502006-10-09 16:18:38 -04001431 int ret;
1432
Trond Myklebust34901f72007-07-25 14:09:54 -04001433 ret = nfs_writepages(mapping, wbc);
Trond Myklebust61822ab2006-12-05 00:35:42 -05001434 if (ret < 0)
1435 goto out;
Trond Myklebust34901f72007-07-25 14:09:54 -04001436 ret = nfs_sync_mapping_wait(mapping, wbc, how);
Trond Myklebusted90ef52007-07-20 13:13:28 -04001437 if (ret < 0)
1438 goto out;
1439 return 0;
Trond Myklebust61822ab2006-12-05 00:35:42 -05001440out:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001441 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
Trond Myklebust1c759502006-10-09 16:18:38 -04001442 return ret;
1443}
1444
Trond Myklebust34901f72007-07-25 14:09:54 -04001445/* Two pass sync: first using WB_SYNC_NONE, then WB_SYNC_ALL */
1446static int nfs_write_mapping(struct address_space *mapping, int how)
1447{
1448 struct writeback_control wbc = {
1449 .bdi = mapping->backing_dev_info,
Trond Myklebust72cb77f2009-03-11 14:10:30 -04001450 .sync_mode = WB_SYNC_ALL,
Trond Myklebust34901f72007-07-25 14:09:54 -04001451 .nr_to_write = LONG_MAX,
Trond Myklebustd7fb1202008-10-06 20:08:56 -04001452 .range_start = 0,
1453 .range_end = LLONG_MAX,
Trond Myklebust34901f72007-07-25 14:09:54 -04001454 .for_writepages = 1,
Trond Myklebust34901f72007-07-25 14:09:54 -04001455 };
Trond Myklebust34901f72007-07-25 14:09:54 -04001456
Trond Myklebust34901f72007-07-25 14:09:54 -04001457 return __nfs_write_mapping(mapping, &wbc, how);
1458}
1459
Trond Myklebusted90ef52007-07-20 13:13:28 -04001460/*
1461 * flush the inode to disk.
1462 */
1463int nfs_wb_all(struct inode *inode)
Trond Myklebust1c759502006-10-09 16:18:38 -04001464{
Trond Myklebusted90ef52007-07-20 13:13:28 -04001465 return nfs_write_mapping(inode->i_mapping, 0);
1466}
Trond Myklebust1c759502006-10-09 16:18:38 -04001467
Trond Myklebusted90ef52007-07-20 13:13:28 -04001468int nfs_wb_nocommit(struct inode *inode)
1469{
1470 return nfs_write_mapping(inode->i_mapping, FLUSH_NOCOMMIT);
Trond Myklebust1c759502006-10-09 16:18:38 -04001471}
1472
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001473int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1474{
1475 struct nfs_page *req;
1476 loff_t range_start = page_offset(page);
1477 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1478 struct writeback_control wbc = {
1479 .bdi = page->mapping->backing_dev_info,
1480 .sync_mode = WB_SYNC_ALL,
1481 .nr_to_write = LONG_MAX,
1482 .range_start = range_start,
1483 .range_end = range_end,
1484 };
1485 int ret = 0;
1486
1487 BUG_ON(!PageLocked(page));
1488 for (;;) {
1489 req = nfs_page_find_request(page);
1490 if (req == NULL)
1491 goto out;
Trond Myklebuste468bae2008-06-13 13:25:22 -04001492 if (test_bit(PG_CLEAN, &req->wb_flags)) {
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001493 nfs_release_request(req);
1494 break;
1495 }
1496 if (nfs_lock_request_dontget(req)) {
1497 nfs_inode_remove_request(req);
1498 /*
1499 * In case nfs_inode_remove_request has marked the
1500 * page as being dirty
1501 */
1502 cancel_dirty_page(page, PAGE_CACHE_SIZE);
1503 nfs_unlock_request(req);
1504 break;
1505 }
1506 ret = nfs_wait_on_request(req);
1507 if (ret < 0)
1508 goto out;
1509 }
1510 if (!PagePrivate(page))
1511 return 0;
1512 ret = nfs_sync_mapping_wait(page->mapping, &wbc, FLUSH_INVALIDATE);
1513out:
1514 return ret;
1515}
1516
Adrian Bunk5334eb12007-11-21 15:04:31 -08001517static int nfs_wb_page_priority(struct inode *inode, struct page *page,
1518 int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001519{
1520 loff_t range_start = page_offset(page);
1521 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001522 struct writeback_control wbc = {
1523 .bdi = page->mapping->backing_dev_info,
1524 .sync_mode = WB_SYNC_ALL,
1525 .nr_to_write = LONG_MAX,
1526 .range_start = range_start,
1527 .range_end = range_end,
1528 };
1529 int ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001530
Trond Myklebust73e33022008-04-11 16:03:54 -04001531 do {
1532 if (clear_page_dirty_for_io(page)) {
1533 ret = nfs_writepage_locked(page, &wbc);
1534 if (ret < 0)
1535 goto out_error;
1536 } else if (!PagePrivate(page))
1537 break;
1538 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001539 if (ret < 0)
Trond Myklebust73e33022008-04-11 16:03:54 -04001540 goto out_error;
1541 } while (PagePrivate(page));
1542 return 0;
1543out_error:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001544 __mark_inode_dirty(inode, I_DIRTY_PAGES);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001545 return ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001546}
1547
1548/*
1549 * Write back all requests on one page - we do this before reading it.
1550 */
1551int nfs_wb_page(struct inode *inode, struct page* page)
1552{
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001553 return nfs_wb_page_priority(inode, page, FLUSH_STABLE);
Trond Myklebust1c759502006-10-09 16:18:38 -04001554}
1555
David Howellsf7b422b2006-06-09 09:34:33 -04001556int __init nfs_init_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1559 sizeof(struct nfs_write_data),
1560 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +09001561 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 if (nfs_wdata_cachep == NULL)
1563 return -ENOMEM;
1564
Matthew Dobson93d23412006-03-26 01:37:50 -08001565 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
1566 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 if (nfs_wdata_mempool == NULL)
1568 return -ENOMEM;
1569
Matthew Dobson93d23412006-03-26 01:37:50 -08001570 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
1571 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 if (nfs_commit_mempool == NULL)
1573 return -ENOMEM;
1574
Peter Zijlstra89a09142007-03-16 13:38:26 -08001575 /*
1576 * NFS congestion size, scale with available memory.
1577 *
1578 * 64MB: 8192k
1579 * 128MB: 11585k
1580 * 256MB: 16384k
1581 * 512MB: 23170k
1582 * 1GB: 32768k
1583 * 2GB: 46340k
1584 * 4GB: 65536k
1585 * 8GB: 92681k
1586 * 16GB: 131072k
1587 *
1588 * This allows larger machines to have larger/more transfers.
1589 * Limit the default to 256M
1590 */
1591 nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
1592 if (nfs_congestion_kb > 256*1024)
1593 nfs_congestion_kb = 256*1024;
1594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 return 0;
1596}
1597
David Brownell266bee82006-06-27 12:59:15 -07001598void nfs_destroy_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
1600 mempool_destroy(nfs_commit_mempool);
1601 mempool_destroy(nfs_wdata_mempool);
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001602 kmem_cache_destroy(nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604