Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pNFS functions to call and manage layout drivers. |
| 3 | * |
| 4 | * Copyright (c) 2002 [year of first publication] |
| 5 | * The Regents of the University of Michigan |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Dean Hildebrand <dhildebz@umich.edu> |
| 9 | * |
| 10 | * Permission is granted to use, copy, create derivative works, and |
| 11 | * redistribute this software and such derivative works for any purpose, |
| 12 | * so long as the name of the University of Michigan is not used in |
| 13 | * any advertising or publicity pertaining to the use or distribution |
| 14 | * of this software without specific, written prior authorization. If |
| 15 | * the above copyright notice or any other identification of the |
| 16 | * University of Michigan is included in any copy of any portion of |
| 17 | * this software, then the disclaimer below must also be included. |
| 18 | * |
| 19 | * This software is provided as is, without representation or warranty |
| 20 | * of any kind either express or implied, including without limitation |
| 21 | * the implied warranties of merchantability, fitness for a particular |
| 22 | * purpose, or noninfringement. The Regents of the University of |
| 23 | * Michigan shall not be liable for any damages, including special, |
| 24 | * indirect, incidental, or consequential damages, with respect to any |
| 25 | * claim arising out of or in connection with the use of the software, |
| 26 | * even if it has been or is hereafter advised of the possibility of |
| 27 | * such damages. |
| 28 | */ |
| 29 | |
| 30 | #include <linux/nfs_fs.h> |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 31 | #include "internal.h" |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 32 | #include "pnfs.h" |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 33 | #include "iostat.h" |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 34 | |
| 35 | #define NFSDBG_FACILITY NFSDBG_PNFS |
| 36 | |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 37 | /* Locking: |
| 38 | * |
| 39 | * pnfs_spinlock: |
| 40 | * protects pnfs_modules_tbl. |
| 41 | */ |
| 42 | static DEFINE_SPINLOCK(pnfs_spinlock); |
| 43 | |
| 44 | /* |
| 45 | * pnfs_modules_tbl holds all pnfs modules |
| 46 | */ |
| 47 | static LIST_HEAD(pnfs_modules_tbl); |
| 48 | |
| 49 | /* Return the registered pnfs layout driver module matching given id */ |
| 50 | static struct pnfs_layoutdriver_type * |
| 51 | find_pnfs_driver_locked(u32 id) |
| 52 | { |
| 53 | struct pnfs_layoutdriver_type *local; |
| 54 | |
| 55 | list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid) |
| 56 | if (local->id == id) |
| 57 | goto out; |
| 58 | local = NULL; |
| 59 | out: |
| 60 | dprintk("%s: Searching for id %u, found %p\n", __func__, id, local); |
| 61 | return local; |
| 62 | } |
| 63 | |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 64 | static struct pnfs_layoutdriver_type * |
| 65 | find_pnfs_driver(u32 id) |
| 66 | { |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 67 | struct pnfs_layoutdriver_type *local; |
| 68 | |
| 69 | spin_lock(&pnfs_spinlock); |
| 70 | local = find_pnfs_driver_locked(id); |
| 71 | spin_unlock(&pnfs_spinlock); |
| 72 | return local; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
| 76 | unset_pnfs_layoutdriver(struct nfs_server *nfss) |
| 77 | { |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 78 | if (nfss->pnfs_curr_ld) |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 79 | module_put(nfss->pnfs_curr_ld->owner); |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 80 | nfss->pnfs_curr_ld = NULL; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Try to set the server's pnfs module to the pnfs layout type specified by id. |
| 85 | * Currently only one pNFS layout driver per filesystem is supported. |
| 86 | * |
| 87 | * @id layout type. Zero (illegal layout type) indicates pNFS not in use. |
| 88 | */ |
| 89 | void |
| 90 | set_pnfs_layoutdriver(struct nfs_server *server, u32 id) |
| 91 | { |
| 92 | struct pnfs_layoutdriver_type *ld_type = NULL; |
| 93 | |
| 94 | if (id == 0) |
| 95 | goto out_no_driver; |
| 96 | if (!(server->nfs_client->cl_exchange_flags & |
| 97 | (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) { |
| 98 | printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__, |
| 99 | id, server->nfs_client->cl_exchange_flags); |
| 100 | goto out_no_driver; |
| 101 | } |
| 102 | ld_type = find_pnfs_driver(id); |
| 103 | if (!ld_type) { |
| 104 | request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id); |
| 105 | ld_type = find_pnfs_driver(id); |
| 106 | if (!ld_type) { |
| 107 | dprintk("%s: No pNFS module found for %u.\n", |
| 108 | __func__, id); |
| 109 | goto out_no_driver; |
| 110 | } |
| 111 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 112 | if (!try_module_get(ld_type->owner)) { |
| 113 | dprintk("%s: Could not grab reference on module\n", __func__); |
| 114 | goto out_no_driver; |
| 115 | } |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 116 | server->pnfs_curr_ld = ld_type; |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 117 | |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 118 | dprintk("%s: pNFS module for %u set\n", __func__, id); |
| 119 | return; |
| 120 | |
| 121 | out_no_driver: |
| 122 | dprintk("%s: Using NFSv4 I/O\n", __func__); |
| 123 | server->pnfs_curr_ld = NULL; |
| 124 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 125 | |
| 126 | int |
| 127 | pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type) |
| 128 | { |
| 129 | int status = -EINVAL; |
| 130 | struct pnfs_layoutdriver_type *tmp; |
| 131 | |
| 132 | if (ld_type->id == 0) { |
| 133 | printk(KERN_ERR "%s id 0 is reserved\n", __func__); |
| 134 | return status; |
| 135 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 136 | if (!ld_type->alloc_lseg || !ld_type->free_lseg) { |
| 137 | printk(KERN_ERR "%s Layout driver must provide " |
| 138 | "alloc_lseg and free_lseg.\n", __func__); |
| 139 | return status; |
| 140 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 141 | |
| 142 | spin_lock(&pnfs_spinlock); |
| 143 | tmp = find_pnfs_driver_locked(ld_type->id); |
| 144 | if (!tmp) { |
| 145 | list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl); |
| 146 | status = 0; |
| 147 | dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id, |
| 148 | ld_type->name); |
| 149 | } else { |
| 150 | printk(KERN_ERR "%s Module with id %d already loaded!\n", |
| 151 | __func__, ld_type->id); |
| 152 | } |
| 153 | spin_unlock(&pnfs_spinlock); |
| 154 | |
| 155 | return status; |
| 156 | } |
| 157 | EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver); |
| 158 | |
| 159 | void |
| 160 | pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type) |
| 161 | { |
| 162 | dprintk("%s Deregistering id:%u\n", __func__, ld_type->id); |
| 163 | spin_lock(&pnfs_spinlock); |
| 164 | list_del(&ld_type->pnfs_tblid); |
| 165 | spin_unlock(&pnfs_spinlock); |
| 166 | } |
| 167 | EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 168 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 169 | /* |
| 170 | * pNFS client layout cache |
| 171 | */ |
| 172 | |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 173 | /* Need to hold i_lock if caller does not already hold reference */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 174 | void |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 175 | get_layout_hdr(struct pnfs_layout_hdr *lo) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 176 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 177 | atomic_inc(&lo->plh_refcount); |
| 178 | } |
| 179 | |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 180 | static struct pnfs_layout_hdr * |
| 181 | pnfs_alloc_layout_hdr(struct inode *ino, gfp_t gfp_flags) |
| 182 | { |
| 183 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld; |
| 184 | return ld->alloc_layout_hdr ? ld->alloc_layout_hdr(ino, gfp_flags) : |
| 185 | kzalloc(sizeof(struct pnfs_layout_hdr), gfp_flags); |
| 186 | } |
| 187 | |
| 188 | static void |
| 189 | pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo) |
| 190 | { |
| 191 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(lo->plh_inode)->pnfs_curr_ld; |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 192 | put_rpccred(lo->plh_lc_cred); |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 193 | return ld->alloc_layout_hdr ? ld->free_layout_hdr(lo) : kfree(lo); |
| 194 | } |
| 195 | |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 196 | static void |
| 197 | destroy_layout_hdr(struct pnfs_layout_hdr *lo) |
| 198 | { |
| 199 | dprintk("%s: freeing layout cache %p\n", __func__, lo); |
| 200 | BUG_ON(!list_empty(&lo->plh_layouts)); |
| 201 | NFS_I(lo->plh_inode)->layout = NULL; |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 202 | pnfs_free_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void |
| 206 | put_layout_hdr_locked(struct pnfs_layout_hdr *lo) |
| 207 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 208 | if (atomic_dec_and_test(&lo->plh_refcount)) |
| 209 | destroy_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 212 | void |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 213 | put_layout_hdr(struct pnfs_layout_hdr *lo) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 214 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 215 | struct inode *inode = lo->plh_inode; |
| 216 | |
| 217 | if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { |
| 218 | destroy_layout_hdr(lo); |
| 219 | spin_unlock(&inode->i_lock); |
| 220 | } |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void |
| 224 | init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg) |
| 225 | { |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 226 | INIT_LIST_HEAD(&lseg->pls_list); |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 227 | INIT_LIST_HEAD(&lseg->pls_lc_list); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 228 | atomic_set(&lseg->pls_refcount, 1); |
| 229 | smp_mb(); |
| 230 | set_bit(NFS_LSEG_VALID, &lseg->pls_flags); |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 231 | lseg->pls_layout = lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 232 | } |
| 233 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 234 | static void free_lseg(struct pnfs_layout_segment *lseg) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 235 | { |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 236 | struct inode *ino = lseg->pls_layout->plh_inode; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 237 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 238 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); |
Fred Isaman | 52fabd7 | 2011-01-06 11:36:18 +0000 | [diff] [blame] | 239 | /* Matched by get_layout_hdr in pnfs_insert_layout */ |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 240 | put_layout_hdr(NFS_I(ino)->layout); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 241 | } |
| 242 | |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 243 | static void |
| 244 | put_lseg_common(struct pnfs_layout_segment *lseg) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 245 | { |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 246 | struct inode *inode = lseg->pls_layout->plh_inode; |
| 247 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 248 | WARN_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 249 | list_del_init(&lseg->pls_list); |
| 250 | if (list_empty(&lseg->pls_layout->plh_segs)) { |
| 251 | set_bit(NFS_LAYOUT_DESTROYED, &lseg->pls_layout->plh_flags); |
| 252 | /* Matched by initial refcount set in alloc_init_layout_hdr */ |
| 253 | put_layout_hdr_locked(lseg->pls_layout); |
| 254 | } |
| 255 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); |
| 256 | } |
| 257 | |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 258 | void |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 259 | put_lseg(struct pnfs_layout_segment *lseg) |
| 260 | { |
| 261 | struct inode *inode; |
| 262 | |
| 263 | if (!lseg) |
| 264 | return; |
| 265 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 266 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, |
| 267 | atomic_read(&lseg->pls_refcount), |
| 268 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 269 | inode = lseg->pls_layout->plh_inode; |
| 270 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { |
| 271 | LIST_HEAD(free_me); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 272 | |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 273 | put_lseg_common(lseg); |
| 274 | list_add(&lseg->pls_list, &free_me); |
| 275 | spin_unlock(&inode->i_lock); |
| 276 | pnfs_free_lseg_list(&free_me); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 277 | } |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 278 | } |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 279 | EXPORT_SYMBOL_GPL(put_lseg); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 280 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 281 | static inline u64 |
| 282 | end_offset(u64 start, u64 len) |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 283 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 284 | u64 end; |
| 285 | |
| 286 | end = start + len; |
| 287 | return end >= start ? end : NFS4_MAX_UINT64; |
| 288 | } |
| 289 | |
| 290 | /* last octet in a range */ |
| 291 | static inline u64 |
| 292 | last_byte_offset(u64 start, u64 len) |
| 293 | { |
| 294 | u64 end; |
| 295 | |
| 296 | BUG_ON(!len); |
| 297 | end = start + len; |
| 298 | return end > start ? end - 1 : NFS4_MAX_UINT64; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * is l2 fully contained in l1? |
| 303 | * start1 end1 |
| 304 | * [----------------------------------) |
| 305 | * start2 end2 |
| 306 | * [----------------) |
| 307 | */ |
| 308 | static inline int |
| 309 | lo_seg_contained(struct pnfs_layout_range *l1, |
| 310 | struct pnfs_layout_range *l2) |
| 311 | { |
| 312 | u64 start1 = l1->offset; |
| 313 | u64 end1 = end_offset(start1, l1->length); |
| 314 | u64 start2 = l2->offset; |
| 315 | u64 end2 = end_offset(start2, l2->length); |
| 316 | |
| 317 | return (start1 <= start2) && (end1 >= end2); |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * is l1 and l2 intersecting? |
| 322 | * start1 end1 |
| 323 | * [----------------------------------) |
| 324 | * start2 end2 |
| 325 | * [----------------) |
| 326 | */ |
| 327 | static inline int |
| 328 | lo_seg_intersecting(struct pnfs_layout_range *l1, |
| 329 | struct pnfs_layout_range *l2) |
| 330 | { |
| 331 | u64 start1 = l1->offset; |
| 332 | u64 end1 = end_offset(start1, l1->length); |
| 333 | u64 start2 = l2->offset; |
| 334 | u64 end2 = end_offset(start2, l2->length); |
| 335 | |
| 336 | return (end1 == NFS4_MAX_UINT64 || end1 > start2) && |
| 337 | (end2 == NFS4_MAX_UINT64 || end2 > start1); |
| 338 | } |
| 339 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 340 | static bool |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 341 | should_free_lseg(struct pnfs_layout_range *lseg_range, |
| 342 | struct pnfs_layout_range *recall_range) |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 343 | { |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 344 | return (recall_range->iomode == IOMODE_ANY || |
| 345 | lseg_range->iomode == recall_range->iomode) && |
| 346 | lo_seg_intersecting(lseg_range, recall_range); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* Returns 1 if lseg is removed from list, 0 otherwise */ |
| 350 | static int mark_lseg_invalid(struct pnfs_layout_segment *lseg, |
| 351 | struct list_head *tmp_list) |
| 352 | { |
| 353 | int rv = 0; |
| 354 | |
| 355 | if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) { |
| 356 | /* Remove the reference keeping the lseg in the |
| 357 | * list. It will now be removed when all |
| 358 | * outstanding io is finished. |
| 359 | */ |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 360 | dprintk("%s: lseg %p ref %d\n", __func__, lseg, |
| 361 | atomic_read(&lseg->pls_refcount)); |
| 362 | if (atomic_dec_and_test(&lseg->pls_refcount)) { |
| 363 | put_lseg_common(lseg); |
| 364 | list_add(&lseg->pls_list, tmp_list); |
| 365 | rv = 1; |
| 366 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 367 | } |
| 368 | return rv; |
| 369 | } |
| 370 | |
| 371 | /* Returns count of number of matching invalid lsegs remaining in list |
| 372 | * after call. |
| 373 | */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 374 | int |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 375 | mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, |
| 376 | struct list_head *tmp_list, |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 377 | struct pnfs_layout_range *recall_range) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 378 | { |
| 379 | struct pnfs_layout_segment *lseg, *next; |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 380 | int invalid = 0, removed = 0; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 381 | |
| 382 | dprintk("%s:Begin lo %p\n", __func__, lo); |
| 383 | |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 384 | if (list_empty(&lo->plh_segs)) { |
| 385 | if (!test_and_set_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) |
| 386 | put_layout_hdr_locked(lo); |
| 387 | return 0; |
| 388 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 389 | list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 390 | if (!recall_range || |
| 391 | should_free_lseg(&lseg->pls_range, recall_range)) { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 392 | dprintk("%s: freeing lseg %p iomode %d " |
| 393 | "offset %llu length %llu\n", __func__, |
| 394 | lseg, lseg->pls_range.iomode, lseg->pls_range.offset, |
| 395 | lseg->pls_range.length); |
| 396 | invalid++; |
| 397 | removed += mark_lseg_invalid(lseg, tmp_list); |
| 398 | } |
| 399 | dprintk("%s:Return %i\n", __func__, invalid - removed); |
| 400 | return invalid - removed; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 403 | /* note free_me must contain lsegs from a single layout_hdr */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 404 | void |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 405 | pnfs_free_lseg_list(struct list_head *free_me) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 406 | { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 407 | struct pnfs_layout_segment *lseg, *tmp; |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 408 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 409 | |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 410 | if (list_empty(free_me)) |
| 411 | return; |
| 412 | |
| 413 | lo = list_first_entry(free_me, struct pnfs_layout_segment, |
| 414 | pls_list)->pls_layout; |
| 415 | |
| 416 | if (test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) { |
| 417 | struct nfs_client *clp; |
| 418 | |
| 419 | clp = NFS_SERVER(lo->plh_inode)->nfs_client; |
| 420 | spin_lock(&clp->cl_lock); |
| 421 | list_del_init(&lo->plh_layouts); |
| 422 | spin_unlock(&clp->cl_lock); |
| 423 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 424 | list_for_each_entry_safe(lseg, tmp, free_me, pls_list) { |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 425 | list_del(&lseg->pls_list); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 426 | free_lseg(lseg); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 430 | void |
| 431 | pnfs_destroy_layout(struct nfs_inode *nfsi) |
| 432 | { |
| 433 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 434 | LIST_HEAD(tmp_list); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 435 | |
| 436 | spin_lock(&nfsi->vfs_inode.i_lock); |
| 437 | lo = nfsi->layout; |
| 438 | if (lo) { |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 439 | lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */ |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 440 | mark_matching_lsegs_invalid(lo, &tmp_list, NULL); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 441 | } |
| 442 | spin_unlock(&nfsi->vfs_inode.i_lock); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 443 | pnfs_free_lseg_list(&tmp_list); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 444 | } |
| 445 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 446 | /* |
| 447 | * Called by the state manger to remove all layouts established under an |
| 448 | * expired lease. |
| 449 | */ |
| 450 | void |
| 451 | pnfs_destroy_all_layouts(struct nfs_client *clp) |
| 452 | { |
| 453 | struct pnfs_layout_hdr *lo; |
| 454 | LIST_HEAD(tmp_list); |
| 455 | |
| 456 | spin_lock(&clp->cl_lock); |
| 457 | list_splice_init(&clp->cl_layouts, &tmp_list); |
| 458 | spin_unlock(&clp->cl_lock); |
| 459 | |
| 460 | while (!list_empty(&tmp_list)) { |
| 461 | lo = list_entry(tmp_list.next, struct pnfs_layout_hdr, |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 462 | plh_layouts); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 463 | dprintk("%s freeing layout for inode %lu\n", __func__, |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 464 | lo->plh_inode->i_ino); |
Andy Adamson | 2887fe4 | 2011-05-11 01:19:58 -0400 | [diff] [blame] | 465 | list_del_init(&lo->plh_layouts); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 466 | pnfs_destroy_layout(NFS_I(lo->plh_inode)); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 470 | /* update lo->plh_stateid with new if is more recent */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 471 | void |
| 472 | pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new, |
| 473 | bool update_barrier) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 474 | { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 475 | u32 oldseq, newseq; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 476 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 477 | oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid); |
| 478 | newseq = be32_to_cpu(new->stateid.seqid); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 479 | if ((int)(newseq - oldseq) > 0) { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 480 | memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid)); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 481 | if (update_barrier) { |
| 482 | u32 new_barrier = be32_to_cpu(new->stateid.seqid); |
| 483 | |
| 484 | if ((int)(new_barrier - lo->plh_barrier)) |
| 485 | lo->plh_barrier = new_barrier; |
| 486 | } else { |
| 487 | /* Because of wraparound, we want to keep the barrier |
| 488 | * "close" to the current seqids. It needs to be |
| 489 | * within 2**31 to count as "behind", so if it |
| 490 | * gets too near that limit, give us a litle leeway |
| 491 | * and bring it to within 2**30. |
| 492 | * NOTE - and yes, this is all unsigned arithmetic. |
| 493 | */ |
| 494 | if (unlikely((newseq - lo->plh_barrier) > (3 << 29))) |
| 495 | lo->plh_barrier = newseq - (1 << 30); |
| 496 | } |
| 497 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 500 | /* lget is set to 1 if called from inside send_layoutget call chain */ |
| 501 | static bool |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 502 | pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid, |
| 503 | int lget) |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 504 | { |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 505 | if ((stateid) && |
| 506 | (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0) |
| 507 | return true; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 508 | return lo->plh_block_lgets || |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 509 | test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) || |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 510 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 511 | (list_empty(&lo->plh_segs) && |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 512 | (atomic_read(&lo->plh_outstanding) > lget)); |
| 513 | } |
| 514 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 515 | int |
| 516 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, |
| 517 | struct nfs4_state *open_state) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 518 | { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 519 | int status = 0; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 520 | |
| 521 | dprintk("--> %s\n", __func__); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 522 | spin_lock(&lo->plh_inode->i_lock); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 523 | if (pnfs_layoutgets_blocked(lo, NULL, 1)) { |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 524 | status = -EAGAIN; |
| 525 | } else if (list_empty(&lo->plh_segs)) { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 526 | int seq; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 527 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 528 | do { |
| 529 | seq = read_seqbegin(&open_state->seqlock); |
| 530 | memcpy(dst->data, open_state->stateid.data, |
| 531 | sizeof(open_state->stateid.data)); |
| 532 | } while (read_seqretry(&open_state->seqlock, seq)); |
| 533 | } else |
| 534 | memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data)); |
| 535 | spin_unlock(&lo->plh_inode->i_lock); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 536 | dprintk("<-- %s\n", __func__); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 537 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Get layout from server. |
| 542 | * for now, assume that whole file layouts are requested. |
| 543 | * arg->offset: 0 |
| 544 | * arg->length: all ones |
| 545 | */ |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 546 | static struct pnfs_layout_segment * |
| 547 | send_layoutget(struct pnfs_layout_hdr *lo, |
| 548 | struct nfs_open_context *ctx, |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 549 | struct pnfs_layout_range *range, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 550 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 551 | { |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 552 | struct inode *ino = lo->plh_inode; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 553 | struct nfs_server *server = NFS_SERVER(ino); |
| 554 | struct nfs4_layoutget *lgp; |
| 555 | struct pnfs_layout_segment *lseg = NULL; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 556 | struct page **pages = NULL; |
| 557 | int i; |
| 558 | u32 max_resp_sz, max_pages; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 559 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 560 | dprintk("--> %s\n", __func__); |
| 561 | |
| 562 | BUG_ON(ctx == NULL); |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 563 | lgp = kzalloc(sizeof(*lgp), gfp_flags); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 564 | if (lgp == NULL) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 565 | return NULL; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 566 | |
| 567 | /* allocate pages for xdr post processing */ |
| 568 | max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 569 | max_pages = max_resp_sz >> PAGE_SHIFT; |
| 570 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 571 | pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 572 | if (!pages) |
| 573 | goto out_err_free; |
| 574 | |
| 575 | for (i = 0; i < max_pages; i++) { |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 576 | pages[i] = alloc_page(gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 577 | if (!pages[i]) |
| 578 | goto out_err_free; |
| 579 | } |
| 580 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 581 | lgp->args.minlength = PAGE_CACHE_SIZE; |
| 582 | if (lgp->args.minlength > range->length) |
| 583 | lgp->args.minlength = range->length; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 584 | lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE; |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 585 | lgp->args.range = *range; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 586 | lgp->args.type = server->pnfs_curr_ld->id; |
| 587 | lgp->args.inode = ino; |
| 588 | lgp->args.ctx = get_nfs_open_context(ctx); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 589 | lgp->args.layout.pages = pages; |
| 590 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 591 | lgp->lsegpp = &lseg; |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 592 | lgp->gfp_flags = gfp_flags; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 593 | |
| 594 | /* Synchronously retrieve layout information from server and |
| 595 | * store in lseg. |
| 596 | */ |
| 597 | nfs4_proc_layoutget(lgp); |
| 598 | if (!lseg) { |
| 599 | /* remember that LAYOUTGET failed and suspend trying */ |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 600 | set_bit(lo_fail_bit(range->iomode), &lo->plh_flags); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 601 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 602 | |
| 603 | /* free xdr pages */ |
| 604 | for (i = 0; i < max_pages; i++) |
| 605 | __free_page(pages[i]); |
| 606 | kfree(pages); |
| 607 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 608 | return lseg; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 609 | |
| 610 | out_err_free: |
| 611 | /* free any allocated xdr pages, lgp as it's not used */ |
| 612 | if (pages) { |
| 613 | for (i = 0; i < max_pages; i++) { |
| 614 | if (!pages[i]) |
| 615 | break; |
| 616 | __free_page(pages[i]); |
| 617 | } |
| 618 | kfree(pages); |
| 619 | } |
| 620 | kfree(lgp); |
| 621 | return NULL; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 622 | } |
| 623 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 624 | /* Initiates a LAYOUTRETURN(FILE) */ |
| 625 | int |
| 626 | _pnfs_return_layout(struct inode *ino) |
| 627 | { |
| 628 | struct pnfs_layout_hdr *lo = NULL; |
| 629 | struct nfs_inode *nfsi = NFS_I(ino); |
| 630 | LIST_HEAD(tmp_list); |
| 631 | struct nfs4_layoutreturn *lrp; |
| 632 | nfs4_stateid stateid; |
| 633 | int status = 0; |
| 634 | |
| 635 | dprintk("--> %s\n", __func__); |
| 636 | |
| 637 | spin_lock(&ino->i_lock); |
| 638 | lo = nfsi->layout; |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 639 | if (!lo) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 640 | spin_unlock(&ino->i_lock); |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 641 | dprintk("%s: no layout to return\n", __func__); |
| 642 | return status; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 643 | } |
| 644 | stateid = nfsi->layout->plh_stateid; |
| 645 | /* Reference matched in nfs4_layoutreturn_release */ |
| 646 | get_layout_hdr(lo); |
Fred Isaman | ea0ded7 | 2011-06-15 12:31:02 -0400 | [diff] [blame] | 647 | mark_matching_lsegs_invalid(lo, &tmp_list, NULL); |
| 648 | lo->plh_block_lgets++; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 649 | spin_unlock(&ino->i_lock); |
| 650 | pnfs_free_lseg_list(&tmp_list); |
| 651 | |
| 652 | WARN_ON(test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)); |
| 653 | |
| 654 | lrp = kzalloc(sizeof(*lrp), GFP_KERNEL); |
| 655 | if (unlikely(lrp == NULL)) { |
| 656 | status = -ENOMEM; |
Fred Isaman | 9e2dfdb | 2011-06-15 14:32:02 -0400 | [diff] [blame] | 657 | set_bit(NFS_LAYOUT_RW_FAILED, &lo->plh_flags); |
| 658 | set_bit(NFS_LAYOUT_RO_FAILED, &lo->plh_flags); |
Benny Halevy | 1ed3a85 | 2011-06-15 11:39:57 -0400 | [diff] [blame] | 659 | put_layout_hdr(lo); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 660 | goto out; |
| 661 | } |
| 662 | |
| 663 | lrp->args.stateid = stateid; |
| 664 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; |
| 665 | lrp->args.inode = ino; |
| 666 | lrp->clp = NFS_SERVER(ino)->nfs_client; |
| 667 | |
| 668 | status = nfs4_proc_layoutreturn(lrp); |
| 669 | out: |
| 670 | dprintk("<-- %s status: %d\n", __func__, status); |
| 671 | return status; |
| 672 | } |
| 673 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 674 | bool pnfs_roc(struct inode *ino) |
| 675 | { |
| 676 | struct pnfs_layout_hdr *lo; |
| 677 | struct pnfs_layout_segment *lseg, *tmp; |
| 678 | LIST_HEAD(tmp_list); |
| 679 | bool found = false; |
| 680 | |
| 681 | spin_lock(&ino->i_lock); |
| 682 | lo = NFS_I(ino)->layout; |
| 683 | if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) || |
| 684 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) |
| 685 | goto out_nolayout; |
| 686 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) |
| 687 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 688 | mark_lseg_invalid(lseg, &tmp_list); |
| 689 | found = true; |
| 690 | } |
| 691 | if (!found) |
| 692 | goto out_nolayout; |
| 693 | lo->plh_block_lgets++; |
| 694 | get_layout_hdr(lo); /* matched in pnfs_roc_release */ |
| 695 | spin_unlock(&ino->i_lock); |
| 696 | pnfs_free_lseg_list(&tmp_list); |
| 697 | return true; |
| 698 | |
| 699 | out_nolayout: |
| 700 | spin_unlock(&ino->i_lock); |
| 701 | return false; |
| 702 | } |
| 703 | |
| 704 | void pnfs_roc_release(struct inode *ino) |
| 705 | { |
| 706 | struct pnfs_layout_hdr *lo; |
| 707 | |
| 708 | spin_lock(&ino->i_lock); |
| 709 | lo = NFS_I(ino)->layout; |
| 710 | lo->plh_block_lgets--; |
| 711 | put_layout_hdr_locked(lo); |
| 712 | spin_unlock(&ino->i_lock); |
| 713 | } |
| 714 | |
| 715 | void pnfs_roc_set_barrier(struct inode *ino, u32 barrier) |
| 716 | { |
| 717 | struct pnfs_layout_hdr *lo; |
| 718 | |
| 719 | spin_lock(&ino->i_lock); |
| 720 | lo = NFS_I(ino)->layout; |
| 721 | if ((int)(barrier - lo->plh_barrier) > 0) |
| 722 | lo->plh_barrier = barrier; |
| 723 | spin_unlock(&ino->i_lock); |
| 724 | } |
| 725 | |
| 726 | bool pnfs_roc_drain(struct inode *ino, u32 *barrier) |
| 727 | { |
| 728 | struct nfs_inode *nfsi = NFS_I(ino); |
| 729 | struct pnfs_layout_segment *lseg; |
| 730 | bool found = false; |
| 731 | |
| 732 | spin_lock(&ino->i_lock); |
| 733 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) |
| 734 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 735 | found = true; |
| 736 | break; |
| 737 | } |
| 738 | if (!found) { |
| 739 | struct pnfs_layout_hdr *lo = nfsi->layout; |
| 740 | u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid); |
| 741 | |
| 742 | /* Since close does not return a layout stateid for use as |
| 743 | * a barrier, we choose the worst-case barrier. |
| 744 | */ |
| 745 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); |
| 746 | } |
| 747 | spin_unlock(&ino->i_lock); |
| 748 | return found; |
| 749 | } |
| 750 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 751 | /* |
| 752 | * Compare two layout segments for sorting into layout cache. |
| 753 | * We want to preferentially return RW over RO layouts, so ensure those |
| 754 | * are seen first. |
| 755 | */ |
| 756 | static s64 |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 757 | cmp_layout(struct pnfs_layout_range *l1, |
| 758 | struct pnfs_layout_range *l2) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 759 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 760 | s64 d; |
| 761 | |
| 762 | /* high offset > low offset */ |
| 763 | d = l1->offset - l2->offset; |
| 764 | if (d) |
| 765 | return d; |
| 766 | |
| 767 | /* short length > long length */ |
| 768 | d = l2->length - l1->length; |
| 769 | if (d) |
| 770 | return d; |
| 771 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 772 | /* read > read/write */ |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 773 | return (int)(l1->iomode == IOMODE_READ) - (int)(l2->iomode == IOMODE_READ); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 774 | } |
| 775 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 776 | static void |
| 777 | pnfs_insert_layout(struct pnfs_layout_hdr *lo, |
| 778 | struct pnfs_layout_segment *lseg) |
| 779 | { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 780 | struct pnfs_layout_segment *lp; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 781 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 782 | dprintk("%s:Begin\n", __func__); |
| 783 | |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 784 | assert_spin_locked(&lo->plh_inode->i_lock); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 785 | list_for_each_entry(lp, &lo->plh_segs, pls_list) { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 786 | if (cmp_layout(&lseg->pls_range, &lp->pls_range) > 0) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 787 | continue; |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 788 | list_add_tail(&lseg->pls_list, &lp->pls_list); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 789 | dprintk("%s: inserted lseg %p " |
| 790 | "iomode %d offset %llu length %llu before " |
| 791 | "lp %p iomode %d offset %llu length %llu\n", |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 792 | __func__, lseg, lseg->pls_range.iomode, |
| 793 | lseg->pls_range.offset, lseg->pls_range.length, |
| 794 | lp, lp->pls_range.iomode, lp->pls_range.offset, |
| 795 | lp->pls_range.length); |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 796 | goto out; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 797 | } |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 798 | list_add_tail(&lseg->pls_list, &lo->plh_segs); |
| 799 | dprintk("%s: inserted lseg %p " |
| 800 | "iomode %d offset %llu length %llu at tail\n", |
| 801 | __func__, lseg, lseg->pls_range.iomode, |
| 802 | lseg->pls_range.offset, lseg->pls_range.length); |
| 803 | out: |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 804 | get_layout_hdr(lo); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 805 | |
| 806 | dprintk("%s:Return\n", __func__); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static struct pnfs_layout_hdr * |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 810 | alloc_init_layout_hdr(struct inode *ino, |
| 811 | struct nfs_open_context *ctx, |
| 812 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 813 | { |
| 814 | struct pnfs_layout_hdr *lo; |
| 815 | |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 816 | lo = pnfs_alloc_layout_hdr(ino, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 817 | if (!lo) |
| 818 | return NULL; |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 819 | atomic_set(&lo->plh_refcount, 1); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 820 | INIT_LIST_HEAD(&lo->plh_layouts); |
| 821 | INIT_LIST_HEAD(&lo->plh_segs); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 822 | INIT_LIST_HEAD(&lo->plh_bulk_recall); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 823 | lo->plh_inode = ino; |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 824 | lo->plh_lc_cred = get_rpccred(ctx->state->owner->so_cred); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 825 | return lo; |
| 826 | } |
| 827 | |
| 828 | static struct pnfs_layout_hdr * |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 829 | pnfs_find_alloc_layout(struct inode *ino, |
| 830 | struct nfs_open_context *ctx, |
| 831 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 832 | { |
| 833 | struct nfs_inode *nfsi = NFS_I(ino); |
| 834 | struct pnfs_layout_hdr *new = NULL; |
| 835 | |
| 836 | dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout); |
| 837 | |
| 838 | assert_spin_locked(&ino->i_lock); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 839 | if (nfsi->layout) { |
| 840 | if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags)) |
| 841 | return NULL; |
| 842 | else |
| 843 | return nfsi->layout; |
| 844 | } |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 845 | spin_unlock(&ino->i_lock); |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 846 | new = alloc_init_layout_hdr(ino, ctx, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 847 | spin_lock(&ino->i_lock); |
| 848 | |
| 849 | if (likely(nfsi->layout == NULL)) /* Won the race? */ |
| 850 | nfsi->layout = new; |
| 851 | else |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 852 | pnfs_free_layout_hdr(new); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 853 | return nfsi->layout; |
| 854 | } |
| 855 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 856 | /* |
| 857 | * iomode matching rules: |
| 858 | * iomode lseg match |
| 859 | * ----- ----- ----- |
| 860 | * ANY READ true |
| 861 | * ANY RW true |
| 862 | * RW READ false |
| 863 | * RW RW true |
| 864 | * READ READ true |
| 865 | * READ RW true |
| 866 | */ |
| 867 | static int |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 868 | is_matching_lseg(struct pnfs_layout_range *ls_range, |
| 869 | struct pnfs_layout_range *range) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 870 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 871 | struct pnfs_layout_range range1; |
| 872 | |
| 873 | if ((range->iomode == IOMODE_RW && |
| 874 | ls_range->iomode != IOMODE_RW) || |
| 875 | !lo_seg_intersecting(ls_range, range)) |
| 876 | return 0; |
| 877 | |
| 878 | /* range1 covers only the first byte in the range */ |
| 879 | range1 = *range; |
| 880 | range1.length = 1; |
| 881 | return lo_seg_contained(ls_range, &range1); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /* |
| 885 | * lookup range in layout |
| 886 | */ |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 887 | static struct pnfs_layout_segment * |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 888 | pnfs_find_lseg(struct pnfs_layout_hdr *lo, |
| 889 | struct pnfs_layout_range *range) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 890 | { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 891 | struct pnfs_layout_segment *lseg, *ret = NULL; |
| 892 | |
| 893 | dprintk("%s:Begin\n", __func__); |
| 894 | |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 895 | assert_spin_locked(&lo->plh_inode->i_lock); |
| 896 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 897 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 898 | is_matching_lseg(&lseg->pls_range, range)) { |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 899 | ret = get_lseg(lseg); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 900 | break; |
| 901 | } |
Benny Halevy | d771e3a | 2011-06-14 16:30:16 -0400 | [diff] [blame] | 902 | if (lseg->pls_range.offset > range->offset) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 903 | break; |
| 904 | } |
| 905 | |
| 906 | dprintk("%s:Return lseg %p ref %d\n", |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 907 | __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 908 | return ret; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /* |
| 912 | * Layout segment is retreived from the server if not cached. |
| 913 | * The appropriate layout segment is referenced and returned to the caller. |
| 914 | */ |
| 915 | struct pnfs_layout_segment * |
| 916 | pnfs_update_layout(struct inode *ino, |
| 917 | struct nfs_open_context *ctx, |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 918 | loff_t pos, |
| 919 | u64 count, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 920 | enum pnfs_iomode iomode, |
| 921 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 922 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 923 | struct pnfs_layout_range arg = { |
| 924 | .iomode = iomode, |
| 925 | .offset = pos, |
| 926 | .length = count, |
| 927 | }; |
Benny Halevy | 707ed5f | 2011-05-22 19:47:46 +0300 | [diff] [blame] | 928 | unsigned pg_offset; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 929 | struct nfs_inode *nfsi = NFS_I(ino); |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 930 | struct nfs_client *clp = NFS_SERVER(ino)->nfs_client; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 931 | struct pnfs_layout_hdr *lo; |
| 932 | struct pnfs_layout_segment *lseg = NULL; |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 933 | bool first = false; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 934 | |
| 935 | if (!pnfs_enabled_sb(NFS_SERVER(ino))) |
| 936 | return NULL; |
| 937 | spin_lock(&ino->i_lock); |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 938 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 939 | if (lo == NULL) { |
| 940 | dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__); |
| 941 | goto out_unlock; |
| 942 | } |
| 943 | |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 944 | /* Do we even need to bother with this? */ |
| 945 | if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || |
| 946 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { |
| 947 | dprintk("%s matches recall, use MDS\n", __func__); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 948 | goto out_unlock; |
| 949 | } |
| 950 | |
| 951 | /* if LAYOUTGET already failed once we don't try again */ |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 952 | if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags)) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 953 | goto out_unlock; |
| 954 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 955 | /* Check to see if the layout for the given range already exists */ |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 956 | lseg = pnfs_find_lseg(lo, &arg); |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 957 | if (lseg) |
| 958 | goto out_unlock; |
| 959 | |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 960 | if (pnfs_layoutgets_blocked(lo, NULL, 0)) |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 961 | goto out_unlock; |
| 962 | atomic_inc(&lo->plh_outstanding); |
| 963 | |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 964 | get_layout_hdr(lo); |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 965 | if (list_empty(&lo->plh_segs)) |
| 966 | first = true; |
| 967 | spin_unlock(&ino->i_lock); |
| 968 | if (first) { |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 969 | /* The lo must be on the clp list if there is any |
| 970 | * chance of a CB_LAYOUTRECALL(FILE) coming in. |
| 971 | */ |
| 972 | spin_lock(&clp->cl_lock); |
| 973 | BUG_ON(!list_empty(&lo->plh_layouts)); |
| 974 | list_add_tail(&lo->plh_layouts, &clp->cl_layouts); |
| 975 | spin_unlock(&clp->cl_lock); |
| 976 | } |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 977 | |
Benny Halevy | 707ed5f | 2011-05-22 19:47:46 +0300 | [diff] [blame] | 978 | pg_offset = arg.offset & ~PAGE_CACHE_MASK; |
| 979 | if (pg_offset) { |
| 980 | arg.offset -= pg_offset; |
| 981 | arg.length += pg_offset; |
| 982 | } |
| 983 | arg.length = PAGE_CACHE_ALIGN(arg.length); |
| 984 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 985 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 986 | if (!lseg && first) { |
| 987 | spin_lock(&clp->cl_lock); |
| 988 | list_del_init(&lo->plh_layouts); |
| 989 | spin_unlock(&clp->cl_lock); |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 990 | } |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 991 | atomic_dec(&lo->plh_outstanding); |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 992 | put_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 993 | out: |
| 994 | dprintk("%s end, state 0x%lx lseg %p\n", __func__, |
Andy Adamson | bf9c138 | 2011-03-01 01:34:07 +0000 | [diff] [blame] | 995 | nfsi->layout ? nfsi->layout->plh_flags : -1, lseg); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 996 | return lseg; |
| 997 | out_unlock: |
| 998 | spin_unlock(&ino->i_lock); |
| 999 | goto out; |
| 1000 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1001 | |
| 1002 | int |
| 1003 | pnfs_layout_process(struct nfs4_layoutget *lgp) |
| 1004 | { |
| 1005 | struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout; |
| 1006 | struct nfs4_layoutget_res *res = &lgp->res; |
| 1007 | struct pnfs_layout_segment *lseg; |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 1008 | struct inode *ino = lo->plh_inode; |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1009 | struct nfs_client *clp = NFS_SERVER(ino)->nfs_client; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1010 | int status = 0; |
| 1011 | |
| 1012 | /* Inject layout blob into I/O device driver */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 1013 | lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1014 | if (!lseg || IS_ERR(lseg)) { |
| 1015 | if (!lseg) |
| 1016 | status = -ENOMEM; |
| 1017 | else |
| 1018 | status = PTR_ERR(lseg); |
| 1019 | dprintk("%s: Could not allocate layout: error %d\n", |
| 1020 | __func__, status); |
| 1021 | goto out; |
| 1022 | } |
| 1023 | |
| 1024 | spin_lock(&ino->i_lock); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1025 | if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || |
| 1026 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { |
| 1027 | dprintk("%s forget reply due to recall\n", __func__); |
| 1028 | goto out_forget_reply; |
| 1029 | } |
| 1030 | |
| 1031 | if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) { |
| 1032 | dprintk("%s forget reply due to state\n", __func__); |
| 1033 | goto out_forget_reply; |
| 1034 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1035 | init_lseg(lo, lseg); |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 1036 | lseg->pls_range = res->range; |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 1037 | *lgp->lsegpp = get_lseg(lseg); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1038 | pnfs_insert_layout(lo, lseg); |
| 1039 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1040 | if (res->return_on_close) { |
| 1041 | set_bit(NFS_LSEG_ROC, &lseg->pls_flags); |
| 1042 | set_bit(NFS_LAYOUT_ROC, &lo->plh_flags); |
| 1043 | } |
| 1044 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1045 | /* Done processing layoutget. Set the layout stateid */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1046 | pnfs_set_layout_stateid(lo, &res->stateid, false); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1047 | spin_unlock(&ino->i_lock); |
| 1048 | out: |
| 1049 | return status; |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1050 | |
| 1051 | out_forget_reply: |
| 1052 | spin_unlock(&ino->i_lock); |
| 1053 | lseg->pls_layout = lo; |
| 1054 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); |
| 1055 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
Benny Halevy | 18ad0a9 | 2011-05-25 21:03:56 +0300 | [diff] [blame] | 1058 | bool |
Benny Halevy | dfed206 | 2011-05-25 20:25:22 +0300 | [diff] [blame] | 1059 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 1060 | struct nfs_page *req) |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1061 | { |
Benny Halevy | dfed206 | 2011-05-25 20:25:22 +0300 | [diff] [blame] | 1062 | enum pnfs_iomode access_type; |
| 1063 | gfp_t gfp_flags; |
| 1064 | |
| 1065 | /* We assume that pg_ioflags == 0 iff we're reading a page */ |
| 1066 | if (pgio->pg_ioflags == 0) { |
| 1067 | access_type = IOMODE_READ; |
| 1068 | gfp_flags = GFP_KERNEL; |
| 1069 | } else { |
| 1070 | access_type = IOMODE_RW; |
| 1071 | gfp_flags = GFP_NOFS; |
| 1072 | } |
| 1073 | |
Trond Myklebust | 8f7d5ef | 2011-06-10 13:30:22 -0400 | [diff] [blame] | 1074 | if (pgio->pg_lseg == NULL) { |
| 1075 | if (pgio->pg_count != prev->wb_bytes) |
| 1076 | return true; |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1077 | /* This is first coelesce call for a series of nfs_pages */ |
| 1078 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 1079 | prev->wb_context, |
Trond Myklebust | 8f7d5ef | 2011-06-10 13:30:22 -0400 | [diff] [blame] | 1080 | req_offset(prev), |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 1081 | pgio->pg_count, |
Benny Halevy | dfed206 | 2011-05-25 20:25:22 +0300 | [diff] [blame] | 1082 | access_type, |
| 1083 | gfp_flags); |
Trond Myklebust | 8f7d5ef | 2011-06-10 13:30:22 -0400 | [diff] [blame] | 1084 | if (pgio->pg_lseg == NULL) |
| 1085 | return true; |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1086 | } |
Benny Halevy | 89a58e3 | 2011-05-25 20:54:40 +0300 | [diff] [blame] | 1087 | |
Trond Myklebust | 19982ba | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1088 | /* |
| 1089 | * Test if a nfs_page is fully contained in the pnfs_layout_range. |
| 1090 | * Note that this test makes several assumptions: |
| 1091 | * - that the previous nfs_page in the struct nfs_pageio_descriptor |
| 1092 | * is known to lie within the range. |
| 1093 | * - that the nfs_page being tested is known to be contiguous with the |
| 1094 | * previous nfs_page. |
| 1095 | * - Layout ranges are page aligned, so we only have to test the |
| 1096 | * start offset of the request. |
| 1097 | * |
| 1098 | * Please also note that 'end_offset' is actually the offset of the |
| 1099 | * first byte that lies outside the pnfs_layout_range. FIXME? |
| 1100 | * |
| 1101 | */ |
| 1102 | return req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset, |
| 1103 | pgio->pg_lseg->pls_range.length); |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1104 | } |
Benny Halevy | 89a58e3 | 2011-05-25 20:54:40 +0300 | [diff] [blame] | 1105 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_test); |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1106 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1107 | /* |
| 1108 | * Called by non rpc-based layout drivers |
| 1109 | */ |
| 1110 | int |
| 1111 | pnfs_ld_write_done(struct nfs_write_data *data) |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 1112 | { |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1113 | int status; |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 1114 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1115 | if (!data->pnfs_error) { |
| 1116 | pnfs_set_layoutcommit(data); |
| 1117 | data->mds_ops->rpc_call_done(&data->task, data); |
| 1118 | data->mds_ops->rpc_release(data); |
| 1119 | return 0; |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1120 | } |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1121 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1122 | dprintk("%s: pnfs_error=%d, retry via MDS\n", __func__, |
| 1123 | data->pnfs_error); |
| 1124 | status = nfs_initiate_write(data, NFS_CLIENT(data->inode), |
| 1125 | data->mds_ops, NFS_FILE_SYNC); |
| 1126 | return status ? : -EAGAIN; |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1127 | } |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1128 | EXPORT_SYMBOL_GPL(pnfs_ld_write_done); |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1129 | |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1130 | enum pnfs_try_status |
| 1131 | pnfs_try_to_write_data(struct nfs_write_data *wdata, |
| 1132 | const struct rpc_call_ops *call_ops, int how) |
| 1133 | { |
| 1134 | struct inode *inode = wdata->inode; |
| 1135 | enum pnfs_try_status trypnfs; |
| 1136 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 1137 | |
| 1138 | wdata->mds_ops = call_ops; |
| 1139 | |
| 1140 | dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__, |
| 1141 | inode->i_ino, wdata->args.count, wdata->args.offset, how); |
| 1142 | |
| 1143 | trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how); |
| 1144 | if (trypnfs == PNFS_NOT_ATTEMPTED) { |
| 1145 | put_lseg(wdata->lseg); |
| 1146 | wdata->lseg = NULL; |
| 1147 | } else |
| 1148 | nfs_inc_stats(inode, NFSIOS_PNFS_WRITE); |
| 1149 | |
| 1150 | dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs); |
| 1151 | return trypnfs; |
| 1152 | } |
| 1153 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1154 | /* |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1155 | * Called by non rpc-based layout drivers |
| 1156 | */ |
| 1157 | int |
| 1158 | pnfs_ld_read_done(struct nfs_read_data *data) |
| 1159 | { |
| 1160 | int status; |
| 1161 | |
| 1162 | if (!data->pnfs_error) { |
| 1163 | __nfs4_read_done_cb(data); |
| 1164 | data->mds_ops->rpc_call_done(&data->task, data); |
| 1165 | data->mds_ops->rpc_release(data); |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | dprintk("%s: pnfs_error=%d, retry via MDS\n", __func__, |
| 1170 | data->pnfs_error); |
| 1171 | status = nfs_initiate_read(data, NFS_CLIENT(data->inode), |
| 1172 | data->mds_ops); |
| 1173 | return status ? : -EAGAIN; |
| 1174 | } |
| 1175 | EXPORT_SYMBOL_GPL(pnfs_ld_read_done); |
| 1176 | |
| 1177 | /* |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1178 | * Call the appropriate parallel I/O subsystem read function. |
| 1179 | */ |
| 1180 | enum pnfs_try_status |
| 1181 | pnfs_try_to_read_data(struct nfs_read_data *rdata, |
| 1182 | const struct rpc_call_ops *call_ops) |
| 1183 | { |
| 1184 | struct inode *inode = rdata->inode; |
| 1185 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 1186 | enum pnfs_try_status trypnfs; |
| 1187 | |
| 1188 | rdata->mds_ops = call_ops; |
| 1189 | |
| 1190 | dprintk("%s: Reading ino:%lu %u@%llu\n", |
| 1191 | __func__, inode->i_ino, rdata->args.count, rdata->args.offset); |
| 1192 | |
| 1193 | trypnfs = nfss->pnfs_curr_ld->read_pagelist(rdata); |
| 1194 | if (trypnfs == PNFS_NOT_ATTEMPTED) { |
| 1195 | put_lseg(rdata->lseg); |
| 1196 | rdata->lseg = NULL; |
| 1197 | } else { |
| 1198 | nfs_inc_stats(inode, NFSIOS_PNFS_READ); |
| 1199 | } |
| 1200 | dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs); |
| 1201 | return trypnfs; |
| 1202 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1205 | * There can be multiple RW segments. |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1206 | */ |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1207 | static void pnfs_list_write_lseg(struct inode *inode, struct list_head *listp) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1208 | { |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1209 | struct pnfs_layout_segment *lseg; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1210 | |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1211 | list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) { |
| 1212 | if (lseg->pls_range.iomode == IOMODE_RW && |
| 1213 | test_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags)) |
| 1214 | list_add(&lseg->pls_lc_list, listp); |
| 1215 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | void |
| 1219 | pnfs_set_layoutcommit(struct nfs_write_data *wdata) |
| 1220 | { |
| 1221 | struct nfs_inode *nfsi = NFS_I(wdata->inode); |
Vitaliy Gusev | 4b8ee2b | 2011-05-20 01:34:46 +0400 | [diff] [blame] | 1222 | loff_t end_pos = wdata->mds_offset + wdata->res.count; |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1223 | bool mark_as_dirty = false; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1224 | |
| 1225 | spin_lock(&nfsi->vfs_inode.i_lock); |
| 1226 | if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1227 | mark_as_dirty = true; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1228 | dprintk("%s: Set layoutcommit for inode %lu ", |
| 1229 | __func__, wdata->inode->i_ino); |
| 1230 | } |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1231 | if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &wdata->lseg->pls_flags)) { |
| 1232 | /* references matched in nfs4_layoutcommit_release */ |
| 1233 | get_lseg(wdata->lseg); |
| 1234 | } |
Peng Tao | a14f191 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1235 | if (end_pos > nfsi->layout->plh_lwb) |
| 1236 | nfsi->layout->plh_lwb = end_pos; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1237 | spin_unlock(&nfsi->vfs_inode.i_lock); |
Peng Tao | a14f191 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1238 | dprintk("%s: lseg %p end_pos %llu\n", |
| 1239 | __func__, wdata->lseg, nfsi->layout->plh_lwb); |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1240 | |
| 1241 | /* if pnfs_layoutcommit_inode() runs between inode locks, the next one |
| 1242 | * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */ |
| 1243 | if (mark_as_dirty) |
| 1244 | mark_inode_dirty_sync(wdata->inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1245 | } |
| 1246 | EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit); |
| 1247 | |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1248 | /* |
| 1249 | * For the LAYOUT4_NFSV4_1_FILES layout type, NFS_DATA_SYNC WRITEs and |
| 1250 | * NFS_UNSTABLE WRITEs with a COMMIT to data servers must store enough |
| 1251 | * data to disk to allow the server to recover the data if it crashes. |
| 1252 | * LAYOUTCOMMIT is only needed when the NFL4_UFLG_COMMIT_THRU_MDS flag |
| 1253 | * is off, and a COMMIT is sent to a data server, or |
| 1254 | * if WRITEs to a data server return NFS_DATA_SYNC. |
| 1255 | */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1256 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 1257 | pnfs_layoutcommit_inode(struct inode *inode, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1258 | { |
| 1259 | struct nfs4_layoutcommit_data *data; |
| 1260 | struct nfs_inode *nfsi = NFS_I(inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1261 | loff_t end_pos; |
| 1262 | int status = 0; |
| 1263 | |
| 1264 | dprintk("--> %s inode %lu\n", __func__, inode->i_ino); |
| 1265 | |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1266 | if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) |
| 1267 | return 0; |
| 1268 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1269 | /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */ |
| 1270 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1271 | if (!data) { |
| 1272 | mark_inode_dirty_sync(inode); |
| 1273 | status = -ENOMEM; |
| 1274 | goto out; |
| 1275 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1276 | |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1277 | INIT_LIST_HEAD(&data->lseg_list); |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1278 | spin_lock(&inode->i_lock); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1279 | if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { |
| 1280 | spin_unlock(&inode->i_lock); |
| 1281 | kfree(data); |
| 1282 | goto out; |
| 1283 | } |
Peng Tao | 892cd4a | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1284 | |
| 1285 | pnfs_list_write_lseg(inode, &data->lseg_list); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1286 | |
Peng Tao | a14f191 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1287 | end_pos = nfsi->layout->plh_lwb; |
Peng Tao | a14f191 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1288 | nfsi->layout->plh_lwb = 0; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1289 | |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1290 | memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data, |
| 1291 | sizeof(nfsi->layout->plh_stateid.data)); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1292 | spin_unlock(&inode->i_lock); |
| 1293 | |
| 1294 | data->args.inode = inode; |
Peng Tao | f45c1d4 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 1295 | data->cred = get_rpccred(nfsi->layout->plh_lc_cred); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1296 | nfs_fattr_init(&data->fattr); |
| 1297 | data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 1298 | data->res.fattr = &data->fattr; |
| 1299 | data->args.lastbytewritten = end_pos - 1; |
| 1300 | data->res.server = NFS_SERVER(inode); |
| 1301 | |
| 1302 | status = nfs4_proc_layoutcommit(data, sync); |
| 1303 | out: |
| 1304 | dprintk("<-- %s status %d\n", __func__, status); |
| 1305 | return status; |
| 1306 | } |