blob: 035e6fb9f57eaf2ac14b81b26f2e93daa20819c3 [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);
Andy Adamson5f7dbd52009-04-01 09:22:05 -040055 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
57 return p;
58}
59
Trond Myklebust5e4424a2008-02-25 21:53:49 -080060void nfs_commit_free(struct nfs_write_data *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Chuck Lever40859d72005-11-30 18:09:02 -050062 if (p && (p->pagevec != &p->page_array[0]))
63 kfree(p->pagevec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 mempool_free(p, nfs_commit_mempool);
65}
66
Trond Myklebust8d5658c2007-04-10 09:26:35 -040067struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050068{
Christoph Lametere6b4f8d2006-12-06 20:33:14 -080069 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS);
Trond Myklebust3feb2d42006-03-20 13:44:37 -050070
71 if (p) {
72 memset(p, 0, sizeof(*p));
73 INIT_LIST_HEAD(&p->pages);
Trond Myklebuste9f7bee2006-09-08 09:48:54 -070074 p->npages = pagecount;
Andy Adamson5f7dbd52009-04-01 09:22:05 -040075 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040076 if (pagecount <= ARRAY_SIZE(p->page_array))
77 p->pagevec = p->page_array;
Trond Myklebust3feb2d42006-03-20 13:44:37 -050078 else {
Chuck Lever0d0b5cb2006-05-25 01:40:53 -040079 p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
80 if (!p->pagevec) {
Trond Myklebust3feb2d42006-03-20 13:44:37 -050081 mempool_free(p, nfs_wdata_mempool);
82 p = NULL;
83 }
84 }
85 }
86 return p;
87}
88
Trond Myklebust5e4424a2008-02-25 21:53:49 -080089static void nfs_writedata_free(struct nfs_write_data *p)
Trond Myklebust3feb2d42006-03-20 13:44:37 -050090{
91 if (p && (p->pagevec != &p->page_array[0]))
92 kfree(p->pagevec);
93 mempool_free(p, nfs_wdata_mempool);
94}
95
Trond Myklebust383ba712008-02-19 20:04:20 -050096void nfs_writedata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Trond Myklebust383ba712008-02-19 20:04:20 -050098 struct nfs_write_data *wdata = data;
99
100 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 nfs_writedata_free(wdata);
102}
103
Trond Myklebust7b159fc2007-07-25 14:09:54 -0400104static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
105{
106 ctx->error = error;
107 smp_wmb();
108 set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
109}
110
Trond Myklebust277459d2006-12-05 00:35:35 -0500111static struct nfs_page *nfs_page_find_request_locked(struct page *page)
112{
113 struct nfs_page *req = NULL;
114
115 if (PagePrivate(page)) {
116 req = (struct nfs_page *)page_private(page);
117 if (req != NULL)
Trond Myklebustc03b4022007-06-17 13:26:38 -0400118 kref_get(&req->wb_kref);
Trond Myklebust277459d2006-12-05 00:35:35 -0500119 }
120 return req;
121}
122
123static struct nfs_page *nfs_page_find_request(struct page *page)
124{
Trond Myklebust587142f2007-07-02 09:57:54 -0400125 struct inode *inode = page->mapping->host;
Trond Myklebust277459d2006-12-05 00:35:35 -0500126 struct nfs_page *req = NULL;
Trond Myklebust277459d2006-12-05 00:35:35 -0500127
Trond Myklebust587142f2007-07-02 09:57:54 -0400128 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500129 req = nfs_page_find_request_locked(page);
Trond Myklebust587142f2007-07-02 09:57:54 -0400130 spin_unlock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500131 return req;
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/* Adjust the file length if we're writing beyond the end */
135static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
136{
137 struct inode *inode = page->mapping->host;
Trond Myklebusta3d01452008-06-11 12:21:19 -0400138 loff_t end, i_size;
139 pgoff_t end_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Trond Myklebusta3d01452008-06-11 12:21:19 -0400141 spin_lock(&inode->i_lock);
142 i_size = i_size_read(inode);
143 end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 if (i_size > 0 && page->index < end_index)
Trond Myklebusta3d01452008-06-11 12:21:19 -0400145 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count);
147 if (i_size >= end)
Trond Myklebusta3d01452008-06-11 12:21:19 -0400148 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 i_size_write(inode, end);
Trond Myklebusta3d01452008-06-11 12:21:19 -0400150 nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
151out:
152 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Trond Myklebusta301b772007-02-06 11:07:15 -0800155/* A writeback failed: mark the page as bad, and invalidate the page cache */
156static void nfs_set_pageerror(struct page *page)
157{
158 SetPageError(page);
159 nfs_zap_mapping(page->mapping->host, page->mapping);
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162/* We can set the PG_uptodate flag if we see that a write request
163 * covers the full page.
164 */
165static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int count)
166{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 if (PageUptodate(page))
168 return;
169 if (base != 0)
170 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500171 if (count != nfs_page_length(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500173 SetPageUptodate(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static int wb_priority(struct writeback_control *wbc)
177{
178 if (wbc->for_reclaim)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400179 return FLUSH_HIGHPRI | FLUSH_STABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (wbc->for_kupdate)
181 return FLUSH_LOWPRI;
182 return 0;
183}
184
185/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800186 * NFS congestion control
187 */
188
189int nfs_congestion_kb;
190
191#define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10))
192#define NFS_CONGESTION_OFF_THRESH \
193 (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2))
194
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400195static int nfs_set_page_writeback(struct page *page)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800196{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400197 int ret = test_set_page_writeback(page);
198
199 if (!ret) {
Peter Zijlstra89a09142007-03-16 13:38:26 -0800200 struct inode *inode = page->mapping->host;
201 struct nfs_server *nfss = NFS_SERVER(inode);
202
Peter Zijlstra277866a2007-05-08 00:35:12 -0700203 if (atomic_long_inc_return(&nfss->writeback) >
Peter Zijlstra89a09142007-03-16 13:38:26 -0800204 NFS_CONGESTION_ON_THRESH)
205 set_bdi_congested(&nfss->backing_dev_info, WRITE);
206 }
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400207 return ret;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800208}
209
210static void nfs_end_page_writeback(struct page *page)
211{
212 struct inode *inode = page->mapping->host;
213 struct nfs_server *nfss = NFS_SERVER(inode);
214
215 end_page_writeback(page);
Peter Zijlstrac4dc4be2007-10-16 23:25:41 -0700216 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800217 clear_bdi_congested(&nfss->backing_dev_info, WRITE);
Peter Zijlstra89a09142007-03-16 13:38:26 -0800218}
219
220/*
Trond Myklebuste261f512006-12-05 00:35:41 -0500221 * Find an associated nfs write request, and prepare to flush it out
Trond Myklebust9cccef92007-07-22 17:09:05 -0400222 * May return an error if the user signalled nfs_wait_on_request().
Trond Myklebuste261f512006-12-05 00:35:41 -0500223 */
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400224static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
225 struct page *page)
Trond Myklebuste261f512006-12-05 00:35:41 -0500226{
Trond Myklebust587142f2007-07-02 09:57:54 -0400227 struct inode *inode = page->mapping->host;
Trond Myklebuste261f512006-12-05 00:35:41 -0500228 struct nfs_page *req;
Trond Myklebuste261f512006-12-05 00:35:41 -0500229 int ret;
230
Trond Myklebust587142f2007-07-02 09:57:54 -0400231 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500232 for(;;) {
233 req = nfs_page_find_request_locked(page);
234 if (req == NULL) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400235 spin_unlock(&inode->i_lock);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400236 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500237 }
Trond Myklebustacee4782008-01-22 17:13:07 -0500238 if (nfs_set_page_tag_locked(req))
Trond Myklebuste261f512006-12-05 00:35:41 -0500239 break;
240 /* Note: If we hold the page lock, as is the case in nfs_writepage,
Trond Myklebustacee4782008-01-22 17:13:07 -0500241 * then the call to nfs_set_page_tag_locked() will always
Trond Myklebuste261f512006-12-05 00:35:41 -0500242 * succeed provided that someone hasn't already marked the
243 * request as dirty (in which case we don't care).
244 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400245 spin_unlock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500246 ret = nfs_wait_on_request(req);
247 nfs_release_request(req);
248 if (ret != 0)
249 return ret;
Trond Myklebust587142f2007-07-02 09:57:54 -0400250 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500251 }
Trond Myklebuste468bae2008-06-13 13:25:22 -0400252 if (test_bit(PG_CLEAN, &req->wb_flags)) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400253 spin_unlock(&inode->i_lock);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400254 BUG();
Trond Myklebust612c9382007-04-20 16:12:45 -0400255 }
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400256 if (nfs_set_page_writeback(page) != 0) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400257 spin_unlock(&inode->i_lock);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400258 BUG();
259 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400260 spin_unlock(&inode->i_lock);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400261 if (!nfs_pageio_add_request(pgio, req)) {
262 nfs_redirty_request(req);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400263 return pgio->pg_error;
264 }
Trond Myklebust9cccef92007-07-22 17:09:05 -0400265 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500266}
267
Trond Myklebustf758c8852007-07-22 19:27:32 -0400268static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
269{
270 struct inode *inode = page->mapping->host;
271
272 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
273 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
274
275 nfs_pageio_cond_complete(pgio, page->index);
276 return nfs_page_async_flush(pgio, page);
277}
278
Trond Myklebuste261f512006-12-05 00:35:41 -0500279/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 * Write an mmapped page to the server.
281 */
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500282static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400284 struct nfs_pageio_descriptor pgio;
Trond Myklebuste261f512006-12-05 00:35:41 -0500285 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Trond Myklebustf758c8852007-07-22 19:27:32 -0400287 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc));
288 err = nfs_do_writepage(page, wbc, &pgio);
289 nfs_pageio_complete(&pgio);
290 if (err < 0)
291 return err;
292 if (pgio.pg_error < 0)
293 return pgio.pg_error;
294 return 0;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500295}
296
297int nfs_writepage(struct page *page, struct writeback_control *wbc)
298{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400299 int ret;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500300
Trond Myklebustf758c8852007-07-22 19:27:32 -0400301 ret = nfs_writepage_locked(page, wbc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 unlock_page(page);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400303 return ret;
304}
305
306static int nfs_writepages_callback(struct page *page, struct writeback_control *wbc, void *data)
307{
308 int ret;
309
310 ret = nfs_do_writepage(page, wbc, data);
311 unlock_page(page);
312 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
316{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 struct inode *inode = mapping->host;
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400318 unsigned long *bitlock = &NFS_I(inode)->flags;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400319 struct nfs_pageio_descriptor pgio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 int err;
321
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400322 /* Stop dirtying of new pages while we sync */
323 err = wait_on_bit_lock(bitlock, NFS_INO_FLUSHING,
324 nfs_wait_bit_killable, TASK_KILLABLE);
325 if (err)
326 goto out_err;
327
Chuck Lever91d5b472006-03-20 13:44:14 -0500328 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
329
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400330 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc));
Trond Myklebustf758c8852007-07-22 19:27:32 -0400331 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400332 nfs_pageio_complete(&pgio);
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400333
334 clear_bit_unlock(NFS_INO_FLUSHING, bitlock);
335 smp_mb__after_clear_bit();
336 wake_up_bit(bitlock, NFS_INO_FLUSHING);
337
Trond Myklebustf758c8852007-07-22 19:27:32 -0400338 if (err < 0)
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400339 goto out_err;
340 err = pgio.pg_error;
341 if (err < 0)
342 goto out_err;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400343 return 0;
Trond Myklebust72cb77f2009-03-11 14:10:30 -0400344out_err:
345 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
348/*
349 * Insert a write request into an inode
350 */
Trond Myklebuste7d39062008-06-13 12:12:32 -0400351static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
353 struct nfs_inode *nfsi = NFS_I(inode);
354 int error;
355
Trond Myklebuste7d39062008-06-13 12:12:32 -0400356 error = radix_tree_preload(GFP_NOFS);
357 if (error != 0)
358 goto out;
359
360 /* Lock the request! */
361 nfs_lock_request_dontget(req);
362
363 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
Nick Piggin27852592008-02-04 23:48:37 -0800365 BUG_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (!nfsi->npages) {
367 igrab(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (nfs_have_delegation(inode, FMODE_WRITE))
369 nfsi->change_attr++;
370 }
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500371 SetPagePrivate(req->wb_page);
Trond Myklebust277459d2006-12-05 00:35:35 -0500372 set_page_private(req->wb_page, (unsigned long)req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 nfsi->npages++;
Trond Myklebustc03b4022007-06-17 13:26:38 -0400374 kref_get(&req->wb_kref);
Nick Piggin27852592008-02-04 23:48:37 -0800375 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
376 NFS_PAGE_TAG_LOCKED);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400377 spin_unlock(&inode->i_lock);
378 radix_tree_preload_end();
379out:
380 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
383/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800384 * Remove a write request from an inode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 */
386static void nfs_inode_remove_request(struct nfs_page *req)
387{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400388 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 struct nfs_inode *nfsi = NFS_I(inode);
390
391 BUG_ON (!NFS_WBACK_BUSY(req));
392
Trond Myklebust587142f2007-07-02 09:57:54 -0400393 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500394 set_page_private(req->wb_page, 0);
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500395 ClearPagePrivate(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
397 nfsi->npages--;
398 if (!nfsi->npages) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400399 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 iput(inode);
401 } else
Trond Myklebust587142f2007-07-02 09:57:54 -0400402 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 nfs_clear_request(req);
404 nfs_release_request(req);
405}
406
Trond Myklebust61822ab2006-12-05 00:35:42 -0500407static void
Fred6d884e82008-03-19 11:24:38 -0400408nfs_mark_request_dirty(struct nfs_page *req)
Trond Myklebust61822ab2006-12-05 00:35:42 -0500409{
Trond Myklebust61822ab2006-12-05 00:35:42 -0500410 __set_page_dirty_nobuffers(req->wb_page);
411}
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
414/*
415 * Add a request to the inode's commit list.
416 */
417static void
418nfs_mark_request_commit(struct nfs_page *req)
419{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400420 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 struct nfs_inode *nfsi = NFS_I(inode);
422
Trond Myklebust587142f2007-07-02 09:57:54 -0400423 spin_lock(&inode->i_lock);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400424 set_bit(PG_CLEAN, &(req)->wb_flags);
Trond Myklebust5c369682007-06-17 15:27:42 -0400425 radix_tree_tag_set(&nfsi->nfs_page_tree,
426 req->wb_index,
427 NFS_PAGE_TAG_COMMIT);
Trond Myklebust587142f2007-07-02 09:57:54 -0400428 spin_unlock(&inode->i_lock);
Christoph Lameterfd39fc82006-06-30 01:55:40 -0700429 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700430 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
Trond Myklebusta1803042006-12-05 00:45:19 -0500431 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400433
Trond Myklebuste468bae2008-06-13 13:25:22 -0400434static int
435nfs_clear_request_commit(struct nfs_page *req)
436{
437 struct page *page = req->wb_page;
438
439 if (test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) {
440 dec_zone_page_state(page, NR_UNSTABLE_NFS);
441 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE);
442 return 1;
443 }
444 return 0;
445}
446
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400447static inline
448int nfs_write_need_commit(struct nfs_write_data *data)
449{
450 return data->verf.committed != NFS_FILE_SYNC;
451}
452
453static inline
454int nfs_reschedule_unstable_write(struct nfs_page *req)
455{
Trond Myklebuste468bae2008-06-13 13:25:22 -0400456 if (test_and_clear_bit(PG_NEED_COMMIT, &req->wb_flags)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400457 nfs_mark_request_commit(req);
458 return 1;
459 }
460 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
Fred6d884e82008-03-19 11:24:38 -0400461 nfs_mark_request_dirty(req);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400462 return 1;
463 }
464 return 0;
465}
466#else
467static inline void
468nfs_mark_request_commit(struct nfs_page *req)
469{
470}
471
Trond Myklebuste468bae2008-06-13 13:25:22 -0400472static inline int
473nfs_clear_request_commit(struct nfs_page *req)
474{
475 return 0;
476}
477
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400478static inline
479int nfs_write_need_commit(struct nfs_write_data *data)
480{
481 return 0;
482}
483
484static inline
485int nfs_reschedule_unstable_write(struct nfs_page *req)
486{
487 return 0;
488}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#endif
490
491/*
492 * Wait for a request to complete.
493 *
Matthew Wilcox150030b2007-12-06 16:24:39 -0500494 * Interruptible by fatal signals only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 */
Trond Myklebustca52fec2007-04-17 17:22:13 -0400496static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 struct nfs_inode *nfsi = NFS_I(inode);
499 struct nfs_page *req;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400500 pgoff_t idx_end, next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 unsigned int res = 0;
502 int error;
503
504 if (npages == 0)
505 idx_end = ~0;
506 else
507 idx_end = idx_start + npages - 1;
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 next = idx_start;
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400510 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 -0700511 if (req->wb_index > idx_end)
512 break;
513
514 next = req->wb_index + 1;
Trond Myklebustc6a556b2005-06-22 17:16:30 +0000515 BUG_ON(!NFS_WBACK_BUSY(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Trond Myklebustc03b4022007-06-17 13:26:38 -0400517 kref_get(&req->wb_kref);
Trond Myklebust587142f2007-07-02 09:57:54 -0400518 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 error = nfs_wait_on_request(req);
520 nfs_release_request(req);
Trond Myklebust587142f2007-07-02 09:57:54 -0400521 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (error < 0)
523 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 res++;
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return res;
527}
528
Trond Myklebust83715ad2006-07-05 13:17:12 -0400529static void nfs_cancel_commit_list(struct list_head *head)
530{
531 struct nfs_page *req;
532
533 while(!list_empty(head)) {
534 req = nfs_list_entry(head->next);
535 nfs_list_remove_request(req);
Trond Myklebuste468bae2008-06-13 13:25:22 -0400536 nfs_clear_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400537 nfs_inode_remove_request(req);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700538 nfs_unlock_request(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400539 }
540}
541
Trond Myklebust47c62562009-03-16 08:13:41 -0400542#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400543static int
544nfs_need_commit(struct nfs_inode *nfsi)
545{
546 return radix_tree_tagged(&nfsi->nfs_page_tree, NFS_PAGE_TAG_COMMIT);
547}
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549/*
550 * nfs_scan_commit - Scan an inode for commit requests
551 * @inode: NFS inode to scan
552 * @dst: destination list
553 * @idx_start: lower bound of page->index to scan.
554 * @npages: idx_start + npages sets the upper bound to scan.
555 *
556 * Moves requests from the inode's 'commit' request list.
557 * The requests are *not* checked to ensure that they form a contiguous set.
558 */
559static int
Trond Myklebustca52fec2007-04-17 17:22:13 -0400560nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 struct nfs_inode *nfsi = NFS_I(inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000563
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400564 if (!nfs_need_commit(nfsi))
565 return 0;
566
567 return nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
Trond Myklebustc42de9d2006-03-20 13:44:51 -0500569#else
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400570static inline int nfs_need_commit(struct nfs_inode *nfsi)
571{
572 return 0;
573}
574
Trond Myklebustca52fec2007-04-17 17:22:13 -0400575static 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 -0500576{
577 return 0;
578}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#endif
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581/*
Trond Myklebuste7d39062008-06-13 12:12:32 -0400582 * Search for an existing write request, and attempt to update
583 * it to reflect a new dirty region on a given page.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *
Trond Myklebuste7d39062008-06-13 12:12:32 -0400585 * If the attempt fails, then the existing request is flushed out
586 * to disk.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 */
Trond Myklebuste7d39062008-06-13 12:12:32 -0400588static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
589 struct page *page,
590 unsigned int offset,
591 unsigned int bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Trond Myklebuste7d39062008-06-13 12:12:32 -0400593 struct nfs_page *req;
594 unsigned int rqend;
595 unsigned int end;
596 int error;
597
598 if (!PagePrivate(page))
599 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 end = offset + bytes;
Trond Myklebuste7d39062008-06-13 12:12:32 -0400602 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 for (;;) {
Trond Myklebust277459d2006-12-05 00:35:35 -0500605 req = nfs_page_find_request_locked(page);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400606 if (req == NULL)
607 goto out_unlock;
Trond Myklebust277459d2006-12-05 00:35:35 -0500608
Trond Myklebuste7d39062008-06-13 12:12:32 -0400609 rqend = req->wb_offset + req->wb_bytes;
610 /*
611 * Tell the caller to flush out the request if
612 * the offsets are non-contiguous.
613 * Note: nfs_flush_incompatible() will already
614 * have flushed out requests having wrong owners.
615 */
Trond Myklebuste468bae2008-06-13 13:25:22 -0400616 if (offset > rqend
Trond Myklebuste7d39062008-06-13 12:12:32 -0400617 || end < req->wb_offset)
618 goto out_flushme;
619
620 if (nfs_set_page_tag_locked(req))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Trond Myklebuste7d39062008-06-13 12:12:32 -0400623 /* The request is locked, so wait and then retry */
Trond Myklebust587142f2007-07-02 09:57:54 -0400624 spin_unlock(&inode->i_lock);
Trond Myklebuste7d39062008-06-13 12:12:32 -0400625 error = nfs_wait_on_request(req);
626 nfs_release_request(req);
627 if (error != 0)
628 goto out_err;
629 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
Trond Myklebuste468bae2008-06-13 13:25:22 -0400632 if (nfs_clear_request_commit(req))
633 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
634 req->wb_index, NFS_PAGE_TAG_COMMIT);
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 /* Okay, the request matches. Update the region */
637 if (offset < req->wb_offset) {
638 req->wb_offset = offset;
639 req->wb_pgbase = offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 if (end > rqend)
642 req->wb_bytes = end - req->wb_offset;
Trond Myklebuste7d39062008-06-13 12:12:32 -0400643 else
644 req->wb_bytes = rqend - req->wb_offset;
645out_unlock:
646 spin_unlock(&inode->i_lock);
647 return req;
648out_flushme:
649 spin_unlock(&inode->i_lock);
650 nfs_release_request(req);
651 error = nfs_wb_page(inode, page);
652out_err:
653 return ERR_PTR(error);
654}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Trond Myklebuste7d39062008-06-13 12:12:32 -0400656/*
657 * Try to update an existing write request, or create one if there is none.
658 *
659 * Note: Should always be called with the Page Lock held to prevent races
660 * if we have to add a new request. Also assumes that the caller has
661 * already called nfs_flush_incompatible() if necessary.
662 */
663static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
664 struct page *page, unsigned int offset, unsigned int bytes)
665{
666 struct inode *inode = page->mapping->host;
667 struct nfs_page *req;
668 int error;
669
670 req = nfs_try_to_update_request(inode, page, offset, bytes);
671 if (req != NULL)
672 goto out;
673 req = nfs_create_request(ctx, inode, page, offset, bytes);
674 if (IS_ERR(req))
675 goto out;
676 error = nfs_inode_add_request(inode, req);
677 if (error != 0) {
678 nfs_release_request(req);
679 req = ERR_PTR(error);
680 }
Trond Myklebustefc91ed2008-06-10 18:31:00 -0400681out:
Trond Myklebust61e930a2007-10-18 17:08:05 -0400682 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Trond Myklebuste7d39062008-06-13 12:12:32 -0400685static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
686 unsigned int offset, unsigned int count)
687{
688 struct nfs_page *req;
689
690 req = nfs_setup_write_request(ctx, page, offset, count);
691 if (IS_ERR(req))
692 return PTR_ERR(req);
693 /* Update file length */
694 nfs_grow_file(page, offset, count);
695 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
696 nfs_clear_page_tag_locked(req);
697 return 0;
698}
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700int nfs_flush_incompatible(struct file *file, struct page *page)
701{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400702 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 struct nfs_page *req;
Trond Myklebust1a545332006-12-05 00:35:40 -0500704 int do_flush, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /*
706 * Look for a request corresponding to this page. If there
707 * is one, and it belongs to another file, we flush it out
708 * before we try to copy anything into the page. Do this
709 * due to the lack of an ACCESS-type call in NFSv2.
710 * Also do the same if we find a request from an existing
711 * dropped page.
712 */
Trond Myklebust1a545332006-12-05 00:35:40 -0500713 do {
714 req = nfs_page_find_request(page);
715 if (req == NULL)
716 return 0;
Trond Myklebuste468bae2008-06-13 13:25:22 -0400717 do_flush = req->wb_page != page || req->wb_context != ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 nfs_release_request(req);
Trond Myklebust1a545332006-12-05 00:35:40 -0500719 if (!do_flush)
720 return 0;
721 status = nfs_wb_page(page->mapping->host, page);
722 } while (status == 0);
723 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
726/*
Trond Myklebust5d47a352008-02-07 17:24:07 -0500727 * If the page cache is marked as unsafe or invalid, then we can't rely on
728 * the PageUptodate() flag. In this case, we will need to turn off
729 * write optimisations that depend on the page contents being correct.
730 */
731static int nfs_write_pageuptodate(struct page *page, struct inode *inode)
732{
733 return PageUptodate(page) &&
734 !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA));
735}
736
737/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 * Update and possibly write a cached page of an NFS file.
739 *
740 * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
741 * things with a page scheduled for an RPC call (e.g. invalidate it).
742 */
743int nfs_updatepage(struct file *file, struct page *page,
744 unsigned int offset, unsigned int count)
745{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400746 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 struct inode *inode = page->mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 int status = 0;
749
Chuck Lever91d5b472006-03-20 13:44:14 -0500750 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
751
Chuck Lever48186c72008-06-11 17:56:05 -0400752 dprintk("NFS: nfs_updatepage(%s/%s %d@%lld)\n",
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800753 file->f_path.dentry->d_parent->d_name.name,
754 file->f_path.dentry->d_name.name, count,
Chuck Lever48186c72008-06-11 17:56:05 -0400755 (long long)(page_offset(page) + offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 /* If we're not using byte range locks, and we know the page
Trond Myklebust5d47a352008-02-07 17:24:07 -0500758 * is up to date, it may be more efficient to extend the write
759 * to cover the entire page in order to avoid fragmentation
760 * inefficiencies.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 */
Trond Myklebust5d47a352008-02-07 17:24:07 -0500762 if (nfs_write_pageuptodate(page, inode) &&
763 inode->i_flock == NULL &&
Trond Myklebust4b5621f2008-02-25 15:56:29 -0800764 !(file->f_flags & O_SYNC)) {
Trond Myklebust49a70f22006-12-05 00:35:38 -0500765 count = max(count + offset, nfs_page_length(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
Trond Myklebuste21195a2006-12-05 00:35:39 -0500769 status = nfs_writepage_setup(ctx, page, offset, count);
Trond Myklebust03fa9e82008-06-05 16:02:35 -0400770 if (status < 0)
771 nfs_set_pageerror(page);
772 else
773 __set_page_dirty_nobuffers(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Chuck Lever48186c72008-06-11 17:56:05 -0400775 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 status, (long long)i_size_read(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return status;
778}
779
780static void nfs_writepage_release(struct nfs_page *req)
781{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Trond Myklebust7e5f6142008-05-25 12:59:19 -0400783 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400784 nfs_end_page_writeback(req->wb_page);
785 nfs_inode_remove_request(req);
786 } else
787 nfs_end_page_writeback(req->wb_page);
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400788 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
Trond Myklebust3ff75762007-07-14 15:40:00 -0400791static int flush_task_priority(int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
793 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
794 case FLUSH_HIGHPRI:
795 return RPC_PRIORITY_HIGH;
796 case FLUSH_LOWPRI:
797 return RPC_PRIORITY_LOW;
798 }
799 return RPC_PRIORITY_NORMAL;
800}
801
802/*
803 * Set up the argument/result storage required for the RPC call.
804 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400805static int nfs_write_rpcsetup(struct nfs_page *req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct nfs_write_data *data,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500807 const struct rpc_call_ops *call_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 unsigned int count, unsigned int offset,
809 int how)
810{
Trond Myklebust84115e12007-07-14 15:39:59 -0400811 struct inode *inode = req->wb_context->path.dentry->d_inode;
812 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -0400813 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -0400814 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400815 struct rpc_message msg = {
816 .rpc_argp = &data->args,
817 .rpc_resp = &data->res,
818 .rpc_cred = req->wb_context->cred,
819 };
Trond Myklebust84115e12007-07-14 15:39:59 -0400820 struct rpc_task_setup task_setup_data = {
821 .rpc_client = NFS_CLIENT(inode),
Trond Myklebust07737692007-10-25 18:42:54 -0400822 .task = &data->task,
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400823 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -0400824 .callback_ops = call_ops,
825 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -0500826 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -0400827 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -0400828 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -0400829 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 /* Set up the RPC argument and reply structs
832 * NB: take care not to mess about with data->commit et al. */
833
834 data->req = req;
Trond Myklebust88be9f92007-06-05 10:42:27 -0400835 data->inode = inode = req->wb_context->path.dentry->d_inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400836 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 data->args.fh = NFS_FH(inode);
839 data->args.offset = req_offset(req) + offset;
840 data->args.pgbase = req->wb_pgbase + offset;
841 data->args.pages = data->pagevec;
842 data->args.count = count;
Trond Myklebust383ba712008-02-19 20:04:20 -0500843 data->args.context = get_nfs_open_context(req->wb_context);
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400844 data->args.stable = NFS_UNSTABLE;
845 if (how & FLUSH_STABLE) {
846 data->args.stable = NFS_DATA_SYNC;
Trond Myklebustfb8a1f12009-03-11 14:10:29 -0400847 if (!nfs_need_commit(NFS_I(inode)))
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400848 data->args.stable = NFS_FILE_SYNC;
849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 data->res.fattr = &data->fattr;
852 data->res.count = count;
853 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400854 nfs_fattr_init(&data->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Trond Myklebust788e7a82006-03-20 13:44:27 -0500856 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400857 NFS_PROTO(inode)->write_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Chuck Levera3f565b2007-01-31 12:14:01 -0500859 dprintk("NFS: %5u initiated write call "
Chuck Lever48186c72008-06-11 17:56:05 -0400860 "(req %s/%lld, %u bytes @ offset %llu)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500861 data->task.tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 inode->i_sb->s_id,
863 (long long)NFS_FILEID(inode),
864 count,
865 (unsigned long long)data->args.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Trond Myklebust07737692007-10-25 18:42:54 -0400867 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400868 if (IS_ERR(task))
869 return PTR_ERR(task);
870 rpc_put_task(task);
871 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872}
873
Fred6d884e82008-03-19 11:24:38 -0400874/* If a nfs_flush_* function fails, it should remove reqs from @head and
875 * call this on each, which will prepare them to be retried on next
876 * writeback using standard nfs.
877 */
878static void nfs_redirty_request(struct nfs_page *req)
879{
880 nfs_mark_request_dirty(req);
881 nfs_end_page_writeback(req->wb_page);
882 nfs_clear_page_tag_locked(req);
883}
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885/*
886 * Generate multiple small requests to write out a single
887 * contiguous dirty area on one page.
888 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400889static 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 -0700890{
891 struct nfs_page *req = nfs_list_entry(head->next);
892 struct page *page = req->wb_page;
893 struct nfs_write_data *data;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700894 size_t wsize = NFS_SERVER(inode)->wsize, nbytes;
895 unsigned int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 int requests = 0;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400897 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 LIST_HEAD(list);
899
900 nfs_list_remove_request(req);
901
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400902 nbytes = count;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700903 do {
904 size_t len = min(nbytes, wsize);
905
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400906 data = nfs_writedata_alloc(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (!data)
908 goto out_bad;
909 list_add(&data->pages, &list);
910 requests++;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700911 nbytes -= len;
912 } while (nbytes != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 atomic_set(&req->wb_complete, requests);
914
915 ClearPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 offset = 0;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400917 nbytes = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 do {
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400919 int ret2;
920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 data = list_entry(list.next, struct nfs_write_data, pages);
922 list_del_init(&data->pages);
923
924 data->pagevec[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400926 if (nbytes < wsize)
927 wsize = nbytes;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400928 ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops,
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400929 wsize, offset, how);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400930 if (ret == 0)
931 ret = ret2;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400932 offset += wsize;
933 nbytes -= wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 } while (nbytes != 0);
935
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400936 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938out_bad:
939 while (!list_empty(&list)) {
940 data = list_entry(list.next, struct nfs_write_data, pages);
941 list_del(&data->pages);
Trond Myklebust8aca67f2006-11-13 16:23:44 -0500942 nfs_writedata_release(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
Trond Myklebust61822ab2006-12-05 00:35:42 -0500944 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return -ENOMEM;
946}
947
948/*
949 * Create an RPC task for the given write request and kick it.
950 * The page must have been locked by the caller.
951 *
952 * It may happen that the page we're passed is not marked dirty.
953 * This is the case if nfs_updatepage detects a conflicting request
954 * that has been written but not committed.
955 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400956static 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 -0700957{
958 struct nfs_page *req;
959 struct page **pages;
960 struct nfs_write_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400962 data = nfs_writedata_alloc(npages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 if (!data)
964 goto out_bad;
965
966 pages = data->pagevec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 while (!list_empty(head)) {
968 req = nfs_list_entry(head->next);
969 nfs_list_remove_request(req);
970 nfs_list_add_request(req, &data->pages);
971 ClearPageError(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 *pages++ = req->wb_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
974 req = nfs_list_entry(data->pages.next);
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400977 return nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 out_bad:
979 while (!list_empty(head)) {
Trond Myklebust10afec92007-05-14 17:16:04 -0400980 req = nfs_list_entry(head->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 nfs_list_remove_request(req);
Trond Myklebust61822ab2006-12-05 00:35:42 -0500982 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
984 return -ENOMEM;
985}
986
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400987static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
988 struct inode *inode, int ioflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Chuck Leverbf4285e2007-12-20 14:54:57 -0500990 size_t wsize = NFS_SERVER(inode)->wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400992 if (wsize < PAGE_CACHE_SIZE)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400993 nfs_pageio_init(pgio, inode, nfs_flush_multi, wsize, ioflags);
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400994 else
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400995 nfs_pageio_init(pgio, inode, nfs_flush_one, wsize, ioflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
998/*
999 * Handle a write reply that flushed part of a page.
1000 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001001static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001003 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Chuck Lever48186c72008-06-11 17:56:05 -04001005 dprintk("NFS: %5u write(%s/%lld %d@%lld)",
1006 task->tk_pid,
1007 data->req->wb_context->path.dentry->d_inode->i_sb->s_id,
1008 (long long)
1009 NFS_FILEID(data->req->wb_context->path.dentry->d_inode),
1010 data->req->wb_bytes, (long long)req_offset(data->req));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001012 nfs_writeback_done(task, data);
1013}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001014
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001015static void nfs_writeback_release_partial(void *calldata)
1016{
1017 struct nfs_write_data *data = calldata;
1018 struct nfs_page *req = data->req;
1019 struct page *page = req->wb_page;
1020 int status = data->task.tk_status;
1021
1022 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001023 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001024 nfs_context_set_write_error(req->wb_context, status);
1025 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001026 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001029 if (nfs_write_need_commit(data)) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001030 struct inode *inode = page->mapping->host;
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001031
Trond Myklebust587142f2007-07-02 09:57:54 -04001032 spin_lock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001033 if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) {
1034 /* Do nothing we need to resend the writes */
1035 } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1036 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1037 dprintk(" defer commit\n");
1038 } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) {
1039 set_bit(PG_NEED_RESCHED, &req->wb_flags);
1040 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
1041 dprintk(" server reboot detected\n");
1042 }
Trond Myklebust587142f2007-07-02 09:57:54 -04001043 spin_unlock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001044 } else
1045 dprintk(" OK\n");
1046
1047out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (atomic_dec_and_test(&req->wb_complete))
1049 nfs_writepage_release(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001050 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
Trond Myklebust788e7a82006-03-20 13:44:27 -05001053static const struct rpc_call_ops nfs_write_partial_ops = {
1054 .rpc_call_done = nfs_writeback_done_partial,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001055 .rpc_release = nfs_writeback_release_partial,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001056};
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058/*
1059 * Handle a write reply that flushes a whole page.
1060 *
1061 * FIXME: There is an inherent race with invalidate_inode_pages and
1062 * writebacks since the page->count is kept > 1 for as long
1063 * as the page has a write request pending.
1064 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001065static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001067 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001069 nfs_writeback_done(task, data);
1070}
1071
1072static void nfs_writeback_release_full(void *calldata)
1073{
1074 struct nfs_write_data *data = calldata;
1075 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 /* Update attributes as result of writeback. */
1078 while (!list_empty(&data->pages)) {
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001079 struct nfs_page *req = nfs_list_entry(data->pages.next);
1080 struct page *page = req->wb_page;
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 nfs_list_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Chuck Lever48186c72008-06-11 17:56:05 -04001084 dprintk("NFS: %5u write (%s/%lld %d@%lld)",
1085 data->task.tk_pid,
Trond Myklebust88be9f92007-06-05 10:42:27 -04001086 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1087 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 req->wb_bytes,
1089 (long long)req_offset(req));
1090
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001091 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001092 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001093 nfs_context_set_write_error(req->wb_context, status);
1094 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001095 goto remove_request;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001098 if (nfs_write_need_commit(data)) {
1099 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1100 nfs_mark_request_commit(req);
1101 nfs_end_page_writeback(page);
1102 dprintk(" marked for commit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 goto next;
1104 }
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001105 dprintk(" OK\n");
1106remove_request:
1107 nfs_end_page_writeback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 nfs_inode_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001110 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001112 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Trond Myklebust788e7a82006-03-20 13:44:27 -05001115static const struct rpc_call_ops nfs_write_full_ops = {
1116 .rpc_call_done = nfs_writeback_done_full,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001117 .rpc_release = nfs_writeback_release_full,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001118};
1119
1120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121/*
1122 * This function is called when the WRITE call is complete.
1123 */
Chuck Lever462d5b32006-03-20 13:44:32 -05001124int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 struct nfs_writeargs *argp = &data->args;
1127 struct nfs_writeres *resp = &data->res;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001128 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Chuck Levera3f565b2007-01-31 12:14:01 -05001130 dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 task->tk_pid, task->tk_status);
1132
Chuck Leverf551e442006-09-20 14:33:04 -04001133 /*
1134 * ->write_done will attempt to use post-op attributes to detect
1135 * conflicting writes by other clients. A strict interpretation
1136 * of close-to-open would allow us to continue caching even if
1137 * another writer had changed the file, but some applications
1138 * depend on tighter cache coherency when writing.
1139 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001140 status = NFS_PROTO(data->inode)->write_done(task, data);
1141 if (status != 0)
1142 return status;
Chuck Lever91d5b472006-03-20 13:44:14 -05001143 nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count);
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1146 if (resp->verf->committed < argp->stable && task->tk_status >= 0) {
1147 /* We tried a write call, but the server did not
1148 * commit data to stable storage even though we
1149 * requested it.
1150 * Note: There is a known bug in Tru64 < 5.0 in which
1151 * the server reports NFS_DATA_SYNC, but performs
1152 * NFS_FILE_SYNC. We therefore implement this checking
1153 * as a dprintk() in order to avoid filling syslog.
1154 */
1155 static unsigned long complain;
1156
1157 if (time_before(complain, jiffies)) {
Chuck Lever48186c72008-06-11 17:56:05 -04001158 dprintk("NFS: faulty NFS server %s:"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 " (committed = %d) != (stable = %d)\n",
David Howells54ceac42006-08-22 20:06:13 -04001160 NFS_SERVER(data->inode)->nfs_client->cl_hostname,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 resp->verf->committed, argp->stable);
1162 complain = jiffies + 300 * HZ;
1163 }
1164 }
1165#endif
1166 /* Is this a short write? */
1167 if (task->tk_status >= 0 && resp->count < argp->count) {
1168 static unsigned long complain;
1169
Chuck Lever91d5b472006-03-20 13:44:14 -05001170 nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE);
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* Has the server at least made some progress? */
1173 if (resp->count != 0) {
1174 /* Was this an NFSv2 write or an NFSv3 stable write? */
1175 if (resp->verf->committed != NFS_UNSTABLE) {
1176 /* Resend from where the server left off */
1177 argp->offset += resp->count;
1178 argp->pgbase += resp->count;
1179 argp->count -= resp->count;
1180 } else {
1181 /* Resend as a stable write in order to avoid
1182 * headaches in the case of a server crash.
1183 */
1184 argp->stable = NFS_FILE_SYNC;
1185 }
1186 rpc_restart_call(task);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001187 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189 if (time_before(complain, jiffies)) {
1190 printk(KERN_WARNING
1191 "NFS: Server wrote zero bytes, expected %u.\n",
1192 argp->count);
1193 complain = jiffies + 300 * HZ;
1194 }
1195 /* Can't do anything about it except throw an error. */
1196 task->tk_status = -EIO;
1197 }
Trond Myklebust788e7a82006-03-20 13:44:27 -05001198 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
1201
1202#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001203void nfs_commitdata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Trond Myklebust383ba712008-02-19 20:04:20 -05001205 struct nfs_write_data *wdata = data;
1206
1207 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 nfs_commit_free(wdata);
1209}
1210
1211/*
1212 * Set up the argument/result storage required for the RPC call.
1213 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001214static int nfs_commit_rpcsetup(struct list_head *head,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001215 struct nfs_write_data *data,
1216 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
Trond Myklebust84115e12007-07-14 15:39:59 -04001218 struct nfs_page *first = nfs_list_entry(head->next);
1219 struct inode *inode = first->wb_context->path.dentry->d_inode;
1220 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -04001221 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -04001222 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001223 struct rpc_message msg = {
1224 .rpc_argp = &data->args,
1225 .rpc_resp = &data->res,
1226 .rpc_cred = first->wb_context->cred,
1227 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001228 struct rpc_task_setup task_setup_data = {
Trond Myklebust07737692007-10-25 18:42:54 -04001229 .task = &data->task,
Trond Myklebust84115e12007-07-14 15:39:59 -04001230 .rpc_client = NFS_CLIENT(inode),
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001231 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -04001232 .callback_ops = &nfs_commit_ops,
1233 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -05001234 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -04001235 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -04001236 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -04001237 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
1239 /* Set up the RPC argument and reply structs
1240 * NB: take care not to mess about with data->commit et al. */
1241
1242 list_splice_init(head, &data->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 data->inode = inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001245 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 data->args.fh = NFS_FH(data->inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001248 /* Note: we always request a commit of the entire inode */
1249 data->args.offset = 0;
1250 data->args.count = 0;
Trond Myklebust383ba712008-02-19 20:04:20 -05001251 data->args.context = get_nfs_open_context(first->wb_context);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001252 data->res.count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 data->res.fattr = &data->fattr;
1254 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001255 nfs_fattr_init(&data->fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001256
1257 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001258 NFS_PROTO(inode)->commit_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Chuck Levera3f565b2007-01-31 12:14:01 -05001260 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001261
Trond Myklebust07737692007-10-25 18:42:54 -04001262 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001263 if (IS_ERR(task))
1264 return PTR_ERR(task);
1265 rpc_put_task(task);
1266 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267}
1268
1269/*
1270 * Commit dirty pages
1271 */
1272static int
Chuck Lever40859d72005-11-30 18:09:02 -05001273nfs_commit_list(struct inode *inode, struct list_head *head, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
1275 struct nfs_write_data *data;
1276 struct nfs_page *req;
1277
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001278 data = nfs_commitdata_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 if (!data)
1281 goto out_bad;
1282
1283 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001284 return nfs_commit_rpcsetup(head, data, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 out_bad:
1286 while (!list_empty(head)) {
1287 req = nfs_list_entry(head->next);
1288 nfs_list_remove_request(req);
1289 nfs_mark_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001290 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001291 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1292 BDI_RECLAIMABLE);
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001293 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 }
1295 return -ENOMEM;
1296}
1297
1298/*
1299 * COMMIT call returned
1300 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001301static void nfs_commit_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001303 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Chuck Levera3f565b2007-01-31 12:14:01 -05001305 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 task->tk_pid, task->tk_status);
1307
Trond Myklebust788e7a82006-03-20 13:44:27 -05001308 /* Call the NFS version-specific code */
1309 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
1310 return;
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001311}
1312
1313static void nfs_commit_release(void *calldata)
1314{
1315 struct nfs_write_data *data = calldata;
1316 struct nfs_page *req;
1317 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 while (!list_empty(&data->pages)) {
1320 req = nfs_list_entry(data->pages.next);
1321 nfs_list_remove_request(req);
Trond Myklebuste468bae2008-06-13 13:25:22 -04001322 nfs_clear_request_commit(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Chuck Lever48186c72008-06-11 17:56:05 -04001324 dprintk("NFS: commit (%s/%lld %d@%lld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -04001325 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1326 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 req->wb_bytes,
1328 (long long)req_offset(req));
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001329 if (status < 0) {
1330 nfs_context_set_write_error(req->wb_context, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 nfs_inode_remove_request(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001332 dprintk(", error = %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 goto next;
1334 }
1335
1336 /* Okay, COMMIT succeeded, apparently. Check the verifier
1337 * returned by the server against all stored verfs. */
1338 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
1339 /* We have a match */
1340 nfs_inode_remove_request(req);
1341 dprintk(" OK\n");
1342 goto next;
1343 }
1344 /* We have a mismatch. Write the page again */
1345 dprintk(" mismatch\n");
Fred6d884e82008-03-19 11:24:38 -04001346 nfs_mark_request_dirty(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001348 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001350 nfs_commitdata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001352
1353static const struct rpc_call_ops nfs_commit_ops = {
1354 .rpc_call_done = nfs_commit_done,
1355 .rpc_release = nfs_commit_release,
1356};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001358int nfs_commit_inode(struct inode *inode, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 LIST_HEAD(head);
Trond Myklebust7d46a492006-03-20 13:44:50 -05001361 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Trond Myklebust587142f2007-07-02 09:57:54 -04001363 spin_lock(&inode->i_lock);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001364 res = nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001365 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 if (res) {
Trond Myklebust7d46a492006-03-20 13:44:50 -05001367 int error = nfs_commit_list(inode, &head, how);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001368 if (error < 0)
1369 return error;
1370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 return res;
1372}
Trond Myklebustc63c7b02007-04-02 19:29:52 -04001373#else
1374static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1375{
1376 return 0;
1377}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378#endif
1379
Trond Myklebust1c759502006-10-09 16:18:38 -04001380long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381{
Trond Myklebust1c759502006-10-09 16:18:38 -04001382 struct inode *inode = mapping->host;
Trond Myklebustca52fec2007-04-17 17:22:13 -04001383 pgoff_t idx_start, idx_end;
Trond Myklebust1c759502006-10-09 16:18:38 -04001384 unsigned int npages = 0;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001385 LIST_HEAD(head);
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001386 int nocommit = how & FLUSH_NOCOMMIT;
Trond Myklebust3f442542006-09-17 14:46:44 -04001387 long pages, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Trond Myklebust1c759502006-10-09 16:18:38 -04001389 /* FIXME */
1390 if (wbc->range_cyclic)
1391 idx_start = 0;
1392 else {
1393 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
1394 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
1395 if (idx_end > idx_start) {
Trond Myklebustca52fec2007-04-17 17:22:13 -04001396 pgoff_t l_npages = 1 + idx_end - idx_start;
Trond Myklebust1c759502006-10-09 16:18:38 -04001397 npages = l_npages;
1398 if (sizeof(npages) != sizeof(l_npages) &&
Trond Myklebustca52fec2007-04-17 17:22:13 -04001399 (pgoff_t)npages != l_npages)
Trond Myklebust1c759502006-10-09 16:18:38 -04001400 npages = 0;
1401 }
1402 }
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001403 how &= ~FLUSH_NOCOMMIT;
Trond Myklebust587142f2007-07-02 09:57:54 -04001404 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 do {
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001406 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1407 if (ret != 0)
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001408 continue;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001409 if (nocommit)
1410 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001411 pages = nfs_scan_commit(inode, &head, idx_start, npages);
Trond Myklebust724c4392007-04-17 17:22:13 -04001412 if (pages == 0)
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001413 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001414 if (how & FLUSH_INVALIDATE) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001415 spin_unlock(&inode->i_lock);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001416 nfs_cancel_commit_list(&head);
Trond Myklebuste8e058e2006-11-15 17:31:56 -05001417 ret = pages;
Trond Myklebust587142f2007-07-02 09:57:54 -04001418 spin_lock(&inode->i_lock);
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001419 continue;
1420 }
1421 pages += nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001422 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001423 ret = nfs_commit_list(inode, &head, how);
Trond Myklebust587142f2007-07-02 09:57:54 -04001424 spin_lock(&inode->i_lock);
1425
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001426 } while (ret >= 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001427 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001428 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
Trond Myklebust34901f72007-07-25 14:09:54 -04001431static int __nfs_write_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001432{
Trond Myklebust1c759502006-10-09 16:18:38 -04001433 int ret;
1434
Trond Myklebust34901f72007-07-25 14:09:54 -04001435 ret = nfs_writepages(mapping, wbc);
Trond Myklebust61822ab2006-12-05 00:35:42 -05001436 if (ret < 0)
1437 goto out;
Trond Myklebust34901f72007-07-25 14:09:54 -04001438 ret = nfs_sync_mapping_wait(mapping, wbc, how);
Trond Myklebusted90ef52007-07-20 13:13:28 -04001439 if (ret < 0)
1440 goto out;
1441 return 0;
Trond Myklebust61822ab2006-12-05 00:35:42 -05001442out:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001443 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
Trond Myklebust1c759502006-10-09 16:18:38 -04001444 return ret;
1445}
1446
Trond Myklebust34901f72007-07-25 14:09:54 -04001447/* Two pass sync: first using WB_SYNC_NONE, then WB_SYNC_ALL */
1448static int nfs_write_mapping(struct address_space *mapping, int how)
1449{
1450 struct writeback_control wbc = {
1451 .bdi = mapping->backing_dev_info,
Trond Myklebust72cb77f2009-03-11 14:10:30 -04001452 .sync_mode = WB_SYNC_ALL,
Trond Myklebust34901f72007-07-25 14:09:54 -04001453 .nr_to_write = LONG_MAX,
Trond Myklebustd7fb1202008-10-06 20:08:56 -04001454 .range_start = 0,
1455 .range_end = LLONG_MAX,
Trond Myklebust34901f72007-07-25 14:09:54 -04001456 .for_writepages = 1,
Trond Myklebust34901f72007-07-25 14:09:54 -04001457 };
Trond Myklebust34901f72007-07-25 14:09:54 -04001458
Trond Myklebust34901f72007-07-25 14:09:54 -04001459 return __nfs_write_mapping(mapping, &wbc, how);
1460}
1461
Trond Myklebusted90ef52007-07-20 13:13:28 -04001462/*
1463 * flush the inode to disk.
1464 */
1465int nfs_wb_all(struct inode *inode)
Trond Myklebust1c759502006-10-09 16:18:38 -04001466{
Trond Myklebusted90ef52007-07-20 13:13:28 -04001467 return nfs_write_mapping(inode->i_mapping, 0);
1468}
Trond Myklebust1c759502006-10-09 16:18:38 -04001469
Trond Myklebusted90ef52007-07-20 13:13:28 -04001470int nfs_wb_nocommit(struct inode *inode)
1471{
1472 return nfs_write_mapping(inode->i_mapping, FLUSH_NOCOMMIT);
Trond Myklebust1c759502006-10-09 16:18:38 -04001473}
1474
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001475int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1476{
1477 struct nfs_page *req;
1478 loff_t range_start = page_offset(page);
1479 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1480 struct writeback_control wbc = {
1481 .bdi = page->mapping->backing_dev_info,
1482 .sync_mode = WB_SYNC_ALL,
1483 .nr_to_write = LONG_MAX,
1484 .range_start = range_start,
1485 .range_end = range_end,
1486 };
1487 int ret = 0;
1488
1489 BUG_ON(!PageLocked(page));
1490 for (;;) {
1491 req = nfs_page_find_request(page);
1492 if (req == NULL)
1493 goto out;
Trond Myklebuste468bae2008-06-13 13:25:22 -04001494 if (test_bit(PG_CLEAN, &req->wb_flags)) {
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001495 nfs_release_request(req);
1496 break;
1497 }
1498 if (nfs_lock_request_dontget(req)) {
1499 nfs_inode_remove_request(req);
1500 /*
1501 * In case nfs_inode_remove_request has marked the
1502 * page as being dirty
1503 */
1504 cancel_dirty_page(page, PAGE_CACHE_SIZE);
1505 nfs_unlock_request(req);
1506 break;
1507 }
1508 ret = nfs_wait_on_request(req);
1509 if (ret < 0)
1510 goto out;
1511 }
1512 if (!PagePrivate(page))
1513 return 0;
1514 ret = nfs_sync_mapping_wait(page->mapping, &wbc, FLUSH_INVALIDATE);
1515out:
1516 return ret;
1517}
1518
Adrian Bunk5334eb12007-11-21 15:04:31 -08001519static int nfs_wb_page_priority(struct inode *inode, struct page *page,
1520 int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001521{
1522 loff_t range_start = page_offset(page);
1523 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001524 struct writeback_control wbc = {
1525 .bdi = page->mapping->backing_dev_info,
1526 .sync_mode = WB_SYNC_ALL,
1527 .nr_to_write = LONG_MAX,
1528 .range_start = range_start,
1529 .range_end = range_end,
1530 };
1531 int ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001532
Trond Myklebust73e33022008-04-11 16:03:54 -04001533 do {
1534 if (clear_page_dirty_for_io(page)) {
1535 ret = nfs_writepage_locked(page, &wbc);
1536 if (ret < 0)
1537 goto out_error;
1538 } else if (!PagePrivate(page))
1539 break;
1540 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001541 if (ret < 0)
Trond Myklebust73e33022008-04-11 16:03:54 -04001542 goto out_error;
1543 } while (PagePrivate(page));
1544 return 0;
1545out_error:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001546 __mark_inode_dirty(inode, I_DIRTY_PAGES);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001547 return ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001548}
1549
1550/*
1551 * Write back all requests on one page - we do this before reading it.
1552 */
1553int nfs_wb_page(struct inode *inode, struct page* page)
1554{
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001555 return nfs_wb_page_priority(inode, page, FLUSH_STABLE);
Trond Myklebust1c759502006-10-09 16:18:38 -04001556}
1557
David Howellsf7b422b2006-06-09 09:34:33 -04001558int __init nfs_init_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
1560 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1561 sizeof(struct nfs_write_data),
1562 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +09001563 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (nfs_wdata_cachep == NULL)
1565 return -ENOMEM;
1566
Matthew Dobson93d23412006-03-26 01:37:50 -08001567 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
1568 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (nfs_wdata_mempool == NULL)
1570 return -ENOMEM;
1571
Matthew Dobson93d23412006-03-26 01:37:50 -08001572 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
1573 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if (nfs_commit_mempool == NULL)
1575 return -ENOMEM;
1576
Peter Zijlstra89a09142007-03-16 13:38:26 -08001577 /*
1578 * NFS congestion size, scale with available memory.
1579 *
1580 * 64MB: 8192k
1581 * 128MB: 11585k
1582 * 256MB: 16384k
1583 * 512MB: 23170k
1584 * 1GB: 32768k
1585 * 2GB: 46340k
1586 * 4GB: 65536k
1587 * 8GB: 92681k
1588 * 16GB: 131072k
1589 *
1590 * This allows larger machines to have larger/more transfers.
1591 * Limit the default to 256M
1592 */
1593 nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
1594 if (nfs_congestion_kb > 256*1024)
1595 nfs_congestion_kb = 256*1024;
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 return 0;
1598}
1599
David Brownell266bee82006-06-27 12:59:15 -07001600void nfs_destroy_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
1602 mempool_destroy(nfs_commit_mempool);
1603 mempool_destroy(nfs_wdata_mempool);
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001604 kmem_cache_destroy(nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606