blob: dc62bc50469340a0872a166767b449f685c8801e [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 */
37static struct nfs_page * nfs_update_request(struct nfs_open_context*,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 struct page *,
39 unsigned int, unsigned int);
Trond Myklebustc63c7b02007-04-02 19:29:52 -040040static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc,
41 struct inode *inode, int ioflags);
Fred Isamanf8512ad2008-03-19 11:24:39 -040042static void nfs_redirty_request(struct nfs_page *req);
Trond Myklebust788e7a82006-03-20 13:44:27 -050043static const struct rpc_call_ops nfs_write_partial_ops;
44static const struct rpc_call_ops nfs_write_full_ops;
45static const struct rpc_call_ops nfs_commit_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Christoph Lametere18b8902006-12-06 20:33:20 -080047static struct kmem_cache *nfs_wdata_cachep;
Trond Myklebust3feb2d42006-03-20 13:44:37 -050048static mempool_t *nfs_wdata_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static mempool_t *nfs_commit_mempool;
50
Trond Myklebustc9d8f892008-04-15 16:56:39 -040051struct nfs_write_data *nfs_commitdata_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Christoph Lametere6b4f8d2006-12-06 20:33:14 -080053 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS);
Chuck Lever40859d72005-11-30 18:09:02 -050054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (p) {
56 memset(p, 0, sizeof(*p));
57 INIT_LIST_HEAD(&p->pages);
58 }
59 return p;
60}
61
Trond Myklebust5e4424a2008-02-25 21:53:49 -080062void nfs_commit_free(struct nfs_write_data *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Chuck Lever40859d72005-11-30 18:09:02 -050064 if (p && (p->pagevec != &p->page_array[0]))
65 kfree(p->pagevec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 mempool_free(p, nfs_commit_mempool);
67}
68
Trond Myklebust8d5658c2007-04-10 09:26:35 -040069struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050070{
Christoph Lametere6b4f8d2006-12-06 20:33:14 -080071 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS);
Trond Myklebust3feb2d42006-03-20 13:44:37 -050072
73 if (p) {
74 memset(p, 0, sizeof(*p));
75 INIT_LIST_HEAD(&p->pages);
Trond Myklebuste9f7bee2006-09-08 09:48:54 -070076 p->npages = pagecount;
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040077 if (pagecount <= ARRAY_SIZE(p->page_array))
78 p->pagevec = p->page_array;
Trond Myklebust3feb2d42006-03-20 13:44:37 -050079 else {
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040080 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
81 if (!p->pagevec) {
Trond Myklebust3feb2d42006-03-20 13:44:37 -050082 mempool_free(p, nfs_wdata_mempool);
83 p = NULL;
84 }
85 }
86 }
87 return p;
88}
89
Trond Myklebust5e4424a2008-02-25 21:53:49 -080090static void nfs_writedata_free(struct nfs_write_data *p)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050091{
92 if (p && (p->pagevec != &p->page_array[0]))
93 kfree(p->pagevec);
94 mempool_free(p, nfs_wdata_mempool);
95}
96
Trond Myklebust383ba712008-02-19 20:04:20 -050097void nfs_writedata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Trond Myklebust383ba712008-02-19 20:04:20 -050099 struct nfs_write_data *wdata = data;
100
101 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 nfs_writedata_free(wdata);
103}
104
Trond Myklebust7b159fc2007-07-25 14:09:54 -0400105static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
106{
107 ctx->error = error;
108 smp_wmb();
109 set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
110}
111
Trond Myklebust277459d2006-12-05 00:35:35 -0500112static struct nfs_page *nfs_page_find_request_locked(struct page *page)
113{
114 struct nfs_page *req = NULL;
115
116 if (PagePrivate(page)) {
117 req = (struct nfs_page *)page_private(page);
118 if (req != NULL)
Trond Myklebustc03b4022007-06-17 13:26:38 -0400119 kref_get(&req->wb_kref);
Trond Myklebust277459d2006-12-05 00:35:35 -0500120 }
121 return req;
122}
123
124static struct nfs_page *nfs_page_find_request(struct page *page)
125{
Trond Myklebust587142f2007-07-02 09:57:54 -0400126 struct inode *inode = page->mapping->host;
Trond Myklebust277459d2006-12-05 00:35:35 -0500127 struct nfs_page *req = NULL;
Trond Myklebust277459d2006-12-05 00:35:35 -0500128
Trond Myklebust587142f2007-07-02 09:57:54 -0400129 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500130 req = nfs_page_find_request_locked(page);
Trond Myklebust587142f2007-07-02 09:57:54 -0400131 spin_unlock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500132 return req;
133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* Adjust the file length if we're writing beyond the end */
136static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
137{
138 struct inode *inode = page->mapping->host;
139 loff_t end, i_size = i_size_read(inode);
Trond Myklebustca52fec2007-04-17 17:22:13 -0400140 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 if (i_size > 0 && page->index < end_index)
143 return;
144 end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count);
145 if (i_size >= end)
146 return;
Chuck Lever91d5b472006-03-20 13:44:14 -0500147 nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 i_size_write(inode, end);
149}
150
Trond Myklebusta301b772007-02-06 11:07:15 -0800151/* A writeback failed: mark the page as bad, and invalidate the page cache */
152static void nfs_set_pageerror(struct page *page)
153{
154 SetPageError(page);
155 nfs_zap_mapping(page->mapping->host, page->mapping);
156}
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/* We can set the PG_uptodate flag if we see that a write request
159 * covers the full page.
160 */
161static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int count)
162{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (PageUptodate(page))
164 return;
165 if (base != 0)
166 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500167 if (count != nfs_page_length(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500169 SetPageUptodate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Trond Myklebuste21195a2006-12-05 00:35:39 -0500172static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 unsigned int offset, unsigned int count)
174{
175 struct nfs_page *req;
Trond Myklebuste21195a2006-12-05 00:35:39 -0500176 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Trond Myklebuste21195a2006-12-05 00:35:39 -0500178 for (;;) {
179 req = nfs_update_request(ctx, page, offset, count);
180 if (!IS_ERR(req))
181 break;
182 ret = PTR_ERR(req);
183 if (ret != -EBUSY)
184 return ret;
185 ret = nfs_wb_page(page->mapping->host, page);
186 if (ret != 0)
187 return ret;
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* Update file length */
190 nfs_grow_file(page, offset, count);
Trond Myklebustacee4782008-01-22 17:13:07 -0500191 nfs_clear_page_tag_locked(req);
Trond Myklebustabd3e642006-01-03 09:55:02 +0100192 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195static int wb_priority(struct writeback_control *wbc)
196{
197 if (wbc->for_reclaim)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400198 return FLUSH_HIGHPRI | FLUSH_STABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (wbc->for_kupdate)
200 return FLUSH_LOWPRI;
201 return 0;
202}
203
204/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800205 * NFS congestion control
206 */
207
208int nfs_congestion_kb;
209
210#define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10))
211#define NFS_CONGESTION_OFF_THRESH \
212 (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2))
213
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400214static int nfs_set_page_writeback(struct page *page)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800215{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400216 int ret = test_set_page_writeback(page);
217
218 if (!ret) {
Peter Zijlstra89a09142007-03-16 13:38:26 -0800219 struct inode *inode = page->mapping->host;
220 struct nfs_server *nfss = NFS_SERVER(inode);
221
Peter Zijlstra277866a2007-05-08 00:35:12 -0700222 if (atomic_long_inc_return(&nfss->writeback) >
Peter Zijlstra89a09142007-03-16 13:38:26 -0800223 NFS_CONGESTION_ON_THRESH)
224 set_bdi_congested(&nfss->backing_dev_info, WRITE);
225 }
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400226 return ret;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800227}
228
229static void nfs_end_page_writeback(struct page *page)
230{
231 struct inode *inode = page->mapping->host;
232 struct nfs_server *nfss = NFS_SERVER(inode);
233
234 end_page_writeback(page);
Peter Zijlstrac4dc4be2007-10-16 23:25:41 -0700235 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800236 clear_bdi_congested(&nfss->backing_dev_info, WRITE);
Peter Zijlstra89a09142007-03-16 13:38:26 -0800237}
238
239/*
Trond Myklebuste261f512006-12-05 00:35:41 -0500240 * Find an associated nfs write request, and prepare to flush it out
Trond Myklebust9cccef92007-07-22 17:09:05 -0400241 * May return an error if the user signalled nfs_wait_on_request().
Trond Myklebuste261f512006-12-05 00:35:41 -0500242 */
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400243static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
244 struct page *page)
Trond Myklebuste261f512006-12-05 00:35:41 -0500245{
Trond Myklebust587142f2007-07-02 09:57:54 -0400246 struct inode *inode = page->mapping->host;
Trond Myklebuste261f512006-12-05 00:35:41 -0500247 struct nfs_page *req;
Trond Myklebuste261f512006-12-05 00:35:41 -0500248 int ret;
249
Trond Myklebust587142f2007-07-02 09:57:54 -0400250 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500251 for(;;) {
252 req = nfs_page_find_request_locked(page);
253 if (req == NULL) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400254 spin_unlock(&inode->i_lock);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400255 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500256 }
Trond Myklebustacee4782008-01-22 17:13:07 -0500257 if (nfs_set_page_tag_locked(req))
Trond Myklebuste261f512006-12-05 00:35:41 -0500258 break;
259 /* Note: If we hold the page lock, as is the case in nfs_writepage,
Trond Myklebustacee4782008-01-22 17:13:07 -0500260 * then the call to nfs_set_page_tag_locked() will always
Trond Myklebuste261f512006-12-05 00:35:41 -0500261 * succeed provided that someone hasn't already marked the
262 * request as dirty (in which case we don't care).
263 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400264 spin_unlock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500265 ret = nfs_wait_on_request(req);
266 nfs_release_request(req);
267 if (ret != 0)
268 return ret;
Trond Myklebust587142f2007-07-02 09:57:54 -0400269 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500270 }
Trond Myklebust612c9382007-04-20 16:12:45 -0400271 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
272 /* This request is marked for commit */
Trond Myklebust587142f2007-07-02 09:57:54 -0400273 spin_unlock(&inode->i_lock);
Trond Myklebustacee4782008-01-22 17:13:07 -0500274 nfs_clear_page_tag_locked(req);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400275 nfs_pageio_complete(pgio);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400276 return 0;
Trond Myklebust612c9382007-04-20 16:12:45 -0400277 }
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400278 if (nfs_set_page_writeback(page) != 0) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400279 spin_unlock(&inode->i_lock);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400280 BUG();
281 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400282 spin_unlock(&inode->i_lock);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400283 if (!nfs_pageio_add_request(pgio, req)) {
284 nfs_redirty_request(req);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400285 return pgio->pg_error;
286 }
Trond Myklebust9cccef92007-07-22 17:09:05 -0400287 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500288}
289
Trond Myklebustf758c8852007-07-22 19:27:32 -0400290static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
291{
292 struct inode *inode = page->mapping->host;
293
294 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
295 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
296
297 nfs_pageio_cond_complete(pgio, page->index);
298 return nfs_page_async_flush(pgio, page);
299}
300
Trond Myklebuste261f512006-12-05 00:35:41 -0500301/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * Write an mmapped page to the server.
303 */
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500304static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400306 struct nfs_pageio_descriptor pgio;
Trond Myklebuste261f512006-12-05 00:35:41 -0500307 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Trond Myklebustf758c8852007-07-22 19:27:32 -0400309 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc));
310 err = nfs_do_writepage(page, wbc, &pgio);
311 nfs_pageio_complete(&pgio);
312 if (err < 0)
313 return err;
314 if (pgio.pg_error < 0)
315 return pgio.pg_error;
316 return 0;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500317}
318
319int nfs_writepage(struct page *page, struct writeback_control *wbc)
320{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400321 int ret;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500322
Trond Myklebustf758c8852007-07-22 19:27:32 -0400323 ret = nfs_writepage_locked(page, wbc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 unlock_page(page);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400325 return ret;
326}
327
328static int nfs_writepages_callback(struct page *page, struct writeback_control *wbc, void *data)
329{
330 int ret;
331
332 ret = nfs_do_writepage(page, wbc, data);
333 unlock_page(page);
334 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
338{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 struct inode *inode = mapping->host;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400340 struct nfs_pageio_descriptor pgio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 int err;
342
Chuck Lever91d5b472006-03-20 13:44:14 -0500343 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
344
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400345 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc));
Trond Myklebustf758c8852007-07-22 19:27:32 -0400346 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400347 nfs_pageio_complete(&pgio);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400348 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return err;
Trond Myklebustf758c8852007-07-22 19:27:32 -0400350 if (pgio.pg_error < 0)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400351 return pgio.pg_error;
352 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355/*
356 * Insert a write request into an inode
357 */
Nick Piggin27852592008-02-04 23:48:37 -0800358static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360 struct nfs_inode *nfsi = NFS_I(inode);
361 int error;
362
363 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
Nick Piggin27852592008-02-04 23:48:37 -0800364 BUG_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (!nfsi->npages) {
366 igrab(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (nfs_have_delegation(inode, FMODE_WRITE))
368 nfsi->change_attr++;
369 }
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500370 SetPagePrivate(req->wb_page);
Trond Myklebust277459d2006-12-05 00:35:35 -0500371 set_page_private(req->wb_page, (unsigned long)req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 nfsi->npages++;
Trond Myklebustc03b4022007-06-17 13:26:38 -0400373 kref_get(&req->wb_kref);
Nick Piggin27852592008-02-04 23:48:37 -0800374 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
375 NFS_PAGE_TAG_LOCKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800379 * Remove a write request from an inode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 */
381static void nfs_inode_remove_request(struct nfs_page *req)
382{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400383 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 struct nfs_inode *nfsi = NFS_I(inode);
385
386 BUG_ON (!NFS_WBACK_BUSY(req));
387
Trond Myklebust587142f2007-07-02 09:57:54 -0400388 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500389 set_page_private(req->wb_page, 0);
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500390 ClearPagePrivate(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
392 nfsi->npages--;
393 if (!nfsi->npages) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400394 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 iput(inode);
396 } else
Trond Myklebust587142f2007-07-02 09:57:54 -0400397 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 nfs_clear_request(req);
399 nfs_release_request(req);
400}
401
Trond Myklebust61822ab2006-12-05 00:35:42 -0500402static void
Fred6d884e82008-03-19 11:24:38 -0400403nfs_mark_request_dirty(struct nfs_page *req)
Trond Myklebust61822ab2006-12-05 00:35:42 -0500404{
Trond Myklebust61822ab2006-12-05 00:35:42 -0500405 __set_page_dirty_nobuffers(req->wb_page);
406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408/*
409 * Check if a request is dirty
410 */
411static inline int
412nfs_dirty_request(struct nfs_page *req)
413{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400414 struct page *page = req->wb_page;
415
Trond Myklebust612c9382007-04-20 16:12:45 -0400416 if (page == NULL || test_bit(PG_NEED_COMMIT, &req->wb_flags))
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400417 return 0;
Fred Isaman38def502008-05-01 20:03:22 +0300418 return !PageWriteback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
422/*
423 * Add a request to the inode's commit list.
424 */
425static void
426nfs_mark_request_commit(struct nfs_page *req)
427{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400428 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 struct nfs_inode *nfsi = NFS_I(inode);
430
Trond Myklebust587142f2007-07-02 09:57:54 -0400431 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 nfsi->ncommit++;
Trond Myklebust612c9382007-04-20 16:12:45 -0400433 set_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Trond Myklebust5c369682007-06-17 15:27:42 -0400434 radix_tree_tag_set(&nfsi->nfs_page_tree,
435 req->wb_index,
436 NFS_PAGE_TAG_COMMIT);
Trond Myklebust587142f2007-07-02 09:57:54 -0400437 spin_unlock(&inode->i_lock);
Christoph Lameterfd39fc82006-06-30 01:55:40 -0700438 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700439 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
Trond Myklebusta1803042006-12-05 00:45:19 -0500440 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400442
443static inline
444int nfs_write_need_commit(struct nfs_write_data *data)
445{
446 return data->verf.committed != NFS_FILE_SYNC;
447}
448
449static inline
450int nfs_reschedule_unstable_write(struct nfs_page *req)
451{
Trond Myklebust612c9382007-04-20 16:12:45 -0400452 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400453 nfs_mark_request_commit(req);
454 return 1;
455 }
456 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
Fred6d884e82008-03-19 11:24:38 -0400457 nfs_mark_request_dirty(req);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400458 return 1;
459 }
460 return 0;
461}
462#else
463static inline void
464nfs_mark_request_commit(struct nfs_page *req)
465{
466}
467
468static inline
469int nfs_write_need_commit(struct nfs_write_data *data)
470{
471 return 0;
472}
473
474static inline
475int nfs_reschedule_unstable_write(struct nfs_page *req)
476{
477 return 0;
478}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#endif
480
481/*
482 * Wait for a request to complete.
483 *
Matthew Wilcox150030b2007-12-06 16:24:39 -0500484 * Interruptible by fatal signals only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 */
Trond Myklebustca52fec2007-04-17 17:22:13 -0400486static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
488 struct nfs_inode *nfsi = NFS_I(inode);
489 struct nfs_page *req;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400490 pgoff_t idx_end, next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 unsigned int res = 0;
492 int error;
493
494 if (npages == 0)
495 idx_end = ~0;
496 else
497 idx_end = idx_start + npages - 1;
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 next = idx_start;
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400500 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 -0700501 if (req->wb_index > idx_end)
502 break;
503
504 next = req->wb_index + 1;
Trond Myklebustc6a556b2005-06-22 17:16:30 +0000505 BUG_ON(!NFS_WBACK_BUSY(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Trond Myklebustc03b4022007-06-17 13:26:38 -0400507 kref_get(&req->wb_kref);
Trond Myklebust587142f2007-07-02 09:57:54 -0400508 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 error = nfs_wait_on_request(req);
510 nfs_release_request(req);
Trond Myklebust587142f2007-07-02 09:57:54 -0400511 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (error < 0)
513 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 res++;
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 return res;
517}
518
Trond Myklebust83715ad2006-07-05 13:17:12 -0400519static void nfs_cancel_commit_list(struct list_head *head)
520{
521 struct nfs_page *req;
522
523 while(!list_empty(head)) {
524 req = nfs_list_entry(head->next);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700525 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700526 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
527 BDI_RECLAIMABLE);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400528 nfs_list_remove_request(req);
Trond Myklebust612c9382007-04-20 16:12:45 -0400529 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400530 nfs_inode_remove_request(req);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700531 nfs_unlock_request(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400532 }
533}
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
536/*
537 * nfs_scan_commit - Scan an inode for commit requests
538 * @inode: NFS inode to scan
539 * @dst: destination list
540 * @idx_start: lower bound of page->index to scan.
541 * @npages: idx_start + npages sets the upper bound to scan.
542 *
543 * Moves requests from the inode's 'commit' request list.
544 * The requests are *not* checked to ensure that they form a contiguous set.
545 */
546static int
Trond Myklebustca52fec2007-04-17 17:22:13 -0400547nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 struct nfs_inode *nfsi = NFS_I(inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000550 int res = 0;
551
552 if (nfsi->ncommit != 0) {
Trond Myklebust5c369682007-06-17 15:27:42 -0400553 res = nfs_scan_list(nfsi, dst, idx_start, npages,
554 NFS_PAGE_TAG_COMMIT);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000555 nfsi->ncommit -= res;
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return res;
558}
Trond Myklebustc42de9d2006-03-20 13:44:51 -0500559#else
Trond Myklebustca52fec2007-04-17 17:22:13 -0400560static 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 -0500561{
562 return 0;
563}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#endif
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*
567 * Try to update any existing write request, or create one if there is none.
568 * In order to match, the request's credentials must match those of
569 * the calling process.
570 *
571 * Note: Should always be called with the Page Lock held!
572 */
573static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx,
Trond Myklebuste21195a2006-12-05 00:35:39 -0500574 struct page *page, unsigned int offset, unsigned int bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Peter Zijlstra89a09142007-03-16 13:38:26 -0800576 struct address_space *mapping = page->mapping;
577 struct inode *inode = mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 struct nfs_page *req, *new = NULL;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400579 pgoff_t rqend, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 end = offset + bytes;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 for (;;) {
584 /* Loop over all inode entries and see if we find
585 * A request for the page we wish to update
586 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400587 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500588 req = nfs_page_find_request_locked(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 if (req) {
Trond Myklebustacee4782008-01-22 17:13:07 -0500590 if (!nfs_set_page_tag_locked(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 int error;
Trond Myklebust277459d2006-12-05 00:35:35 -0500592
Trond Myklebust587142f2007-07-02 09:57:54 -0400593 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 error = nfs_wait_on_request(req);
595 nfs_release_request(req);
Neil Brown1dd594b2006-03-20 13:44:04 -0500596 if (error < 0) {
Nick Piggin27852592008-02-04 23:48:37 -0800597 if (new) {
598 radix_tree_preload_end();
Neil Brown1dd594b2006-03-20 13:44:04 -0500599 nfs_release_request(new);
Nick Piggin27852592008-02-04 23:48:37 -0800600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 return ERR_PTR(error);
Neil Brown1dd594b2006-03-20 13:44:04 -0500602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 continue;
604 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400605 spin_unlock(&inode->i_lock);
Nick Piggin27852592008-02-04 23:48:37 -0800606 if (new) {
607 radix_tree_preload_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 nfs_release_request(new);
Nick Piggin27852592008-02-04 23:48:37 -0800609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 break;
611 }
612
613 if (new) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 nfs_lock_request_dontget(new);
Nick Piggin27852592008-02-04 23:48:37 -0800615 nfs_inode_add_request(inode, new);
Trond Myklebust587142f2007-07-02 09:57:54 -0400616 spin_unlock(&inode->i_lock);
Nick Piggin27852592008-02-04 23:48:37 -0800617 radix_tree_preload_end();
Trond Myklebust61e930a2007-10-18 17:08:05 -0400618 req = new;
619 goto zero_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400621 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 new = nfs_create_request(ctx, inode, page, offset, bytes);
624 if (IS_ERR(new))
625 return new;
Trond Myklebustf3d47a32008-06-05 15:17:39 -0400626 if (radix_tree_preload(GFP_NOFS)) {
627 nfs_release_request(new);
628 return ERR_PTR(-ENOMEM);
629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
632 /* We have a request for our page.
633 * If the creds don't match, or the
634 * page addresses don't match,
635 * tell the caller to wait on the conflicting
636 * request.
637 */
638 rqend = req->wb_offset + req->wb_bytes;
639 if (req->wb_context != ctx
640 || req->wb_page != page
641 || !nfs_dirty_request(req)
642 || offset > rqend || end < req->wb_offset) {
Trond Myklebustacee4782008-01-22 17:13:07 -0500643 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return ERR_PTR(-EBUSY);
645 }
646
647 /* Okay, the request matches. Update the region */
648 if (offset < req->wb_offset) {
649 req->wb_offset = offset;
650 req->wb_pgbase = offset;
Trond Myklebust61e930a2007-10-18 17:08:05 -0400651 req->wb_bytes = max(end, rqend) - req->wb_offset;
652 goto zero_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654
655 if (end > rqend)
656 req->wb_bytes = end - req->wb_offset;
657
658 return req;
Trond Myklebust61e930a2007-10-18 17:08:05 -0400659zero_page:
660 /* If this page might potentially be marked as up to date,
661 * then we need to zero any uninitalised data. */
662 if (req->wb_pgbase == 0 && req->wb_bytes != PAGE_CACHE_SIZE
663 && !PageUptodate(req->wb_page))
Christoph Lametereebd2aa2008-02-04 22:28:29 -0800664 zero_user_segment(req->wb_page, req->wb_bytes, PAGE_CACHE_SIZE);
Trond Myklebust61e930a2007-10-18 17:08:05 -0400665 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668int nfs_flush_incompatible(struct file *file, struct page *page)
669{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400670 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 struct nfs_page *req;
Trond Myklebust1a545332006-12-05 00:35:40 -0500672 int do_flush, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 /*
674 * Look for a request corresponding to this page. If there
675 * is one, and it belongs to another file, we flush it out
676 * before we try to copy anything into the page. Do this
677 * due to the lack of an ACCESS-type call in NFSv2.
678 * Also do the same if we find a request from an existing
679 * dropped page.
680 */
Trond Myklebust1a545332006-12-05 00:35:40 -0500681 do {
682 req = nfs_page_find_request(page);
683 if (req == NULL)
684 return 0;
685 do_flush = req->wb_page != page || req->wb_context != ctx
Trond Myklebuste261f512006-12-05 00:35:41 -0500686 || !nfs_dirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 nfs_release_request(req);
Trond Myklebust1a545332006-12-05 00:35:40 -0500688 if (!do_flush)
689 return 0;
690 status = nfs_wb_page(page->mapping->host, page);
691 } while (status == 0);
692 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695/*
Trond Myklebust5d47a352008-02-07 17:24:07 -0500696 * If the page cache is marked as unsafe or invalid, then we can't rely on
697 * the PageUptodate() flag. In this case, we will need to turn off
698 * write optimisations that depend on the page contents being correct.
699 */
700static int nfs_write_pageuptodate(struct page *page, struct inode *inode)
701{
702 return PageUptodate(page) &&
703 !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA));
704}
705
706/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 * Update and possibly write a cached page of an NFS file.
708 *
709 * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
710 * things with a page scheduled for an RPC call (e.g. invalidate it).
711 */
712int nfs_updatepage(struct file *file, struct page *page,
713 unsigned int offset, unsigned int count)
714{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400715 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 struct inode *inode = page->mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 int status = 0;
718
Chuck Lever91d5b472006-03-20 13:44:14 -0500719 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n",
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800722 file->f_path.dentry->d_parent->d_name.name,
723 file->f_path.dentry->d_name.name, count,
Chuck Lever0bbacc42005-11-01 16:53:32 -0500724 (long long)(page_offset(page) +offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* If we're not using byte range locks, and we know the page
Trond Myklebust5d47a352008-02-07 17:24:07 -0500727 * is up to date, it may be more efficient to extend the write
728 * to cover the entire page in order to avoid fragmentation
729 * inefficiencies.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 */
Trond Myklebust5d47a352008-02-07 17:24:07 -0500731 if (nfs_write_pageuptodate(page, inode) &&
732 inode->i_flock == NULL &&
Trond Myklebust4b5621f2008-02-25 15:56:29 -0800733 !(file->f_flags & O_SYNC)) {
Trond Myklebust49a70f22006-12-05 00:35:38 -0500734 count = max(count + offset, nfs_page_length(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
Trond Myklebuste21195a2006-12-05 00:35:39 -0500738 status = nfs_writepage_setup(ctx, page, offset, count);
Trond Myklebust03fa9e82008-06-05 16:02:35 -0400739 if (status < 0)
740 nfs_set_pageerror(page);
741 else
742 __set_page_dirty_nobuffers(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 dprintk("NFS: nfs_updatepage returns %d (isize %Ld)\n",
745 status, (long long)i_size_read(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 return status;
747}
748
749static void nfs_writepage_release(struct nfs_page *req)
750{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Trond Myklebust44dd1512007-05-19 11:58:03 -0400752 if (PageError(req->wb_page)) {
753 nfs_end_page_writeback(req->wb_page);
754 nfs_inode_remove_request(req);
755 } else if (!nfs_reschedule_unstable_write(req)) {
756 /* Set the PG_uptodate flag */
757 nfs_mark_uptodate(req->wb_page, req->wb_pgbase, req->wb_bytes);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400758 nfs_end_page_writeback(req->wb_page);
759 nfs_inode_remove_request(req);
760 } else
761 nfs_end_page_writeback(req->wb_page);
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400762 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Trond Myklebust3ff75762007-07-14 15:40:00 -0400765static int flush_task_priority(int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
768 case FLUSH_HIGHPRI:
769 return RPC_PRIORITY_HIGH;
770 case FLUSH_LOWPRI:
771 return RPC_PRIORITY_LOW;
772 }
773 return RPC_PRIORITY_NORMAL;
774}
775
776/*
777 * Set up the argument/result storage required for the RPC call.
778 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400779static int nfs_write_rpcsetup(struct nfs_page *req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 struct nfs_write_data *data,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500781 const struct rpc_call_ops *call_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 unsigned int count, unsigned int offset,
783 int how)
784{
Trond Myklebust84115e12007-07-14 15:39:59 -0400785 struct inode *inode = req->wb_context->path.dentry->d_inode;
786 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -0400787 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -0400788 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400789 struct rpc_message msg = {
790 .rpc_argp = &data->args,
791 .rpc_resp = &data->res,
792 .rpc_cred = req->wb_context->cred,
793 };
Trond Myklebust84115e12007-07-14 15:39:59 -0400794 struct rpc_task_setup task_setup_data = {
795 .rpc_client = NFS_CLIENT(inode),
Trond Myklebust07737692007-10-25 18:42:54 -0400796 .task = &data->task,
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400797 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -0400798 .callback_ops = call_ops,
799 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -0500800 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -0400801 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -0400802 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -0400803 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 /* Set up the RPC argument and reply structs
806 * NB: take care not to mess about with data->commit et al. */
807
808 data->req = req;
Trond Myklebust88be9f92007-06-05 10:42:27 -0400809 data->inode = inode = req->wb_context->path.dentry->d_inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400810 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 data->args.fh = NFS_FH(inode);
813 data->args.offset = req_offset(req) + offset;
814 data->args.pgbase = req->wb_pgbase + offset;
815 data->args.pages = data->pagevec;
816 data->args.count = count;
Trond Myklebust383ba712008-02-19 20:04:20 -0500817 data->args.context = get_nfs_open_context(req->wb_context);
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400818 data->args.stable = NFS_UNSTABLE;
819 if (how & FLUSH_STABLE) {
820 data->args.stable = NFS_DATA_SYNC;
821 if (!NFS_I(inode)->ncommit)
822 data->args.stable = NFS_FILE_SYNC;
823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 data->res.fattr = &data->fattr;
826 data->res.count = count;
827 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400828 nfs_fattr_init(&data->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Trond Myklebust788e7a82006-03-20 13:44:27 -0500830 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400831 NFS_PROTO(inode)->write_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Chuck Levera3f565b2007-01-31 12:14:01 -0500833 dprintk("NFS: %5u initiated write call "
834 "(req %s/%Ld, %u bytes @ offset %Lu)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500835 data->task.tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 inode->i_sb->s_id,
837 (long long)NFS_FILEID(inode),
838 count,
839 (unsigned long long)data->args.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Trond Myklebust07737692007-10-25 18:42:54 -0400841 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400842 if (IS_ERR(task))
843 return PTR_ERR(task);
844 rpc_put_task(task);
845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Fred6d884e82008-03-19 11:24:38 -0400848/* If a nfs_flush_* function fails, it should remove reqs from @head and
849 * call this on each, which will prepare them to be retried on next
850 * writeback using standard nfs.
851 */
852static void nfs_redirty_request(struct nfs_page *req)
853{
854 nfs_mark_request_dirty(req);
855 nfs_end_page_writeback(req->wb_page);
856 nfs_clear_page_tag_locked(req);
857}
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859/*
860 * Generate multiple small requests to write out a single
861 * contiguous dirty area on one page.
862 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400863static 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 -0700864{
865 struct nfs_page *req = nfs_list_entry(head->next);
866 struct page *page = req->wb_page;
867 struct nfs_write_data *data;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700868 size_t wsize = NFS_SERVER(inode)->wsize, nbytes;
869 unsigned int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 int requests = 0;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400871 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 LIST_HEAD(list);
873
874 nfs_list_remove_request(req);
875
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400876 nbytes = count;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700877 do {
878 size_t len = min(nbytes, wsize);
879
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400880 data = nfs_writedata_alloc(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (!data)
882 goto out_bad;
883 list_add(&data->pages, &list);
884 requests++;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700885 nbytes -= len;
886 } while (nbytes != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 atomic_set(&req->wb_complete, requests);
888
889 ClearPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 offset = 0;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400891 nbytes = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 do {
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400893 int ret2;
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 data = list_entry(list.next, struct nfs_write_data, pages);
896 list_del_init(&data->pages);
897
898 data->pagevec[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400900 if (nbytes < wsize)
901 wsize = nbytes;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400902 ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops,
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400903 wsize, offset, how);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400904 if (ret == 0)
905 ret = ret2;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400906 offset += wsize;
907 nbytes -= wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 } while (nbytes != 0);
909
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400910 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912out_bad:
913 while (!list_empty(&list)) {
914 data = list_entry(list.next, struct nfs_write_data, pages);
915 list_del(&data->pages);
Trond Myklebust8aca67f2006-11-13 16:23:44 -0500916 nfs_writedata_release(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
Trond Myklebust61822ab2006-12-05 00:35:42 -0500918 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 return -ENOMEM;
920}
921
922/*
923 * Create an RPC task for the given write request and kick it.
924 * The page must have been locked by the caller.
925 *
926 * It may happen that the page we're passed is not marked dirty.
927 * This is the case if nfs_updatepage detects a conflicting request
928 * that has been written but not committed.
929 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400930static 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 -0700931{
932 struct nfs_page *req;
933 struct page **pages;
934 struct nfs_write_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400936 data = nfs_writedata_alloc(npages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (!data)
938 goto out_bad;
939
940 pages = data->pagevec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 while (!list_empty(head)) {
942 req = nfs_list_entry(head->next);
943 nfs_list_remove_request(req);
944 nfs_list_add_request(req, &data->pages);
945 ClearPageError(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 *pages++ = req->wb_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 req = nfs_list_entry(data->pages.next);
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400951 return nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 out_bad:
953 while (!list_empty(head)) {
Trond Myklebust10afec92007-05-14 17:16:04 -0400954 req = nfs_list_entry(head->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 nfs_list_remove_request(req);
Trond Myklebust61822ab2006-12-05 00:35:42 -0500956 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958 return -ENOMEM;
959}
960
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400961static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
962 struct inode *inode, int ioflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
Chuck Leverbf4285e2007-12-20 14:54:57 -0500964 size_t wsize = NFS_SERVER(inode)->wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400966 if (wsize < PAGE_CACHE_SIZE)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400967 nfs_pageio_init(pgio, inode, nfs_flush_multi, wsize, ioflags);
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400968 else
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400969 nfs_pageio_init(pgio, inode, nfs_flush_one, wsize, ioflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
972/*
973 * Handle a write reply that flushed part of a page.
974 */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500975static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Trond Myklebust788e7a82006-03-20 13:44:27 -0500977 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 struct nfs_page *req = data->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 dprintk("NFS: write (%s/%Ld %d@%Ld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -0400981 req->wb_context->path.dentry->d_inode->i_sb->s_id,
982 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 req->wb_bytes,
984 (long long)req_offset(req));
985
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400986 nfs_writeback_done(task, data);
987}
Trond Myklebust788e7a82006-03-20 13:44:27 -0500988
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400989static void nfs_writeback_release_partial(void *calldata)
990{
991 struct nfs_write_data *data = calldata;
992 struct nfs_page *req = data->req;
993 struct page *page = req->wb_page;
994 int status = data->task.tk_status;
995
996 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -0800997 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400998 nfs_context_set_write_error(req->wb_context, status);
999 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001000 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001003 if (nfs_write_need_commit(data)) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001004 struct inode *inode = page->mapping->host;
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001005
Trond Myklebust587142f2007-07-02 09:57:54 -04001006 spin_lock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001007 if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) {
1008 /* Do nothing we need to resend the writes */
1009 } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1010 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1011 dprintk(" defer commit\n");
1012 } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) {
1013 set_bit(PG_NEED_RESCHED, &req->wb_flags);
1014 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
1015 dprintk(" server reboot detected\n");
1016 }
Trond Myklebust587142f2007-07-02 09:57:54 -04001017 spin_unlock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001018 } else
1019 dprintk(" OK\n");
1020
1021out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (atomic_dec_and_test(&req->wb_complete))
1023 nfs_writepage_release(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001024 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025}
1026
Trond Myklebust788e7a82006-03-20 13:44:27 -05001027static const struct rpc_call_ops nfs_write_partial_ops = {
1028 .rpc_call_done = nfs_writeback_done_partial,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001029 .rpc_release = nfs_writeback_release_partial,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001030};
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032/*
1033 * Handle a write reply that flushes a whole page.
1034 *
1035 * FIXME: There is an inherent race with invalidate_inode_pages and
1036 * writebacks since the page->count is kept > 1 for as long
1037 * as the page has a write request pending.
1038 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001039static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001041 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001043 nfs_writeback_done(task, data);
1044}
1045
1046static void nfs_writeback_release_full(void *calldata)
1047{
1048 struct nfs_write_data *data = calldata;
1049 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 /* Update attributes as result of writeback. */
1052 while (!list_empty(&data->pages)) {
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001053 struct nfs_page *req = nfs_list_entry(data->pages.next);
1054 struct page *page = req->wb_page;
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 nfs_list_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 dprintk("NFS: write (%s/%Ld %d@%Ld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -04001059 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1060 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 req->wb_bytes,
1062 (long long)req_offset(req));
1063
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001064 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001065 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001066 nfs_context_set_write_error(req->wb_context, status);
1067 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001068 goto remove_request;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001071 if (nfs_write_need_commit(data)) {
1072 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1073 nfs_mark_request_commit(req);
1074 nfs_end_page_writeback(page);
1075 dprintk(" marked for commit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 goto next;
1077 }
Trond Myklebust44dd1512007-05-19 11:58:03 -04001078 /* Set the PG_uptodate flag? */
1079 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001080 dprintk(" OK\n");
1081remove_request:
1082 nfs_end_page_writeback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 nfs_inode_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001085 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001087 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Trond Myklebust788e7a82006-03-20 13:44:27 -05001090static const struct rpc_call_ops nfs_write_full_ops = {
1091 .rpc_call_done = nfs_writeback_done_full,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001092 .rpc_release = nfs_writeback_release_full,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001093};
1094
1095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096/*
1097 * This function is called when the WRITE call is complete.
1098 */
Chuck Lever462d5b32006-03-20 13:44:32 -05001099int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 struct nfs_writeargs *argp = &data->args;
1102 struct nfs_writeres *resp = &data->res;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001103 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Chuck Levera3f565b2007-01-31 12:14:01 -05001105 dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 task->tk_pid, task->tk_status);
1107
Chuck Leverf551e442006-09-20 14:33:04 -04001108 /*
1109 * ->write_done will attempt to use post-op attributes to detect
1110 * conflicting writes by other clients. A strict interpretation
1111 * of close-to-open would allow us to continue caching even if
1112 * another writer had changed the file, but some applications
1113 * depend on tighter cache coherency when writing.
1114 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001115 status = NFS_PROTO(data->inode)->write_done(task, data);
1116 if (status != 0)
1117 return status;
Chuck Lever91d5b472006-03-20 13:44:14 -05001118 nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count);
1119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1121 if (resp->verf->committed < argp->stable && task->tk_status >= 0) {
1122 /* We tried a write call, but the server did not
1123 * commit data to stable storage even though we
1124 * requested it.
1125 * Note: There is a known bug in Tru64 < 5.0 in which
1126 * the server reports NFS_DATA_SYNC, but performs
1127 * NFS_FILE_SYNC. We therefore implement this checking
1128 * as a dprintk() in order to avoid filling syslog.
1129 */
1130 static unsigned long complain;
1131
1132 if (time_before(complain, jiffies)) {
1133 dprintk("NFS: faulty NFS server %s:"
1134 " (committed = %d) != (stable = %d)\n",
David Howells54ceac42006-08-22 20:06:13 -04001135 NFS_SERVER(data->inode)->nfs_client->cl_hostname,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 resp->verf->committed, argp->stable);
1137 complain = jiffies + 300 * HZ;
1138 }
1139 }
1140#endif
1141 /* Is this a short write? */
1142 if (task->tk_status >= 0 && resp->count < argp->count) {
1143 static unsigned long complain;
1144
Chuck Lever91d5b472006-03-20 13:44:14 -05001145 nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE);
1146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 /* Has the server at least made some progress? */
1148 if (resp->count != 0) {
1149 /* Was this an NFSv2 write or an NFSv3 stable write? */
1150 if (resp->verf->committed != NFS_UNSTABLE) {
1151 /* Resend from where the server left off */
1152 argp->offset += resp->count;
1153 argp->pgbase += resp->count;
1154 argp->count -= resp->count;
1155 } else {
1156 /* Resend as a stable write in order to avoid
1157 * headaches in the case of a server crash.
1158 */
1159 argp->stable = NFS_FILE_SYNC;
1160 }
1161 rpc_restart_call(task);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001162 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164 if (time_before(complain, jiffies)) {
1165 printk(KERN_WARNING
1166 "NFS: Server wrote zero bytes, expected %u.\n",
1167 argp->count);
1168 complain = jiffies + 300 * HZ;
1169 }
1170 /* Can't do anything about it except throw an error. */
1171 task->tk_status = -EIO;
1172 }
Trond Myklebust788e7a82006-03-20 13:44:27 -05001173 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
1176
1177#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001178void nfs_commitdata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Trond Myklebust383ba712008-02-19 20:04:20 -05001180 struct nfs_write_data *wdata = data;
1181
1182 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 nfs_commit_free(wdata);
1184}
1185
1186/*
1187 * Set up the argument/result storage required for the RPC call.
1188 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001189static int nfs_commit_rpcsetup(struct list_head *head,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001190 struct nfs_write_data *data,
1191 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Trond Myklebust84115e12007-07-14 15:39:59 -04001193 struct nfs_page *first = nfs_list_entry(head->next);
1194 struct inode *inode = first->wb_context->path.dentry->d_inode;
1195 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -04001196 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -04001197 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001198 struct rpc_message msg = {
1199 .rpc_argp = &data->args,
1200 .rpc_resp = &data->res,
1201 .rpc_cred = first->wb_context->cred,
1202 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001203 struct rpc_task_setup task_setup_data = {
Trond Myklebust07737692007-10-25 18:42:54 -04001204 .task = &data->task,
Trond Myklebust84115e12007-07-14 15:39:59 -04001205 .rpc_client = NFS_CLIENT(inode),
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001206 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -04001207 .callback_ops = &nfs_commit_ops,
1208 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -05001209 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -04001210 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -04001211 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -04001212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 /* Set up the RPC argument and reply structs
1215 * NB: take care not to mess about with data->commit et al. */
1216
1217 list_splice_init(head, &data->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 data->inode = inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001220 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 data->args.fh = NFS_FH(data->inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001223 /* Note: we always request a commit of the entire inode */
1224 data->args.offset = 0;
1225 data->args.count = 0;
Trond Myklebust383ba712008-02-19 20:04:20 -05001226 data->args.context = get_nfs_open_context(first->wb_context);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001227 data->res.count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 data->res.fattr = &data->fattr;
1229 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001230 nfs_fattr_init(&data->fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001231
1232 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001233 NFS_PROTO(inode)->commit_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Chuck Levera3f565b2007-01-31 12:14:01 -05001235 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001236
Trond Myklebust07737692007-10-25 18:42:54 -04001237 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001238 if (IS_ERR(task))
1239 return PTR_ERR(task);
1240 rpc_put_task(task);
1241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
1244/*
1245 * Commit dirty pages
1246 */
1247static int
Chuck Lever40859d72005-11-30 18:09:02 -05001248nfs_commit_list(struct inode *inode, struct list_head *head, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 struct nfs_write_data *data;
1251 struct nfs_page *req;
1252
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001253 data = nfs_commitdata_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 if (!data)
1256 goto out_bad;
1257
1258 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001259 return nfs_commit_rpcsetup(head, data, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 out_bad:
1261 while (!list_empty(head)) {
1262 req = nfs_list_entry(head->next);
1263 nfs_list_remove_request(req);
1264 nfs_mark_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001265 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001266 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1267 BDI_RECLAIMABLE);
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001268 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
1270 return -ENOMEM;
1271}
1272
1273/*
1274 * COMMIT call returned
1275 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001276static void nfs_commit_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001278 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Chuck Levera3f565b2007-01-31 12:14:01 -05001280 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 task->tk_pid, task->tk_status);
1282
Trond Myklebust788e7a82006-03-20 13:44:27 -05001283 /* Call the NFS version-specific code */
1284 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
1285 return;
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001286}
1287
1288static void nfs_commit_release(void *calldata)
1289{
1290 struct nfs_write_data *data = calldata;
1291 struct nfs_page *req;
1292 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 while (!list_empty(&data->pages)) {
1295 req = nfs_list_entry(data->pages.next);
1296 nfs_list_remove_request(req);
Trond Myklebust612c9382007-04-20 16:12:45 -04001297 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Christoph Lameterfd39fc82006-06-30 01:55:40 -07001298 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001299 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1300 BDI_RECLAIMABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 dprintk("NFS: commit (%s/%Ld %d@%Ld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -04001303 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1304 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 req->wb_bytes,
1306 (long long)req_offset(req));
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001307 if (status < 0) {
1308 nfs_context_set_write_error(req->wb_context, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 nfs_inode_remove_request(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001310 dprintk(", error = %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 goto next;
1312 }
1313
1314 /* Okay, COMMIT succeeded, apparently. Check the verifier
1315 * returned by the server against all stored verfs. */
1316 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
1317 /* We have a match */
Trond Myklebust44dd1512007-05-19 11:58:03 -04001318 /* Set the PG_uptodate flag */
1319 nfs_mark_uptodate(req->wb_page, req->wb_pgbase,
1320 req->wb_bytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 nfs_inode_remove_request(req);
1322 dprintk(" OK\n");
1323 goto next;
1324 }
1325 /* We have a mismatch. Write the page again */
1326 dprintk(" mismatch\n");
Fred6d884e82008-03-19 11:24:38 -04001327 nfs_mark_request_dirty(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001329 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001331 nfs_commitdata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001333
1334static const struct rpc_call_ops nfs_commit_ops = {
1335 .rpc_call_done = nfs_commit_done,
1336 .rpc_release = nfs_commit_release,
1337};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001339int nfs_commit_inode(struct inode *inode, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 LIST_HEAD(head);
Trond Myklebust7d46a492006-03-20 13:44:50 -05001342 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Trond Myklebust587142f2007-07-02 09:57:54 -04001344 spin_lock(&inode->i_lock);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001345 res = nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001346 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 if (res) {
Trond Myklebust7d46a492006-03-20 13:44:50 -05001348 int error = nfs_commit_list(inode, &head, how);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001349 if (error < 0)
1350 return error;
1351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 return res;
1353}
Trond Myklebustc63c7b02007-04-02 19:29:52 -04001354#else
1355static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1356{
1357 return 0;
1358}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#endif
1360
Trond Myklebust1c759502006-10-09 16:18:38 -04001361long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Trond Myklebust1c759502006-10-09 16:18:38 -04001363 struct inode *inode = mapping->host;
Trond Myklebustca52fec2007-04-17 17:22:13 -04001364 pgoff_t idx_start, idx_end;
Trond Myklebust1c759502006-10-09 16:18:38 -04001365 unsigned int npages = 0;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001366 LIST_HEAD(head);
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001367 int nocommit = how & FLUSH_NOCOMMIT;
Trond Myklebust3f442542006-09-17 14:46:44 -04001368 long pages, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Trond Myklebust1c759502006-10-09 16:18:38 -04001370 /* FIXME */
1371 if (wbc->range_cyclic)
1372 idx_start = 0;
1373 else {
1374 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
1375 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
1376 if (idx_end > idx_start) {
Trond Myklebustca52fec2007-04-17 17:22:13 -04001377 pgoff_t l_npages = 1 + idx_end - idx_start;
Trond Myklebust1c759502006-10-09 16:18:38 -04001378 npages = l_npages;
1379 if (sizeof(npages) != sizeof(l_npages) &&
Trond Myklebustca52fec2007-04-17 17:22:13 -04001380 (pgoff_t)npages != l_npages)
Trond Myklebust1c759502006-10-09 16:18:38 -04001381 npages = 0;
1382 }
1383 }
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001384 how &= ~FLUSH_NOCOMMIT;
Trond Myklebust587142f2007-07-02 09:57:54 -04001385 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 do {
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001387 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1388 if (ret != 0)
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001389 continue;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001390 if (nocommit)
1391 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001392 pages = nfs_scan_commit(inode, &head, idx_start, npages);
Trond Myklebust724c4392007-04-17 17:22:13 -04001393 if (pages == 0)
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001394 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001395 if (how & FLUSH_INVALIDATE) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001396 spin_unlock(&inode->i_lock);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001397 nfs_cancel_commit_list(&head);
Trond Myklebuste8e058e2006-11-15 17:31:56 -05001398 ret = pages;
Trond Myklebust587142f2007-07-02 09:57:54 -04001399 spin_lock(&inode->i_lock);
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001400 continue;
1401 }
1402 pages += nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001403 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001404 ret = nfs_commit_list(inode, &head, how);
Trond Myklebust587142f2007-07-02 09:57:54 -04001405 spin_lock(&inode->i_lock);
1406
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001407 } while (ret >= 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001408 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001409 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Trond Myklebust34901f72007-07-25 14:09:54 -04001412static int __nfs_write_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001413{
Trond Myklebust1c759502006-10-09 16:18:38 -04001414 int ret;
1415
Trond Myklebust34901f72007-07-25 14:09:54 -04001416 ret = nfs_writepages(mapping, wbc);
Trond Myklebust61822ab2006-12-05 00:35:42 -05001417 if (ret < 0)
1418 goto out;
Trond Myklebust34901f72007-07-25 14:09:54 -04001419 ret = nfs_sync_mapping_wait(mapping, wbc, how);
Trond Myklebusted90ef52007-07-20 13:13:28 -04001420 if (ret < 0)
1421 goto out;
1422 return 0;
Trond Myklebust61822ab2006-12-05 00:35:42 -05001423out:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001424 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
Trond Myklebust1c759502006-10-09 16:18:38 -04001425 return ret;
1426}
1427
Trond Myklebust34901f72007-07-25 14:09:54 -04001428/* Two pass sync: first using WB_SYNC_NONE, then WB_SYNC_ALL */
1429static int nfs_write_mapping(struct address_space *mapping, int how)
1430{
1431 struct writeback_control wbc = {
1432 .bdi = mapping->backing_dev_info,
1433 .sync_mode = WB_SYNC_NONE,
1434 .nr_to_write = LONG_MAX,
1435 .for_writepages = 1,
1436 .range_cyclic = 1,
1437 };
1438 int ret;
1439
1440 ret = __nfs_write_mapping(mapping, &wbc, how);
1441 if (ret < 0)
1442 return ret;
1443 wbc.sync_mode = WB_SYNC_ALL;
1444 return __nfs_write_mapping(mapping, &wbc, how);
1445}
1446
Trond Myklebusted90ef52007-07-20 13:13:28 -04001447/*
1448 * flush the inode to disk.
1449 */
1450int nfs_wb_all(struct inode *inode)
Trond Myklebust1c759502006-10-09 16:18:38 -04001451{
Trond Myklebusted90ef52007-07-20 13:13:28 -04001452 return nfs_write_mapping(inode->i_mapping, 0);
1453}
Trond Myklebust1c759502006-10-09 16:18:38 -04001454
Trond Myklebusted90ef52007-07-20 13:13:28 -04001455int nfs_wb_nocommit(struct inode *inode)
1456{
1457 return nfs_write_mapping(inode->i_mapping, FLUSH_NOCOMMIT);
Trond Myklebust1c759502006-10-09 16:18:38 -04001458}
1459
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001460int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1461{
1462 struct nfs_page *req;
1463 loff_t range_start = page_offset(page);
1464 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1465 struct writeback_control wbc = {
1466 .bdi = page->mapping->backing_dev_info,
1467 .sync_mode = WB_SYNC_ALL,
1468 .nr_to_write = LONG_MAX,
1469 .range_start = range_start,
1470 .range_end = range_end,
1471 };
1472 int ret = 0;
1473
1474 BUG_ON(!PageLocked(page));
1475 for (;;) {
1476 req = nfs_page_find_request(page);
1477 if (req == NULL)
1478 goto out;
1479 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1480 nfs_release_request(req);
1481 break;
1482 }
1483 if (nfs_lock_request_dontget(req)) {
1484 nfs_inode_remove_request(req);
1485 /*
1486 * In case nfs_inode_remove_request has marked the
1487 * page as being dirty
1488 */
1489 cancel_dirty_page(page, PAGE_CACHE_SIZE);
1490 nfs_unlock_request(req);
1491 break;
1492 }
1493 ret = nfs_wait_on_request(req);
1494 if (ret < 0)
1495 goto out;
1496 }
1497 if (!PagePrivate(page))
1498 return 0;
1499 ret = nfs_sync_mapping_wait(page->mapping, &wbc, FLUSH_INVALIDATE);
1500out:
1501 return ret;
1502}
1503
Adrian Bunk5334eb12007-11-21 15:04:31 -08001504static int nfs_wb_page_priority(struct inode *inode, struct page *page,
1505 int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001506{
1507 loff_t range_start = page_offset(page);
1508 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001509 struct writeback_control wbc = {
1510 .bdi = page->mapping->backing_dev_info,
1511 .sync_mode = WB_SYNC_ALL,
1512 .nr_to_write = LONG_MAX,
1513 .range_start = range_start,
1514 .range_end = range_end,
1515 };
1516 int ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001517
Trond Myklebust73e33022008-04-11 16:03:54 -04001518 do {
1519 if (clear_page_dirty_for_io(page)) {
1520 ret = nfs_writepage_locked(page, &wbc);
1521 if (ret < 0)
1522 goto out_error;
1523 } else if (!PagePrivate(page))
1524 break;
1525 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001526 if (ret < 0)
Trond Myklebust73e33022008-04-11 16:03:54 -04001527 goto out_error;
1528 } while (PagePrivate(page));
1529 return 0;
1530out_error:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001531 __mark_inode_dirty(inode, I_DIRTY_PAGES);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001532 return ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001533}
1534
1535/*
1536 * Write back all requests on one page - we do this before reading it.
1537 */
1538int nfs_wb_page(struct inode *inode, struct page* page)
1539{
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001540 return nfs_wb_page_priority(inode, page, FLUSH_STABLE);
Trond Myklebust1c759502006-10-09 16:18:38 -04001541}
1542
David Howellsf7b422b2006-06-09 09:34:33 -04001543int __init nfs_init_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
1545 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1546 sizeof(struct nfs_write_data),
1547 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +09001548 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 if (nfs_wdata_cachep == NULL)
1550 return -ENOMEM;
1551
Matthew Dobson93d23412006-03-26 01:37:50 -08001552 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
1553 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 if (nfs_wdata_mempool == NULL)
1555 return -ENOMEM;
1556
Matthew Dobson93d23412006-03-26 01:37:50 -08001557 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
1558 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 if (nfs_commit_mempool == NULL)
1560 return -ENOMEM;
1561
Peter Zijlstra89a09142007-03-16 13:38:26 -08001562 /*
1563 * NFS congestion size, scale with available memory.
1564 *
1565 * 64MB: 8192k
1566 * 128MB: 11585k
1567 * 256MB: 16384k
1568 * 512MB: 23170k
1569 * 1GB: 32768k
1570 * 2GB: 46340k
1571 * 4GB: 65536k
1572 * 8GB: 92681k
1573 * 16GB: 131072k
1574 *
1575 * This allows larger machines to have larger/more transfers.
1576 * Limit the default to 256M
1577 */
1578 nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
1579 if (nfs_congestion_kb > 256*1024)
1580 nfs_congestion_kb = 256*1024;
1581
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 return 0;
1583}
1584
David Brownell266bee82006-06-27 12:59:15 -07001585void nfs_destroy_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
1587 mempool_destroy(nfs_commit_mempool);
1588 mempool_destroy(nfs_wdata_mempool);
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001589 kmem_cache_destroy(nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591