Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/write.c |
| 3 | * |
Trond Myklebust | 7c85d90 | 2006-12-13 15:23:48 -0500 | [diff] [blame] | 4 | * Write file data over NFS. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de> |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/writeback.h> |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 15 | #include <linux/swap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 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 Morton | 3fcfab1 | 2006-10-19 23:28:16 -0700 | [diff] [blame] | 21 | #include <linux/backing-dev.h> |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/uaccess.h> |
| 24 | #include <linux/smp_lock.h> |
| 25 | |
| 26 | #include "delegation.h" |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 27 | #include "internal.h" |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 28 | #include "iostat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #define NFSDBG_FACILITY NFSDBG_PAGECACHE |
| 31 | |
| 32 | #define MIN_POOL_WRITE (32) |
| 33 | #define MIN_POOL_COMMIT (4) |
| 34 | |
| 35 | /* |
| 36 | * Local function declarations |
| 37 | */ |
| 38 | static struct nfs_page * nfs_update_request(struct nfs_open_context*, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | struct page *, |
| 40 | unsigned int, unsigned int); |
Trond Myklebust | 3f44254 | 2006-09-17 14:46:44 -0400 | [diff] [blame] | 41 | static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 42 | static const struct rpc_call_ops nfs_write_partial_ops; |
| 43 | static const struct rpc_call_ops nfs_write_full_ops; |
| 44 | static const struct rpc_call_ops nfs_commit_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 46 | static struct kmem_cache *nfs_wdata_cachep; |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 47 | static mempool_t *nfs_wdata_mempool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static mempool_t *nfs_commit_mempool; |
| 49 | |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 50 | struct nfs_write_data *nfs_commit_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 52 | struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); |
Chuck Lever | 40859d7 | 2005-11-30 18:09:02 -0500 | [diff] [blame] | 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if (p) { |
| 55 | memset(p, 0, sizeof(*p)); |
| 56 | INIT_LIST_HEAD(&p->pages); |
| 57 | } |
| 58 | return p; |
| 59 | } |
| 60 | |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 61 | void nfs_commit_rcu_free(struct rcu_head *head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 63 | struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu); |
Chuck Lever | 40859d7 | 2005-11-30 18:09:02 -0500 | [diff] [blame] | 64 | if (p && (p->pagevec != &p->page_array[0])) |
| 65 | kfree(p->pagevec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | mempool_free(p, nfs_commit_mempool); |
| 67 | } |
| 68 | |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 69 | void nfs_commit_free(struct nfs_write_data *wdata) |
| 70 | { |
| 71 | call_rcu_bh(&wdata->task.u.tk_rcu, nfs_commit_rcu_free); |
| 72 | } |
| 73 | |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 74 | struct nfs_write_data *nfs_writedata_alloc(size_t len) |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 75 | { |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 76 | unsigned int pagecount = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 77 | struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 78 | |
| 79 | if (p) { |
| 80 | memset(p, 0, sizeof(*p)); |
| 81 | INIT_LIST_HEAD(&p->pages); |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 82 | p->npages = pagecount; |
Chuck Lever | 0d0b5cb | 2006-05-25 01:40:53 -0400 | [diff] [blame] | 83 | if (pagecount <= ARRAY_SIZE(p->page_array)) |
| 84 | p->pagevec = p->page_array; |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 85 | else { |
Chuck Lever | 0d0b5cb | 2006-05-25 01:40:53 -0400 | [diff] [blame] | 86 | p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS); |
| 87 | if (!p->pagevec) { |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 88 | mempool_free(p, nfs_wdata_mempool); |
| 89 | p = NULL; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return p; |
| 94 | } |
| 95 | |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 96 | static void nfs_writedata_rcu_free(struct rcu_head *head) |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 97 | { |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 98 | struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu); |
Trond Myklebust | 3feb2d4 | 2006-03-20 13:44:37 -0500 | [diff] [blame] | 99 | if (p && (p->pagevec != &p->page_array[0])) |
| 100 | kfree(p->pagevec); |
| 101 | mempool_free(p, nfs_wdata_mempool); |
| 102 | } |
| 103 | |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 104 | static void nfs_writedata_free(struct nfs_write_data *wdata) |
| 105 | { |
| 106 | call_rcu_bh(&wdata->task.u.tk_rcu, nfs_writedata_rcu_free); |
| 107 | } |
| 108 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 109 | void nfs_writedata_release(void *wdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | nfs_writedata_free(wdata); |
| 112 | } |
| 113 | |
Trond Myklebust | 277459d | 2006-12-05 00:35:35 -0500 | [diff] [blame] | 114 | static struct nfs_page *nfs_page_find_request_locked(struct page *page) |
| 115 | { |
| 116 | struct nfs_page *req = NULL; |
| 117 | |
| 118 | if (PagePrivate(page)) { |
| 119 | req = (struct nfs_page *)page_private(page); |
| 120 | if (req != NULL) |
| 121 | atomic_inc(&req->wb_count); |
| 122 | } |
| 123 | return req; |
| 124 | } |
| 125 | |
| 126 | static struct nfs_page *nfs_page_find_request(struct page *page) |
| 127 | { |
| 128 | struct nfs_page *req = NULL; |
| 129 | spinlock_t *req_lock = &NFS_I(page->mapping->host)->req_lock; |
| 130 | |
| 131 | spin_lock(req_lock); |
| 132 | req = nfs_page_find_request_locked(page); |
| 133 | spin_unlock(req_lock); |
| 134 | return req; |
| 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* Adjust the file length if we're writing beyond the end */ |
| 138 | static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count) |
| 139 | { |
| 140 | struct inode *inode = page->mapping->host; |
| 141 | loff_t end, i_size = i_size_read(inode); |
| 142 | unsigned long end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; |
| 143 | |
| 144 | if (i_size > 0 && page->index < end_index) |
| 145 | return; |
| 146 | end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count); |
| 147 | if (i_size >= end) |
| 148 | return; |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 149 | nfs_inc_stats(inode, NFSIOS_EXTENDWRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | i_size_write(inode, end); |
| 151 | } |
| 152 | |
Trond Myklebust | a301b77 | 2007-02-06 11:07:15 -0800 | [diff] [blame] | 153 | /* A writeback failed: mark the page as bad, and invalidate the page cache */ |
| 154 | static void nfs_set_pageerror(struct page *page) |
| 155 | { |
| 156 | SetPageError(page); |
| 157 | nfs_zap_mapping(page->mapping->host, page->mapping); |
| 158 | } |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* We can set the PG_uptodate flag if we see that a write request |
| 161 | * covers the full page. |
| 162 | */ |
| 163 | static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int count) |
| 164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | if (PageUptodate(page)) |
| 166 | return; |
| 167 | if (base != 0) |
| 168 | return; |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 169 | if (count != nfs_page_length(page)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return; |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 171 | if (count != PAGE_CACHE_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | memclear_highpage_flush(page, count, PAGE_CACHE_SIZE - count); |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 173 | SetPageUptodate(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Trond Myklebust | e21195a | 2006-12-05 00:35:39 -0500 | [diff] [blame] | 176 | static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | unsigned int offset, unsigned int count) |
| 178 | { |
| 179 | struct nfs_page *req; |
Trond Myklebust | e21195a | 2006-12-05 00:35:39 -0500 | [diff] [blame] | 180 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Trond Myklebust | e21195a | 2006-12-05 00:35:39 -0500 | [diff] [blame] | 182 | for (;;) { |
| 183 | req = nfs_update_request(ctx, page, offset, count); |
| 184 | if (!IS_ERR(req)) |
| 185 | break; |
| 186 | ret = PTR_ERR(req); |
| 187 | if (ret != -EBUSY) |
| 188 | return ret; |
| 189 | ret = nfs_wb_page(page->mapping->host, page); |
| 190 | if (ret != 0) |
| 191 | return ret; |
| 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | /* Update file length */ |
| 194 | nfs_grow_file(page, offset, count); |
| 195 | /* Set the PG_uptodate flag? */ |
| 196 | nfs_mark_uptodate(page, offset, count); |
| 197 | nfs_unlock_request(req); |
Trond Myklebust | abd3e64 | 2006-01-03 09:55:02 +0100 | [diff] [blame] | 198 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int wb_priority(struct writeback_control *wbc) |
| 202 | { |
| 203 | if (wbc->for_reclaim) |
| 204 | return FLUSH_HIGHPRI; |
| 205 | if (wbc->for_kupdate) |
| 206 | return FLUSH_LOWPRI; |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /* |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 211 | * NFS congestion control |
| 212 | */ |
| 213 | |
| 214 | int nfs_congestion_kb; |
| 215 | |
| 216 | #define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10)) |
| 217 | #define NFS_CONGESTION_OFF_THRESH \ |
| 218 | (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2)) |
| 219 | |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 220 | static int nfs_set_page_writeback(struct page *page) |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 221 | { |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 222 | int ret = test_set_page_writeback(page); |
| 223 | |
| 224 | if (!ret) { |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 225 | struct inode *inode = page->mapping->host; |
| 226 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 227 | |
| 228 | if (atomic_inc_return(&nfss->writeback) > |
| 229 | NFS_CONGESTION_ON_THRESH) |
| 230 | set_bdi_congested(&nfss->backing_dev_info, WRITE); |
| 231 | } |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 232 | return ret; |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void nfs_end_page_writeback(struct page *page) |
| 236 | { |
| 237 | struct inode *inode = page->mapping->host; |
| 238 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 239 | |
| 240 | end_page_writeback(page); |
| 241 | if (atomic_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) { |
| 242 | clear_bdi_congested(&nfss->backing_dev_info, WRITE); |
| 243 | congestion_end(WRITE); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 248 | * Find an associated nfs write request, and prepare to flush it out |
| 249 | * Returns 1 if there was no write request, or if the request was |
| 250 | * already tagged by nfs_set_page_dirty.Returns 0 if the request |
| 251 | * was not tagged. |
| 252 | * May also return an error if the user signalled nfs_wait_on_request(). |
| 253 | */ |
| 254 | static int nfs_page_mark_flush(struct page *page) |
| 255 | { |
| 256 | struct nfs_page *req; |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 257 | struct nfs_inode *nfsi = NFS_I(page->mapping->host); |
| 258 | spinlock_t *req_lock = &nfsi->req_lock; |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 259 | int ret; |
| 260 | |
| 261 | spin_lock(req_lock); |
| 262 | for(;;) { |
| 263 | req = nfs_page_find_request_locked(page); |
| 264 | if (req == NULL) { |
| 265 | spin_unlock(req_lock); |
| 266 | return 1; |
| 267 | } |
| 268 | if (nfs_lock_request_dontget(req)) |
| 269 | break; |
| 270 | /* Note: If we hold the page lock, as is the case in nfs_writepage, |
| 271 | * then the call to nfs_lock_request_dontget() will always |
| 272 | * succeed provided that someone hasn't already marked the |
| 273 | * request as dirty (in which case we don't care). |
| 274 | */ |
| 275 | spin_unlock(req_lock); |
| 276 | ret = nfs_wait_on_request(req); |
| 277 | nfs_release_request(req); |
| 278 | if (ret != 0) |
| 279 | return ret; |
| 280 | spin_lock(req_lock); |
| 281 | } |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 282 | if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { |
| 283 | /* This request is marked for commit */ |
| 284 | spin_unlock(req_lock); |
| 285 | nfs_unlock_request(req); |
| 286 | return 1; |
| 287 | } |
Trond Myklebust | eb4cac1 | 2007-04-15 16:21:49 -0400 | [diff] [blame] | 288 | if (nfs_set_page_writeback(page) == 0) { |
| 289 | nfs_list_remove_request(req); |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 290 | /* add the request to the inode's dirty list. */ |
| 291 | radix_tree_tag_set(&nfsi->nfs_page_tree, |
| 292 | req->wb_index, NFS_PAGE_TAG_DIRTY); |
| 293 | nfs_list_add_request(req, &nfsi->dirty); |
| 294 | nfsi->ndirty++; |
| 295 | spin_unlock(req_lock); |
| 296 | __mark_inode_dirty(page->mapping->host, I_DIRTY_PAGES); |
| 297 | } else |
| 298 | spin_unlock(req_lock); |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 299 | ret = test_bit(PG_NEED_FLUSH, &req->wb_flags); |
| 300 | nfs_unlock_request(req); |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | * Write an mmapped page to the server. |
| 306 | */ |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 307 | static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | struct nfs_open_context *ctx; |
| 310 | struct inode *inode = page->mapping->host; |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 311 | unsigned offset; |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 312 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 314 | nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE); |
| 315 | nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1); |
| 316 | |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 317 | err = nfs_page_mark_flush(page); |
| 318 | if (err <= 0) |
| 319 | goto out; |
| 320 | err = 0; |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 321 | offset = nfs_page_length(page); |
| 322 | if (!offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | goto out; |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 324 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 325 | ctx = nfs_find_open_context(inode, NULL, FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (ctx == NULL) { |
| 327 | err = -EBADF; |
| 328 | goto out; |
| 329 | } |
Trond Myklebust | 200baa2 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 330 | err = nfs_writepage_setup(ctx, page, 0, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | put_nfs_open_context(ctx); |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 332 | if (err != 0) |
| 333 | goto out; |
| 334 | err = nfs_page_mark_flush(page); |
| 335 | if (err > 0) |
| 336 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | out: |
Trond Myklebust | 200baa2 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 338 | if (!wbc->for_writepages) |
Trond Myklebust | 02241bc | 2007-01-13 02:28:07 -0500 | [diff] [blame] | 339 | nfs_flush_mapping(page->mapping, wbc, FLUSH_STABLE|wb_priority(wbc)); |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 340 | return err; |
| 341 | } |
| 342 | |
| 343 | int nfs_writepage(struct page *page, struct writeback_control *wbc) |
| 344 | { |
| 345 | int err; |
| 346 | |
| 347 | err = nfs_writepage_locked(page, wbc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | unlock_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return err; |
| 350 | } |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) |
| 353 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | struct inode *inode = mapping->host; |
| 355 | int err; |
| 356 | |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 357 | nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | err = generic_writepages(mapping, wbc); |
| 360 | if (err) |
| 361 | return err; |
Trond Myklebust | 28c6925 | 2006-09-16 13:04:50 -0400 | [diff] [blame] | 362 | err = nfs_flush_mapping(mapping, wbc, wb_priority(wbc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (err < 0) |
| 364 | goto out; |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 365 | nfs_add_stats(inode, NFSIOS_WRITEPAGES, err); |
Trond Myklebust | d30c834 | 2006-12-13 15:23:47 -0500 | [diff] [blame] | 366 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return err; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Insert a write request into an inode |
| 373 | */ |
| 374 | static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) |
| 375 | { |
| 376 | struct nfs_inode *nfsi = NFS_I(inode); |
| 377 | int error; |
| 378 | |
| 379 | error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req); |
| 380 | BUG_ON(error == -EEXIST); |
| 381 | if (error) |
| 382 | return error; |
| 383 | if (!nfsi->npages) { |
| 384 | igrab(inode); |
| 385 | nfs_begin_data_update(inode); |
| 386 | if (nfs_have_delegation(inode, FMODE_WRITE)) |
| 387 | nfsi->change_attr++; |
| 388 | } |
Trond Myklebust | deb7d63 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 389 | SetPagePrivate(req->wb_page); |
Trond Myklebust | 277459d | 2006-12-05 00:35:35 -0500 | [diff] [blame] | 390 | set_page_private(req->wb_page, (unsigned long)req); |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 391 | if (PageDirty(req->wb_page)) |
| 392 | set_bit(PG_NEED_FLUSH, &req->wb_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | nfsi->npages++; |
| 394 | atomic_inc(&req->wb_count); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | /* |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 399 | * Remove a write request from an inode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | */ |
| 401 | static void nfs_inode_remove_request(struct nfs_page *req) |
| 402 | { |
| 403 | struct inode *inode = req->wb_context->dentry->d_inode; |
| 404 | struct nfs_inode *nfsi = NFS_I(inode); |
| 405 | |
| 406 | BUG_ON (!NFS_WBACK_BUSY(req)); |
| 407 | |
| 408 | spin_lock(&nfsi->req_lock); |
Trond Myklebust | 277459d | 2006-12-05 00:35:35 -0500 | [diff] [blame] | 409 | set_page_private(req->wb_page, 0); |
Trond Myklebust | deb7d63 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 410 | ClearPagePrivate(req->wb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index); |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 412 | if (test_and_clear_bit(PG_NEED_FLUSH, &req->wb_flags)) |
| 413 | __set_page_dirty_nobuffers(req->wb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | nfsi->npages--; |
| 415 | if (!nfsi->npages) { |
| 416 | spin_unlock(&nfsi->req_lock); |
Trond Myklebust | 951a143 | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 417 | nfs_end_data_update(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | iput(inode); |
| 419 | } else |
| 420 | spin_unlock(&nfsi->req_lock); |
| 421 | nfs_clear_request(req); |
| 422 | nfs_release_request(req); |
| 423 | } |
| 424 | |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 425 | static void |
| 426 | nfs_redirty_request(struct nfs_page *req) |
| 427 | { |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 428 | __set_page_dirty_nobuffers(req->wb_page); |
| 429 | } |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* |
| 432 | * Check if a request is dirty |
| 433 | */ |
| 434 | static inline int |
| 435 | nfs_dirty_request(struct nfs_page *req) |
| 436 | { |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 437 | struct page *page = req->wb_page; |
| 438 | |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 439 | if (page == NULL || test_bit(PG_NEED_COMMIT, &req->wb_flags)) |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 440 | return 0; |
| 441 | return !PageWriteback(req->wb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
| 445 | /* |
| 446 | * Add a request to the inode's commit list. |
| 447 | */ |
| 448 | static void |
| 449 | nfs_mark_request_commit(struct nfs_page *req) |
| 450 | { |
| 451 | struct inode *inode = req->wb_context->dentry->d_inode; |
| 452 | struct nfs_inode *nfsi = NFS_I(inode); |
| 453 | |
| 454 | spin_lock(&nfsi->req_lock); |
| 455 | nfs_list_add_request(req, &nfsi->commit); |
| 456 | nfsi->ncommit++; |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 457 | set_bit(PG_NEED_COMMIT, &(req)->wb_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | spin_unlock(&nfsi->req_lock); |
Christoph Lameter | fd39fc8 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 459 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
Trond Myklebust | a180304 | 2006-12-05 00:45:19 -0500 | [diff] [blame] | 460 | __mark_inode_dirty(inode, I_DIRTY_DATASYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 462 | |
| 463 | static inline |
| 464 | int nfs_write_need_commit(struct nfs_write_data *data) |
| 465 | { |
| 466 | return data->verf.committed != NFS_FILE_SYNC; |
| 467 | } |
| 468 | |
| 469 | static inline |
| 470 | int nfs_reschedule_unstable_write(struct nfs_page *req) |
| 471 | { |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 472 | if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 473 | nfs_mark_request_commit(req); |
| 474 | return 1; |
| 475 | } |
| 476 | if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) { |
| 477 | nfs_redirty_request(req); |
| 478 | return 1; |
| 479 | } |
| 480 | return 0; |
| 481 | } |
| 482 | #else |
| 483 | static inline void |
| 484 | nfs_mark_request_commit(struct nfs_page *req) |
| 485 | { |
| 486 | } |
| 487 | |
| 488 | static inline |
| 489 | int nfs_write_need_commit(struct nfs_write_data *data) |
| 490 | { |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static inline |
| 495 | int nfs_reschedule_unstable_write(struct nfs_page *req) |
| 496 | { |
| 497 | return 0; |
| 498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | #endif |
| 500 | |
| 501 | /* |
| 502 | * Wait for a request to complete. |
| 503 | * |
| 504 | * Interruptible by signals only if mounted with intr flag. |
| 505 | */ |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 506 | static int nfs_wait_on_requests_locked(struct inode *inode, unsigned long idx_start, unsigned int npages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
| 508 | struct nfs_inode *nfsi = NFS_I(inode); |
| 509 | struct nfs_page *req; |
| 510 | unsigned long idx_end, next; |
| 511 | unsigned int res = 0; |
| 512 | int error; |
| 513 | |
| 514 | if (npages == 0) |
| 515 | idx_end = ~0; |
| 516 | else |
| 517 | idx_end = idx_start + npages - 1; |
| 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | next = idx_start; |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 520 | while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_WRITEBACK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if (req->wb_index > idx_end) |
| 522 | break; |
| 523 | |
| 524 | next = req->wb_index + 1; |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 525 | BUG_ON(!NFS_WBACK_BUSY(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | atomic_inc(&req->wb_count); |
| 528 | spin_unlock(&nfsi->req_lock); |
| 529 | error = nfs_wait_on_request(req); |
| 530 | nfs_release_request(req); |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 531 | spin_lock(&nfsi->req_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (error < 0) |
| 533 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | res++; |
| 535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return res; |
| 537 | } |
| 538 | |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 539 | static void nfs_cancel_dirty_list(struct list_head *head) |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 540 | { |
| 541 | struct nfs_page *req; |
| 542 | while(!list_empty(head)) { |
| 543 | req = nfs_list_entry(head->next); |
| 544 | nfs_list_remove_request(req); |
Trond Myklebust | 5a6d41b | 2007-04-14 19:10:12 -0400 | [diff] [blame] | 545 | nfs_end_page_writeback(req->wb_page); |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 546 | nfs_inode_remove_request(req); |
| 547 | nfs_clear_page_writeback(req); |
| 548 | } |
| 549 | } |
| 550 | |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 551 | static void nfs_cancel_commit_list(struct list_head *head) |
| 552 | { |
| 553 | struct nfs_page *req; |
| 554 | |
| 555 | while(!list_empty(head)) { |
| 556 | req = nfs_list_entry(head->next); |
Trond Myklebust | b6dff26 | 2006-10-19 23:28:38 -0700 | [diff] [blame] | 557 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 558 | nfs_list_remove_request(req); |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 559 | clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 560 | nfs_inode_remove_request(req); |
Trond Myklebust | b6dff26 | 2006-10-19 23:28:38 -0700 | [diff] [blame] | 561 | nfs_unlock_request(req); |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
| 566 | /* |
| 567 | * nfs_scan_commit - Scan an inode for commit requests |
| 568 | * @inode: NFS inode to scan |
| 569 | * @dst: destination list |
| 570 | * @idx_start: lower bound of page->index to scan. |
| 571 | * @npages: idx_start + npages sets the upper bound to scan. |
| 572 | * |
| 573 | * Moves requests from the inode's 'commit' request list. |
| 574 | * The requests are *not* checked to ensure that they form a contiguous set. |
| 575 | */ |
| 576 | static int |
| 577 | nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_start, unsigned int npages) |
| 578 | { |
| 579 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 580 | int res = 0; |
| 581 | |
| 582 | if (nfsi->ncommit != 0) { |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 583 | res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages); |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 584 | nfsi->ncommit -= res; |
| 585 | if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit)) |
| 586 | printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n"); |
| 587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | return res; |
| 589 | } |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 590 | #else |
| 591 | static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_start, unsigned int npages) |
| 592 | { |
| 593 | return 0; |
| 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | #endif |
| 596 | |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 597 | static int nfs_wait_on_write_congestion(struct address_space *mapping) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 599 | struct inode *inode = mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | struct backing_dev_info *bdi = mapping->backing_dev_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | int ret = 0; |
| 602 | |
| 603 | might_sleep(); |
| 604 | |
| 605 | if (!bdi_write_congested(bdi)) |
| 606 | return 0; |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 607 | |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 608 | nfs_inc_stats(inode, NFSIOS_CONGESTIONWAIT); |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 609 | |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 610 | do { |
| 611 | struct rpc_clnt *clnt = NFS_CLIENT(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | sigset_t oldset; |
| 613 | |
| 614 | rpc_clnt_sigmask(clnt, &oldset); |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 615 | ret = congestion_wait_interruptible(WRITE, HZ/10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | rpc_clnt_sigunmask(clnt, &oldset); |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 617 | if (ret == -ERESTARTSYS) |
| 618 | break; |
| 619 | ret = 0; |
| 620 | } while (bdi_write_congested(bdi)); |
| 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return ret; |
| 623 | } |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | /* |
| 626 | * Try to update any existing write request, or create one if there is none. |
| 627 | * In order to match, the request's credentials must match those of |
| 628 | * the calling process. |
| 629 | * |
| 630 | * Note: Should always be called with the Page Lock held! |
| 631 | */ |
| 632 | static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx, |
Trond Myklebust | e21195a | 2006-12-05 00:35:39 -0500 | [diff] [blame] | 633 | struct page *page, unsigned int offset, unsigned int bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 635 | struct address_space *mapping = page->mapping; |
| 636 | struct inode *inode = mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | struct nfs_inode *nfsi = NFS_I(inode); |
| 638 | struct nfs_page *req, *new = NULL; |
| 639 | unsigned long rqend, end; |
| 640 | |
| 641 | end = offset + bytes; |
| 642 | |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 643 | if (nfs_wait_on_write_congestion(mapping)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | return ERR_PTR(-ERESTARTSYS); |
| 645 | for (;;) { |
| 646 | /* Loop over all inode entries and see if we find |
| 647 | * A request for the page we wish to update |
| 648 | */ |
| 649 | spin_lock(&nfsi->req_lock); |
Trond Myklebust | 277459d | 2006-12-05 00:35:35 -0500 | [diff] [blame] | 650 | req = nfs_page_find_request_locked(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | if (req) { |
| 652 | if (!nfs_lock_request_dontget(req)) { |
| 653 | int error; |
Trond Myklebust | 277459d | 2006-12-05 00:35:35 -0500 | [diff] [blame] | 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | spin_unlock(&nfsi->req_lock); |
| 656 | error = nfs_wait_on_request(req); |
| 657 | nfs_release_request(req); |
Neil Brown | 1dd594b | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 658 | if (error < 0) { |
| 659 | if (new) |
| 660 | nfs_release_request(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return ERR_PTR(error); |
Neil Brown | 1dd594b | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | continue; |
| 664 | } |
| 665 | spin_unlock(&nfsi->req_lock); |
| 666 | if (new) |
| 667 | nfs_release_request(new); |
| 668 | break; |
| 669 | } |
| 670 | |
| 671 | if (new) { |
| 672 | int error; |
| 673 | nfs_lock_request_dontget(new); |
| 674 | error = nfs_inode_add_request(inode, new); |
| 675 | if (error) { |
| 676 | spin_unlock(&nfsi->req_lock); |
| 677 | nfs_unlock_request(new); |
| 678 | return ERR_PTR(error); |
| 679 | } |
| 680 | spin_unlock(&nfsi->req_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return new; |
| 682 | } |
| 683 | spin_unlock(&nfsi->req_lock); |
| 684 | |
| 685 | new = nfs_create_request(ctx, inode, page, offset, bytes); |
| 686 | if (IS_ERR(new)) |
| 687 | return new; |
| 688 | } |
| 689 | |
| 690 | /* We have a request for our page. |
| 691 | * If the creds don't match, or the |
| 692 | * page addresses don't match, |
| 693 | * tell the caller to wait on the conflicting |
| 694 | * request. |
| 695 | */ |
| 696 | rqend = req->wb_offset + req->wb_bytes; |
| 697 | if (req->wb_context != ctx |
| 698 | || req->wb_page != page |
| 699 | || !nfs_dirty_request(req) |
| 700 | || offset > rqend || end < req->wb_offset) { |
| 701 | nfs_unlock_request(req); |
| 702 | return ERR_PTR(-EBUSY); |
| 703 | } |
| 704 | |
| 705 | /* Okay, the request matches. Update the region */ |
| 706 | if (offset < req->wb_offset) { |
| 707 | req->wb_offset = offset; |
| 708 | req->wb_pgbase = offset; |
| 709 | req->wb_bytes = rqend - req->wb_offset; |
| 710 | } |
| 711 | |
| 712 | if (end > rqend) |
| 713 | req->wb_bytes = end - req->wb_offset; |
| 714 | |
| 715 | return req; |
| 716 | } |
| 717 | |
| 718 | int nfs_flush_incompatible(struct file *file, struct page *page) |
| 719 | { |
| 720 | struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | struct nfs_page *req; |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 722 | int do_flush, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* |
| 724 | * Look for a request corresponding to this page. If there |
| 725 | * is one, and it belongs to another file, we flush it out |
| 726 | * before we try to copy anything into the page. Do this |
| 727 | * due to the lack of an ACCESS-type call in NFSv2. |
| 728 | * Also do the same if we find a request from an existing |
| 729 | * dropped page. |
| 730 | */ |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 731 | do { |
| 732 | req = nfs_page_find_request(page); |
| 733 | if (req == NULL) |
| 734 | return 0; |
| 735 | do_flush = req->wb_page != page || req->wb_context != ctx |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 736 | || !nfs_dirty_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | nfs_release_request(req); |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 738 | if (!do_flush) |
| 739 | return 0; |
| 740 | status = nfs_wb_page(page->mapping->host, page); |
| 741 | } while (status == 0); |
| 742 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /* |
| 746 | * Update and possibly write a cached page of an NFS file. |
| 747 | * |
| 748 | * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad |
| 749 | * things with a page scheduled for an RPC call (e.g. invalidate it). |
| 750 | */ |
| 751 | int nfs_updatepage(struct file *file, struct page *page, |
| 752 | unsigned int offset, unsigned int count) |
| 753 | { |
| 754 | struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | struct inode *inode = page->mapping->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | int status = 0; |
| 757 | |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 758 | nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n", |
Josef "Jeff" Sipek | 01cce93 | 2006-12-08 02:36:40 -0800 | [diff] [blame] | 761 | file->f_path.dentry->d_parent->d_name.name, |
| 762 | file->f_path.dentry->d_name.name, count, |
Chuck Lever | 0bbacc4 | 2005-11-01 16:53:32 -0500 | [diff] [blame] | 763 | (long long)(page_offset(page) +offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | /* If we're not using byte range locks, and we know the page |
| 766 | * is entirely in cache, it may be more efficient to avoid |
| 767 | * fragmenting write requests. |
| 768 | */ |
Trond Myklebust | ab0a3db | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 769 | if (PageUptodate(page) && inode->i_flock == NULL && !(file->f_mode & O_SYNC)) { |
Trond Myklebust | 49a70f2 | 2006-12-05 00:35:38 -0500 | [diff] [blame] | 770 | count = max(count + offset, nfs_page_length(page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Trond Myklebust | e21195a | 2006-12-05 00:35:39 -0500 | [diff] [blame] | 774 | status = nfs_writepage_setup(ctx, page, offset, count); |
Trond Myklebust | e261f51 | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 775 | __set_page_dirty_nobuffers(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | dprintk("NFS: nfs_updatepage returns %d (isize %Ld)\n", |
| 778 | status, (long long)i_size_read(inode)); |
| 779 | if (status < 0) |
Trond Myklebust | a301b77 | 2007-02-06 11:07:15 -0800 | [diff] [blame] | 780 | nfs_set_pageerror(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | return status; |
| 782 | } |
| 783 | |
| 784 | static void nfs_writepage_release(struct nfs_page *req) |
| 785 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 787 | if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) { |
| 788 | nfs_end_page_writeback(req->wb_page); |
| 789 | nfs_inode_remove_request(req); |
| 790 | } else |
| 791 | nfs_end_page_writeback(req->wb_page); |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 792 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static inline int flush_task_priority(int how) |
| 796 | { |
| 797 | switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) { |
| 798 | case FLUSH_HIGHPRI: |
| 799 | return RPC_PRIORITY_HIGH; |
| 800 | case FLUSH_LOWPRI: |
| 801 | return RPC_PRIORITY_LOW; |
| 802 | } |
| 803 | return RPC_PRIORITY_NORMAL; |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 | * Set up the argument/result storage required for the RPC call. |
| 808 | */ |
| 809 | static void nfs_write_rpcsetup(struct nfs_page *req, |
| 810 | struct nfs_write_data *data, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 811 | const struct rpc_call_ops *call_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | unsigned int count, unsigned int offset, |
| 813 | int how) |
| 814 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | struct inode *inode; |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 816 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | /* Set up the RPC argument and reply structs |
| 819 | * NB: take care not to mess about with data->commit et al. */ |
| 820 | |
| 821 | data->req = req; |
| 822 | data->inode = inode = req->wb_context->dentry->d_inode; |
| 823 | data->cred = req->wb_context->cred; |
| 824 | |
| 825 | data->args.fh = NFS_FH(inode); |
| 826 | data->args.offset = req_offset(req) + offset; |
| 827 | data->args.pgbase = req->wb_pgbase + offset; |
| 828 | data->args.pages = data->pagevec; |
| 829 | data->args.count = count; |
| 830 | data->args.context = req->wb_context; |
| 831 | |
| 832 | data->res.fattr = &data->fattr; |
| 833 | data->res.count = count; |
| 834 | data->res.verf = &data->verf; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 835 | nfs_fattr_init(&data->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 837 | /* Set up the initial task struct. */ |
| 838 | flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC; |
| 839 | rpc_init_task(&data->task, NFS_CLIENT(inode), flags, call_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | NFS_PROTO(inode)->write_setup(data, how); |
| 841 | |
| 842 | data->task.tk_priority = flush_task_priority(how); |
| 843 | data->task.tk_cookie = (unsigned long)inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Chuck Lever | a3f565b | 2007-01-31 12:14:01 -0500 | [diff] [blame] | 845 | dprintk("NFS: %5u initiated write call " |
| 846 | "(req %s/%Ld, %u bytes @ offset %Lu)\n", |
Chuck Lever | 0bbacc4 | 2005-11-01 16:53:32 -0500 | [diff] [blame] | 847 | data->task.tk_pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | inode->i_sb->s_id, |
| 849 | (long long)NFS_FILEID(inode), |
| 850 | count, |
| 851 | (unsigned long long)data->args.offset); |
| 852 | } |
| 853 | |
| 854 | static void nfs_execute_write(struct nfs_write_data *data) |
| 855 | { |
| 856 | struct rpc_clnt *clnt = NFS_CLIENT(data->inode); |
| 857 | sigset_t oldset; |
| 858 | |
| 859 | rpc_clnt_sigmask(clnt, &oldset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | rpc_execute(&data->task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | rpc_clnt_sigunmask(clnt, &oldset); |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * Generate multiple small requests to write out a single |
| 866 | * contiguous dirty area on one page. |
| 867 | */ |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 868 | static int nfs_flush_multi(struct inode *inode, struct list_head *head, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | struct nfs_page *req = nfs_list_entry(head->next); |
| 871 | struct page *page = req->wb_page; |
| 872 | struct nfs_write_data *data; |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 873 | size_t wsize = NFS_SERVER(inode)->wsize, nbytes; |
| 874 | unsigned int offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | int requests = 0; |
| 876 | LIST_HEAD(list); |
| 877 | |
| 878 | nfs_list_remove_request(req); |
| 879 | |
| 880 | nbytes = req->wb_bytes; |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 881 | do { |
| 882 | size_t len = min(nbytes, wsize); |
| 883 | |
| 884 | data = nfs_writedata_alloc(len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | if (!data) |
| 886 | goto out_bad; |
| 887 | list_add(&data->pages, &list); |
| 888 | requests++; |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 889 | nbytes -= len; |
| 890 | } while (nbytes != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | atomic_set(&req->wb_complete, requests); |
| 892 | |
| 893 | ClearPageError(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | offset = 0; |
| 895 | nbytes = req->wb_bytes; |
| 896 | do { |
| 897 | data = list_entry(list.next, struct nfs_write_data, pages); |
| 898 | list_del_init(&data->pages); |
| 899 | |
| 900 | data->pagevec[0] = page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | if (nbytes > wsize) { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 903 | nfs_write_rpcsetup(req, data, &nfs_write_partial_ops, |
| 904 | wsize, offset, how); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | offset += wsize; |
| 906 | nbytes -= wsize; |
| 907 | } else { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 908 | nfs_write_rpcsetup(req, data, &nfs_write_partial_ops, |
| 909 | nbytes, offset, how); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | nbytes = 0; |
| 911 | } |
| 912 | nfs_execute_write(data); |
| 913 | } while (nbytes != 0); |
| 914 | |
| 915 | return 0; |
| 916 | |
| 917 | out_bad: |
| 918 | while (!list_empty(&list)) { |
| 919 | data = list_entry(list.next, struct nfs_write_data, pages); |
| 920 | list_del(&data->pages); |
Trond Myklebust | 8aca67f | 2006-11-13 16:23:44 -0500 | [diff] [blame] | 921 | nfs_writedata_release(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 923 | nfs_redirty_request(req); |
Trond Myklebust | 6d677e3 | 2007-04-20 16:12:40 -0400 | [diff] [blame] | 924 | nfs_end_page_writeback(req->wb_page); |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 925 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return -ENOMEM; |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Create an RPC task for the given write request and kick it. |
| 931 | * The page must have been locked by the caller. |
| 932 | * |
| 933 | * It may happen that the page we're passed is not marked dirty. |
| 934 | * This is the case if nfs_updatepage detects a conflicting request |
| 935 | * that has been written but not committed. |
| 936 | */ |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 937 | static int nfs_flush_one(struct inode *inode, struct list_head *head, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | { |
| 939 | struct nfs_page *req; |
| 940 | struct page **pages; |
| 941 | struct nfs_write_data *data; |
| 942 | unsigned int count; |
| 943 | |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 944 | data = nfs_writedata_alloc(NFS_SERVER(inode)->wsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | if (!data) |
| 946 | goto out_bad; |
| 947 | |
| 948 | pages = data->pagevec; |
| 949 | count = 0; |
| 950 | while (!list_empty(head)) { |
| 951 | req = nfs_list_entry(head->next); |
| 952 | nfs_list_remove_request(req); |
| 953 | nfs_list_add_request(req, &data->pages); |
| 954 | ClearPageError(req->wb_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | *pages++ = req->wb_page; |
| 956 | count += req->wb_bytes; |
| 957 | } |
| 958 | req = nfs_list_entry(data->pages.next); |
| 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | /* Set up the argument struct */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 961 | nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
| 963 | nfs_execute_write(data); |
| 964 | return 0; |
| 965 | out_bad: |
| 966 | while (!list_empty(head)) { |
| 967 | struct nfs_page *req = nfs_list_entry(head->next); |
| 968 | nfs_list_remove_request(req); |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 969 | nfs_redirty_request(req); |
Trond Myklebust | 6d677e3 | 2007-04-20 16:12:40 -0400 | [diff] [blame] | 970 | nfs_end_page_writeback(req->wb_page); |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 971 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | return -ENOMEM; |
| 974 | } |
| 975 | |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 976 | static int nfs_flush_list(struct inode *inode, struct list_head *head, int npages, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
| 978 | LIST_HEAD(one_request); |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 979 | int (*flush_one)(struct inode *, struct list_head *, int); |
| 980 | struct nfs_page *req; |
| 981 | int wpages = NFS_SERVER(inode)->wpages; |
| 982 | int wsize = NFS_SERVER(inode)->wsize; |
| 983 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 985 | flush_one = nfs_flush_one; |
| 986 | if (wsize < PAGE_CACHE_SIZE) |
| 987 | flush_one = nfs_flush_multi; |
| 988 | /* For single writes, FLUSH_STABLE is more efficient */ |
| 989 | if (npages <= wpages && npages == NFS_I(inode)->npages |
| 990 | && nfs_list_entry(head->next)->wb_bytes <= wsize) |
| 991 | how |= FLUSH_STABLE; |
| 992 | |
| 993 | do { |
| 994 | nfs_coalesce_requests(head, &one_request, wpages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | req = nfs_list_entry(one_request.next); |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 996 | error = flush_one(inode, &one_request, how); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (error < 0) |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 998 | goto out_err; |
| 999 | } while (!list_empty(head)); |
| 1000 | return 0; |
| 1001 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | while (!list_empty(head)) { |
| 1003 | req = nfs_list_entry(head->next); |
| 1004 | nfs_list_remove_request(req); |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1005 | nfs_redirty_request(req); |
Trond Myklebust | 6d677e3 | 2007-04-20 16:12:40 -0400 | [diff] [blame] | 1006 | nfs_end_page_writeback(req->wb_page); |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 1007 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | return error; |
| 1010 | } |
| 1011 | |
| 1012 | /* |
| 1013 | * Handle a write reply that flushed part of a page. |
| 1014 | */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1015 | static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1017 | struct nfs_write_data *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | struct nfs_page *req = data->req; |
| 1019 | struct page *page = req->wb_page; |
| 1020 | |
| 1021 | dprintk("NFS: write (%s/%Ld %d@%Ld)", |
| 1022 | req->wb_context->dentry->d_inode->i_sb->s_id, |
| 1023 | (long long)NFS_FILEID(req->wb_context->dentry->d_inode), |
| 1024 | req->wb_bytes, |
| 1025 | (long long)req_offset(req)); |
| 1026 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1027 | if (nfs_writeback_done(task, data) != 0) |
| 1028 | return; |
| 1029 | |
| 1030 | if (task->tk_status < 0) { |
Trond Myklebust | a301b77 | 2007-02-06 11:07:15 -0800 | [diff] [blame] | 1031 | nfs_set_pageerror(page); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1032 | req->wb_context->error = task->tk_status; |
| 1033 | dprintk(", error = %d\n", task->tk_status); |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 1034 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 1037 | if (nfs_write_need_commit(data)) { |
| 1038 | spinlock_t *req_lock = &NFS_I(page->mapping->host)->req_lock; |
| 1039 | |
| 1040 | spin_lock(req_lock); |
| 1041 | if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) { |
| 1042 | /* Do nothing we need to resend the writes */ |
| 1043 | } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) { |
| 1044 | memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf)); |
| 1045 | dprintk(" defer commit\n"); |
| 1046 | } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) { |
| 1047 | set_bit(PG_NEED_RESCHED, &req->wb_flags); |
| 1048 | clear_bit(PG_NEED_COMMIT, &req->wb_flags); |
| 1049 | dprintk(" server reboot detected\n"); |
| 1050 | } |
| 1051 | spin_unlock(req_lock); |
| 1052 | } else |
| 1053 | dprintk(" OK\n"); |
| 1054 | |
| 1055 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (atomic_dec_and_test(&req->wb_complete)) |
| 1057 | nfs_writepage_release(req); |
| 1058 | } |
| 1059 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1060 | static const struct rpc_call_ops nfs_write_partial_ops = { |
| 1061 | .rpc_call_done = nfs_writeback_done_partial, |
| 1062 | .rpc_release = nfs_writedata_release, |
| 1063 | }; |
| 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | /* |
| 1066 | * Handle a write reply that flushes a whole page. |
| 1067 | * |
| 1068 | * FIXME: There is an inherent race with invalidate_inode_pages and |
| 1069 | * writebacks since the page->count is kept > 1 for as long |
| 1070 | * as the page has a write request pending. |
| 1071 | */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1072 | static void nfs_writeback_done_full(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1074 | struct nfs_write_data *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | struct nfs_page *req; |
| 1076 | struct page *page; |
| 1077 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1078 | if (nfs_writeback_done(task, data) != 0) |
| 1079 | return; |
| 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | /* Update attributes as result of writeback. */ |
| 1082 | while (!list_empty(&data->pages)) { |
| 1083 | req = nfs_list_entry(data->pages.next); |
| 1084 | nfs_list_remove_request(req); |
| 1085 | page = req->wb_page; |
| 1086 | |
| 1087 | dprintk("NFS: write (%s/%Ld %d@%Ld)", |
| 1088 | req->wb_context->dentry->d_inode->i_sb->s_id, |
| 1089 | (long long)NFS_FILEID(req->wb_context->dentry->d_inode), |
| 1090 | req->wb_bytes, |
| 1091 | (long long)req_offset(req)); |
| 1092 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1093 | if (task->tk_status < 0) { |
Trond Myklebust | a301b77 | 2007-02-06 11:07:15 -0800 | [diff] [blame] | 1094 | nfs_set_pageerror(page); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1095 | req->wb_context->error = task->tk_status; |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1096 | dprintk(", error = %d\n", task->tk_status); |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 1097 | goto remove_request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 1100 | if (nfs_write_need_commit(data)) { |
| 1101 | memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf)); |
| 1102 | nfs_mark_request_commit(req); |
| 1103 | nfs_end_page_writeback(page); |
| 1104 | dprintk(" marked for commit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | goto next; |
| 1106 | } |
Trond Myklebust | 8e821ca | 2007-04-20 16:12:34 -0400 | [diff] [blame] | 1107 | dprintk(" OK\n"); |
| 1108 | remove_request: |
| 1109 | nfs_end_page_writeback(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | nfs_inode_remove_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | next: |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 1112 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1116 | static const struct rpc_call_ops nfs_write_full_ops = { |
| 1117 | .rpc_call_done = nfs_writeback_done_full, |
| 1118 | .rpc_release = nfs_writedata_release, |
| 1119 | }; |
| 1120 | |
| 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | /* |
| 1123 | * This function is called when the WRITE call is complete. |
| 1124 | */ |
Chuck Lever | 462d5b3 | 2006-03-20 13:44:32 -0500 | [diff] [blame] | 1125 | int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | struct nfs_writeargs *argp = &data->args; |
| 1128 | struct nfs_writeres *resp = &data->res; |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1129 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Chuck Lever | a3f565b | 2007-01-31 12:14:01 -0500 | [diff] [blame] | 1131 | dprintk("NFS: %5u nfs_writeback_done (status %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | task->tk_pid, task->tk_status); |
| 1133 | |
Chuck Lever | f551e44 | 2006-09-20 14:33:04 -0400 | [diff] [blame] | 1134 | /* |
| 1135 | * ->write_done will attempt to use post-op attributes to detect |
| 1136 | * conflicting writes by other clients. A strict interpretation |
| 1137 | * of close-to-open would allow us to continue caching even if |
| 1138 | * another writer had changed the file, but some applications |
| 1139 | * depend on tighter cache coherency when writing. |
| 1140 | */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1141 | status = NFS_PROTO(data->inode)->write_done(task, data); |
| 1142 | if (status != 0) |
| 1143 | return status; |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 1144 | nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count); |
| 1145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
| 1147 | if (resp->verf->committed < argp->stable && task->tk_status >= 0) { |
| 1148 | /* We tried a write call, but the server did not |
| 1149 | * commit data to stable storage even though we |
| 1150 | * requested it. |
| 1151 | * Note: There is a known bug in Tru64 < 5.0 in which |
| 1152 | * the server reports NFS_DATA_SYNC, but performs |
| 1153 | * NFS_FILE_SYNC. We therefore implement this checking |
| 1154 | * as a dprintk() in order to avoid filling syslog. |
| 1155 | */ |
| 1156 | static unsigned long complain; |
| 1157 | |
| 1158 | if (time_before(complain, jiffies)) { |
| 1159 | dprintk("NFS: faulty NFS server %s:" |
| 1160 | " (committed = %d) != (stable = %d)\n", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1161 | NFS_SERVER(data->inode)->nfs_client->cl_hostname, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | resp->verf->committed, argp->stable); |
| 1163 | complain = jiffies + 300 * HZ; |
| 1164 | } |
| 1165 | } |
| 1166 | #endif |
| 1167 | /* Is this a short write? */ |
| 1168 | if (task->tk_status >= 0 && resp->count < argp->count) { |
| 1169 | static unsigned long complain; |
| 1170 | |
Chuck Lever | 91d5b47 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 1171 | nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE); |
| 1172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | /* Has the server at least made some progress? */ |
| 1174 | if (resp->count != 0) { |
| 1175 | /* Was this an NFSv2 write or an NFSv3 stable write? */ |
| 1176 | if (resp->verf->committed != NFS_UNSTABLE) { |
| 1177 | /* Resend from where the server left off */ |
| 1178 | argp->offset += resp->count; |
| 1179 | argp->pgbase += resp->count; |
| 1180 | argp->count -= resp->count; |
| 1181 | } else { |
| 1182 | /* Resend as a stable write in order to avoid |
| 1183 | * headaches in the case of a server crash. |
| 1184 | */ |
| 1185 | argp->stable = NFS_FILE_SYNC; |
| 1186 | } |
| 1187 | rpc_restart_call(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1188 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
| 1190 | if (time_before(complain, jiffies)) { |
| 1191 | printk(KERN_WARNING |
| 1192 | "NFS: Server wrote zero bytes, expected %u.\n", |
| 1193 | argp->count); |
| 1194 | complain = jiffies + 300 * HZ; |
| 1195 | } |
| 1196 | /* Can't do anything about it except throw an error. */ |
| 1197 | task->tk_status = -EIO; |
| 1198 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1199 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1204 | void nfs_commit_release(void *wdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | nfs_commit_free(wdata); |
| 1207 | } |
| 1208 | |
| 1209 | /* |
| 1210 | * Set up the argument/result storage required for the RPC call. |
| 1211 | */ |
| 1212 | static void nfs_commit_rpcsetup(struct list_head *head, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1213 | struct nfs_write_data *data, |
| 1214 | int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 1216 | struct nfs_page *first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | struct inode *inode; |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1218 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
| 1220 | /* Set up the RPC argument and reply structs |
| 1221 | * NB: take care not to mess about with data->commit et al. */ |
| 1222 | |
| 1223 | list_splice_init(head, &data->pages); |
| 1224 | first = nfs_list_entry(data->pages.next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | inode = first->wb_context->dentry->d_inode; |
| 1226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | data->inode = inode; |
| 1228 | data->cred = first->wb_context->cred; |
| 1229 | |
| 1230 | data->args.fh = NFS_FH(data->inode); |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 1231 | /* Note: we always request a commit of the entire inode */ |
| 1232 | data->args.offset = 0; |
| 1233 | data->args.count = 0; |
| 1234 | data->res.count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | data->res.fattr = &data->fattr; |
| 1236 | data->res.verf = &data->verf; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1237 | nfs_fattr_init(&data->fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1238 | |
| 1239 | /* Set up the initial task struct. */ |
| 1240 | flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC; |
| 1241 | rpc_init_task(&data->task, NFS_CLIENT(inode), flags, &nfs_commit_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | NFS_PROTO(inode)->commit_setup(data, how); |
| 1243 | |
| 1244 | data->task.tk_priority = flush_task_priority(how); |
| 1245 | data->task.tk_cookie = (unsigned long)inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Chuck Lever | a3f565b | 2007-01-31 12:14:01 -0500 | [diff] [blame] | 1247 | dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | /* |
| 1251 | * Commit dirty pages |
| 1252 | */ |
| 1253 | static int |
Chuck Lever | 40859d7 | 2005-11-30 18:09:02 -0500 | [diff] [blame] | 1254 | nfs_commit_list(struct inode *inode, struct list_head *head, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | { |
| 1256 | struct nfs_write_data *data; |
| 1257 | struct nfs_page *req; |
| 1258 | |
Trond Myklebust | e9f7bee | 2006-09-08 09:48:54 -0700 | [diff] [blame] | 1259 | data = nfs_commit_alloc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | if (!data) |
| 1262 | goto out_bad; |
| 1263 | |
| 1264 | /* Set up the argument struct */ |
| 1265 | nfs_commit_rpcsetup(head, data, how); |
| 1266 | |
| 1267 | nfs_execute_write(data); |
| 1268 | return 0; |
| 1269 | out_bad: |
| 1270 | while (!list_empty(head)) { |
| 1271 | req = nfs_list_entry(head->next); |
| 1272 | nfs_list_remove_request(req); |
| 1273 | nfs_mark_request_commit(req); |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 1274 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
Trond Myklebust | 5c2d97c | 2006-09-18 23:20:35 -0400 | [diff] [blame] | 1275 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | return -ENOMEM; |
| 1278 | } |
| 1279 | |
| 1280 | /* |
| 1281 | * COMMIT call returned |
| 1282 | */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1283 | static void nfs_commit_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1285 | struct nfs_write_data *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | struct nfs_page *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
Chuck Lever | a3f565b | 2007-01-31 12:14:01 -0500 | [diff] [blame] | 1288 | dprintk("NFS: %5u nfs_commit_done (status %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | task->tk_pid, task->tk_status); |
| 1290 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1291 | /* Call the NFS version-specific code */ |
| 1292 | if (NFS_PROTO(data->inode)->commit_done(task, data) != 0) |
| 1293 | return; |
| 1294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | while (!list_empty(&data->pages)) { |
| 1296 | req = nfs_list_entry(data->pages.next); |
| 1297 | nfs_list_remove_request(req); |
Trond Myklebust | 612c938 | 2007-04-20 16:12:45 -0400 | [diff] [blame] | 1298 | clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); |
Christoph Lameter | fd39fc8 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 1299 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
| 1301 | dprintk("NFS: commit (%s/%Ld %d@%Ld)", |
| 1302 | req->wb_context->dentry->d_inode->i_sb->s_id, |
| 1303 | (long long)NFS_FILEID(req->wb_context->dentry->d_inode), |
| 1304 | req->wb_bytes, |
| 1305 | (long long)req_offset(req)); |
| 1306 | if (task->tk_status < 0) { |
| 1307 | req->wb_context->error = task->tk_status; |
| 1308 | nfs_inode_remove_request(req); |
| 1309 | dprintk(", error = %d\n", task->tk_status); |
| 1310 | goto next; |
| 1311 | } |
| 1312 | |
| 1313 | /* Okay, COMMIT succeeded, apparently. Check the verifier |
| 1314 | * returned by the server against all stored verfs. */ |
| 1315 | if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) { |
| 1316 | /* We have a match */ |
| 1317 | nfs_inode_remove_request(req); |
| 1318 | dprintk(" OK\n"); |
| 1319 | goto next; |
| 1320 | } |
| 1321 | /* We have a mismatch. Write the page again */ |
| 1322 | dprintk(" mismatch\n"); |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1323 | nfs_redirty_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | next: |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 1325 | nfs_clear_page_writeback(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1328 | |
| 1329 | static const struct rpc_call_ops nfs_commit_ops = { |
| 1330 | .rpc_call_done = nfs_commit_done, |
| 1331 | .rpc_release = nfs_commit_release, |
| 1332 | }; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1333 | #else |
| 1334 | static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how) |
| 1335 | { |
| 1336 | return 0; |
| 1337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | #endif |
| 1339 | |
Trond Myklebust | 3f44254 | 2006-09-17 14:46:44 -0400 | [diff] [blame] | 1340 | static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | { |
Trond Myklebust | 28c6925 | 2006-09-16 13:04:50 -0400 | [diff] [blame] | 1342 | struct nfs_inode *nfsi = NFS_I(mapping->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | LIST_HEAD(head); |
Trond Myklebust | 3f44254 | 2006-09-17 14:46:44 -0400 | [diff] [blame] | 1344 | long res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
| 1346 | spin_lock(&nfsi->req_lock); |
Trond Myklebust | 3f44254 | 2006-09-17 14:46:44 -0400 | [diff] [blame] | 1347 | res = nfs_scan_dirty(mapping, wbc, &head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | spin_unlock(&nfsi->req_lock); |
Trond Myklebust | ab0a3db | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 1349 | if (res) { |
Trond Myklebust | 28c6925 | 2006-09-16 13:04:50 -0400 | [diff] [blame] | 1350 | int error = nfs_flush_list(mapping->host, &head, res, how); |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 1351 | if (error < 0) |
| 1352 | return error; |
Trond Myklebust | ab0a3db | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 1353 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return res; |
| 1355 | } |
| 1356 | |
| 1357 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 1358 | int nfs_commit_inode(struct inode *inode, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
| 1360 | struct nfs_inode *nfsi = NFS_I(inode); |
| 1361 | LIST_HEAD(head); |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 1362 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
| 1364 | spin_lock(&nfsi->req_lock); |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 1365 | res = nfs_scan_commit(inode, &head, 0, 0); |
| 1366 | spin_unlock(&nfsi->req_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | if (res) { |
Trond Myklebust | 7d46a49 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 1368 | int error = nfs_commit_list(inode, &head, how); |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 1369 | if (error < 0) |
| 1370 | return error; |
| 1371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | return res; |
| 1373 | } |
| 1374 | #endif |
| 1375 | |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1376 | long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | { |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1378 | struct inode *inode = mapping->host; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1379 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1380 | unsigned long idx_start, idx_end; |
| 1381 | unsigned int npages = 0; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1382 | LIST_HEAD(head); |
Trond Myklebust | 70b9ecb | 2006-01-03 09:55:34 +0100 | [diff] [blame] | 1383 | int nocommit = how & FLUSH_NOCOMMIT; |
Trond Myklebust | 3f44254 | 2006-09-17 14:46:44 -0400 | [diff] [blame] | 1384 | long pages, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1386 | /* FIXME */ |
| 1387 | if (wbc->range_cyclic) |
| 1388 | idx_start = 0; |
| 1389 | else { |
| 1390 | idx_start = wbc->range_start >> PAGE_CACHE_SHIFT; |
| 1391 | idx_end = wbc->range_end >> PAGE_CACHE_SHIFT; |
| 1392 | if (idx_end > idx_start) { |
| 1393 | unsigned long l_npages = 1 + idx_end - idx_start; |
| 1394 | npages = l_npages; |
| 1395 | if (sizeof(npages) != sizeof(l_npages) && |
| 1396 | (unsigned long)npages != l_npages) |
| 1397 | npages = 0; |
| 1398 | } |
| 1399 | } |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1400 | how &= ~FLUSH_NOCOMMIT; |
| 1401 | spin_lock(&nfsi->req_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | do { |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1403 | wbc->pages_skipped = 0; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1404 | ret = nfs_wait_on_requests_locked(inode, idx_start, npages); |
| 1405 | if (ret != 0) |
Trond Myklebust | 70b9ecb | 2006-01-03 09:55:34 +0100 | [diff] [blame] | 1406 | continue; |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1407 | pages = nfs_scan_dirty(mapping, wbc, &head); |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1408 | if (pages != 0) { |
| 1409 | spin_unlock(&nfsi->req_lock); |
Trond Myklebust | e8e058e | 2006-11-15 17:31:56 -0500 | [diff] [blame] | 1410 | if (how & FLUSH_INVALIDATE) { |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 1411 | nfs_cancel_dirty_list(&head); |
Trond Myklebust | e8e058e | 2006-11-15 17:31:56 -0500 | [diff] [blame] | 1412 | ret = pages; |
| 1413 | } else |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 1414 | ret = nfs_flush_list(inode, &head, pages, how); |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1415 | spin_lock(&nfsi->req_lock); |
| 1416 | continue; |
| 1417 | } |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1418 | if (wbc->pages_skipped != 0) |
| 1419 | continue; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1420 | if (nocommit) |
| 1421 | break; |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 1422 | pages = nfs_scan_commit(inode, &head, idx_start, npages); |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1423 | if (pages == 0) { |
| 1424 | if (wbc->pages_skipped != 0) |
| 1425 | continue; |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1426 | break; |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1427 | } |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 1428 | if (how & FLUSH_INVALIDATE) { |
| 1429 | spin_unlock(&nfsi->req_lock); |
Trond Myklebust | 83715ad | 2006-07-05 13:17:12 -0400 | [diff] [blame] | 1430 | nfs_cancel_commit_list(&head); |
Trond Myklebust | e8e058e | 2006-11-15 17:31:56 -0500 | [diff] [blame] | 1431 | ret = pages; |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 1432 | spin_lock(&nfsi->req_lock); |
| 1433 | continue; |
| 1434 | } |
| 1435 | pages += nfs_scan_commit(inode, &head, 0, 0); |
Trond Myklebust | c42de9d | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1436 | spin_unlock(&nfsi->req_lock); |
| 1437 | ret = nfs_commit_list(inode, &head, how); |
| 1438 | spin_lock(&nfsi->req_lock); |
| 1439 | } while (ret >= 0); |
| 1440 | spin_unlock(&nfsi->req_lock); |
| 1441 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1444 | /* |
| 1445 | * flush the inode to disk. |
| 1446 | */ |
| 1447 | int nfs_wb_all(struct inode *inode) |
| 1448 | { |
| 1449 | struct address_space *mapping = inode->i_mapping; |
| 1450 | struct writeback_control wbc = { |
| 1451 | .bdi = mapping->backing_dev_info, |
| 1452 | .sync_mode = WB_SYNC_ALL, |
| 1453 | .nr_to_write = LONG_MAX, |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1454 | .for_writepages = 1, |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1455 | .range_cyclic = 1, |
| 1456 | }; |
| 1457 | int ret; |
| 1458 | |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1459 | ret = generic_writepages(mapping, &wbc); |
| 1460 | if (ret < 0) |
| 1461 | goto out; |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1462 | ret = nfs_sync_mapping_wait(mapping, &wbc, 0); |
| 1463 | if (ret >= 0) |
| 1464 | return 0; |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1465 | out: |
Trond Myklebust | e507d9e | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1466 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1467 | return ret; |
| 1468 | } |
| 1469 | |
| 1470 | int nfs_sync_mapping_range(struct address_space *mapping, loff_t range_start, loff_t range_end, int how) |
| 1471 | { |
| 1472 | struct writeback_control wbc = { |
| 1473 | .bdi = mapping->backing_dev_info, |
| 1474 | .sync_mode = WB_SYNC_ALL, |
| 1475 | .nr_to_write = LONG_MAX, |
| 1476 | .range_start = range_start, |
| 1477 | .range_end = range_end, |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1478 | .for_writepages = 1, |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1479 | }; |
| 1480 | int ret; |
| 1481 | |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1482 | if (!(how & FLUSH_NOWRITEPAGE)) { |
| 1483 | ret = generic_writepages(mapping, &wbc); |
| 1484 | if (ret < 0) |
| 1485 | goto out; |
| 1486 | } |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1487 | ret = nfs_sync_mapping_wait(mapping, &wbc, how); |
| 1488 | if (ret >= 0) |
| 1489 | return 0; |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1490 | out: |
Trond Myklebust | e507d9e | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1491 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1492 | return ret; |
| 1493 | } |
| 1494 | |
Trond Myklebust | 61822ab | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1495 | int nfs_wb_page_priority(struct inode *inode, struct page *page, int how) |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1496 | { |
| 1497 | loff_t range_start = page_offset(page); |
| 1498 | loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1); |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 1499 | struct writeback_control wbc = { |
| 1500 | .bdi = page->mapping->backing_dev_info, |
| 1501 | .sync_mode = WB_SYNC_ALL, |
| 1502 | .nr_to_write = LONG_MAX, |
| 1503 | .range_start = range_start, |
| 1504 | .range_end = range_end, |
| 1505 | }; |
| 1506 | int ret; |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1507 | |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 1508 | BUG_ON(!PageLocked(page)); |
| 1509 | if (!(how & FLUSH_NOWRITEPAGE) && clear_page_dirty_for_io(page)) { |
| 1510 | ret = nfs_writepage_locked(page, &wbc); |
| 1511 | if (ret < 0) |
| 1512 | goto out; |
| 1513 | } |
Trond Myklebust | f40313a | 2007-01-13 02:28:08 -0500 | [diff] [blame] | 1514 | if (!PagePrivate(page)) |
| 1515 | return 0; |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 1516 | ret = nfs_sync_mapping_wait(page->mapping, &wbc, how); |
| 1517 | if (ret >= 0) |
| 1518 | return 0; |
| 1519 | out: |
Trond Myklebust | e507d9e | 2006-12-05 00:35:42 -0500 | [diff] [blame] | 1520 | __mark_inode_dirty(inode, I_DIRTY_PAGES); |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 1521 | return ret; |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /* |
| 1525 | * Write back all requests on one page - we do this before reading it. |
| 1526 | */ |
| 1527 | int nfs_wb_page(struct inode *inode, struct page* page) |
| 1528 | { |
Trond Myklebust | 4d770cc | 2006-12-05 00:35:41 -0500 | [diff] [blame] | 1529 | return nfs_wb_page_priority(inode, page, FLUSH_STABLE); |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1532 | int nfs_set_page_dirty(struct page *page) |
| 1533 | { |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1534 | spinlock_t *req_lock = &NFS_I(page->mapping->host)->req_lock; |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1535 | struct nfs_page *req; |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1536 | int ret; |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1537 | |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1538 | spin_lock(req_lock); |
| 1539 | req = nfs_page_find_request_locked(page); |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1540 | if (req != NULL) { |
| 1541 | /* Mark any existing write requests for flushing */ |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1542 | ret = !test_and_set_bit(PG_NEED_FLUSH, &req->wb_flags); |
| 1543 | spin_unlock(req_lock); |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1544 | nfs_release_request(req); |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1545 | return ret; |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1546 | } |
Trond Myklebust | 2b82f19 | 2007-04-20 16:12:50 -0400 | [diff] [blame^] | 1547 | ret = __set_page_dirty_nobuffers(page); |
| 1548 | spin_unlock(req_lock); |
| 1549 | return ret; |
Trond Myklebust | 1a54533 | 2006-12-05 00:35:40 -0500 | [diff] [blame] | 1550 | } |
| 1551 | |
Trond Myklebust | 1c75950 | 2006-10-09 16:18:38 -0400 | [diff] [blame] | 1552 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1553 | int __init nfs_init_writepagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | { |
| 1555 | nfs_wdata_cachep = kmem_cache_create("nfs_write_data", |
| 1556 | sizeof(struct nfs_write_data), |
| 1557 | 0, SLAB_HWCACHE_ALIGN, |
| 1558 | NULL, NULL); |
| 1559 | if (nfs_wdata_cachep == NULL) |
| 1560 | return -ENOMEM; |
| 1561 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 1562 | nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE, |
| 1563 | nfs_wdata_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | if (nfs_wdata_mempool == NULL) |
| 1565 | return -ENOMEM; |
| 1566 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 1567 | nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, |
| 1568 | nfs_wdata_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (nfs_commit_mempool == NULL) |
| 1570 | return -ENOMEM; |
| 1571 | |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 1572 | /* |
| 1573 | * NFS congestion size, scale with available memory. |
| 1574 | * |
| 1575 | * 64MB: 8192k |
| 1576 | * 128MB: 11585k |
| 1577 | * 256MB: 16384k |
| 1578 | * 512MB: 23170k |
| 1579 | * 1GB: 32768k |
| 1580 | * 2GB: 46340k |
| 1581 | * 4GB: 65536k |
| 1582 | * 8GB: 92681k |
| 1583 | * 16GB: 131072k |
| 1584 | * |
| 1585 | * This allows larger machines to have larger/more transfers. |
| 1586 | * Limit the default to 256M |
| 1587 | */ |
| 1588 | nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10); |
| 1589 | if (nfs_congestion_kb > 256*1024) |
| 1590 | nfs_congestion_kb = 256*1024; |
| 1591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | return 0; |
| 1593 | } |
| 1594 | |
David Brownell | 266bee8 | 2006-06-27 12:59:15 -0700 | [diff] [blame] | 1595 | void nfs_destroy_writepagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | { |
| 1597 | mempool_destroy(nfs_commit_mempool); |
| 1598 | mempool_destroy(nfs_wdata_mempool); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 1599 | kmem_cache_destroy(nfs_wdata_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |