Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/pagelist.c |
| 3 | * |
| 4 | * A set of helper functions for managing NFS read and write requests. |
| 5 | * The main purpose of these routines is to provide support for the |
| 6 | * coalescing of several requests into a single RPC call. |
| 7 | * |
| 8 | * Copyright 2000, 2001 (c) Trond Myklebust <trond.myklebust@fys.uio.no> |
| 9 | * |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/file.h> |
| 14 | #include <linux/sunrpc/clnt.h> |
| 15 | #include <linux/nfs3.h> |
| 16 | #include <linux/nfs4.h> |
| 17 | #include <linux/nfs_page.h> |
| 18 | #include <linux/nfs_fs.h> |
| 19 | #include <linux/nfs_mount.h> |
| 20 | |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 21 | #include "internal.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define NFS_PARANOIA 1 |
| 24 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 25 | static struct kmem_cache *nfs_page_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | static inline struct nfs_page * |
| 28 | nfs_page_alloc(void) |
| 29 | { |
| 30 | struct nfs_page *p; |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 31 | p = kmem_cache_alloc(nfs_page_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | if (p) { |
| 33 | memset(p, 0, sizeof(*p)); |
| 34 | INIT_LIST_HEAD(&p->wb_list); |
| 35 | } |
| 36 | return p; |
| 37 | } |
| 38 | |
| 39 | static inline void |
| 40 | nfs_page_free(struct nfs_page *p) |
| 41 | { |
| 42 | kmem_cache_free(nfs_page_cachep, p); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * nfs_create_request - Create an NFS read/write request. |
| 47 | * @file: file descriptor to use |
| 48 | * @inode: inode to which the request is attached |
| 49 | * @page: page to write |
| 50 | * @offset: starting offset within the page for the write |
| 51 | * @count: number of bytes to read/write |
| 52 | * |
| 53 | * The page must be locked by the caller. This makes sure we never |
Jason Uhlenkott | a19b89c | 2007-04-26 17:25:51 -0700 | [diff] [blame^] | 54 | * create two different requests for the same page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * User should ensure it is safe to sleep in this function. |
| 56 | */ |
| 57 | struct nfs_page * |
| 58 | nfs_create_request(struct nfs_open_context *ctx, struct inode *inode, |
| 59 | struct page *page, |
| 60 | unsigned int offset, unsigned int count) |
| 61 | { |
| 62 | struct nfs_server *server = NFS_SERVER(inode); |
| 63 | struct nfs_page *req; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | for (;;) { |
| 66 | /* try to allocate the request struct */ |
| 67 | req = nfs_page_alloc(); |
| 68 | if (req != NULL) |
| 69 | break; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if (signalled() && (server->flags & NFS_MOUNT_INTR)) |
| 72 | return ERR_PTR(-ERESTARTSYS); |
| 73 | yield(); |
| 74 | } |
| 75 | |
| 76 | /* Initialize the request struct. Initially, we assume a |
| 77 | * long write-back delay. This will be adjusted in |
| 78 | * update_nfs_request below if the region is not locked. */ |
| 79 | req->wb_page = page; |
| 80 | atomic_set(&req->wb_complete, 0); |
| 81 | req->wb_index = page->index; |
| 82 | page_cache_get(page); |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 83 | BUG_ON(PagePrivate(page)); |
| 84 | BUG_ON(!PageLocked(page)); |
| 85 | BUG_ON(page->mapping->host != inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | req->wb_offset = offset; |
| 87 | req->wb_pgbase = offset; |
| 88 | req->wb_bytes = count; |
| 89 | atomic_set(&req->wb_count, 1); |
| 90 | req->wb_context = get_nfs_open_context(ctx); |
| 91 | |
| 92 | return req; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * nfs_unlock_request - Unlock request and wake up sleepers. |
| 97 | * @req: |
| 98 | */ |
| 99 | void nfs_unlock_request(struct nfs_page *req) |
| 100 | { |
| 101 | if (!NFS_WBACK_BUSY(req)) { |
| 102 | printk(KERN_ERR "NFS: Invalid unlock attempted\n"); |
| 103 | BUG(); |
| 104 | } |
| 105 | smp_mb__before_clear_bit(); |
| 106 | clear_bit(PG_BUSY, &req->wb_flags); |
| 107 | smp_mb__after_clear_bit(); |
Trond Myklebust | 464a98b | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 108 | wake_up_bit(&req->wb_flags, PG_BUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | nfs_release_request(req); |
| 110 | } |
| 111 | |
| 112 | /** |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 113 | * nfs_set_page_writeback_locked - Lock a request for writeback |
| 114 | * @req: |
| 115 | */ |
| 116 | int nfs_set_page_writeback_locked(struct nfs_page *req) |
| 117 | { |
| 118 | struct nfs_inode *nfsi = NFS_I(req->wb_context->dentry->d_inode); |
| 119 | |
| 120 | if (!nfs_lock_request(req)) |
| 121 | return 0; |
| 122 | radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_WRITEBACK); |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * nfs_clear_page_writeback - Unlock request and wake up sleepers |
| 128 | */ |
| 129 | void nfs_clear_page_writeback(struct nfs_page *req) |
| 130 | { |
| 131 | struct nfs_inode *nfsi = NFS_I(req->wb_context->dentry->d_inode); |
| 132 | |
Trond Myklebust | deb7d63 | 2006-03-20 13:44:50 -0500 | [diff] [blame] | 133 | if (req->wb_page != NULL) { |
| 134 | spin_lock(&nfsi->req_lock); |
| 135 | radix_tree_tag_clear(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_WRITEBACK); |
| 136 | spin_unlock(&nfsi->req_lock); |
| 137 | } |
Trond Myklebust | c6a556b | 2005-06-22 17:16:30 +0000 | [diff] [blame] | 138 | nfs_unlock_request(req); |
| 139 | } |
| 140 | |
| 141 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * nfs_clear_request - Free up all resources allocated to the request |
| 143 | * @req: |
| 144 | * |
| 145 | * Release page resources associated with a write request after it |
| 146 | * has completed. |
| 147 | */ |
| 148 | void nfs_clear_request(struct nfs_page *req) |
| 149 | { |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 150 | struct page *page = req->wb_page; |
| 151 | if (page != NULL) { |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 152 | page_cache_release(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | req->wb_page = NULL; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * nfs_release_request - Release the count on an NFS read/write request |
| 160 | * @req: request to release |
| 161 | * |
| 162 | * Note: Should never be called with the spinlock held! |
| 163 | */ |
| 164 | void |
| 165 | nfs_release_request(struct nfs_page *req) |
| 166 | { |
| 167 | if (!atomic_dec_and_test(&req->wb_count)) |
| 168 | return; |
| 169 | |
| 170 | #ifdef NFS_PARANOIA |
| 171 | BUG_ON (!list_empty(&req->wb_list)); |
| 172 | BUG_ON (NFS_WBACK_BUSY(req)); |
| 173 | #endif |
| 174 | |
| 175 | /* Release struct file or cached credential */ |
| 176 | nfs_clear_request(req); |
| 177 | put_nfs_open_context(req->wb_context); |
| 178 | nfs_page_free(req); |
| 179 | } |
| 180 | |
Trond Myklebust | 464a98b | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 181 | static int nfs_wait_bit_interruptible(void *word) |
| 182 | { |
| 183 | int ret = 0; |
| 184 | |
| 185 | if (signal_pending(current)) |
| 186 | ret = -ERESTARTSYS; |
| 187 | else |
| 188 | schedule(); |
| 189 | return ret; |
| 190 | } |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /** |
| 193 | * nfs_wait_on_request - Wait for a request to complete. |
| 194 | * @req: request to wait upon. |
| 195 | * |
| 196 | * Interruptible by signals only if mounted with intr flag. |
| 197 | * The user is responsible for holding a count on the request. |
| 198 | */ |
| 199 | int |
| 200 | nfs_wait_on_request(struct nfs_page *req) |
| 201 | { |
Trond Myklebust | 464a98b | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 202 | struct rpc_clnt *clnt = NFS_CLIENT(req->wb_context->dentry->d_inode); |
| 203 | sigset_t oldmask; |
| 204 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Trond Myklebust | 464a98b | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 206 | if (!test_bit(PG_BUSY, &req->wb_flags)) |
| 207 | goto out; |
| 208 | /* |
| 209 | * Note: the call to rpc_clnt_sigmask() suffices to ensure that we |
| 210 | * are not interrupted if intr flag is not set |
| 211 | */ |
| 212 | rpc_clnt_sigmask(clnt, &oldmask); |
| 213 | ret = out_of_line_wait_on_bit(&req->wb_flags, PG_BUSY, |
| 214 | nfs_wait_bit_interruptible, TASK_INTERRUPTIBLE); |
| 215 | rpc_clnt_sigunmask(clnt, &oldmask); |
| 216 | out: |
| 217 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 221 | * nfs_pageio_init - initialise a page io descriptor |
| 222 | * @desc: pointer to descriptor |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 223 | * @inode: pointer to inode |
| 224 | * @doio: pointer to io function |
| 225 | * @bsize: io block size |
| 226 | * @io_flags: extra parameters for the io function |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 227 | */ |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 228 | void nfs_pageio_init(struct nfs_pageio_descriptor *desc, |
| 229 | struct inode *inode, |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 230 | int (*doio)(struct inode *, struct list_head *, unsigned int, size_t, int), |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 231 | unsigned int bsize, |
| 232 | int io_flags) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 233 | { |
| 234 | INIT_LIST_HEAD(&desc->pg_list); |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 235 | desc->pg_bytes_written = 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 236 | desc->pg_count = 0; |
| 237 | desc->pg_bsize = bsize; |
| 238 | desc->pg_base = 0; |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 239 | desc->pg_inode = inode; |
| 240 | desc->pg_doio = doio; |
| 241 | desc->pg_ioflags = io_flags; |
| 242 | desc->pg_error = 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * nfs_can_coalesce_requests - test two requests for compatibility |
| 247 | * @prev: pointer to nfs_page |
| 248 | * @req: pointer to nfs_page |
| 249 | * |
| 250 | * The nfs_page structures 'prev' and 'req' are compared to ensure that the |
| 251 | * page data area they describe is contiguous, and that their RPC |
| 252 | * credentials, NFSv4 open state, and lockowners are the same. |
| 253 | * |
| 254 | * Return 'true' if this is the case, else return 'false'. |
| 255 | */ |
| 256 | static int nfs_can_coalesce_requests(struct nfs_page *prev, |
| 257 | struct nfs_page *req) |
| 258 | { |
| 259 | if (req->wb_context->cred != prev->wb_context->cred) |
| 260 | return 0; |
| 261 | if (req->wb_context->lockowner != prev->wb_context->lockowner) |
| 262 | return 0; |
| 263 | if (req->wb_context->state != prev->wb_context->state) |
| 264 | return 0; |
| 265 | if (req->wb_index != (prev->wb_index + 1)) |
| 266 | return 0; |
| 267 | if (req->wb_pgbase != 0) |
| 268 | return 0; |
| 269 | if (prev->wb_pgbase + prev->wb_bytes != PAGE_CACHE_SIZE) |
| 270 | return 0; |
| 271 | return 1; |
| 272 | } |
| 273 | |
| 274 | /** |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 275 | * nfs_pageio_do_add_request - Attempt to coalesce a request into a page list. |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 276 | * @desc: destination io descriptor |
| 277 | * @req: request |
| 278 | * |
| 279 | * Returns true if the request 'req' was successfully coalesced into the |
| 280 | * existing list of pages 'desc'. |
| 281 | */ |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 282 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, |
| 283 | struct nfs_page *req) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 284 | { |
| 285 | size_t newlen = req->wb_bytes; |
| 286 | |
| 287 | if (desc->pg_count != 0) { |
| 288 | struct nfs_page *prev; |
| 289 | |
| 290 | /* |
| 291 | * FIXME: ideally we should be able to coalesce all requests |
| 292 | * that are not block boundary aligned, but currently this |
| 293 | * is problematic for the case of bsize < PAGE_CACHE_SIZE, |
| 294 | * since nfs_flush_multi and nfs_pagein_multi assume you |
| 295 | * can have only one struct nfs_page. |
| 296 | */ |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 297 | if (desc->pg_bsize < PAGE_SIZE) |
| 298 | return 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 299 | newlen += desc->pg_count; |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 300 | if (newlen > desc->pg_bsize) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 301 | return 0; |
| 302 | prev = nfs_list_entry(desc->pg_list.prev); |
| 303 | if (!nfs_can_coalesce_requests(prev, req)) |
| 304 | return 0; |
| 305 | } else |
| 306 | desc->pg_base = req->wb_pgbase; |
| 307 | nfs_list_remove_request(req); |
| 308 | nfs_list_add_request(req, &desc->pg_list); |
| 309 | desc->pg_count = newlen; |
| 310 | return 1; |
| 311 | } |
| 312 | |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 313 | /* |
| 314 | * Helper for nfs_pageio_add_request and nfs_pageio_complete |
| 315 | */ |
| 316 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) |
| 317 | { |
| 318 | if (!list_empty(&desc->pg_list)) { |
| 319 | int error = desc->pg_doio(desc->pg_inode, |
| 320 | &desc->pg_list, |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 321 | nfs_page_array_len(desc->pg_base, |
| 322 | desc->pg_count), |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 323 | desc->pg_count, |
| 324 | desc->pg_ioflags); |
| 325 | if (error < 0) |
| 326 | desc->pg_error = error; |
| 327 | else |
| 328 | desc->pg_bytes_written += desc->pg_count; |
| 329 | } |
| 330 | if (list_empty(&desc->pg_list)) { |
| 331 | desc->pg_count = 0; |
| 332 | desc->pg_base = 0; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * nfs_pageio_add_request - Attempt to coalesce a request into a page list. |
| 338 | * @desc: destination io descriptor |
| 339 | * @req: request |
| 340 | * |
| 341 | * Returns true if the request 'req' was successfully coalesced into the |
| 342 | * existing list of pages 'desc'. |
| 343 | */ |
Trond Myklebust | 8b09bee | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 344 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, |
| 345 | struct nfs_page *req) |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 346 | { |
| 347 | while (!nfs_pageio_do_add_request(desc, req)) { |
| 348 | nfs_pageio_doio(desc); |
| 349 | if (desc->pg_error < 0) |
| 350 | return 0; |
| 351 | } |
| 352 | return 1; |
| 353 | } |
| 354 | |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 355 | /** |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 356 | * nfs_pageio_complete - Complete I/O on an nfs_pageio_descriptor |
| 357 | * @desc: pointer to io descriptor |
| 358 | */ |
| 359 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) |
| 360 | { |
| 361 | nfs_pageio_doio(desc); |
| 362 | } |
| 363 | |
Trond Myklebust | 3da28eb | 2005-06-22 17:16:31 +0000 | [diff] [blame] | 364 | #define NFS_SCAN_MAXENTRIES 16 |
| 365 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | * nfs_scan_list - Scan a list for matching requests |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 367 | * @nfsi: NFS inode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | * @head: One of the NFS inode request lists |
| 369 | * @dst: Destination list |
| 370 | * @idx_start: lower bound of page->index to scan |
| 371 | * @npages: idx_start + npages sets the upper bound to scan. |
| 372 | * |
| 373 | * Moves elements from one of the inode request lists. |
| 374 | * If the number of requests is set to 0, the entire address_space |
| 375 | * starting at index idx_start, is scanned. |
| 376 | * The requests are *not* checked to ensure that they form a contiguous set. |
| 377 | * You must be holding the inode's req_lock when calling this function |
| 378 | */ |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 379 | int nfs_scan_list(struct nfs_inode *nfsi, struct list_head *head, |
Trond Myklebust | ca52fec | 2007-04-17 17:22:13 -0400 | [diff] [blame] | 380 | struct list_head *dst, pgoff_t idx_start, |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 381 | unsigned int npages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 383 | struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES]; |
| 384 | struct nfs_page *req; |
Trond Myklebust | ca52fec | 2007-04-17 17:22:13 -0400 | [diff] [blame] | 385 | pgoff_t idx_end; |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 386 | int found, i; |
| 387 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | res = 0; |
| 390 | if (npages == 0) |
| 391 | idx_end = ~0; |
| 392 | else |
| 393 | idx_end = idx_start + npages - 1; |
| 394 | |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 395 | for (;;) { |
| 396 | found = radix_tree_gang_lookup(&nfsi->nfs_page_tree, |
| 397 | (void **)&pgvec[0], idx_start, |
| 398 | NFS_SCAN_MAXENTRIES); |
| 399 | if (found <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | break; |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 401 | for (i = 0; i < found; i++) { |
| 402 | req = pgvec[i]; |
| 403 | if (req->wb_index > idx_end) |
| 404 | goto out; |
| 405 | idx_start = req->wb_index + 1; |
| 406 | if (req->wb_list_head != head) |
| 407 | continue; |
| 408 | if (nfs_set_page_writeback_locked(req)) { |
| 409 | nfs_list_remove_request(req); |
| 410 | nfs_list_add_request(req, dst); |
| 411 | res++; |
| 412 | } |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
Trond Myklebust | d2ccddf | 2006-05-31 01:13:38 -0400 | [diff] [blame] | 416 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return res; |
| 418 | } |
| 419 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 420 | int __init nfs_init_nfspagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | nfs_page_cachep = kmem_cache_create("nfs_page", |
| 423 | sizeof(struct nfs_page), |
| 424 | 0, SLAB_HWCACHE_ALIGN, |
| 425 | NULL, NULL); |
| 426 | if (nfs_page_cachep == NULL) |
| 427 | return -ENOMEM; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
David Brownell | 266bee8 | 2006-06-27 12:59:15 -0700 | [diff] [blame] | 432 | void nfs_destroy_nfspagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 434 | kmem_cache_destroy(nfs_page_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |