blob: 21d8a48b624b4ed1f7379fa44b073fbc2e7c5c50 [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 Myklebust7e5f6142008-05-25 12:59:19 -0400191 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
Trond Myklebustacee4782008-01-22 17:13:07 -0500192 nfs_clear_page_tag_locked(req);
Trond Myklebustabd3e642006-01-03 09:55:02 +0100193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196static int wb_priority(struct writeback_control *wbc)
197{
198 if (wbc->for_reclaim)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400199 return FLUSH_HIGHPRI | FLUSH_STABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (wbc->for_kupdate)
201 return FLUSH_LOWPRI;
202 return 0;
203}
204
205/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800206 * NFS congestion control
207 */
208
209int nfs_congestion_kb;
210
211#define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10))
212#define NFS_CONGESTION_OFF_THRESH \
213 (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2))
214
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400215static int nfs_set_page_writeback(struct page *page)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800216{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400217 int ret = test_set_page_writeback(page);
218
219 if (!ret) {
Peter Zijlstra89a09142007-03-16 13:38:26 -0800220 struct inode *inode = page->mapping->host;
221 struct nfs_server *nfss = NFS_SERVER(inode);
222
Peter Zijlstra277866a2007-05-08 00:35:12 -0700223 if (atomic_long_inc_return(&nfss->writeback) >
Peter Zijlstra89a09142007-03-16 13:38:26 -0800224 NFS_CONGESTION_ON_THRESH)
225 set_bdi_congested(&nfss->backing_dev_info, WRITE);
226 }
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400227 return ret;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800228}
229
230static void nfs_end_page_writeback(struct page *page)
231{
232 struct inode *inode = page->mapping->host;
233 struct nfs_server *nfss = NFS_SERVER(inode);
234
235 end_page_writeback(page);
Peter Zijlstrac4dc4be2007-10-16 23:25:41 -0700236 if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
Peter Zijlstra89a09142007-03-16 13:38:26 -0800237 clear_bdi_congested(&nfss->backing_dev_info, WRITE);
Peter Zijlstra89a09142007-03-16 13:38:26 -0800238}
239
240/*
Trond Myklebuste261f512006-12-05 00:35:41 -0500241 * Find an associated nfs write request, and prepare to flush it out
Trond Myklebust9cccef92007-07-22 17:09:05 -0400242 * May return an error if the user signalled nfs_wait_on_request().
Trond Myklebuste261f512006-12-05 00:35:41 -0500243 */
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400244static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
245 struct page *page)
Trond Myklebuste261f512006-12-05 00:35:41 -0500246{
Trond Myklebust587142f2007-07-02 09:57:54 -0400247 struct inode *inode = page->mapping->host;
Trond Myklebuste261f512006-12-05 00:35:41 -0500248 struct nfs_page *req;
Trond Myklebuste261f512006-12-05 00:35:41 -0500249 int ret;
250
Trond Myklebust587142f2007-07-02 09:57:54 -0400251 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500252 for(;;) {
253 req = nfs_page_find_request_locked(page);
254 if (req == NULL) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400255 spin_unlock(&inode->i_lock);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400256 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500257 }
Trond Myklebustacee4782008-01-22 17:13:07 -0500258 if (nfs_set_page_tag_locked(req))
Trond Myklebuste261f512006-12-05 00:35:41 -0500259 break;
260 /* Note: If we hold the page lock, as is the case in nfs_writepage,
Trond Myklebustacee4782008-01-22 17:13:07 -0500261 * then the call to nfs_set_page_tag_locked() will always
Trond Myklebuste261f512006-12-05 00:35:41 -0500262 * succeed provided that someone hasn't already marked the
263 * request as dirty (in which case we don't care).
264 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400265 spin_unlock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500266 ret = nfs_wait_on_request(req);
267 nfs_release_request(req);
268 if (ret != 0)
269 return ret;
Trond Myklebust587142f2007-07-02 09:57:54 -0400270 spin_lock(&inode->i_lock);
Trond Myklebuste261f512006-12-05 00:35:41 -0500271 }
Trond Myklebust612c9382007-04-20 16:12:45 -0400272 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
273 /* This request is marked for commit */
Trond Myklebust587142f2007-07-02 09:57:54 -0400274 spin_unlock(&inode->i_lock);
Trond Myklebustacee4782008-01-22 17:13:07 -0500275 nfs_clear_page_tag_locked(req);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400276 nfs_pageio_complete(pgio);
Trond Myklebust9cccef92007-07-22 17:09:05 -0400277 return 0;
Trond Myklebust612c9382007-04-20 16:12:45 -0400278 }
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400279 if (nfs_set_page_writeback(page) != 0) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400280 spin_unlock(&inode->i_lock);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400281 BUG();
282 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400283 spin_unlock(&inode->i_lock);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400284 if (!nfs_pageio_add_request(pgio, req)) {
285 nfs_redirty_request(req);
Fred Isamanf8512ad2008-03-19 11:24:39 -0400286 return pgio->pg_error;
287 }
Trond Myklebust9cccef92007-07-22 17:09:05 -0400288 return 0;
Trond Myklebuste261f512006-12-05 00:35:41 -0500289}
290
Trond Myklebustf758c8852007-07-22 19:27:32 -0400291static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
292{
293 struct inode *inode = page->mapping->host;
294
295 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
296 nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1);
297
298 nfs_pageio_cond_complete(pgio, page->index);
299 return nfs_page_async_flush(pgio, page);
300}
301
Trond Myklebuste261f512006-12-05 00:35:41 -0500302/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 * Write an mmapped page to the server.
304 */
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500305static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400307 struct nfs_pageio_descriptor pgio;
Trond Myklebuste261f512006-12-05 00:35:41 -0500308 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Trond Myklebustf758c8852007-07-22 19:27:32 -0400310 nfs_pageio_init_write(&pgio, page->mapping->host, wb_priority(wbc));
311 err = nfs_do_writepage(page, wbc, &pgio);
312 nfs_pageio_complete(&pgio);
313 if (err < 0)
314 return err;
315 if (pgio.pg_error < 0)
316 return pgio.pg_error;
317 return 0;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500318}
319
320int nfs_writepage(struct page *page, struct writeback_control *wbc)
321{
Trond Myklebustf758c8852007-07-22 19:27:32 -0400322 int ret;
Trond Myklebust4d770cc2006-12-05 00:35:41 -0500323
Trond Myklebustf758c8852007-07-22 19:27:32 -0400324 ret = nfs_writepage_locked(page, wbc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 unlock_page(page);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400326 return ret;
327}
328
329static int nfs_writepages_callback(struct page *page, struct writeback_control *wbc, void *data)
330{
331 int ret;
332
333 ret = nfs_do_writepage(page, wbc, data);
334 unlock_page(page);
335 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
339{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct inode *inode = mapping->host;
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400341 struct nfs_pageio_descriptor pgio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 int err;
343
Chuck Lever91d5b472006-03-20 13:44:14 -0500344 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
345
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400346 nfs_pageio_init_write(&pgio, inode, wb_priority(wbc));
Trond Myklebustf758c8852007-07-22 19:27:32 -0400347 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400348 nfs_pageio_complete(&pgio);
Trond Myklebustf758c8852007-07-22 19:27:32 -0400349 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return err;
Trond Myklebustf758c8852007-07-22 19:27:32 -0400351 if (pgio.pg_error < 0)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400352 return pgio.pg_error;
353 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356/*
357 * Insert a write request into an inode
358 */
Nick Piggin27852592008-02-04 23:48:37 -0800359static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 struct nfs_inode *nfsi = NFS_I(inode);
362 int error;
363
364 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379/*
Peter Zijlstra89a09142007-03-16 13:38:26 -0800380 * Remove a write request from an inode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 */
382static void nfs_inode_remove_request(struct nfs_page *req)
383{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400384 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 struct nfs_inode *nfsi = NFS_I(inode);
386
387 BUG_ON (!NFS_WBACK_BUSY(req));
388
Trond Myklebust587142f2007-07-02 09:57:54 -0400389 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500390 set_page_private(req->wb_page, 0);
Trond Myklebustdeb7d632006-03-20 13:44:50 -0500391 ClearPagePrivate(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
393 nfsi->npages--;
394 if (!nfsi->npages) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400395 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 iput(inode);
397 } else
Trond Myklebust587142f2007-07-02 09:57:54 -0400398 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 nfs_clear_request(req);
400 nfs_release_request(req);
401}
402
Trond Myklebust61822ab2006-12-05 00:35:42 -0500403static void
Fred6d884e82008-03-19 11:24:38 -0400404nfs_mark_request_dirty(struct nfs_page *req)
Trond Myklebust61822ab2006-12-05 00:35:42 -0500405{
Trond Myklebust61822ab2006-12-05 00:35:42 -0500406 __set_page_dirty_nobuffers(req->wb_page);
407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/*
410 * Check if a request is dirty
411 */
412static inline int
413nfs_dirty_request(struct nfs_page *req)
414{
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400415 struct page *page = req->wb_page;
416
Trond Myklebust612c9382007-04-20 16:12:45 -0400417 if (page == NULL || test_bit(PG_NEED_COMMIT, &req->wb_flags))
Trond Myklebust5a6d41b2007-04-14 19:10:12 -0400418 return 0;
Fred Isaman38def502008-05-01 20:03:22 +0300419 return !PageWriteback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
423/*
424 * Add a request to the inode's commit list.
425 */
426static void
427nfs_mark_request_commit(struct nfs_page *req)
428{
Trond Myklebust88be9f92007-06-05 10:42:27 -0400429 struct inode *inode = req->wb_context->path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 struct nfs_inode *nfsi = NFS_I(inode);
431
Trond Myklebust587142f2007-07-02 09:57:54 -0400432 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 nfsi->ncommit++;
Trond Myklebust612c9382007-04-20 16:12:45 -0400434 set_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Trond Myklebust5c369682007-06-17 15:27:42 -0400435 radix_tree_tag_set(&nfsi->nfs_page_tree,
436 req->wb_index,
437 NFS_PAGE_TAG_COMMIT);
Trond Myklebust587142f2007-07-02 09:57:54 -0400438 spin_unlock(&inode->i_lock);
Christoph Lameterfd39fc82006-06-30 01:55:40 -0700439 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700440 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
Trond Myklebusta1803042006-12-05 00:45:19 -0500441 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400443
444static inline
445int nfs_write_need_commit(struct nfs_write_data *data)
446{
447 return data->verf.committed != NFS_FILE_SYNC;
448}
449
450static inline
451int nfs_reschedule_unstable_write(struct nfs_page *req)
452{
Trond Myklebust612c9382007-04-20 16:12:45 -0400453 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400454 nfs_mark_request_commit(req);
455 return 1;
456 }
457 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
Fred6d884e82008-03-19 11:24:38 -0400458 nfs_mark_request_dirty(req);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400459 return 1;
460 }
461 return 0;
462}
463#else
464static inline void
465nfs_mark_request_commit(struct nfs_page *req)
466{
467}
468
469static inline
470int nfs_write_need_commit(struct nfs_write_data *data)
471{
472 return 0;
473}
474
475static inline
476int nfs_reschedule_unstable_write(struct nfs_page *req)
477{
478 return 0;
479}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#endif
481
482/*
483 * Wait for a request to complete.
484 *
Matthew Wilcox150030b2007-12-06 16:24:39 -0500485 * Interruptible by fatal signals only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 */
Trond Myklebustca52fec2007-04-17 17:22:13 -0400487static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 struct nfs_inode *nfsi = NFS_I(inode);
490 struct nfs_page *req;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400491 pgoff_t idx_end, next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 unsigned int res = 0;
493 int error;
494
495 if (npages == 0)
496 idx_end = ~0;
497 else
498 idx_end = idx_start + npages - 1;
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 next = idx_start;
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400501 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 -0700502 if (req->wb_index > idx_end)
503 break;
504
505 next = req->wb_index + 1;
Trond Myklebustc6a556b2005-06-22 17:16:30 +0000506 BUG_ON(!NFS_WBACK_BUSY(req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Trond Myklebustc03b4022007-06-17 13:26:38 -0400508 kref_get(&req->wb_kref);
Trond Myklebust587142f2007-07-02 09:57:54 -0400509 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 error = nfs_wait_on_request(req);
511 nfs_release_request(req);
Trond Myklebust587142f2007-07-02 09:57:54 -0400512 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (error < 0)
514 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 res++;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return res;
518}
519
Trond Myklebust83715ad2006-07-05 13:17:12 -0400520static void nfs_cancel_commit_list(struct list_head *head)
521{
522 struct nfs_page *req;
523
524 while(!list_empty(head)) {
525 req = nfs_list_entry(head->next);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700526 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -0700527 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
528 BDI_RECLAIMABLE);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400529 nfs_list_remove_request(req);
Trond Myklebust612c9382007-04-20 16:12:45 -0400530 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400531 nfs_inode_remove_request(req);
Trond Myklebustb6dff262006-10-19 23:28:38 -0700532 nfs_unlock_request(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -0400533 }
534}
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
537/*
538 * nfs_scan_commit - Scan an inode for commit requests
539 * @inode: NFS inode to scan
540 * @dst: destination list
541 * @idx_start: lower bound of page->index to scan.
542 * @npages: idx_start + npages sets the upper bound to scan.
543 *
544 * Moves requests from the inode's 'commit' request list.
545 * The requests are *not* checked to ensure that they form a contiguous set.
546 */
547static int
Trond Myklebustca52fec2007-04-17 17:22:13 -0400548nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 struct nfs_inode *nfsi = NFS_I(inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000551 int res = 0;
552
553 if (nfsi->ncommit != 0) {
Trond Myklebust5c369682007-06-17 15:27:42 -0400554 res = nfs_scan_list(nfsi, dst, idx_start, npages,
555 NFS_PAGE_TAG_COMMIT);
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000556 nfsi->ncommit -= res;
Trond Myklebust3da28eb2005-06-22 17:16:31 +0000557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 return res;
559}
Trond Myklebustc42de9d2006-03-20 13:44:51 -0500560#else
Trond Myklebustca52fec2007-04-17 17:22:13 -0400561static 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 -0500562{
563 return 0;
564}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#endif
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/*
568 * Try to update any existing write request, or create one if there is none.
569 * In order to match, the request's credentials must match those of
570 * the calling process.
571 *
572 * Note: Should always be called with the Page Lock held!
573 */
574static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx,
Trond Myklebuste21195a2006-12-05 00:35:39 -0500575 struct page *page, unsigned int offset, unsigned int bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Peter Zijlstra89a09142007-03-16 13:38:26 -0800577 struct address_space *mapping = page->mapping;
578 struct inode *inode = mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 struct nfs_page *req, *new = NULL;
Trond Myklebustca52fec2007-04-17 17:22:13 -0400580 pgoff_t rqend, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 end = offset + bytes;
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 for (;;) {
585 /* Loop over all inode entries and see if we find
586 * A request for the page we wish to update
587 */
Trond Myklebust587142f2007-07-02 09:57:54 -0400588 spin_lock(&inode->i_lock);
Trond Myklebust277459d2006-12-05 00:35:35 -0500589 req = nfs_page_find_request_locked(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (req) {
Trond Myklebustacee4782008-01-22 17:13:07 -0500591 if (!nfs_set_page_tag_locked(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 int error;
Trond Myklebust277459d2006-12-05 00:35:35 -0500593
Trond Myklebust587142f2007-07-02 09:57:54 -0400594 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 error = nfs_wait_on_request(req);
596 nfs_release_request(req);
Neil Brown1dd594b2006-03-20 13:44:04 -0500597 if (error < 0) {
Nick Piggin27852592008-02-04 23:48:37 -0800598 if (new) {
599 radix_tree_preload_end();
Neil Brown1dd594b2006-03-20 13:44:04 -0500600 nfs_release_request(new);
Nick Piggin27852592008-02-04 23:48:37 -0800601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return ERR_PTR(error);
Neil Brown1dd594b2006-03-20 13:44:04 -0500603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 continue;
605 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400606 spin_unlock(&inode->i_lock);
Nick Piggin27852592008-02-04 23:48:37 -0800607 if (new) {
608 radix_tree_preload_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 nfs_release_request(new);
Nick Piggin27852592008-02-04 23:48:37 -0800610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 break;
612 }
613
614 if (new) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 nfs_lock_request_dontget(new);
Nick Piggin27852592008-02-04 23:48:37 -0800616 nfs_inode_add_request(inode, new);
Trond Myklebust587142f2007-07-02 09:57:54 -0400617 spin_unlock(&inode->i_lock);
Nick Piggin27852592008-02-04 23:48:37 -0800618 radix_tree_preload_end();
Trond Myklebust61e930a2007-10-18 17:08:05 -0400619 req = new;
Trond Myklebustefc91ed2008-06-10 18:31:00 -0400620 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
Trond Myklebust587142f2007-07-02 09:57:54 -0400622 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 new = nfs_create_request(ctx, inode, page, offset, bytes);
625 if (IS_ERR(new))
626 return new;
Trond Myklebustf3d47a32008-06-05 15:17:39 -0400627 if (radix_tree_preload(GFP_NOFS)) {
628 nfs_release_request(new);
629 return ERR_PTR(-ENOMEM);
630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632
633 /* We have a request for our page.
634 * If the creds don't match, or the
635 * page addresses don't match,
636 * tell the caller to wait on the conflicting
637 * request.
638 */
639 rqend = req->wb_offset + req->wb_bytes;
640 if (req->wb_context != ctx
641 || req->wb_page != page
642 || !nfs_dirty_request(req)
643 || offset > rqend || end < req->wb_offset) {
Trond Myklebustacee4782008-01-22 17:13:07 -0500644 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return ERR_PTR(-EBUSY);
646 }
647
648 /* Okay, the request matches. Update the region */
649 if (offset < req->wb_offset) {
650 req->wb_offset = offset;
651 req->wb_pgbase = offset;
Trond Myklebust61e930a2007-10-18 17:08:05 -0400652 req->wb_bytes = max(end, rqend) - req->wb_offset;
Trond Myklebustefc91ed2008-06-10 18:31:00 -0400653 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
656 if (end > rqend)
657 req->wb_bytes = end - req->wb_offset;
658
Trond Myklebustefc91ed2008-06-10 18:31:00 -0400659out:
Trond Myklebust61e930a2007-10-18 17:08:05 -0400660 return req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
663int nfs_flush_incompatible(struct file *file, struct page *page)
664{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400665 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 struct nfs_page *req;
Trond Myklebust1a545332006-12-05 00:35:40 -0500667 int do_flush, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /*
669 * Look for a request corresponding to this page. If there
670 * is one, and it belongs to another file, we flush it out
671 * before we try to copy anything into the page. Do this
672 * due to the lack of an ACCESS-type call in NFSv2.
673 * Also do the same if we find a request from an existing
674 * dropped page.
675 */
Trond Myklebust1a545332006-12-05 00:35:40 -0500676 do {
677 req = nfs_page_find_request(page);
678 if (req == NULL)
679 return 0;
680 do_flush = req->wb_page != page || req->wb_context != ctx
Trond Myklebuste261f512006-12-05 00:35:41 -0500681 || !nfs_dirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 nfs_release_request(req);
Trond Myklebust1a545332006-12-05 00:35:40 -0500683 if (!do_flush)
684 return 0;
685 status = nfs_wb_page(page->mapping->host, page);
686 } while (status == 0);
687 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690/*
Trond Myklebust5d47a352008-02-07 17:24:07 -0500691 * If the page cache is marked as unsafe or invalid, then we can't rely on
692 * the PageUptodate() flag. In this case, we will need to turn off
693 * write optimisations that depend on the page contents being correct.
694 */
695static int nfs_write_pageuptodate(struct page *page, struct inode *inode)
696{
697 return PageUptodate(page) &&
698 !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA));
699}
700
701/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 * Update and possibly write a cached page of an NFS file.
703 *
704 * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
705 * things with a page scheduled for an RPC call (e.g. invalidate it).
706 */
707int nfs_updatepage(struct file *file, struct page *page,
708 unsigned int offset, unsigned int count)
709{
Trond Myklebustcd3758e2007-08-10 17:44:32 -0400710 struct nfs_open_context *ctx = nfs_file_open_context(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 struct inode *inode = page->mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int status = 0;
713
Chuck Lever91d5b472006-03-20 13:44:14 -0500714 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
715
Chuck Lever48186c72008-06-11 17:56:05 -0400716 dprintk("NFS: nfs_updatepage(%s/%s %d@%lld)\n",
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800717 file->f_path.dentry->d_parent->d_name.name,
718 file->f_path.dentry->d_name.name, count,
Chuck Lever48186c72008-06-11 17:56:05 -0400719 (long long)(page_offset(page) + offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 /* If we're not using byte range locks, and we know the page
Trond Myklebust5d47a352008-02-07 17:24:07 -0500722 * is up to date, it may be more efficient to extend the write
723 * to cover the entire page in order to avoid fragmentation
724 * inefficiencies.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 */
Trond Myklebust5d47a352008-02-07 17:24:07 -0500726 if (nfs_write_pageuptodate(page, inode) &&
727 inode->i_flock == NULL &&
Trond Myklebust4b5621f2008-02-25 15:56:29 -0800728 !(file->f_flags & O_SYNC)) {
Trond Myklebust49a70f22006-12-05 00:35:38 -0500729 count = max(count + offset, nfs_page_length(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 }
732
Trond Myklebuste21195a2006-12-05 00:35:39 -0500733 status = nfs_writepage_setup(ctx, page, offset, count);
Trond Myklebust03fa9e82008-06-05 16:02:35 -0400734 if (status < 0)
735 nfs_set_pageerror(page);
736 else
737 __set_page_dirty_nobuffers(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Chuck Lever48186c72008-06-11 17:56:05 -0400739 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 status, (long long)i_size_read(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return status;
742}
743
744static void nfs_writepage_release(struct nfs_page *req)
745{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Trond Myklebust7e5f6142008-05-25 12:59:19 -0400747 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) {
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400748 nfs_end_page_writeback(req->wb_page);
749 nfs_inode_remove_request(req);
750 } else
751 nfs_end_page_writeback(req->wb_page);
Trond Myklebust9fd367f2007-06-17 15:10:24 -0400752 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
Trond Myklebust3ff75762007-07-14 15:40:00 -0400755static int flush_task_priority(int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
757 switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
758 case FLUSH_HIGHPRI:
759 return RPC_PRIORITY_HIGH;
760 case FLUSH_LOWPRI:
761 return RPC_PRIORITY_LOW;
762 }
763 return RPC_PRIORITY_NORMAL;
764}
765
766/*
767 * Set up the argument/result storage required for the RPC call.
768 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400769static int nfs_write_rpcsetup(struct nfs_page *req,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 struct nfs_write_data *data,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500771 const struct rpc_call_ops *call_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 unsigned int count, unsigned int offset,
773 int how)
774{
Trond Myklebust84115e12007-07-14 15:39:59 -0400775 struct inode *inode = req->wb_context->path.dentry->d_inode;
776 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -0400777 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -0400778 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400779 struct rpc_message msg = {
780 .rpc_argp = &data->args,
781 .rpc_resp = &data->res,
782 .rpc_cred = req->wb_context->cred,
783 };
Trond Myklebust84115e12007-07-14 15:39:59 -0400784 struct rpc_task_setup task_setup_data = {
785 .rpc_client = NFS_CLIENT(inode),
Trond Myklebust07737692007-10-25 18:42:54 -0400786 .task = &data->task,
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400787 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -0400788 .callback_ops = call_ops,
789 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -0500790 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -0400791 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -0400792 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -0400793 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 /* Set up the RPC argument and reply structs
796 * NB: take care not to mess about with data->commit et al. */
797
798 data->req = req;
Trond Myklebust88be9f92007-06-05 10:42:27 -0400799 data->inode = inode = req->wb_context->path.dentry->d_inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400800 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 data->args.fh = NFS_FH(inode);
803 data->args.offset = req_offset(req) + offset;
804 data->args.pgbase = req->wb_pgbase + offset;
805 data->args.pages = data->pagevec;
806 data->args.count = count;
Trond Myklebust383ba712008-02-19 20:04:20 -0500807 data->args.context = get_nfs_open_context(req->wb_context);
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400808 data->args.stable = NFS_UNSTABLE;
809 if (how & FLUSH_STABLE) {
810 data->args.stable = NFS_DATA_SYNC;
811 if (!NFS_I(inode)->ncommit)
812 data->args.stable = NFS_FILE_SYNC;
813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 data->res.fattr = &data->fattr;
816 data->res.count = count;
817 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400818 nfs_fattr_init(&data->fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Trond Myklebust788e7a82006-03-20 13:44:27 -0500820 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400821 NFS_PROTO(inode)->write_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Chuck Levera3f565b2007-01-31 12:14:01 -0500823 dprintk("NFS: %5u initiated write call "
Chuck Lever48186c72008-06-11 17:56:05 -0400824 "(req %s/%lld, %u bytes @ offset %llu)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500825 data->task.tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 inode->i_sb->s_id,
827 (long long)NFS_FILEID(inode),
828 count,
829 (unsigned long long)data->args.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Trond Myklebust07737692007-10-25 18:42:54 -0400831 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400832 if (IS_ERR(task))
833 return PTR_ERR(task);
834 rpc_put_task(task);
835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
Fred6d884e82008-03-19 11:24:38 -0400838/* If a nfs_flush_* function fails, it should remove reqs from @head and
839 * call this on each, which will prepare them to be retried on next
840 * writeback using standard nfs.
841 */
842static void nfs_redirty_request(struct nfs_page *req)
843{
844 nfs_mark_request_dirty(req);
845 nfs_end_page_writeback(req->wb_page);
846 nfs_clear_page_tag_locked(req);
847}
848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849/*
850 * Generate multiple small requests to write out a single
851 * contiguous dirty area on one page.
852 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400853static 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 -0700854{
855 struct nfs_page *req = nfs_list_entry(head->next);
856 struct page *page = req->wb_page;
857 struct nfs_write_data *data;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700858 size_t wsize = NFS_SERVER(inode)->wsize, nbytes;
859 unsigned int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 int requests = 0;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400861 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 LIST_HEAD(list);
863
864 nfs_list_remove_request(req);
865
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400866 nbytes = count;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700867 do {
868 size_t len = min(nbytes, wsize);
869
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400870 data = nfs_writedata_alloc(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (!data)
872 goto out_bad;
873 list_add(&data->pages, &list);
874 requests++;
Trond Myklebuste9f7bee2006-09-08 09:48:54 -0700875 nbytes -= len;
876 } while (nbytes != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 atomic_set(&req->wb_complete, requests);
878
879 ClearPageError(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 offset = 0;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400881 nbytes = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 do {
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400883 int ret2;
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 data = list_entry(list.next, struct nfs_write_data, pages);
886 list_del_init(&data->pages);
887
888 data->pagevec[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400890 if (nbytes < wsize)
891 wsize = nbytes;
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400892 ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops,
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400893 wsize, offset, how);
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400894 if (ret == 0)
895 ret = ret2;
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400896 offset += wsize;
897 nbytes -= wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 } while (nbytes != 0);
899
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400900 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902out_bad:
903 while (!list_empty(&list)) {
904 data = list_entry(list.next, struct nfs_write_data, pages);
905 list_del(&data->pages);
Trond Myklebust8aca67f2006-11-13 16:23:44 -0500906 nfs_writedata_release(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 }
Trond Myklebust61822ab2006-12-05 00:35:42 -0500908 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return -ENOMEM;
910}
911
912/*
913 * Create an RPC task for the given write request and kick it.
914 * The page must have been locked by the caller.
915 *
916 * It may happen that the page we're passed is not marked dirty.
917 * This is the case if nfs_updatepage detects a conflicting request
918 * that has been written but not committed.
919 */
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400920static 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 -0700921{
922 struct nfs_page *req;
923 struct page **pages;
924 struct nfs_write_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400926 data = nfs_writedata_alloc(npages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 if (!data)
928 goto out_bad;
929
930 pages = data->pagevec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 while (!list_empty(head)) {
932 req = nfs_list_entry(head->next);
933 nfs_list_remove_request(req);
934 nfs_list_add_request(req, &data->pages);
935 ClearPageError(req->wb_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 *pages++ = req->wb_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
938 req = nfs_list_entry(data->pages.next);
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -0400941 return nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 out_bad:
943 while (!list_empty(head)) {
Trond Myklebust10afec92007-05-14 17:16:04 -0400944 req = nfs_list_entry(head->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 nfs_list_remove_request(req);
Trond Myklebust61822ab2006-12-05 00:35:42 -0500946 nfs_redirty_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 return -ENOMEM;
949}
950
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400951static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
952 struct inode *inode, int ioflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Chuck Leverbf4285e2007-12-20 14:54:57 -0500954 size_t wsize = NFS_SERVER(inode)->wsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400956 if (wsize < PAGE_CACHE_SIZE)
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400957 nfs_pageio_init(pgio, inode, nfs_flush_multi, wsize, ioflags);
Trond Myklebustbcb71bb2007-04-02 18:48:28 -0400958 else
Trond Myklebustc63c7b02007-04-02 19:29:52 -0400959 nfs_pageio_init(pgio, inode, nfs_flush_one, wsize, ioflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
962/*
963 * Handle a write reply that flushed part of a page.
964 */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500965static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Trond Myklebust788e7a82006-03-20 13:44:27 -0500967 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Chuck Lever48186c72008-06-11 17:56:05 -0400969 dprintk("NFS: %5u write(%s/%lld %d@%lld)",
970 task->tk_pid,
971 data->req->wb_context->path.dentry->d_inode->i_sb->s_id,
972 (long long)
973 NFS_FILEID(data->req->wb_context->path.dentry->d_inode),
974 data->req->wb_bytes, (long long)req_offset(data->req));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400976 nfs_writeback_done(task, data);
977}
Trond Myklebust788e7a82006-03-20 13:44:27 -0500978
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400979static void nfs_writeback_release_partial(void *calldata)
980{
981 struct nfs_write_data *data = calldata;
982 struct nfs_page *req = data->req;
983 struct page *page = req->wb_page;
984 int status = data->task.tk_status;
985
986 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -0800987 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -0400988 nfs_context_set_write_error(req->wb_context, status);
989 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400990 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400993 if (nfs_write_need_commit(data)) {
Trond Myklebust587142f2007-07-02 09:57:54 -0400994 struct inode *inode = page->mapping->host;
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400995
Trond Myklebust587142f2007-07-02 09:57:54 -0400996 spin_lock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -0400997 if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) {
998 /* Do nothing we need to resend the writes */
999 } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1000 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1001 dprintk(" defer commit\n");
1002 } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) {
1003 set_bit(PG_NEED_RESCHED, &req->wb_flags);
1004 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
1005 dprintk(" server reboot detected\n");
1006 }
Trond Myklebust587142f2007-07-02 09:57:54 -04001007 spin_unlock(&inode->i_lock);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001008 } else
1009 dprintk(" OK\n");
1010
1011out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (atomic_dec_and_test(&req->wb_complete))
1013 nfs_writepage_release(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001014 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Trond Myklebust788e7a82006-03-20 13:44:27 -05001017static const struct rpc_call_ops nfs_write_partial_ops = {
1018 .rpc_call_done = nfs_writeback_done_partial,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001019 .rpc_release = nfs_writeback_release_partial,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001020};
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022/*
1023 * Handle a write reply that flushes a whole page.
1024 *
1025 * FIXME: There is an inherent race with invalidate_inode_pages and
1026 * writebacks since the page->count is kept > 1 for as long
1027 * as the page has a write request pending.
1028 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001029static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
Trond Myklebust788e7a82006-03-20 13:44:27 -05001031 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001033 nfs_writeback_done(task, data);
1034}
1035
1036static void nfs_writeback_release_full(void *calldata)
1037{
1038 struct nfs_write_data *data = calldata;
1039 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 /* Update attributes as result of writeback. */
1042 while (!list_empty(&data->pages)) {
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001043 struct nfs_page *req = nfs_list_entry(data->pages.next);
1044 struct page *page = req->wb_page;
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 nfs_list_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Chuck Lever48186c72008-06-11 17:56:05 -04001048 dprintk("NFS: %5u write (%s/%lld %d@%lld)",
1049 data->task.tk_pid,
Trond Myklebust88be9f92007-06-05 10:42:27 -04001050 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1051 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 req->wb_bytes,
1053 (long long)req_offset(req));
1054
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001055 if (status < 0) {
Trond Myklebusta301b772007-02-06 11:07:15 -08001056 nfs_set_pageerror(page);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001057 nfs_context_set_write_error(req->wb_context, status);
1058 dprintk(", error = %d\n", status);
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001059 goto remove_request;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001062 if (nfs_write_need_commit(data)) {
1063 memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf));
1064 nfs_mark_request_commit(req);
1065 nfs_end_page_writeback(page);
1066 dprintk(" marked for commit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 goto next;
1068 }
Trond Myklebust8e821ca2007-04-20 16:12:34 -04001069 dprintk(" OK\n");
1070remove_request:
1071 nfs_end_page_writeback(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 nfs_inode_remove_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001074 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001076 nfs_writedata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Trond Myklebust788e7a82006-03-20 13:44:27 -05001079static const struct rpc_call_ops nfs_write_full_ops = {
1080 .rpc_call_done = nfs_writeback_done_full,
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001081 .rpc_release = nfs_writeback_release_full,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001082};
1083
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085/*
1086 * This function is called when the WRITE call is complete.
1087 */
Chuck Lever462d5b32006-03-20 13:44:32 -05001088int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 struct nfs_writeargs *argp = &data->args;
1091 struct nfs_writeres *resp = &data->res;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001092 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Chuck Levera3f565b2007-01-31 12:14:01 -05001094 dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 task->tk_pid, task->tk_status);
1096
Chuck Leverf551e442006-09-20 14:33:04 -04001097 /*
1098 * ->write_done will attempt to use post-op attributes to detect
1099 * conflicting writes by other clients. A strict interpretation
1100 * of close-to-open would allow us to continue caching even if
1101 * another writer had changed the file, but some applications
1102 * depend on tighter cache coherency when writing.
1103 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001104 status = NFS_PROTO(data->inode)->write_done(task, data);
1105 if (status != 0)
1106 return status;
Chuck Lever91d5b472006-03-20 13:44:14 -05001107 nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count);
1108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1110 if (resp->verf->committed < argp->stable && task->tk_status >= 0) {
1111 /* We tried a write call, but the server did not
1112 * commit data to stable storage even though we
1113 * requested it.
1114 * Note: There is a known bug in Tru64 < 5.0 in which
1115 * the server reports NFS_DATA_SYNC, but performs
1116 * NFS_FILE_SYNC. We therefore implement this checking
1117 * as a dprintk() in order to avoid filling syslog.
1118 */
1119 static unsigned long complain;
1120
1121 if (time_before(complain, jiffies)) {
Chuck Lever48186c72008-06-11 17:56:05 -04001122 dprintk("NFS: faulty NFS server %s:"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 " (committed = %d) != (stable = %d)\n",
David Howells54ceac42006-08-22 20:06:13 -04001124 NFS_SERVER(data->inode)->nfs_client->cl_hostname,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 resp->verf->committed, argp->stable);
1126 complain = jiffies + 300 * HZ;
1127 }
1128 }
1129#endif
1130 /* Is this a short write? */
1131 if (task->tk_status >= 0 && resp->count < argp->count) {
1132 static unsigned long complain;
1133
Chuck Lever91d5b472006-03-20 13:44:14 -05001134 nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE);
1135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 /* Has the server at least made some progress? */
1137 if (resp->count != 0) {
1138 /* Was this an NFSv2 write or an NFSv3 stable write? */
1139 if (resp->verf->committed != NFS_UNSTABLE) {
1140 /* Resend from where the server left off */
1141 argp->offset += resp->count;
1142 argp->pgbase += resp->count;
1143 argp->count -= resp->count;
1144 } else {
1145 /* Resend as a stable write in order to avoid
1146 * headaches in the case of a server crash.
1147 */
1148 argp->stable = NFS_FILE_SYNC;
1149 }
1150 rpc_restart_call(task);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001151 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 }
1153 if (time_before(complain, jiffies)) {
1154 printk(KERN_WARNING
1155 "NFS: Server wrote zero bytes, expected %u.\n",
1156 argp->count);
1157 complain = jiffies + 300 * HZ;
1158 }
1159 /* Can't do anything about it except throw an error. */
1160 task->tk_status = -EIO;
1161 }
Trond Myklebust788e7a82006-03-20 13:44:27 -05001162 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165
1166#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001167void nfs_commitdata_release(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Trond Myklebust383ba712008-02-19 20:04:20 -05001169 struct nfs_write_data *wdata = data;
1170
1171 put_nfs_open_context(wdata->args.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 nfs_commit_free(wdata);
1173}
1174
1175/*
1176 * Set up the argument/result storage required for the RPC call.
1177 */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001178static int nfs_commit_rpcsetup(struct list_head *head,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001179 struct nfs_write_data *data,
1180 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
Trond Myklebust84115e12007-07-14 15:39:59 -04001182 struct nfs_page *first = nfs_list_entry(head->next);
1183 struct inode *inode = first->wb_context->path.dentry->d_inode;
1184 int flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
Trond Myklebust3ff75762007-07-14 15:40:00 -04001185 int priority = flush_task_priority(how);
Trond Myklebust07737692007-10-25 18:42:54 -04001186 struct rpc_task *task;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001187 struct rpc_message msg = {
1188 .rpc_argp = &data->args,
1189 .rpc_resp = &data->res,
1190 .rpc_cred = first->wb_context->cred,
1191 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001192 struct rpc_task_setup task_setup_data = {
Trond Myklebust07737692007-10-25 18:42:54 -04001193 .task = &data->task,
Trond Myklebust84115e12007-07-14 15:39:59 -04001194 .rpc_client = NFS_CLIENT(inode),
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001195 .rpc_message = &msg,
Trond Myklebust84115e12007-07-14 15:39:59 -04001196 .callback_ops = &nfs_commit_ops,
1197 .callback_data = data,
Trond Myklebust101070c2008-02-19 20:04:23 -05001198 .workqueue = nfsiod_workqueue,
Trond Myklebust84115e12007-07-14 15:39:59 -04001199 .flags = flags,
Trond Myklebust3ff75762007-07-14 15:40:00 -04001200 .priority = priority,
Trond Myklebust84115e12007-07-14 15:39:59 -04001201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 /* Set up the RPC argument and reply structs
1204 * NB: take care not to mess about with data->commit et al. */
1205
1206 list_splice_init(head, &data->pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 data->inode = inode;
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001209 data->cred = msg.rpc_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 data->args.fh = NFS_FH(data->inode);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001212 /* Note: we always request a commit of the entire inode */
1213 data->args.offset = 0;
1214 data->args.count = 0;
Trond Myklebust383ba712008-02-19 20:04:20 -05001215 data->args.context = get_nfs_open_context(first->wb_context);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001216 data->res.count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 data->res.fattr = &data->fattr;
1218 data->res.verf = &data->verf;
Trond Myklebust0e574af2005-10-27 22:12:38 -04001219 nfs_fattr_init(&data->fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -05001220
1221 /* Set up the initial task struct. */
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001222 NFS_PROTO(inode)->commit_setup(data, &msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Chuck Levera3f565b2007-01-31 12:14:01 -05001224 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
Trond Myklebustbdc7f022007-07-14 15:40:00 -04001225
Trond Myklebust07737692007-10-25 18:42:54 -04001226 task = rpc_run_task(&task_setup_data);
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001227 if (IS_ERR(task))
1228 return PTR_ERR(task);
1229 rpc_put_task(task);
1230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233/*
1234 * Commit dirty pages
1235 */
1236static int
Chuck Lever40859d72005-11-30 18:09:02 -05001237nfs_commit_list(struct inode *inode, struct list_head *head, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239 struct nfs_write_data *data;
1240 struct nfs_page *req;
1241
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001242 data = nfs_commitdata_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 if (!data)
1245 goto out_bad;
1246
1247 /* Set up the argument struct */
Trond Myklebustdbae4c72008-04-14 14:54:53 -04001248 return nfs_commit_rpcsetup(head, data, how);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 out_bad:
1250 while (!list_empty(head)) {
1251 req = nfs_list_entry(head->next);
1252 nfs_list_remove_request(req);
1253 nfs_mark_request_commit(req);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001254 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001255 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1256 BDI_RECLAIMABLE);
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001257 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
1259 return -ENOMEM;
1260}
1261
1262/*
1263 * COMMIT call returned
1264 */
Trond Myklebust788e7a82006-03-20 13:44:27 -05001265static void nfs_commit_done(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001267 struct nfs_write_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Chuck Levera3f565b2007-01-31 12:14:01 -05001269 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 task->tk_pid, task->tk_status);
1271
Trond Myklebust788e7a82006-03-20 13:44:27 -05001272 /* Call the NFS version-specific code */
1273 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
1274 return;
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001275}
1276
1277static void nfs_commit_release(void *calldata)
1278{
1279 struct nfs_write_data *data = calldata;
1280 struct nfs_page *req;
1281 int status = data->task.tk_status;
Trond Myklebust788e7a82006-03-20 13:44:27 -05001282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 while (!list_empty(&data->pages)) {
1284 req = nfs_list_entry(data->pages.next);
1285 nfs_list_remove_request(req);
Trond Myklebust612c9382007-04-20 16:12:45 -04001286 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags);
Christoph Lameterfd39fc82006-06-30 01:55:40 -07001287 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
Peter Zijlstrac9e51e42007-10-16 23:25:47 -07001288 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1289 BDI_RECLAIMABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Chuck Lever48186c72008-06-11 17:56:05 -04001291 dprintk("NFS: commit (%s/%lld %d@%lld)",
Trond Myklebust88be9f92007-06-05 10:42:27 -04001292 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1293 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 req->wb_bytes,
1295 (long long)req_offset(req));
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001296 if (status < 0) {
1297 nfs_context_set_write_error(req->wb_context, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 nfs_inode_remove_request(req);
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001299 dprintk(", error = %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 goto next;
1301 }
1302
1303 /* Okay, COMMIT succeeded, apparently. Check the verifier
1304 * returned by the server against all stored verfs. */
1305 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
1306 /* We have a match */
1307 nfs_inode_remove_request(req);
1308 dprintk(" OK\n");
1309 goto next;
1310 }
1311 /* We have a mismatch. Write the page again */
1312 dprintk(" mismatch\n");
Fred6d884e82008-03-19 11:24:38 -04001313 nfs_mark_request_dirty(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 next:
Trond Myklebust9fd367f2007-06-17 15:10:24 -04001315 nfs_clear_page_tag_locked(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 }
Trond Myklebustc9d8f892008-04-15 16:56:39 -04001317 nfs_commitdata_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
Trond Myklebust788e7a82006-03-20 13:44:27 -05001319
1320static const struct rpc_call_ops nfs_commit_ops = {
1321 .rpc_call_done = nfs_commit_done,
1322 .rpc_release = nfs_commit_release,
1323};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001325int nfs_commit_inode(struct inode *inode, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 LIST_HEAD(head);
Trond Myklebust7d46a492006-03-20 13:44:50 -05001328 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust587142f2007-07-02 09:57:54 -04001330 spin_lock(&inode->i_lock);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001331 res = nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001332 spin_unlock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 if (res) {
Trond Myklebust7d46a492006-03-20 13:44:50 -05001334 int error = nfs_commit_list(inode, &head, how);
Trond Myklebust3da28eb2005-06-22 17:16:31 +00001335 if (error < 0)
1336 return error;
1337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 return res;
1339}
Trond Myklebustc63c7b02007-04-02 19:29:52 -04001340#else
1341static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1342{
1343 return 0;
1344}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345#endif
1346
Trond Myklebust1c759502006-10-09 16:18:38 -04001347long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Trond Myklebust1c759502006-10-09 16:18:38 -04001349 struct inode *inode = mapping->host;
Trond Myklebustca52fec2007-04-17 17:22:13 -04001350 pgoff_t idx_start, idx_end;
Trond Myklebust1c759502006-10-09 16:18:38 -04001351 unsigned int npages = 0;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001352 LIST_HEAD(head);
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001353 int nocommit = how & FLUSH_NOCOMMIT;
Trond Myklebust3f442542006-09-17 14:46:44 -04001354 long pages, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Trond Myklebust1c759502006-10-09 16:18:38 -04001356 /* FIXME */
1357 if (wbc->range_cyclic)
1358 idx_start = 0;
1359 else {
1360 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
1361 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
1362 if (idx_end > idx_start) {
Trond Myklebustca52fec2007-04-17 17:22:13 -04001363 pgoff_t l_npages = 1 + idx_end - idx_start;
Trond Myklebust1c759502006-10-09 16:18:38 -04001364 npages = l_npages;
1365 if (sizeof(npages) != sizeof(l_npages) &&
Trond Myklebustca52fec2007-04-17 17:22:13 -04001366 (pgoff_t)npages != l_npages)
Trond Myklebust1c759502006-10-09 16:18:38 -04001367 npages = 0;
1368 }
1369 }
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001370 how &= ~FLUSH_NOCOMMIT;
Trond Myklebust587142f2007-07-02 09:57:54 -04001371 spin_lock(&inode->i_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 do {
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001373 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1374 if (ret != 0)
Trond Myklebust70b9ecb2006-01-03 09:55:34 +01001375 continue;
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001376 if (nocommit)
1377 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001378 pages = nfs_scan_commit(inode, &head, idx_start, npages);
Trond Myklebust724c4392007-04-17 17:22:13 -04001379 if (pages == 0)
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001380 break;
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001381 if (how & FLUSH_INVALIDATE) {
Trond Myklebust587142f2007-07-02 09:57:54 -04001382 spin_unlock(&inode->i_lock);
Trond Myklebust83715ad2006-07-05 13:17:12 -04001383 nfs_cancel_commit_list(&head);
Trond Myklebuste8e058e2006-11-15 17:31:56 -05001384 ret = pages;
Trond Myklebust587142f2007-07-02 09:57:54 -04001385 spin_lock(&inode->i_lock);
Trond Myklebustd2ccddf2006-05-31 01:13:38 -04001386 continue;
1387 }
1388 pages += nfs_scan_commit(inode, &head, 0, 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001389 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001390 ret = nfs_commit_list(inode, &head, how);
Trond Myklebust587142f2007-07-02 09:57:54 -04001391 spin_lock(&inode->i_lock);
1392
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001393 } while (ret >= 0);
Trond Myklebust587142f2007-07-02 09:57:54 -04001394 spin_unlock(&inode->i_lock);
Trond Myklebustc42de9d2006-03-20 13:44:51 -05001395 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Trond Myklebust34901f72007-07-25 14:09:54 -04001398static int __nfs_write_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001399{
Trond Myklebust1c759502006-10-09 16:18:38 -04001400 int ret;
1401
Trond Myklebust34901f72007-07-25 14:09:54 -04001402 ret = nfs_writepages(mapping, wbc);
Trond Myklebust61822ab2006-12-05 00:35:42 -05001403 if (ret < 0)
1404 goto out;
Trond Myklebust34901f72007-07-25 14:09:54 -04001405 ret = nfs_sync_mapping_wait(mapping, wbc, how);
Trond Myklebusted90ef52007-07-20 13:13:28 -04001406 if (ret < 0)
1407 goto out;
1408 return 0;
Trond Myklebust61822ab2006-12-05 00:35:42 -05001409out:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001410 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
Trond Myklebust1c759502006-10-09 16:18:38 -04001411 return ret;
1412}
1413
Trond Myklebust34901f72007-07-25 14:09:54 -04001414/* Two pass sync: first using WB_SYNC_NONE, then WB_SYNC_ALL */
1415static int nfs_write_mapping(struct address_space *mapping, int how)
1416{
1417 struct writeback_control wbc = {
1418 .bdi = mapping->backing_dev_info,
1419 .sync_mode = WB_SYNC_NONE,
1420 .nr_to_write = LONG_MAX,
1421 .for_writepages = 1,
1422 .range_cyclic = 1,
1423 };
1424 int ret;
1425
1426 ret = __nfs_write_mapping(mapping, &wbc, how);
1427 if (ret < 0)
1428 return ret;
1429 wbc.sync_mode = WB_SYNC_ALL;
1430 return __nfs_write_mapping(mapping, &wbc, how);
1431}
1432
Trond Myklebusted90ef52007-07-20 13:13:28 -04001433/*
1434 * flush the inode to disk.
1435 */
1436int nfs_wb_all(struct inode *inode)
Trond Myklebust1c759502006-10-09 16:18:38 -04001437{
Trond Myklebusted90ef52007-07-20 13:13:28 -04001438 return nfs_write_mapping(inode->i_mapping, 0);
1439}
Trond Myklebust1c759502006-10-09 16:18:38 -04001440
Trond Myklebusted90ef52007-07-20 13:13:28 -04001441int nfs_wb_nocommit(struct inode *inode)
1442{
1443 return nfs_write_mapping(inode->i_mapping, FLUSH_NOCOMMIT);
Trond Myklebust1c759502006-10-09 16:18:38 -04001444}
1445
Trond Myklebust1b3b4a12007-08-28 10:29:36 -04001446int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1447{
1448 struct nfs_page *req;
1449 loff_t range_start = page_offset(page);
1450 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1451 struct writeback_control wbc = {
1452 .bdi = page->mapping->backing_dev_info,
1453 .sync_mode = WB_SYNC_ALL,
1454 .nr_to_write = LONG_MAX,
1455 .range_start = range_start,
1456 .range_end = range_end,
1457 };
1458 int ret = 0;
1459
1460 BUG_ON(!PageLocked(page));
1461 for (;;) {
1462 req = nfs_page_find_request(page);
1463 if (req == NULL)
1464 goto out;
1465 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) {
1466 nfs_release_request(req);
1467 break;
1468 }
1469 if (nfs_lock_request_dontget(req)) {
1470 nfs_inode_remove_request(req);
1471 /*
1472 * In case nfs_inode_remove_request has marked the
1473 * page as being dirty
1474 */
1475 cancel_dirty_page(page, PAGE_CACHE_SIZE);
1476 nfs_unlock_request(req);
1477 break;
1478 }
1479 ret = nfs_wait_on_request(req);
1480 if (ret < 0)
1481 goto out;
1482 }
1483 if (!PagePrivate(page))
1484 return 0;
1485 ret = nfs_sync_mapping_wait(page->mapping, &wbc, FLUSH_INVALIDATE);
1486out:
1487 return ret;
1488}
1489
Adrian Bunk5334eb12007-11-21 15:04:31 -08001490static int nfs_wb_page_priority(struct inode *inode, struct page *page,
1491 int how)
Trond Myklebust1c759502006-10-09 16:18:38 -04001492{
1493 loff_t range_start = page_offset(page);
1494 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001495 struct writeback_control wbc = {
1496 .bdi = page->mapping->backing_dev_info,
1497 .sync_mode = WB_SYNC_ALL,
1498 .nr_to_write = LONG_MAX,
1499 .range_start = range_start,
1500 .range_end = range_end,
1501 };
1502 int ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001503
Trond Myklebust73e33022008-04-11 16:03:54 -04001504 do {
1505 if (clear_page_dirty_for_io(page)) {
1506 ret = nfs_writepage_locked(page, &wbc);
1507 if (ret < 0)
1508 goto out_error;
1509 } else if (!PagePrivate(page))
1510 break;
1511 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001512 if (ret < 0)
Trond Myklebust73e33022008-04-11 16:03:54 -04001513 goto out_error;
1514 } while (PagePrivate(page));
1515 return 0;
1516out_error:
Trond Myklebuste507d9e2006-12-05 00:35:42 -05001517 __mark_inode_dirty(inode, I_DIRTY_PAGES);
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001518 return ret;
Trond Myklebust1c759502006-10-09 16:18:38 -04001519}
1520
1521/*
1522 * Write back all requests on one page - we do this before reading it.
1523 */
1524int nfs_wb_page(struct inode *inode, struct page* page)
1525{
Trond Myklebust4d770cc2006-12-05 00:35:41 -05001526 return nfs_wb_page_priority(inode, page, FLUSH_STABLE);
Trond Myklebust1c759502006-10-09 16:18:38 -04001527}
1528
David Howellsf7b422b2006-06-09 09:34:33 -04001529int __init nfs_init_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
1531 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
1532 sizeof(struct nfs_write_data),
1533 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +09001534 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 if (nfs_wdata_cachep == NULL)
1536 return -ENOMEM;
1537
Matthew Dobson93d23412006-03-26 01:37:50 -08001538 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
1539 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (nfs_wdata_mempool == NULL)
1541 return -ENOMEM;
1542
Matthew Dobson93d23412006-03-26 01:37:50 -08001543 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
1544 nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 if (nfs_commit_mempool == NULL)
1546 return -ENOMEM;
1547
Peter Zijlstra89a09142007-03-16 13:38:26 -08001548 /*
1549 * NFS congestion size, scale with available memory.
1550 *
1551 * 64MB: 8192k
1552 * 128MB: 11585k
1553 * 256MB: 16384k
1554 * 512MB: 23170k
1555 * 1GB: 32768k
1556 * 2GB: 46340k
1557 * 4GB: 65536k
1558 * 8GB: 92681k
1559 * 16GB: 131072k
1560 *
1561 * This allows larger machines to have larger/more transfers.
1562 * Limit the default to 256M
1563 */
1564 nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
1565 if (nfs_congestion_kb > 256*1024)
1566 nfs_congestion_kb = 256*1024;
1567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return 0;
1569}
1570
David Brownell266bee82006-06-27 12:59:15 -07001571void nfs_destroy_writepagecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
1573 mempool_destroy(nfs_commit_mempool);
1574 mempool_destroy(nfs_wdata_mempool);
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001575 kmem_cache_destroy(nfs_wdata_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577