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> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 14 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sunrpc/clnt.h> |
Trond Myklebust | 1313e60 | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 16 | #include <linux/nfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/nfs3.h> |
| 18 | #include <linux/nfs4.h> |
| 19 | #include <linux/nfs_page.h> |
| 20 | #include <linux/nfs_fs.h> |
| 21 | #include <linux/nfs_mount.h> |
Paul Gortmaker | afeacc8 | 2011-05-26 16:00:52 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 24 | #include "internal.h" |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 25 | #include "pnfs.h" |
Trond Myklebust | 8d5658c | 2007-04-10 09:26:35 -0400 | [diff] [blame] | 26 | |
Anna Schumaker | 0eecb21 | 2014-05-06 09:12:32 -0400 | [diff] [blame] | 27 | #define NFSDBG_FACILITY NFSDBG_PAGECACHE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static struct kmem_cache *nfs_page_cachep; |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 30 | static const struct rpc_call_ops nfs_pgio_common_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 32 | static void nfs_free_request(struct nfs_page *); |
| 33 | |
Anna Schumaker | 00bfa30 | 2014-05-06 09:12:29 -0400 | [diff] [blame] | 34 | static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount) |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 35 | { |
| 36 | p->npages = pagecount; |
| 37 | if (pagecount <= ARRAY_SIZE(p->page_array)) |
| 38 | p->pagevec = p->page_array; |
| 39 | else { |
| 40 | p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL); |
| 41 | if (!p->pagevec) |
| 42 | p->npages = 0; |
| 43 | } |
| 44 | return p->pagevec != NULL; |
| 45 | } |
| 46 | |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 47 | void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, |
| 48 | struct nfs_pgio_header *hdr, |
| 49 | void (*release)(struct nfs_pgio_header *hdr)) |
| 50 | { |
| 51 | hdr->req = nfs_list_entry(desc->pg_list.next); |
| 52 | hdr->inode = desc->pg_inode; |
| 53 | hdr->cred = hdr->req->wb_context->cred; |
| 54 | hdr->io_start = req_offset(hdr->req); |
| 55 | hdr->good_bytes = desc->pg_count; |
Fred Isaman | 584aa81 | 2012-04-20 14:47:51 -0400 | [diff] [blame] | 56 | hdr->dreq = desc->pg_dreq; |
Peng Tao | f616638 | 2012-08-02 15:36:09 +0300 | [diff] [blame] | 57 | hdr->layout_private = desc->pg_layout_private; |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 58 | hdr->release = release; |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 59 | hdr->completion_ops = desc->pg_completion_ops; |
Fred Isaman | 584aa81 | 2012-04-20 14:47:51 -0400 | [diff] [blame] | 60 | if (hdr->completion_ops->init_hdr) |
| 61 | hdr->completion_ops->init_hdr(hdr); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 62 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 63 | EXPORT_SYMBOL_GPL(nfs_pgheader_init); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 64 | |
| 65 | void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos) |
| 66 | { |
| 67 | spin_lock(&hdr->lock); |
| 68 | if (pos < hdr->io_start + hdr->good_bytes) { |
| 69 | set_bit(NFS_IOHDR_ERROR, &hdr->flags); |
| 70 | clear_bit(NFS_IOHDR_EOF, &hdr->flags); |
| 71 | hdr->good_bytes = pos - hdr->io_start; |
| 72 | hdr->error = error; |
| 73 | } |
| 74 | spin_unlock(&hdr->lock); |
| 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static inline struct nfs_page * |
| 78 | nfs_page_alloc(void) |
| 79 | { |
Mel Gorman | 192e501 | 2012-07-31 16:45:16 -0700 | [diff] [blame] | 80 | struct nfs_page *p = kmem_cache_zalloc(nfs_page_cachep, GFP_NOIO); |
Jesper Juhl | 72895b1 | 2010-12-09 23:17:15 +0100 | [diff] [blame] | 81 | if (p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | INIT_LIST_HEAD(&p->wb_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return p; |
| 84 | } |
| 85 | |
| 86 | static inline void |
| 87 | nfs_page_free(struct nfs_page *p) |
| 88 | { |
| 89 | kmem_cache_free(nfs_page_cachep, p); |
| 90 | } |
| 91 | |
Trond Myklebust | 577b423 | 2013-04-08 21:38:12 -0400 | [diff] [blame] | 92 | static void |
| 93 | nfs_iocounter_inc(struct nfs_io_counter *c) |
| 94 | { |
| 95 | atomic_inc(&c->io_count); |
| 96 | } |
| 97 | |
| 98 | static void |
| 99 | nfs_iocounter_dec(struct nfs_io_counter *c) |
| 100 | { |
| 101 | if (atomic_dec_and_test(&c->io_count)) { |
| 102 | clear_bit(NFS_IO_INPROGRESS, &c->flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 103 | smp_mb__after_atomic(); |
Trond Myklebust | 577b423 | 2013-04-08 21:38:12 -0400 | [diff] [blame] | 104 | wake_up_bit(&c->flags, NFS_IO_INPROGRESS); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static int |
| 109 | __nfs_iocounter_wait(struct nfs_io_counter *c) |
| 110 | { |
| 111 | wait_queue_head_t *wq = bit_waitqueue(&c->flags, NFS_IO_INPROGRESS); |
| 112 | DEFINE_WAIT_BIT(q, &c->flags, NFS_IO_INPROGRESS); |
| 113 | int ret = 0; |
| 114 | |
| 115 | do { |
| 116 | prepare_to_wait(wq, &q.wait, TASK_KILLABLE); |
| 117 | set_bit(NFS_IO_INPROGRESS, &c->flags); |
| 118 | if (atomic_read(&c->io_count) == 0) |
| 119 | break; |
NeilBrown | c122132 | 2014-07-07 15:16:04 +1000 | [diff] [blame^] | 120 | ret = nfs_wait_bit_killable(&q.key); |
Trond Myklebust | 577b423 | 2013-04-08 21:38:12 -0400 | [diff] [blame] | 121 | } while (atomic_read(&c->io_count) != 0); |
| 122 | finish_wait(wq, &q.wait); |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * nfs_iocounter_wait - wait for i/o to complete |
| 128 | * @c: nfs_io_counter to use |
| 129 | * |
| 130 | * returns -ERESTARTSYS if interrupted by a fatal signal. |
| 131 | * Otherwise returns 0 once the io_count hits 0. |
| 132 | */ |
| 133 | int |
| 134 | nfs_iocounter_wait(struct nfs_io_counter *c) |
| 135 | { |
| 136 | if (atomic_read(&c->io_count) == 0) |
| 137 | return 0; |
| 138 | return __nfs_iocounter_wait(c); |
| 139 | } |
| 140 | |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 141 | /* |
| 142 | * nfs_page_group_lock - lock the head of the page group |
| 143 | * @req - request in group that is to be locked |
| 144 | * |
| 145 | * this lock must be held if modifying the page group list |
| 146 | */ |
| 147 | void |
| 148 | nfs_page_group_lock(struct nfs_page *req) |
| 149 | { |
| 150 | struct nfs_page *head = req->wb_head; |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 151 | |
| 152 | WARN_ON_ONCE(head != head->wb_head); |
| 153 | |
Trond Myklebust | f868089 | 2014-05-29 11:45:57 -0400 | [diff] [blame] | 154 | wait_on_bit_lock(&head->wb_flags, PG_HEADLOCK, |
Trond Myklebust | f868089 | 2014-05-29 11:45:57 -0400 | [diff] [blame] | 155 | TASK_UNINTERRUPTIBLE); |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * nfs_page_group_unlock - unlock the head of the page group |
| 160 | * @req - request in group that is to be unlocked |
| 161 | */ |
| 162 | void |
| 163 | nfs_page_group_unlock(struct nfs_page *req) |
| 164 | { |
| 165 | struct nfs_page *head = req->wb_head; |
| 166 | |
| 167 | WARN_ON_ONCE(head != head->wb_head); |
| 168 | |
Linus Torvalds | d1e1cda | 2014-06-10 15:02:42 -0700 | [diff] [blame] | 169 | smp_mb__before_atomic(); |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 170 | clear_bit(PG_HEADLOCK, &head->wb_flags); |
Linus Torvalds | d1e1cda | 2014-06-10 15:02:42 -0700 | [diff] [blame] | 171 | smp_mb__after_atomic(); |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 172 | wake_up_bit(&head->wb_flags, PG_HEADLOCK); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * nfs_page_group_sync_on_bit_locked |
| 177 | * |
| 178 | * must be called with page group lock held |
| 179 | */ |
| 180 | static bool |
| 181 | nfs_page_group_sync_on_bit_locked(struct nfs_page *req, unsigned int bit) |
| 182 | { |
| 183 | struct nfs_page *head = req->wb_head; |
| 184 | struct nfs_page *tmp; |
| 185 | |
| 186 | WARN_ON_ONCE(!test_bit(PG_HEADLOCK, &head->wb_flags)); |
| 187 | WARN_ON_ONCE(test_and_set_bit(bit, &req->wb_flags)); |
| 188 | |
| 189 | tmp = req->wb_this_page; |
| 190 | while (tmp != req) { |
| 191 | if (!test_bit(bit, &tmp->wb_flags)) |
| 192 | return false; |
| 193 | tmp = tmp->wb_this_page; |
| 194 | } |
| 195 | |
| 196 | /* true! reset all bits */ |
| 197 | tmp = req; |
| 198 | do { |
| 199 | clear_bit(bit, &tmp->wb_flags); |
| 200 | tmp = tmp->wb_this_page; |
| 201 | } while (tmp != req); |
| 202 | |
| 203 | return true; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * nfs_page_group_sync_on_bit - set bit on current request, but only |
| 208 | * return true if the bit is set for all requests in page group |
| 209 | * @req - request in page group |
| 210 | * @bit - PG_* bit that is used to sync page group |
| 211 | */ |
| 212 | bool nfs_page_group_sync_on_bit(struct nfs_page *req, unsigned int bit) |
| 213 | { |
| 214 | bool ret; |
| 215 | |
| 216 | nfs_page_group_lock(req); |
| 217 | ret = nfs_page_group_sync_on_bit_locked(req, bit); |
| 218 | nfs_page_group_unlock(req); |
| 219 | |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * nfs_page_group_init - Initialize the page group linkage for @req |
| 225 | * @req - a new nfs request |
| 226 | * @prev - the previous request in page group, or NULL if @req is the first |
| 227 | * or only request in the group (the head). |
| 228 | */ |
| 229 | static inline void |
| 230 | nfs_page_group_init(struct nfs_page *req, struct nfs_page *prev) |
| 231 | { |
| 232 | WARN_ON_ONCE(prev == req); |
| 233 | |
| 234 | if (!prev) { |
| 235 | req->wb_head = req; |
| 236 | req->wb_this_page = req; |
| 237 | } else { |
| 238 | WARN_ON_ONCE(prev->wb_this_page != prev->wb_head); |
| 239 | WARN_ON_ONCE(!test_bit(PG_HEADLOCK, &prev->wb_head->wb_flags)); |
| 240 | req->wb_head = prev->wb_head; |
| 241 | req->wb_this_page = prev->wb_this_page; |
| 242 | prev->wb_this_page = req; |
| 243 | |
| 244 | /* grab extra ref if head request has extra ref from |
| 245 | * the write/commit path to handle handoff between write |
| 246 | * and commit lists */ |
| 247 | if (test_bit(PG_INODE_REF, &prev->wb_head->wb_flags)) |
| 248 | kref_get(&req->wb_kref); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * nfs_page_group_destroy - sync the destruction of page groups |
| 254 | * @req - request that no longer needs the page group |
| 255 | * |
| 256 | * releases the page group reference from each member once all |
| 257 | * members have called this function. |
| 258 | */ |
| 259 | static void |
| 260 | nfs_page_group_destroy(struct kref *kref) |
| 261 | { |
| 262 | struct nfs_page *req = container_of(kref, struct nfs_page, wb_kref); |
| 263 | struct nfs_page *tmp, *next; |
| 264 | |
| 265 | if (!nfs_page_group_sync_on_bit(req, PG_TEARDOWN)) |
| 266 | return; |
| 267 | |
| 268 | tmp = req; |
| 269 | do { |
| 270 | next = tmp->wb_this_page; |
| 271 | /* unlink and free */ |
| 272 | tmp->wb_this_page = tmp; |
| 273 | tmp->wb_head = tmp; |
| 274 | nfs_free_request(tmp); |
| 275 | tmp = next; |
| 276 | } while (tmp != req); |
| 277 | } |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /** |
| 280 | * nfs_create_request - Create an NFS read/write request. |
Chuck Lever | c02f557 | 2011-10-25 12:17:43 -0400 | [diff] [blame] | 281 | * @ctx: open context to use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | * @page: page to write |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 283 | * @last: last nfs request created for this page group or NULL if head |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | * @offset: starting offset within the page for the write |
| 285 | * @count: number of bytes to read/write |
| 286 | * |
| 287 | * 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] | 288 | * create two different requests for the same page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * User should ensure it is safe to sleep in this function. |
| 290 | */ |
| 291 | struct nfs_page * |
Weston Andros Adamson | 8c8f1ac1 | 2014-05-15 11:56:42 -0400 | [diff] [blame] | 292 | nfs_create_request(struct nfs_open_context *ctx, struct page *page, |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 293 | struct nfs_page *last, unsigned int offset, |
| 294 | unsigned int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | struct nfs_page *req; |
Trond Myklebust | b3c54de | 2012-08-13 17:15:50 -0400 | [diff] [blame] | 297 | struct nfs_lock_context *l_ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Trond Myklebust | c58c844 | 2013-03-18 19:45:14 -0400 | [diff] [blame] | 299 | if (test_bit(NFS_CONTEXT_BAD, &ctx->flags)) |
| 300 | return ERR_PTR(-EBADF); |
Trond Myklebust | 18eb884 | 2010-05-13 12:51:02 -0400 | [diff] [blame] | 301 | /* try to allocate the request struct */ |
| 302 | req = nfs_page_alloc(); |
| 303 | if (req == NULL) |
| 304 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Jeff Layton | 015f021 | 2010-10-28 10:10:37 -0400 | [diff] [blame] | 306 | /* get lock context early so we can deal with alloc failures */ |
Trond Myklebust | b3c54de | 2012-08-13 17:15:50 -0400 | [diff] [blame] | 307 | l_ctx = nfs_get_lock_context(ctx); |
| 308 | if (IS_ERR(l_ctx)) { |
Jeff Layton | 015f021 | 2010-10-28 10:10:37 -0400 | [diff] [blame] | 309 | nfs_page_free(req); |
Trond Myklebust | b3c54de | 2012-08-13 17:15:50 -0400 | [diff] [blame] | 310 | return ERR_CAST(l_ctx); |
Jeff Layton | 015f021 | 2010-10-28 10:10:37 -0400 | [diff] [blame] | 311 | } |
Trond Myklebust | b3c54de | 2012-08-13 17:15:50 -0400 | [diff] [blame] | 312 | req->wb_lock_context = l_ctx; |
Trond Myklebust | 577b423 | 2013-04-08 21:38:12 -0400 | [diff] [blame] | 313 | nfs_iocounter_inc(&l_ctx->io_count); |
Jeff Layton | 015f021 | 2010-10-28 10:10:37 -0400 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* Initialize the request struct. Initially, we assume a |
| 316 | * long write-back delay. This will be adjusted in |
| 317 | * update_nfs_request below if the region is not locked. */ |
| 318 | req->wb_page = page; |
Mel Gorman | d56b4dd | 2012-07-31 16:45:06 -0700 | [diff] [blame] | 319 | req->wb_index = page_file_index(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | page_cache_get(page); |
| 321 | req->wb_offset = offset; |
| 322 | req->wb_pgbase = offset; |
| 323 | req->wb_bytes = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | req->wb_context = get_nfs_open_context(ctx); |
Trond Myklebust | c03b402 | 2007-06-17 13:26:38 -0400 | [diff] [blame] | 325 | kref_init(&req->wb_kref); |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 326 | nfs_page_group_init(req, last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return req; |
| 328 | } |
| 329 | |
| 330 | /** |
Trond Myklebust | 1d1afcb | 2012-05-09 14:04:55 -0400 | [diff] [blame] | 331 | * nfs_unlock_request - Unlock request and wake up sleepers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | * @req: |
| 333 | */ |
Trond Myklebust | 1d1afcb | 2012-05-09 14:04:55 -0400 | [diff] [blame] | 334 | void nfs_unlock_request(struct nfs_page *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | if (!NFS_WBACK_BUSY(req)) { |
| 337 | printk(KERN_ERR "NFS: Invalid unlock attempted\n"); |
| 338 | BUG(); |
| 339 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 340 | smp_mb__before_atomic(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | clear_bit(PG_BUSY, &req->wb_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 342 | smp_mb__after_atomic(); |
Trond Myklebust | 464a98b | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 343 | wake_up_bit(&req->wb_flags, PG_BUSY); |
Trond Myklebust | 3aff4eb | 2012-05-09 14:30:35 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /** |
Trond Myklebust | 1d1afcb | 2012-05-09 14:04:55 -0400 | [diff] [blame] | 347 | * nfs_unlock_and_release_request - Unlock request and release the nfs_page |
| 348 | * @req: |
Trond Myklebust | 3aff4eb | 2012-05-09 14:30:35 -0400 | [diff] [blame] | 349 | */ |
Trond Myklebust | 1d1afcb | 2012-05-09 14:04:55 -0400 | [diff] [blame] | 350 | void nfs_unlock_and_release_request(struct nfs_page *req) |
Trond Myklebust | 3aff4eb | 2012-05-09 14:30:35 -0400 | [diff] [blame] | 351 | { |
Trond Myklebust | 1d1afcb | 2012-05-09 14:04:55 -0400 | [diff] [blame] | 352 | nfs_unlock_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | nfs_release_request(req); |
| 354 | } |
| 355 | |
Trond Myklebust | 4d65c52 | 2011-03-25 14:15:11 -0400 | [diff] [blame] | 356 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | * nfs_clear_request - Free up all resources allocated to the request |
| 358 | * @req: |
| 359 | * |
Trond Myklebust | bb6fbc4 | 2010-03-11 09:19:35 -0500 | [diff] [blame] | 360 | * Release page and open context resources associated with a read/write |
| 361 | * request after it has completed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | */ |
Trond Myklebust | 4d65c52 | 2011-03-25 14:15:11 -0400 | [diff] [blame] | 363 | static void nfs_clear_request(struct nfs_page *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 365 | struct page *page = req->wb_page; |
Trond Myklebust | bb6fbc4 | 2010-03-11 09:19:35 -0500 | [diff] [blame] | 366 | struct nfs_open_context *ctx = req->wb_context; |
Trond Myklebust | f11ac8d | 2010-06-25 16:35:53 -0400 | [diff] [blame] | 367 | struct nfs_lock_context *l_ctx = req->wb_lock_context; |
Trond Myklebust | bb6fbc4 | 2010-03-11 09:19:35 -0500 | [diff] [blame] | 368 | |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 369 | if (page != NULL) { |
Trond Myklebust | cd52ed3 | 2006-03-20 13:44:04 -0500 | [diff] [blame] | 370 | page_cache_release(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | req->wb_page = NULL; |
| 372 | } |
Trond Myklebust | f11ac8d | 2010-06-25 16:35:53 -0400 | [diff] [blame] | 373 | if (l_ctx != NULL) { |
Trond Myklebust | 577b423 | 2013-04-08 21:38:12 -0400 | [diff] [blame] | 374 | nfs_iocounter_dec(&l_ctx->io_count); |
Trond Myklebust | f11ac8d | 2010-06-25 16:35:53 -0400 | [diff] [blame] | 375 | nfs_put_lock_context(l_ctx); |
| 376 | req->wb_lock_context = NULL; |
| 377 | } |
Trond Myklebust | bb6fbc4 | 2010-03-11 09:19:35 -0500 | [diff] [blame] | 378 | if (ctx != NULL) { |
| 379 | put_nfs_open_context(ctx); |
| 380 | req->wb_context = NULL; |
| 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /** |
| 385 | * nfs_release_request - Release the count on an NFS read/write request |
| 386 | * @req: request to release |
| 387 | * |
| 388 | * Note: Should never be called with the spinlock held! |
| 389 | */ |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 390 | static void nfs_free_request(struct nfs_page *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 392 | WARN_ON_ONCE(req->wb_this_page != req); |
| 393 | |
| 394 | /* extra debug: make sure no sync bits are still set */ |
| 395 | WARN_ON_ONCE(test_bit(PG_TEARDOWN, &req->wb_flags)); |
Weston Andros Adamson | 67d0338 | 2014-05-15 11:56:46 -0400 | [diff] [blame] | 396 | WARN_ON_ONCE(test_bit(PG_UNLOCKPAGE, &req->wb_flags)); |
| 397 | WARN_ON_ONCE(test_bit(PG_UPTODATE, &req->wb_flags)); |
Weston Andros Adamson | 20633f0 | 2014-05-15 11:56:47 -0400 | [diff] [blame] | 398 | WARN_ON_ONCE(test_bit(PG_WB_END, &req->wb_flags)); |
| 399 | WARN_ON_ONCE(test_bit(PG_REMOVE, &req->wb_flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Trond Myklebust | bb6fbc4 | 2010-03-11 09:19:35 -0500 | [diff] [blame] | 401 | /* Release struct file and open context */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | nfs_clear_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | nfs_page_free(req); |
| 404 | } |
| 405 | |
Trond Myklebust | c03b402 | 2007-06-17 13:26:38 -0400 | [diff] [blame] | 406 | void nfs_release_request(struct nfs_page *req) |
| 407 | { |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 408 | kref_put(&req->wb_kref, nfs_page_group_destroy); |
Trond Myklebust | 9f557cd | 2010-02-03 08:27:22 -0500 | [diff] [blame] | 409 | } |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /** |
| 412 | * nfs_wait_on_request - Wait for a request to complete. |
| 413 | * @req: request to wait upon. |
| 414 | * |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 415 | * Interruptible by fatal signals only. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | * The user is responsible for holding a count on the request. |
| 417 | */ |
| 418 | int |
| 419 | nfs_wait_on_request(struct nfs_page *req) |
| 420 | { |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 421 | return wait_on_bit_io(&req->wb_flags, PG_BUSY, |
| 422 | TASK_UNINTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 425 | /* |
| 426 | * nfs_generic_pg_test - determine if requests can be coalesced |
| 427 | * @desc: pointer to descriptor |
| 428 | * @prev: previous request in desc, or NULL |
| 429 | * @req: this request |
| 430 | * |
| 431 | * Returns zero if @req can be coalesced into @desc, otherwise it returns |
| 432 | * the size of the request. |
| 433 | */ |
| 434 | size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, |
| 435 | struct nfs_page *prev, struct nfs_page *req) |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 436 | { |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 437 | if (desc->pg_count > desc->pg_bsize) { |
| 438 | /* should never happen */ |
| 439 | WARN_ON_ONCE(1); |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 440 | return 0; |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 441 | } |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 442 | |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 443 | return min(desc->pg_bsize - desc->pg_count, (size_t)req->wb_bytes); |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 444 | } |
Benny Halevy | 19345cb | 2011-06-19 18:33:46 -0400 | [diff] [blame] | 445 | EXPORT_SYMBOL_GPL(nfs_generic_pg_test); |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 446 | |
Anna Schumaker | 00bfa30 | 2014-05-06 09:12:29 -0400 | [diff] [blame] | 447 | static inline struct nfs_rw_header *NFS_RW_HEADER(struct nfs_pgio_header *hdr) |
| 448 | { |
| 449 | return container_of(hdr, struct nfs_rw_header, header); |
| 450 | } |
| 451 | |
| 452 | /** |
Anna Schumaker | 4a0de55 | 2014-05-06 09:12:30 -0400 | [diff] [blame] | 453 | * nfs_rw_header_alloc - Allocate a header for a read or write |
| 454 | * @ops: Read or write function vector |
| 455 | */ |
| 456 | struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *ops) |
| 457 | { |
| 458 | struct nfs_rw_header *header = ops->rw_alloc_header(); |
| 459 | |
| 460 | if (header) { |
| 461 | struct nfs_pgio_header *hdr = &header->header; |
| 462 | |
| 463 | INIT_LIST_HEAD(&hdr->pages); |
Anna Schumaker | 4a0de55 | 2014-05-06 09:12:30 -0400 | [diff] [blame] | 464 | spin_lock_init(&hdr->lock); |
| 465 | atomic_set(&hdr->refcnt, 0); |
| 466 | hdr->rw_ops = ops; |
| 467 | } |
| 468 | return header; |
| 469 | } |
| 470 | EXPORT_SYMBOL_GPL(nfs_rw_header_alloc); |
| 471 | |
| 472 | /* |
| 473 | * nfs_rw_header_free - Free a read or write header |
| 474 | * @hdr: The header to free |
| 475 | */ |
| 476 | void nfs_rw_header_free(struct nfs_pgio_header *hdr) |
| 477 | { |
| 478 | hdr->rw_ops->rw_free_header(NFS_RW_HEADER(hdr)); |
| 479 | } |
| 480 | EXPORT_SYMBOL_GPL(nfs_rw_header_free); |
| 481 | |
| 482 | /** |
Anna Schumaker | 00bfa30 | 2014-05-06 09:12:29 -0400 | [diff] [blame] | 483 | * nfs_pgio_data_alloc - Allocate pageio data |
| 484 | * @hdr: The header making a request |
| 485 | * @pagecount: Number of pages to create |
| 486 | */ |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 487 | static struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *hdr, |
| 488 | unsigned int pagecount) |
Anna Schumaker | 00bfa30 | 2014-05-06 09:12:29 -0400 | [diff] [blame] | 489 | { |
| 490 | struct nfs_pgio_data *data, *prealloc; |
| 491 | |
| 492 | prealloc = &NFS_RW_HEADER(hdr)->rpc_data; |
| 493 | if (prealloc->header == NULL) |
| 494 | data = prealloc; |
| 495 | else |
| 496 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 497 | if (!data) |
| 498 | goto out; |
| 499 | |
| 500 | if (nfs_pgarray_set(&data->pages, pagecount)) { |
| 501 | data->header = hdr; |
| 502 | atomic_inc(&hdr->refcnt); |
| 503 | } else { |
| 504 | if (data != prealloc) |
| 505 | kfree(data); |
| 506 | data = NULL; |
| 507 | } |
| 508 | out: |
| 509 | return data; |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * nfs_pgio_data_release - Properly free pageio data |
| 514 | * @data: The data to release |
| 515 | */ |
| 516 | void nfs_pgio_data_release(struct nfs_pgio_data *data) |
| 517 | { |
| 518 | struct nfs_pgio_header *hdr = data->header; |
| 519 | struct nfs_rw_header *pageio_header = NFS_RW_HEADER(hdr); |
| 520 | |
| 521 | put_nfs_open_context(data->args.context); |
| 522 | if (data->pages.pagevec != data->pages.page_array) |
| 523 | kfree(data->pages.pagevec); |
| 524 | if (data == &pageio_header->rpc_data) { |
| 525 | data->header = NULL; |
| 526 | data = NULL; |
| 527 | } |
| 528 | if (atomic_dec_and_test(&hdr->refcnt)) |
| 529 | hdr->completion_ops->completion(hdr); |
| 530 | /* Note: we only free the rpc_task after callbacks are done. |
| 531 | * See the comment in rpc_free_task() for why |
| 532 | */ |
| 533 | kfree(data); |
| 534 | } |
| 535 | EXPORT_SYMBOL_GPL(nfs_pgio_data_release); |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /** |
Anna Schumaker | ce59515 | 2014-05-06 09:12:34 -0400 | [diff] [blame] | 538 | * nfs_pgio_rpcsetup - Set up arguments for a pageio call |
| 539 | * @data: The pageio data |
| 540 | * @count: Number of bytes to read |
| 541 | * @offset: Initial offset |
| 542 | * @how: How to commit data (writes only) |
| 543 | * @cinfo: Commit information for the call (writes only) |
| 544 | */ |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 545 | static void nfs_pgio_rpcsetup(struct nfs_pgio_data *data, |
Anna Schumaker | ce59515 | 2014-05-06 09:12:34 -0400 | [diff] [blame] | 546 | unsigned int count, unsigned int offset, |
| 547 | int how, struct nfs_commit_info *cinfo) |
| 548 | { |
| 549 | struct nfs_page *req = data->header->req; |
| 550 | |
| 551 | /* Set up the RPC argument and reply structs |
| 552 | * NB: take care not to mess about with data->commit et al. */ |
| 553 | |
| 554 | data->args.fh = NFS_FH(data->header->inode); |
| 555 | data->args.offset = req_offset(req) + offset; |
| 556 | /* pnfs_set_layoutcommit needs this */ |
| 557 | data->mds_offset = data->args.offset; |
| 558 | data->args.pgbase = req->wb_pgbase + offset; |
| 559 | data->args.pages = data->pages.pagevec; |
| 560 | data->args.count = count; |
| 561 | data->args.context = get_nfs_open_context(req->wb_context); |
| 562 | data->args.lock_context = req->wb_lock_context; |
| 563 | data->args.stable = NFS_UNSTABLE; |
| 564 | switch (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) { |
| 565 | case 0: |
| 566 | break; |
| 567 | case FLUSH_COND_STABLE: |
| 568 | if (nfs_reqs_to_commit(cinfo)) |
| 569 | break; |
| 570 | default: |
| 571 | data->args.stable = NFS_FILE_SYNC; |
| 572 | } |
| 573 | |
| 574 | data->res.fattr = &data->fattr; |
| 575 | data->res.count = count; |
| 576 | data->res.eof = 0; |
| 577 | data->res.verf = &data->verf; |
| 578 | nfs_fattr_init(&data->fattr); |
| 579 | } |
| 580 | |
| 581 | /** |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 582 | * nfs_pgio_prepare - Prepare pageio data to go over the wire |
| 583 | * @task: The current task |
| 584 | * @calldata: pageio data to prepare |
| 585 | */ |
Anna Schumaker | 6f92fa4 | 2014-05-06 09:12:33 -0400 | [diff] [blame] | 586 | static void nfs_pgio_prepare(struct rpc_task *task, void *calldata) |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 587 | { |
| 588 | struct nfs_pgio_data *data = calldata; |
| 589 | int err; |
| 590 | err = NFS_PROTO(data->header->inode)->pgio_rpc_prepare(task, data); |
| 591 | if (err) |
| 592 | rpc_exit(task, err); |
| 593 | } |
| 594 | |
Anna Schumaker | 1ed26f3 | 2014-05-06 09:12:37 -0400 | [diff] [blame] | 595 | int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_data *data, |
| 596 | const struct rpc_call_ops *call_ops, int how, int flags) |
| 597 | { |
| 598 | struct rpc_task *task; |
| 599 | struct rpc_message msg = { |
| 600 | .rpc_argp = &data->args, |
| 601 | .rpc_resp = &data->res, |
| 602 | .rpc_cred = data->header->cred, |
| 603 | }; |
| 604 | struct rpc_task_setup task_setup_data = { |
| 605 | .rpc_client = clnt, |
| 606 | .task = &data->task, |
| 607 | .rpc_message = &msg, |
| 608 | .callback_ops = call_ops, |
| 609 | .callback_data = data, |
| 610 | .workqueue = nfsiod_workqueue, |
| 611 | .flags = RPC_TASK_ASYNC | flags, |
| 612 | }; |
| 613 | int ret = 0; |
| 614 | |
| 615 | data->header->rw_ops->rw_initiate(data, &msg, &task_setup_data, how); |
| 616 | |
| 617 | dprintk("NFS: %5u initiated pgio call " |
| 618 | "(req %s/%llu, %u bytes @ offset %llu)\n", |
| 619 | data->task.tk_pid, |
| 620 | data->header->inode->i_sb->s_id, |
| 621 | (unsigned long long)NFS_FILEID(data->header->inode), |
| 622 | data->args.count, |
| 623 | (unsigned long long)data->args.offset); |
| 624 | |
| 625 | task = rpc_run_task(&task_setup_data); |
| 626 | if (IS_ERR(task)) { |
| 627 | ret = PTR_ERR(task); |
| 628 | goto out; |
| 629 | } |
| 630 | if (how & FLUSH_SYNC) { |
| 631 | ret = rpc_wait_for_completion_task(task); |
| 632 | if (ret == 0) |
| 633 | ret = task->tk_status; |
| 634 | } |
| 635 | rpc_put_task(task); |
| 636 | out: |
| 637 | return ret; |
| 638 | } |
| 639 | EXPORT_SYMBOL_GPL(nfs_initiate_pgio); |
| 640 | |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 641 | /** |
Anna Schumaker | 844c9e6 | 2014-05-06 09:12:35 -0400 | [diff] [blame] | 642 | * nfs_pgio_error - Clean up from a pageio error |
| 643 | * @desc: IO descriptor |
| 644 | * @hdr: pageio header |
| 645 | */ |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 646 | static int nfs_pgio_error(struct nfs_pageio_descriptor *desc, |
Anna Schumaker | 844c9e6 | 2014-05-06 09:12:35 -0400 | [diff] [blame] | 647 | struct nfs_pgio_header *hdr) |
| 648 | { |
Anna Schumaker | 844c9e6 | 2014-05-06 09:12:35 -0400 | [diff] [blame] | 649 | set_bit(NFS_IOHDR_REDO, &hdr->flags); |
Weston Andros Adamson | 7f71472 | 2014-05-15 11:56:53 -0400 | [diff] [blame] | 650 | nfs_pgio_data_release(hdr->data); |
| 651 | hdr->data = NULL; |
Anna Schumaker | 844c9e6 | 2014-05-06 09:12:35 -0400 | [diff] [blame] | 652 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); |
| 653 | return -ENOMEM; |
| 654 | } |
| 655 | |
| 656 | /** |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 657 | * nfs_pgio_release - Release pageio data |
| 658 | * @calldata: The pageio data to release |
| 659 | */ |
Anna Schumaker | 6f92fa4 | 2014-05-06 09:12:33 -0400 | [diff] [blame] | 660 | static void nfs_pgio_release(void *calldata) |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 661 | { |
| 662 | struct nfs_pgio_data *data = calldata; |
| 663 | if (data->header->rw_ops->rw_release) |
| 664 | data->header->rw_ops->rw_release(data); |
| 665 | nfs_pgio_data_release(data); |
| 666 | } |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /** |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 669 | * nfs_pageio_init - initialise a page io descriptor |
| 670 | * @desc: pointer to descriptor |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 671 | * @inode: pointer to inode |
| 672 | * @doio: pointer to io function |
| 673 | * @bsize: io block size |
| 674 | * @io_flags: extra parameters for the io function |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 675 | */ |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 676 | void nfs_pageio_init(struct nfs_pageio_descriptor *desc, |
| 677 | struct inode *inode, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 678 | const struct nfs_pageio_ops *pg_ops, |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 679 | const struct nfs_pgio_completion_ops *compl_ops, |
Anna Schumaker | 4a0de55 | 2014-05-06 09:12:30 -0400 | [diff] [blame] | 680 | const struct nfs_rw_ops *rw_ops, |
Trond Myklebust | 84dde76 | 2007-05-04 14:44:06 -0400 | [diff] [blame] | 681 | size_t bsize, |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 682 | int io_flags) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 683 | { |
| 684 | INIT_LIST_HEAD(&desc->pg_list); |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 685 | desc->pg_bytes_written = 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 686 | desc->pg_count = 0; |
| 687 | desc->pg_bsize = bsize; |
| 688 | desc->pg_base = 0; |
Trond Myklebust | b31268a | 2011-03-21 17:02:00 -0400 | [diff] [blame] | 689 | desc->pg_moreio = 0; |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 690 | desc->pg_recoalesce = 0; |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 691 | desc->pg_inode = inode; |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 692 | desc->pg_ops = pg_ops; |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 693 | desc->pg_completion_ops = compl_ops; |
Anna Schumaker | 4a0de55 | 2014-05-06 09:12:30 -0400 | [diff] [blame] | 694 | desc->pg_rw_ops = rw_ops; |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 695 | desc->pg_ioflags = io_flags; |
| 696 | desc->pg_error = 0; |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 697 | desc->pg_lseg = NULL; |
Fred Isaman | 584aa81 | 2012-04-20 14:47:51 -0400 | [diff] [blame] | 698 | desc->pg_dreq = NULL; |
Peng Tao | f616638 | 2012-08-02 15:36:09 +0300 | [diff] [blame] | 699 | desc->pg_layout_private = NULL; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 700 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 701 | EXPORT_SYMBOL_GPL(nfs_pageio_init); |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 702 | |
Anna Schumaker | 0eecb21 | 2014-05-06 09:12:32 -0400 | [diff] [blame] | 703 | /** |
| 704 | * nfs_pgio_result - Basic pageio error handling |
| 705 | * @task: The task that ran |
| 706 | * @calldata: Pageio data to check |
| 707 | */ |
Anna Schumaker | 6f92fa4 | 2014-05-06 09:12:33 -0400 | [diff] [blame] | 708 | static void nfs_pgio_result(struct rpc_task *task, void *calldata) |
Anna Schumaker | 0eecb21 | 2014-05-06 09:12:32 -0400 | [diff] [blame] | 709 | { |
| 710 | struct nfs_pgio_data *data = calldata; |
| 711 | struct inode *inode = data->header->inode; |
| 712 | |
| 713 | dprintk("NFS: %s: %5u, (status %d)\n", __func__, |
| 714 | task->tk_pid, task->tk_status); |
| 715 | |
| 716 | if (data->header->rw_ops->rw_done(task, data, inode) != 0) |
| 717 | return; |
| 718 | if (task->tk_status < 0) |
| 719 | nfs_set_pgio_error(data->header, task->tk_status, data->args.offset); |
| 720 | else |
| 721 | data->header->rw_ops->rw_result(task, data); |
| 722 | } |
| 723 | |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 724 | /* |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 725 | * Create an RPC task for the given read or write request and kick it. |
| 726 | * The page must have been locked by the caller. |
| 727 | * |
| 728 | * It may happen that the page we're passed is not marked dirty. |
| 729 | * This is the case if nfs_updatepage detects a conflicting request |
| 730 | * that has been written but not committed. |
| 731 | */ |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 732 | int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, |
| 733 | struct nfs_pgio_header *hdr) |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 734 | { |
| 735 | struct nfs_page *req; |
| 736 | struct page **pages; |
| 737 | struct nfs_pgio_data *data; |
| 738 | struct list_head *head = &desc->pg_list; |
| 739 | struct nfs_commit_info cinfo; |
| 740 | |
| 741 | data = nfs_pgio_data_alloc(hdr, nfs_page_array_len(desc->pg_base, |
| 742 | desc->pg_count)); |
| 743 | if (!data) |
| 744 | return nfs_pgio_error(desc, hdr); |
| 745 | |
| 746 | nfs_init_cinfo(&cinfo, desc->pg_inode, desc->pg_dreq); |
| 747 | pages = data->pages.pagevec; |
| 748 | while (!list_empty(head)) { |
| 749 | req = nfs_list_entry(head->next); |
| 750 | nfs_list_remove_request(req); |
| 751 | nfs_list_add_request(req, &hdr->pages); |
| 752 | *pages++ = req->wb_page; |
| 753 | } |
| 754 | |
| 755 | if ((desc->pg_ioflags & FLUSH_COND_STABLE) && |
| 756 | (desc->pg_moreio || nfs_reqs_to_commit(&cinfo))) |
| 757 | desc->pg_ioflags &= ~FLUSH_COND_STABLE; |
| 758 | |
| 759 | /* Set up the argument struct */ |
| 760 | nfs_pgio_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo); |
Weston Andros Adamson | 7f71472 | 2014-05-15 11:56:53 -0400 | [diff] [blame] | 761 | hdr->data = data; |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 762 | desc->pg_rpc_callops = &nfs_pgio_common_ops; |
| 763 | return 0; |
| 764 | } |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 765 | EXPORT_SYMBOL_GPL(nfs_generic_pgio); |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 766 | |
Anna Schumaker | 41d8d5b | 2014-05-06 09:12:40 -0400 | [diff] [blame] | 767 | static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc) |
Anna Schumaker | cf485fc | 2014-05-06 09:12:39 -0400 | [diff] [blame] | 768 | { |
| 769 | struct nfs_rw_header *rw_hdr; |
| 770 | struct nfs_pgio_header *hdr; |
| 771 | int ret; |
| 772 | |
| 773 | rw_hdr = nfs_rw_header_alloc(desc->pg_rw_ops); |
| 774 | if (!rw_hdr) { |
| 775 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); |
| 776 | return -ENOMEM; |
| 777 | } |
| 778 | hdr = &rw_hdr->header; |
| 779 | nfs_pgheader_init(desc, hdr, nfs_rw_header_free); |
| 780 | atomic_inc(&hdr->refcnt); |
| 781 | ret = nfs_generic_pgio(desc, hdr); |
| 782 | if (ret == 0) |
Weston Andros Adamson | 7f71472 | 2014-05-15 11:56:53 -0400 | [diff] [blame] | 783 | ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode), |
| 784 | hdr->data, desc->pg_rpc_callops, |
| 785 | desc->pg_ioflags, 0); |
Anna Schumaker | cf485fc | 2014-05-06 09:12:39 -0400 | [diff] [blame] | 786 | if (atomic_dec_and_test(&hdr->refcnt)) |
| 787 | hdr->completion_ops->completion(hdr); |
| 788 | return ret; |
| 789 | } |
| 790 | |
Trond Myklebust | 4109bb7 | 2013-09-06 11:09:38 -0400 | [diff] [blame] | 791 | static bool nfs_match_open_context(const struct nfs_open_context *ctx1, |
| 792 | const struct nfs_open_context *ctx2) |
| 793 | { |
| 794 | return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state; |
| 795 | } |
| 796 | |
| 797 | static bool nfs_match_lock_context(const struct nfs_lock_context *l1, |
| 798 | const struct nfs_lock_context *l2) |
| 799 | { |
| 800 | return l1->lockowner.l_owner == l2->lockowner.l_owner |
| 801 | && l1->lockowner.l_pid == l2->lockowner.l_pid; |
| 802 | } |
| 803 | |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 804 | /** |
| 805 | * nfs_can_coalesce_requests - test two requests for compatibility |
| 806 | * @prev: pointer to nfs_page |
| 807 | * @req: pointer to nfs_page |
| 808 | * |
| 809 | * The nfs_page structures 'prev' and 'req' are compared to ensure that the |
| 810 | * page data area they describe is contiguous, and that their RPC |
| 811 | * credentials, NFSv4 open state, and lockowners are the same. |
| 812 | * |
| 813 | * Return 'true' if this is the case, else return 'false'. |
| 814 | */ |
Benny Halevy | 18ad0a9 | 2011-05-25 21:03:56 +0300 | [diff] [blame] | 815 | static bool nfs_can_coalesce_requests(struct nfs_page *prev, |
| 816 | struct nfs_page *req, |
| 817 | struct nfs_pageio_descriptor *pgio) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 818 | { |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 819 | size_t size; |
| 820 | |
Weston Andros Adamson | ab75e41 | 2014-05-15 11:56:44 -0400 | [diff] [blame] | 821 | if (prev) { |
| 822 | if (!nfs_match_open_context(req->wb_context, prev->wb_context)) |
| 823 | return false; |
| 824 | if (req->wb_context->dentry->d_inode->i_flock != NULL && |
| 825 | !nfs_match_lock_context(req->wb_lock_context, |
| 826 | prev->wb_lock_context)) |
| 827 | return false; |
Weston Andros Adamson | ab75e41 | 2014-05-15 11:56:44 -0400 | [diff] [blame] | 828 | if (req_offset(req) != req_offset(prev) + prev->wb_bytes) |
| 829 | return false; |
| 830 | } |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 831 | size = pgio->pg_ops->pg_test(pgio, prev, req); |
Weston Andros Adamson | f0cb9ab | 2014-05-15 11:56:52 -0400 | [diff] [blame] | 832 | WARN_ON_ONCE(size > req->wb_bytes); |
| 833 | if (size && size < req->wb_bytes) |
| 834 | req->wb_bytes = size; |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 835 | return size > 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | /** |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 839 | * 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] | 840 | * @desc: destination io descriptor |
| 841 | * @req: request |
| 842 | * |
| 843 | * Returns true if the request 'req' was successfully coalesced into the |
| 844 | * existing list of pages 'desc'. |
| 845 | */ |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 846 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, |
| 847 | struct nfs_page *req) |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 848 | { |
Weston Andros Adamson | ab75e41 | 2014-05-15 11:56:44 -0400 | [diff] [blame] | 849 | struct nfs_page *prev = NULL; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 850 | if (desc->pg_count != 0) { |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 851 | prev = nfs_list_entry(desc->pg_list.prev); |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 852 | } else { |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 853 | if (desc->pg_ops->pg_init) |
| 854 | desc->pg_ops->pg_init(desc, req); |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 855 | desc->pg_base = req->wb_pgbase; |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 856 | } |
Weston Andros Adamson | ab75e41 | 2014-05-15 11:56:44 -0400 | [diff] [blame] | 857 | if (!nfs_can_coalesce_requests(prev, req, desc)) |
| 858 | return 0; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 859 | nfs_list_remove_request(req); |
| 860 | nfs_list_add_request(req, &desc->pg_list); |
Boaz Harrosh | 5b36c7d | 2011-05-29 11:45:39 +0300 | [diff] [blame] | 861 | desc->pg_count += req->wb_bytes; |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 862 | return 1; |
| 863 | } |
| 864 | |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 865 | /* |
| 866 | * Helper for nfs_pageio_add_request and nfs_pageio_complete |
| 867 | */ |
| 868 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) |
| 869 | { |
| 870 | if (!list_empty(&desc->pg_list)) { |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 871 | int error = desc->pg_ops->pg_doio(desc); |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 872 | if (error < 0) |
| 873 | desc->pg_error = error; |
| 874 | else |
| 875 | desc->pg_bytes_written += desc->pg_count; |
| 876 | } |
| 877 | if (list_empty(&desc->pg_list)) { |
| 878 | desc->pg_count = 0; |
| 879 | desc->pg_base = 0; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * nfs_pageio_add_request - Attempt to coalesce a request into a page list. |
| 885 | * @desc: destination io descriptor |
| 886 | * @req: request |
| 887 | * |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 888 | * This may split a request into subrequests which are all part of the |
| 889 | * same page group. |
| 890 | * |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 891 | * Returns true if the request 'req' was successfully coalesced into the |
| 892 | * existing list of pages 'desc'. |
| 893 | */ |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 894 | static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, |
Trond Myklebust | 8b09bee | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 895 | struct nfs_page *req) |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 896 | { |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 897 | struct nfs_page *subreq; |
| 898 | unsigned int bytes_left = 0; |
| 899 | unsigned int offset, pgbase; |
| 900 | |
| 901 | nfs_page_group_lock(req); |
| 902 | |
| 903 | subreq = req; |
| 904 | bytes_left = subreq->wb_bytes; |
| 905 | offset = subreq->wb_offset; |
| 906 | pgbase = subreq->wb_pgbase; |
| 907 | |
| 908 | do { |
| 909 | if (!nfs_pageio_do_add_request(desc, subreq)) { |
| 910 | /* make sure pg_test call(s) did nothing */ |
| 911 | WARN_ON_ONCE(subreq->wb_bytes != bytes_left); |
| 912 | WARN_ON_ONCE(subreq->wb_offset != offset); |
| 913 | WARN_ON_ONCE(subreq->wb_pgbase != pgbase); |
| 914 | |
| 915 | nfs_page_group_unlock(req); |
| 916 | desc->pg_moreio = 1; |
| 917 | nfs_pageio_doio(desc); |
| 918 | if (desc->pg_error < 0) |
| 919 | return 0; |
| 920 | desc->pg_moreio = 0; |
| 921 | if (desc->pg_recoalesce) |
| 922 | return 0; |
| 923 | /* retry add_request for this subreq */ |
| 924 | nfs_page_group_lock(req); |
| 925 | continue; |
| 926 | } |
| 927 | |
| 928 | /* check for buggy pg_test call(s) */ |
| 929 | WARN_ON_ONCE(subreq->wb_bytes + subreq->wb_pgbase > PAGE_SIZE); |
| 930 | WARN_ON_ONCE(subreq->wb_bytes > bytes_left); |
| 931 | WARN_ON_ONCE(subreq->wb_bytes == 0); |
| 932 | |
| 933 | bytes_left -= subreq->wb_bytes; |
| 934 | offset += subreq->wb_bytes; |
| 935 | pgbase += subreq->wb_bytes; |
| 936 | |
| 937 | if (bytes_left) { |
| 938 | subreq = nfs_create_request(req->wb_context, |
| 939 | req->wb_page, |
| 940 | subreq, pgbase, bytes_left); |
Trond Myklebust | c110955 | 2014-05-29 11:38:15 -0400 | [diff] [blame] | 941 | if (IS_ERR(subreq)) |
| 942 | goto err_ptr; |
Weston Andros Adamson | 2bfc6e5 | 2014-05-15 11:56:45 -0400 | [diff] [blame] | 943 | nfs_lock_request(subreq); |
| 944 | subreq->wb_offset = offset; |
| 945 | subreq->wb_index = req->wb_index; |
| 946 | } |
| 947 | } while (bytes_left > 0); |
| 948 | |
| 949 | nfs_page_group_unlock(req); |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 950 | return 1; |
Trond Myklebust | c110955 | 2014-05-29 11:38:15 -0400 | [diff] [blame] | 951 | err_ptr: |
| 952 | desc->pg_error = PTR_ERR(subreq); |
| 953 | nfs_page_group_unlock(req); |
| 954 | return 0; |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 957 | static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) |
| 958 | { |
| 959 | LIST_HEAD(head); |
| 960 | |
| 961 | do { |
| 962 | list_splice_init(&desc->pg_list, &head); |
| 963 | desc->pg_bytes_written -= desc->pg_count; |
| 964 | desc->pg_count = 0; |
| 965 | desc->pg_base = 0; |
| 966 | desc->pg_recoalesce = 0; |
| 967 | |
| 968 | while (!list_empty(&head)) { |
| 969 | struct nfs_page *req; |
| 970 | |
| 971 | req = list_first_entry(&head, struct nfs_page, wb_list); |
| 972 | nfs_list_remove_request(req); |
| 973 | if (__nfs_pageio_add_request(desc, req)) |
| 974 | continue; |
| 975 | if (desc->pg_error < 0) |
| 976 | return 0; |
| 977 | break; |
| 978 | } |
| 979 | } while (desc->pg_recoalesce); |
| 980 | return 1; |
| 981 | } |
| 982 | |
| 983 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, |
| 984 | struct nfs_page *req) |
| 985 | { |
| 986 | int ret; |
| 987 | |
| 988 | do { |
| 989 | ret = __nfs_pageio_add_request(desc, req); |
| 990 | if (ret) |
| 991 | break; |
| 992 | if (desc->pg_error < 0) |
| 993 | break; |
| 994 | ret = nfs_do_recoalesce(desc); |
| 995 | } while (ret); |
| 996 | return ret; |
| 997 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 998 | EXPORT_SYMBOL_GPL(nfs_pageio_add_request); |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 999 | |
Trond Myklebust | d8a5ad7 | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 1000 | /** |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 1001 | * nfs_pageio_complete - Complete I/O on an nfs_pageio_descriptor |
| 1002 | * @desc: pointer to io descriptor |
| 1003 | */ |
| 1004 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) |
| 1005 | { |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 1006 | for (;;) { |
| 1007 | nfs_pageio_doio(desc); |
| 1008 | if (!desc->pg_recoalesce) |
| 1009 | break; |
| 1010 | if (!nfs_do_recoalesce(desc)) |
| 1011 | break; |
| 1012 | } |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 1013 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 1014 | EXPORT_SYMBOL_GPL(nfs_pageio_complete); |
Trond Myklebust | bcb71bb | 2007-04-02 18:48:28 -0400 | [diff] [blame] | 1015 | |
Trond Myklebust | 7fe7f84 | 2007-05-20 10:18:27 -0400 | [diff] [blame] | 1016 | /** |
| 1017 | * nfs_pageio_cond_complete - Conditional I/O completion |
| 1018 | * @desc: pointer to io descriptor |
| 1019 | * @index: page index |
| 1020 | * |
| 1021 | * It is important to ensure that processes don't try to take locks |
| 1022 | * on non-contiguous ranges of pages as that might deadlock. This |
| 1023 | * function should be called before attempting to wait on a locked |
| 1024 | * nfs_page. It will complete the I/O if the page index 'index' |
| 1025 | * is not contiguous with the existing list of pages in 'desc'. |
| 1026 | */ |
| 1027 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) |
| 1028 | { |
| 1029 | if (!list_empty(&desc->pg_list)) { |
| 1030 | struct nfs_page *prev = nfs_list_entry(desc->pg_list.prev); |
| 1031 | if (index != prev->wb_index + 1) |
Trond Myklebust | d9156f9 | 2011-07-12 13:42:02 -0400 | [diff] [blame] | 1032 | nfs_pageio_complete(desc); |
Trond Myklebust | 7fe7f84 | 2007-05-20 10:18:27 -0400 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1036 | int __init nfs_init_nfspagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
| 1038 | nfs_page_cachep = kmem_cache_create("nfs_page", |
| 1039 | sizeof(struct nfs_page), |
| 1040 | 0, SLAB_HWCACHE_ALIGN, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1041 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | if (nfs_page_cachep == NULL) |
| 1043 | return -ENOMEM; |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
David Brownell | 266bee8 | 2006-06-27 12:59:15 -0700 | [diff] [blame] | 1048 | void nfs_destroy_nfspagecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | { |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 1050 | kmem_cache_destroy(nfs_page_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Anna Schumaker | ef2c488 | 2014-05-06 09:12:36 -0400 | [diff] [blame] | 1053 | static const struct rpc_call_ops nfs_pgio_common_ops = { |
Anna Schumaker | 6f92fa4 | 2014-05-06 09:12:33 -0400 | [diff] [blame] | 1054 | .rpc_call_prepare = nfs_pgio_prepare, |
| 1055 | .rpc_call_done = nfs_pgio_result, |
| 1056 | .rpc_release = nfs_pgio_release, |
| 1057 | }; |
Anna Schumaker | 41d8d5b | 2014-05-06 09:12:40 -0400 | [diff] [blame] | 1058 | |
| 1059 | const struct nfs_pageio_ops nfs_pgio_rw_ops = { |
| 1060 | .pg_test = nfs_generic_pg_test, |
| 1061 | .pg_doio = nfs_generic_pg_pgios, |
| 1062 | }; |