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> |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 31 | #include <linux/nfs_page.h> |
Paul Gortmaker | 143cb49 | 2011-07-01 14:23:34 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 33 | #include "internal.h" |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 34 | #include "pnfs.h" |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 35 | #include "iostat.h" |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 36 | |
| 37 | #define NFSDBG_FACILITY NFSDBG_PNFS |
| 38 | |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 39 | /* Locking: |
| 40 | * |
| 41 | * pnfs_spinlock: |
| 42 | * protects pnfs_modules_tbl. |
| 43 | */ |
| 44 | static DEFINE_SPINLOCK(pnfs_spinlock); |
| 45 | |
| 46 | /* |
| 47 | * pnfs_modules_tbl holds all pnfs modules |
| 48 | */ |
| 49 | static LIST_HEAD(pnfs_modules_tbl); |
| 50 | |
| 51 | /* Return the registered pnfs layout driver module matching given id */ |
| 52 | static struct pnfs_layoutdriver_type * |
| 53 | find_pnfs_driver_locked(u32 id) |
| 54 | { |
| 55 | struct pnfs_layoutdriver_type *local; |
| 56 | |
| 57 | list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid) |
| 58 | if (local->id == id) |
| 59 | goto out; |
| 60 | local = NULL; |
| 61 | out: |
| 62 | dprintk("%s: Searching for id %u, found %p\n", __func__, id, local); |
| 63 | return local; |
| 64 | } |
| 65 | |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 66 | static struct pnfs_layoutdriver_type * |
| 67 | find_pnfs_driver(u32 id) |
| 68 | { |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 69 | struct pnfs_layoutdriver_type *local; |
| 70 | |
| 71 | spin_lock(&pnfs_spinlock); |
| 72 | local = find_pnfs_driver_locked(id); |
Trond Myklebust | 0a9c63f | 2012-06-15 13:02:58 -0400 | [diff] [blame] | 73 | if (local != NULL && !try_module_get(local->owner)) { |
| 74 | dprintk("%s: Could not grab reference on module\n", __func__); |
| 75 | local = NULL; |
| 76 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 77 | spin_unlock(&pnfs_spinlock); |
| 78 | return local; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
| 82 | unset_pnfs_layoutdriver(struct nfs_server *nfss) |
| 83 | { |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 84 | if (nfss->pnfs_curr_ld) { |
| 85 | if (nfss->pnfs_curr_ld->clear_layoutdriver) |
| 86 | nfss->pnfs_curr_ld->clear_layoutdriver(nfss); |
Trond Myklebust | 2a4c899 | 2012-06-14 13:08:38 -0400 | [diff] [blame] | 87 | /* Decrement the MDS count. Purge the deviceid cache if zero */ |
| 88 | if (atomic_dec_and_test(&nfss->nfs_client->cl_mds_count)) |
| 89 | nfs4_deviceid_purge_client(nfss->nfs_client); |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 90 | module_put(nfss->pnfs_curr_ld->owner); |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 91 | } |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 92 | nfss->pnfs_curr_ld = NULL; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Try to set the server's pnfs module to the pnfs layout type specified by id. |
| 97 | * Currently only one pNFS layout driver per filesystem is supported. |
| 98 | * |
| 99 | * @id layout type. Zero (illegal layout type) indicates pNFS not in use. |
| 100 | */ |
| 101 | void |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 102 | set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh, |
| 103 | u32 id) |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 104 | { |
| 105 | struct pnfs_layoutdriver_type *ld_type = NULL; |
| 106 | |
| 107 | if (id == 0) |
| 108 | goto out_no_driver; |
| 109 | if (!(server->nfs_client->cl_exchange_flags & |
| 110 | (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 111 | printk(KERN_ERR "NFS: %s: id %u cl_exchange_flags 0x%x\n", |
| 112 | __func__, id, server->nfs_client->cl_exchange_flags); |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 113 | goto out_no_driver; |
| 114 | } |
| 115 | ld_type = find_pnfs_driver(id); |
| 116 | if (!ld_type) { |
| 117 | request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id); |
| 118 | ld_type = find_pnfs_driver(id); |
| 119 | if (!ld_type) { |
| 120 | dprintk("%s: No pNFS module found for %u.\n", |
| 121 | __func__, id); |
| 122 | goto out_no_driver; |
| 123 | } |
| 124 | } |
| 125 | server->pnfs_curr_ld = ld_type; |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 126 | if (ld_type->set_layoutdriver |
| 127 | && ld_type->set_layoutdriver(server, mntfh)) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 128 | printk(KERN_ERR "NFS: %s: Error initializing pNFS layout " |
| 129 | "driver %u.\n", __func__, id); |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 130 | module_put(ld_type->owner); |
| 131 | goto out_no_driver; |
| 132 | } |
Trond Myklebust | 2a4c899 | 2012-06-14 13:08:38 -0400 | [diff] [blame] | 133 | /* Bump the MDS count */ |
| 134 | atomic_inc(&server->nfs_client->cl_mds_count); |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 135 | |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 136 | dprintk("%s: pNFS module for %u set\n", __func__, id); |
| 137 | return; |
| 138 | |
| 139 | out_no_driver: |
| 140 | dprintk("%s: Using NFSv4 I/O\n", __func__); |
| 141 | server->pnfs_curr_ld = NULL; |
| 142 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 143 | |
| 144 | int |
| 145 | pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type) |
| 146 | { |
| 147 | int status = -EINVAL; |
| 148 | struct pnfs_layoutdriver_type *tmp; |
| 149 | |
| 150 | if (ld_type->id == 0) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 151 | printk(KERN_ERR "NFS: %s id 0 is reserved\n", __func__); |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 152 | return status; |
| 153 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 154 | if (!ld_type->alloc_lseg || !ld_type->free_lseg) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 155 | printk(KERN_ERR "NFS: %s Layout driver must provide " |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 156 | "alloc_lseg and free_lseg.\n", __func__); |
| 157 | return status; |
| 158 | } |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 159 | |
| 160 | spin_lock(&pnfs_spinlock); |
| 161 | tmp = find_pnfs_driver_locked(ld_type->id); |
| 162 | if (!tmp) { |
| 163 | list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl); |
| 164 | status = 0; |
| 165 | dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id, |
| 166 | ld_type->name); |
| 167 | } else { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 168 | printk(KERN_ERR "NFS: %s Module with id %d already loaded!\n", |
Fred Isaman | 02c35fc | 2010-10-20 00:17:59 -0400 | [diff] [blame] | 169 | __func__, ld_type->id); |
| 170 | } |
| 171 | spin_unlock(&pnfs_spinlock); |
| 172 | |
| 173 | return status; |
| 174 | } |
| 175 | EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver); |
| 176 | |
| 177 | void |
| 178 | pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type) |
| 179 | { |
| 180 | dprintk("%s Deregistering id:%u\n", __func__, ld_type->id); |
| 181 | spin_lock(&pnfs_spinlock); |
| 182 | list_del(&ld_type->pnfs_tblid); |
| 183 | spin_unlock(&pnfs_spinlock); |
| 184 | } |
| 185 | EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 186 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 187 | /* |
| 188 | * pNFS client layout cache |
| 189 | */ |
| 190 | |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 191 | /* Need to hold i_lock if caller does not already hold reference */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 192 | void |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 193 | pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 194 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 195 | atomic_inc(&lo->plh_refcount); |
| 196 | } |
| 197 | |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 198 | static struct pnfs_layout_hdr * |
| 199 | pnfs_alloc_layout_hdr(struct inode *ino, gfp_t gfp_flags) |
| 200 | { |
| 201 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld; |
| 202 | return ld->alloc_layout_hdr ? ld->alloc_layout_hdr(ino, gfp_flags) : |
| 203 | kzalloc(sizeof(struct pnfs_layout_hdr), gfp_flags); |
| 204 | } |
| 205 | |
| 206 | static void |
| 207 | pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo) |
| 208 | { |
| 209 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(lo->plh_inode)->pnfs_curr_ld; |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 210 | put_rpccred(lo->plh_lc_cred); |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 211 | return ld->alloc_layout_hdr ? ld->free_layout_hdr(lo) : kfree(lo); |
| 212 | } |
| 213 | |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 214 | static void |
| 215 | destroy_layout_hdr(struct pnfs_layout_hdr *lo) |
| 216 | { |
| 217 | dprintk("%s: freeing layout cache %p\n", __func__, lo); |
| 218 | BUG_ON(!list_empty(&lo->plh_layouts)); |
| 219 | NFS_I(lo->plh_inode)->layout = NULL; |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 220 | pnfs_free_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 224 | pnfs_put_layout_hdr_locked(struct pnfs_layout_hdr *lo) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 225 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 226 | if (atomic_dec_and_test(&lo->plh_refcount)) |
| 227 | destroy_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 230 | void |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 231 | pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 232 | { |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 233 | struct inode *inode = lo->plh_inode; |
| 234 | |
| 235 | if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { |
| 236 | destroy_layout_hdr(lo); |
| 237 | spin_unlock(&inode->i_lock); |
| 238 | } |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void |
| 242 | init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg) |
| 243 | { |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 244 | INIT_LIST_HEAD(&lseg->pls_list); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 245 | INIT_LIST_HEAD(&lseg->pls_lc_list); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 246 | atomic_set(&lseg->pls_refcount, 1); |
| 247 | smp_mb(); |
| 248 | set_bit(NFS_LSEG_VALID, &lseg->pls_flags); |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 249 | lseg->pls_layout = lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 252 | static void free_lseg(struct pnfs_layout_segment *lseg) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 253 | { |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 254 | struct inode *ino = lseg->pls_layout->plh_inode; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 255 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 256 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 257 | /* Matched by pnfs_get_layout_hdr in pnfs_insert_layout */ |
| 258 | pnfs_put_layout_hdr(NFS_I(ino)->layout); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 259 | } |
| 260 | |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 261 | static void |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 262 | pnfs_put_lseg_common(struct pnfs_layout_segment *lseg) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 263 | { |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 264 | struct inode *inode = lseg->pls_layout->plh_inode; |
| 265 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 266 | WARN_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 267 | list_del_init(&lseg->pls_list); |
| 268 | if (list_empty(&lseg->pls_layout->plh_segs)) { |
| 269 | set_bit(NFS_LAYOUT_DESTROYED, &lseg->pls_layout->plh_flags); |
| 270 | /* Matched by initial refcount set in alloc_init_layout_hdr */ |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 271 | pnfs_put_layout_hdr_locked(lseg->pls_layout); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 272 | } |
| 273 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); |
| 274 | } |
| 275 | |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 276 | void |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 277 | pnfs_put_lseg(struct pnfs_layout_segment *lseg) |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 278 | { |
| 279 | struct inode *inode; |
| 280 | |
| 281 | if (!lseg) |
| 282 | return; |
| 283 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 284 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, |
| 285 | atomic_read(&lseg->pls_refcount), |
| 286 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 287 | inode = lseg->pls_layout->plh_inode; |
| 288 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { |
| 289 | LIST_HEAD(free_me); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 290 | |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 291 | pnfs_put_lseg_common(lseg); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 292 | list_add(&lseg->pls_list, &free_me); |
| 293 | spin_unlock(&inode->i_lock); |
| 294 | pnfs_free_lseg_list(&free_me); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 295 | } |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 296 | } |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 297 | EXPORT_SYMBOL_GPL(pnfs_put_lseg); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 298 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 299 | static inline u64 |
| 300 | end_offset(u64 start, u64 len) |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 301 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 302 | u64 end; |
| 303 | |
| 304 | end = start + len; |
| 305 | return end >= start ? end : NFS4_MAX_UINT64; |
| 306 | } |
| 307 | |
| 308 | /* last octet in a range */ |
| 309 | static inline u64 |
| 310 | last_byte_offset(u64 start, u64 len) |
| 311 | { |
| 312 | u64 end; |
| 313 | |
| 314 | BUG_ON(!len); |
| 315 | end = start + len; |
| 316 | return end > start ? end - 1 : NFS4_MAX_UINT64; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * is l2 fully contained in l1? |
| 321 | * start1 end1 |
| 322 | * [----------------------------------) |
| 323 | * start2 end2 |
| 324 | * [----------------) |
| 325 | */ |
| 326 | static inline int |
| 327 | lo_seg_contained(struct pnfs_layout_range *l1, |
| 328 | struct pnfs_layout_range *l2) |
| 329 | { |
| 330 | u64 start1 = l1->offset; |
| 331 | u64 end1 = end_offset(start1, l1->length); |
| 332 | u64 start2 = l2->offset; |
| 333 | u64 end2 = end_offset(start2, l2->length); |
| 334 | |
| 335 | return (start1 <= start2) && (end1 >= end2); |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * is l1 and l2 intersecting? |
| 340 | * start1 end1 |
| 341 | * [----------------------------------) |
| 342 | * start2 end2 |
| 343 | * [----------------) |
| 344 | */ |
| 345 | static inline int |
| 346 | lo_seg_intersecting(struct pnfs_layout_range *l1, |
| 347 | struct pnfs_layout_range *l2) |
| 348 | { |
| 349 | u64 start1 = l1->offset; |
| 350 | u64 end1 = end_offset(start1, l1->length); |
| 351 | u64 start2 = l2->offset; |
| 352 | u64 end2 = end_offset(start2, l2->length); |
| 353 | |
| 354 | return (end1 == NFS4_MAX_UINT64 || end1 > start2) && |
| 355 | (end2 == NFS4_MAX_UINT64 || end2 > start1); |
| 356 | } |
| 357 | |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 358 | static bool |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 359 | should_free_lseg(struct pnfs_layout_range *lseg_range, |
| 360 | struct pnfs_layout_range *recall_range) |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 361 | { |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 362 | return (recall_range->iomode == IOMODE_ANY || |
| 363 | lseg_range->iomode == recall_range->iomode) && |
| 364 | lo_seg_intersecting(lseg_range, recall_range); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* Returns 1 if lseg is removed from list, 0 otherwise */ |
| 368 | static int mark_lseg_invalid(struct pnfs_layout_segment *lseg, |
| 369 | struct list_head *tmp_list) |
| 370 | { |
| 371 | int rv = 0; |
| 372 | |
| 373 | if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) { |
| 374 | /* Remove the reference keeping the lseg in the |
| 375 | * list. It will now be removed when all |
| 376 | * outstanding io is finished. |
| 377 | */ |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 378 | dprintk("%s: lseg %p ref %d\n", __func__, lseg, |
| 379 | atomic_read(&lseg->pls_refcount)); |
| 380 | if (atomic_dec_and_test(&lseg->pls_refcount)) { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 381 | pnfs_put_lseg_common(lseg); |
Fred Isaman | d684d2a | 2011-03-01 01:34:13 +0000 | [diff] [blame] | 382 | list_add(&lseg->pls_list, tmp_list); |
| 383 | rv = 1; |
| 384 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 385 | } |
| 386 | return rv; |
| 387 | } |
| 388 | |
| 389 | /* Returns count of number of matching invalid lsegs remaining in list |
| 390 | * after call. |
| 391 | */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 392 | int |
Trond Myklebust | 49a8506 | 2012-09-18 20:43:31 -0400 | [diff] [blame] | 393 | pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 394 | struct list_head *tmp_list, |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 395 | struct pnfs_layout_range *recall_range) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 396 | { |
| 397 | struct pnfs_layout_segment *lseg, *next; |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 398 | int invalid = 0, removed = 0; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 399 | |
| 400 | dprintk("%s:Begin lo %p\n", __func__, lo); |
| 401 | |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 402 | if (list_empty(&lo->plh_segs)) { |
Andy Adamson | 2701d08 | 2012-05-24 13:13:24 -0400 | [diff] [blame] | 403 | /* Reset MDS Threshold I/O counters */ |
| 404 | NFS_I(lo->plh_inode)->write_io = 0; |
| 405 | NFS_I(lo->plh_inode)->read_io = 0; |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 406 | if (!test_and_set_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 407 | pnfs_put_layout_hdr_locked(lo); |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 408 | return 0; |
| 409 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 410 | list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) |
Benny Halevy | 778b550 | 2011-05-22 19:48:02 +0300 | [diff] [blame] | 411 | if (!recall_range || |
| 412 | should_free_lseg(&lseg->pls_range, recall_range)) { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 413 | dprintk("%s: freeing lseg %p iomode %d " |
| 414 | "offset %llu length %llu\n", __func__, |
| 415 | lseg, lseg->pls_range.iomode, lseg->pls_range.offset, |
| 416 | lseg->pls_range.length); |
| 417 | invalid++; |
| 418 | removed += mark_lseg_invalid(lseg, tmp_list); |
| 419 | } |
| 420 | dprintk("%s:Return %i\n", __func__, invalid - removed); |
| 421 | return invalid - removed; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 422 | } |
| 423 | |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 424 | /* note free_me must contain lsegs from a single layout_hdr */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 425 | void |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 426 | pnfs_free_lseg_list(struct list_head *free_me) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 427 | { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 428 | struct pnfs_layout_segment *lseg, *tmp; |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 429 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 430 | |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 431 | if (list_empty(free_me)) |
| 432 | return; |
| 433 | |
| 434 | lo = list_first_entry(free_me, struct pnfs_layout_segment, |
| 435 | pls_list)->pls_layout; |
| 436 | |
| 437 | if (test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) { |
| 438 | struct nfs_client *clp; |
| 439 | |
| 440 | clp = NFS_SERVER(lo->plh_inode)->nfs_client; |
| 441 | spin_lock(&clp->cl_lock); |
| 442 | list_del_init(&lo->plh_layouts); |
| 443 | spin_unlock(&clp->cl_lock); |
| 444 | } |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 445 | list_for_each_entry_safe(lseg, tmp, free_me, pls_list) { |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 446 | list_del(&lseg->pls_list); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 447 | free_lseg(lseg); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 451 | void |
| 452 | pnfs_destroy_layout(struct nfs_inode *nfsi) |
| 453 | { |
| 454 | struct pnfs_layout_hdr *lo; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 455 | LIST_HEAD(tmp_list); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 456 | |
| 457 | spin_lock(&nfsi->vfs_inode.i_lock); |
| 458 | lo = nfsi->layout; |
| 459 | if (lo) { |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 460 | lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */ |
Trond Myklebust | 49a8506 | 2012-09-18 20:43:31 -0400 | [diff] [blame] | 461 | pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 462 | } |
| 463 | spin_unlock(&nfsi->vfs_inode.i_lock); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 464 | pnfs_free_lseg_list(&tmp_list); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 465 | } |
Andy Adamson | 041245c | 2012-04-27 17:53:53 -0400 | [diff] [blame] | 466 | EXPORT_SYMBOL_GPL(pnfs_destroy_layout); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 467 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 468 | /* |
| 469 | * Called by the state manger to remove all layouts established under an |
| 470 | * expired lease. |
| 471 | */ |
| 472 | void |
| 473 | pnfs_destroy_all_layouts(struct nfs_client *clp) |
| 474 | { |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 475 | struct nfs_server *server; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 476 | struct pnfs_layout_hdr *lo; |
| 477 | LIST_HEAD(tmp_list); |
| 478 | |
Andy Adamson | c47abcf | 2011-06-15 17:52:40 -0400 | [diff] [blame] | 479 | nfs4_deviceid_mark_client_invalid(clp); |
| 480 | nfs4_deviceid_purge_client(clp); |
| 481 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 482 | spin_lock(&clp->cl_lock); |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 483 | rcu_read_lock(); |
| 484 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
| 485 | if (!list_empty(&server->layouts)) |
| 486 | list_splice_init(&server->layouts, &tmp_list); |
| 487 | } |
| 488 | rcu_read_unlock(); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 489 | spin_unlock(&clp->cl_lock); |
| 490 | |
| 491 | while (!list_empty(&tmp_list)) { |
| 492 | lo = list_entry(tmp_list.next, struct pnfs_layout_hdr, |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 493 | plh_layouts); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 494 | dprintk("%s freeing layout for inode %lu\n", __func__, |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 495 | lo->plh_inode->i_ino); |
Andy Adamson | 2887fe4 | 2011-05-11 01:19:58 -0400 | [diff] [blame] | 496 | list_del_init(&lo->plh_layouts); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 497 | pnfs_destroy_layout(NFS_I(lo->plh_inode)); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 501 | /* update lo->plh_stateid with new if is more recent */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 502 | void |
| 503 | pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new, |
| 504 | bool update_barrier) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 505 | { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 506 | u32 oldseq, newseq; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 507 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 508 | oldseq = be32_to_cpu(lo->plh_stateid.seqid); |
| 509 | newseq = be32_to_cpu(new->seqid); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 510 | if ((int)(newseq - oldseq) > 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 511 | nfs4_stateid_copy(&lo->plh_stateid, new); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 512 | if (update_barrier) { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 513 | u32 new_barrier = be32_to_cpu(new->seqid); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 514 | |
| 515 | if ((int)(new_barrier - lo->plh_barrier)) |
| 516 | lo->plh_barrier = new_barrier; |
| 517 | } else { |
| 518 | /* Because of wraparound, we want to keep the barrier |
| 519 | * "close" to the current seqids. It needs to be |
| 520 | * within 2**31 to count as "behind", so if it |
| 521 | * gets too near that limit, give us a litle leeway |
| 522 | * and bring it to within 2**30. |
| 523 | * NOTE - and yes, this is all unsigned arithmetic. |
| 524 | */ |
| 525 | if (unlikely((newseq - lo->plh_barrier) > (3 << 29))) |
| 526 | lo->plh_barrier = newseq - (1 << 30); |
| 527 | } |
| 528 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 531 | /* lget is set to 1 if called from inside send_layoutget call chain */ |
| 532 | static bool |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 533 | pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid, |
| 534 | int lget) |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 535 | { |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 536 | if ((stateid) && |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 537 | (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0) |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 538 | return true; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 539 | return lo->plh_block_lgets || |
Fred Isaman | 3851172 | 2011-02-03 18:28:50 +0000 | [diff] [blame] | 540 | test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) || |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 541 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 542 | (list_empty(&lo->plh_segs) && |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 543 | (atomic_read(&lo->plh_outstanding) > lget)); |
| 544 | } |
| 545 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 546 | int |
| 547 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, |
| 548 | struct nfs4_state *open_state) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 549 | { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 550 | int status = 0; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 551 | |
| 552 | dprintk("--> %s\n", __func__); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 553 | spin_lock(&lo->plh_inode->i_lock); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 554 | if (pnfs_layoutgets_blocked(lo, NULL, 1)) { |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 555 | status = -EAGAIN; |
| 556 | } else if (list_empty(&lo->plh_segs)) { |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 557 | int seq; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 558 | |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 559 | do { |
| 560 | seq = read_seqbegin(&open_state->seqlock); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 561 | nfs4_stateid_copy(dst, &open_state->stateid); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 562 | } while (read_seqretry(&open_state->seqlock, seq)); |
| 563 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 564 | nfs4_stateid_copy(dst, &lo->plh_stateid); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 565 | spin_unlock(&lo->plh_inode->i_lock); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 566 | dprintk("<-- %s\n", __func__); |
Fred Isaman | fd6002e | 2011-01-06 11:36:22 +0000 | [diff] [blame] | 567 | return status; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Get layout from server. |
| 572 | * for now, assume that whole file layouts are requested. |
| 573 | * arg->offset: 0 |
| 574 | * arg->length: all ones |
| 575 | */ |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 576 | static struct pnfs_layout_segment * |
| 577 | send_layoutget(struct pnfs_layout_hdr *lo, |
| 578 | struct nfs_open_context *ctx, |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 579 | struct pnfs_layout_range *range, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 580 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 581 | { |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 582 | struct inode *ino = lo->plh_inode; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 583 | struct nfs_server *server = NFS_SERVER(ino); |
| 584 | struct nfs4_layoutget *lgp; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 585 | struct pnfs_layout_segment *lseg; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 586 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 587 | dprintk("--> %s\n", __func__); |
| 588 | |
| 589 | BUG_ON(ctx == NULL); |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 590 | lgp = kzalloc(sizeof(*lgp), gfp_flags); |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 591 | if (lgp == NULL) |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 592 | return NULL; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 593 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 594 | lgp->args.minlength = PAGE_CACHE_SIZE; |
| 595 | if (lgp->args.minlength > range->length) |
| 596 | lgp->args.minlength = range->length; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 597 | lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE; |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 598 | lgp->args.range = *range; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 599 | lgp->args.type = server->pnfs_curr_ld->id; |
| 600 | lgp->args.inode = ino; |
| 601 | lgp->args.ctx = get_nfs_open_context(ctx); |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 602 | lgp->gfp_flags = gfp_flags; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 603 | |
| 604 | /* Synchronously retrieve layout information from server and |
| 605 | * store in lseg. |
| 606 | */ |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 607 | lseg = nfs4_proc_layoutget(lgp, gfp_flags); |
| 608 | if (IS_ERR(lseg)) { |
| 609 | switch (PTR_ERR(lseg)) { |
| 610 | case -ENOMEM: |
| 611 | case -ERESTARTSYS: |
| 612 | break; |
| 613 | default: |
| 614 | /* remember that LAYOUTGET failed and suspend trying */ |
| 615 | set_bit(lo_fail_bit(range->iomode), &lo->plh_flags); |
| 616 | } |
| 617 | return NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 618 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 619 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 620 | return lseg; |
| 621 | } |
| 622 | |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 623 | /* |
| 624 | * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr |
| 625 | * when the layout segment list is empty. |
| 626 | * |
| 627 | * Note that a pnfs_layout_hdr can exist with an empty layout segment |
| 628 | * list when LAYOUTGET has failed, or when LAYOUTGET succeeded, but the |
| 629 | * deviceid is marked invalid. |
| 630 | */ |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 631 | int |
| 632 | _pnfs_return_layout(struct inode *ino) |
| 633 | { |
| 634 | struct pnfs_layout_hdr *lo = NULL; |
| 635 | struct nfs_inode *nfsi = NFS_I(ino); |
| 636 | LIST_HEAD(tmp_list); |
| 637 | struct nfs4_layoutreturn *lrp; |
| 638 | nfs4_stateid stateid; |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 639 | int status = 0, empty; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 640 | |
Andy Adamson | 366d505 | 2012-06-20 15:03:33 -0400 | [diff] [blame] | 641 | dprintk("NFS: %s for inode %lu\n", __func__, ino->i_ino); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 642 | |
| 643 | spin_lock(&ino->i_lock); |
| 644 | lo = nfsi->layout; |
Andy Adamson | 366d505 | 2012-06-20 15:03:33 -0400 | [diff] [blame] | 645 | if (!lo || pnfs_test_layout_returned(lo)) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 646 | spin_unlock(&ino->i_lock); |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 647 | dprintk("NFS: %s no layout to return\n", __func__); |
| 648 | goto out; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 649 | } |
| 650 | stateid = nfsi->layout->plh_stateid; |
| 651 | /* Reference matched in nfs4_layoutreturn_release */ |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 652 | pnfs_get_layout_hdr(lo); |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 653 | empty = list_empty(&lo->plh_segs); |
Trond Myklebust | 49a8506 | 2012-09-18 20:43:31 -0400 | [diff] [blame] | 654 | pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL); |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 655 | /* Don't send a LAYOUTRETURN if list was initially empty */ |
| 656 | if (empty) { |
| 657 | spin_unlock(&ino->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 658 | pnfs_put_layout_hdr(lo); |
Andy Adamson | 293b3b0 | 2012-06-20 15:03:34 -0400 | [diff] [blame] | 659 | dprintk("NFS: %s no layout segments to return\n", __func__); |
| 660 | goto out; |
| 661 | } |
Fred Isaman | ea0ded7 | 2011-06-15 12:31:02 -0400 | [diff] [blame] | 662 | lo->plh_block_lgets++; |
Andy Adamson | 366d505 | 2012-06-20 15:03:33 -0400 | [diff] [blame] | 663 | pnfs_mark_layout_returned(lo); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 664 | spin_unlock(&ino->i_lock); |
| 665 | pnfs_free_lseg_list(&tmp_list); |
| 666 | |
| 667 | WARN_ON(test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)); |
| 668 | |
| 669 | lrp = kzalloc(sizeof(*lrp), GFP_KERNEL); |
| 670 | if (unlikely(lrp == NULL)) { |
| 671 | status = -ENOMEM; |
Fred Isaman | 9e2dfdb | 2011-06-15 14:32:02 -0400 | [diff] [blame] | 672 | set_bit(NFS_LAYOUT_RW_FAILED, &lo->plh_flags); |
| 673 | set_bit(NFS_LAYOUT_RO_FAILED, &lo->plh_flags); |
Andy Adamson | 366d505 | 2012-06-20 15:03:33 -0400 | [diff] [blame] | 674 | pnfs_clear_layout_returned(lo); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 675 | pnfs_put_layout_hdr(lo); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 676 | goto out; |
| 677 | } |
| 678 | |
| 679 | lrp->args.stateid = stateid; |
| 680 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; |
| 681 | lrp->args.inode = ino; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 682 | lrp->args.layout = lo; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 683 | lrp->clp = NFS_SERVER(ino)->nfs_client; |
| 684 | |
| 685 | status = nfs4_proc_layoutreturn(lrp); |
| 686 | out: |
| 687 | dprintk("<-- %s status: %d\n", __func__, status); |
| 688 | return status; |
| 689 | } |
Andy Adamson | 0a57cda | 2012-04-27 17:53:50 -0400 | [diff] [blame] | 690 | EXPORT_SYMBOL_GPL(_pnfs_return_layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 691 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 692 | bool pnfs_roc(struct inode *ino) |
| 693 | { |
| 694 | struct pnfs_layout_hdr *lo; |
| 695 | struct pnfs_layout_segment *lseg, *tmp; |
| 696 | LIST_HEAD(tmp_list); |
| 697 | bool found = false; |
| 698 | |
| 699 | spin_lock(&ino->i_lock); |
| 700 | lo = NFS_I(ino)->layout; |
| 701 | if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) || |
| 702 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) |
| 703 | goto out_nolayout; |
| 704 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) |
| 705 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 706 | mark_lseg_invalid(lseg, &tmp_list); |
| 707 | found = true; |
| 708 | } |
| 709 | if (!found) |
| 710 | goto out_nolayout; |
| 711 | lo->plh_block_lgets++; |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 712 | pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 713 | spin_unlock(&ino->i_lock); |
| 714 | pnfs_free_lseg_list(&tmp_list); |
| 715 | return true; |
| 716 | |
| 717 | out_nolayout: |
| 718 | spin_unlock(&ino->i_lock); |
| 719 | return false; |
| 720 | } |
| 721 | |
| 722 | void pnfs_roc_release(struct inode *ino) |
| 723 | { |
| 724 | struct pnfs_layout_hdr *lo; |
| 725 | |
| 726 | spin_lock(&ino->i_lock); |
| 727 | lo = NFS_I(ino)->layout; |
| 728 | lo->plh_block_lgets--; |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 729 | pnfs_put_layout_hdr_locked(lo); |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 730 | spin_unlock(&ino->i_lock); |
| 731 | } |
| 732 | |
| 733 | void pnfs_roc_set_barrier(struct inode *ino, u32 barrier) |
| 734 | { |
| 735 | struct pnfs_layout_hdr *lo; |
| 736 | |
| 737 | spin_lock(&ino->i_lock); |
| 738 | lo = NFS_I(ino)->layout; |
| 739 | if ((int)(barrier - lo->plh_barrier) > 0) |
| 740 | lo->plh_barrier = barrier; |
| 741 | spin_unlock(&ino->i_lock); |
| 742 | } |
| 743 | |
| 744 | bool pnfs_roc_drain(struct inode *ino, u32 *barrier) |
| 745 | { |
| 746 | struct nfs_inode *nfsi = NFS_I(ino); |
| 747 | struct pnfs_layout_segment *lseg; |
| 748 | bool found = false; |
| 749 | |
| 750 | spin_lock(&ino->i_lock); |
| 751 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) |
| 752 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 753 | found = true; |
| 754 | break; |
| 755 | } |
| 756 | if (!found) { |
| 757 | struct pnfs_layout_hdr *lo = nfsi->layout; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 758 | u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid); |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 759 | |
| 760 | /* Since close does not return a layout stateid for use as |
| 761 | * a barrier, we choose the worst-case barrier. |
| 762 | */ |
| 763 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); |
| 764 | } |
| 765 | spin_unlock(&ino->i_lock); |
| 766 | return found; |
| 767 | } |
| 768 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 769 | /* |
| 770 | * Compare two layout segments for sorting into layout cache. |
| 771 | * We want to preferentially return RW over RO layouts, so ensure those |
| 772 | * are seen first. |
| 773 | */ |
| 774 | static s64 |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 775 | cmp_layout(struct pnfs_layout_range *l1, |
| 776 | struct pnfs_layout_range *l2) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 777 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 778 | s64 d; |
| 779 | |
| 780 | /* high offset > low offset */ |
| 781 | d = l1->offset - l2->offset; |
| 782 | if (d) |
| 783 | return d; |
| 784 | |
| 785 | /* short length > long length */ |
| 786 | d = l2->length - l1->length; |
| 787 | if (d) |
| 788 | return d; |
| 789 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 790 | /* read > read/write */ |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 791 | return (int)(l1->iomode == IOMODE_READ) - (int)(l2->iomode == IOMODE_READ); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 792 | } |
| 793 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 794 | static void |
| 795 | pnfs_insert_layout(struct pnfs_layout_hdr *lo, |
| 796 | struct pnfs_layout_segment *lseg) |
| 797 | { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 798 | struct pnfs_layout_segment *lp; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 799 | |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 800 | dprintk("%s:Begin\n", __func__); |
| 801 | |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 802 | assert_spin_locked(&lo->plh_inode->i_lock); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 803 | list_for_each_entry(lp, &lo->plh_segs, pls_list) { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 804 | if (cmp_layout(&lseg->pls_range, &lp->pls_range) > 0) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 805 | continue; |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 806 | list_add_tail(&lseg->pls_list, &lp->pls_list); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 807 | dprintk("%s: inserted lseg %p " |
| 808 | "iomode %d offset %llu length %llu before " |
| 809 | "lp %p iomode %d offset %llu length %llu\n", |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 810 | __func__, lseg, lseg->pls_range.iomode, |
| 811 | lseg->pls_range.offset, lseg->pls_range.length, |
| 812 | lp, lp->pls_range.iomode, lp->pls_range.offset, |
| 813 | lp->pls_range.length); |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 814 | goto out; |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 815 | } |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 816 | list_add_tail(&lseg->pls_list, &lo->plh_segs); |
| 817 | dprintk("%s: inserted lseg %p " |
| 818 | "iomode %d offset %llu length %llu at tail\n", |
| 819 | __func__, lseg, lseg->pls_range.iomode, |
| 820 | lseg->pls_range.offset, lseg->pls_range.length); |
| 821 | out: |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 822 | pnfs_get_layout_hdr(lo); |
Andy Adamson | 974cec8 | 2010-10-20 00:18:02 -0400 | [diff] [blame] | 823 | |
| 824 | dprintk("%s:Return\n", __func__); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static struct pnfs_layout_hdr * |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 828 | alloc_init_layout_hdr(struct inode *ino, |
| 829 | struct nfs_open_context *ctx, |
| 830 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 831 | { |
| 832 | struct pnfs_layout_hdr *lo; |
| 833 | |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 834 | lo = pnfs_alloc_layout_hdr(ino, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 835 | if (!lo) |
| 836 | return NULL; |
Fred Isaman | cc6e534 | 2011-01-06 11:36:28 +0000 | [diff] [blame] | 837 | atomic_set(&lo->plh_refcount, 1); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 838 | INIT_LIST_HEAD(&lo->plh_layouts); |
| 839 | INIT_LIST_HEAD(&lo->plh_segs); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 840 | INIT_LIST_HEAD(&lo->plh_bulk_recall); |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 841 | lo->plh_inode = ino; |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 842 | lo->plh_lc_cred = get_rpccred(ctx->state->owner->so_cred); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 843 | return lo; |
| 844 | } |
| 845 | |
| 846 | static struct pnfs_layout_hdr * |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 847 | pnfs_find_alloc_layout(struct inode *ino, |
| 848 | struct nfs_open_context *ctx, |
| 849 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 850 | { |
| 851 | struct nfs_inode *nfsi = NFS_I(ino); |
| 852 | struct pnfs_layout_hdr *new = NULL; |
| 853 | |
| 854 | dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout); |
| 855 | |
| 856 | assert_spin_locked(&ino->i_lock); |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 857 | if (nfsi->layout) { |
| 858 | if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags)) |
| 859 | return NULL; |
| 860 | else |
| 861 | return nfsi->layout; |
| 862 | } |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 863 | spin_unlock(&ino->i_lock); |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 864 | new = alloc_init_layout_hdr(ino, ctx, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 865 | spin_lock(&ino->i_lock); |
| 866 | |
| 867 | if (likely(nfsi->layout == NULL)) /* Won the race? */ |
| 868 | nfsi->layout = new; |
| 869 | else |
Benny Halevy | 636fb9c | 2011-05-22 19:51:33 +0300 | [diff] [blame] | 870 | pnfs_free_layout_hdr(new); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 871 | return nfsi->layout; |
| 872 | } |
| 873 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 874 | /* |
| 875 | * iomode matching rules: |
| 876 | * iomode lseg match |
| 877 | * ----- ----- ----- |
| 878 | * ANY READ true |
| 879 | * ANY RW true |
| 880 | * RW READ false |
| 881 | * RW RW true |
| 882 | * READ READ true |
| 883 | * READ RW true |
| 884 | */ |
| 885 | static int |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 886 | is_matching_lseg(struct pnfs_layout_range *ls_range, |
| 887 | struct pnfs_layout_range *range) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 888 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 889 | struct pnfs_layout_range range1; |
| 890 | |
| 891 | if ((range->iomode == IOMODE_RW && |
| 892 | ls_range->iomode != IOMODE_RW) || |
| 893 | !lo_seg_intersecting(ls_range, range)) |
| 894 | return 0; |
| 895 | |
| 896 | /* range1 covers only the first byte in the range */ |
| 897 | range1 = *range; |
| 898 | range1.length = 1; |
| 899 | return lo_seg_contained(ls_range, &range1); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* |
| 903 | * lookup range in layout |
| 904 | */ |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 905 | static struct pnfs_layout_segment * |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 906 | pnfs_find_lseg(struct pnfs_layout_hdr *lo, |
| 907 | struct pnfs_layout_range *range) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 908 | { |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 909 | struct pnfs_layout_segment *lseg, *ret = NULL; |
| 910 | |
| 911 | dprintk("%s:Begin\n", __func__); |
| 912 | |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 913 | assert_spin_locked(&lo->plh_inode->i_lock); |
| 914 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 915 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 916 | is_matching_lseg(&lseg->pls_range, range)) { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 917 | ret = pnfs_get_lseg(lseg); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 918 | break; |
| 919 | } |
Benny Halevy | d771e3a | 2011-06-14 16:30:16 -0400 | [diff] [blame] | 920 | if (lseg->pls_range.offset > range->offset) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 921 | break; |
| 922 | } |
| 923 | |
| 924 | dprintk("%s:Return lseg %p ref %d\n", |
Fred Isaman | 4541d16 | 2011-01-06 11:36:23 +0000 | [diff] [blame] | 925 | __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 926 | return ret; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* |
Andy Adamson | d23d61c | 2012-05-23 05:02:37 -0400 | [diff] [blame] | 930 | * Use mdsthreshold hints set at each OPEN to determine if I/O should go |
| 931 | * to the MDS or over pNFS |
| 932 | * |
| 933 | * The nfs_inode read_io and write_io fields are cumulative counters reset |
| 934 | * when there are no layout segments. Note that in pnfs_update_layout iomode |
| 935 | * is set to IOMODE_READ for a READ request, and set to IOMODE_RW for a |
| 936 | * WRITE request. |
| 937 | * |
| 938 | * A return of true means use MDS I/O. |
| 939 | * |
| 940 | * From rfc 5661: |
| 941 | * If a file's size is smaller than the file size threshold, data accesses |
| 942 | * SHOULD be sent to the metadata server. If an I/O request has a length that |
| 943 | * is below the I/O size threshold, the I/O SHOULD be sent to the metadata |
| 944 | * server. If both file size and I/O size are provided, the client SHOULD |
| 945 | * reach or exceed both thresholds before sending its read or write |
| 946 | * requests to the data server. |
| 947 | */ |
| 948 | static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx, |
| 949 | struct inode *ino, int iomode) |
| 950 | { |
| 951 | struct nfs4_threshold *t = ctx->mdsthreshold; |
| 952 | struct nfs_inode *nfsi = NFS_I(ino); |
| 953 | loff_t fsize = i_size_read(ino); |
| 954 | bool size = false, size_set = false, io = false, io_set = false, ret = false; |
| 955 | |
| 956 | if (t == NULL) |
| 957 | return ret; |
| 958 | |
| 959 | dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n", |
| 960 | __func__, t->bm, t->rd_sz, t->wr_sz, t->rd_io_sz, t->wr_io_sz); |
| 961 | |
| 962 | switch (iomode) { |
| 963 | case IOMODE_READ: |
| 964 | if (t->bm & THRESHOLD_RD) { |
| 965 | dprintk("%s fsize %llu\n", __func__, fsize); |
| 966 | size_set = true; |
| 967 | if (fsize < t->rd_sz) |
| 968 | size = true; |
| 969 | } |
| 970 | if (t->bm & THRESHOLD_RD_IO) { |
| 971 | dprintk("%s nfsi->read_io %llu\n", __func__, |
| 972 | nfsi->read_io); |
| 973 | io_set = true; |
| 974 | if (nfsi->read_io < t->rd_io_sz) |
| 975 | io = true; |
| 976 | } |
| 977 | break; |
| 978 | case IOMODE_RW: |
| 979 | if (t->bm & THRESHOLD_WR) { |
| 980 | dprintk("%s fsize %llu\n", __func__, fsize); |
| 981 | size_set = true; |
| 982 | if (fsize < t->wr_sz) |
| 983 | size = true; |
| 984 | } |
| 985 | if (t->bm & THRESHOLD_WR_IO) { |
| 986 | dprintk("%s nfsi->write_io %llu\n", __func__, |
| 987 | nfsi->write_io); |
| 988 | io_set = true; |
| 989 | if (nfsi->write_io < t->wr_io_sz) |
| 990 | io = true; |
| 991 | } |
| 992 | break; |
| 993 | } |
| 994 | if (size_set && io_set) { |
| 995 | if (size && io) |
| 996 | ret = true; |
| 997 | } else if (size || io) |
| 998 | ret = true; |
| 999 | |
| 1000 | dprintk("<-- %s size %d io %d ret %d\n", __func__, size, io, ret); |
| 1001 | return ret; |
| 1002 | } |
| 1003 | |
| 1004 | /* |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1005 | * Layout segment is retreived from the server if not cached. |
| 1006 | * The appropriate layout segment is referenced and returned to the caller. |
| 1007 | */ |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 1008 | struct pnfs_layout_segment * |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1009 | pnfs_update_layout(struct inode *ino, |
| 1010 | struct nfs_open_context *ctx, |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 1011 | loff_t pos, |
| 1012 | u64 count, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 1013 | enum pnfs_iomode iomode, |
| 1014 | gfp_t gfp_flags) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1015 | { |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 1016 | struct pnfs_layout_range arg = { |
| 1017 | .iomode = iomode, |
| 1018 | .offset = pos, |
| 1019 | .length = count, |
| 1020 | }; |
Benny Halevy | 707ed5f | 2011-05-22 19:47:46 +0300 | [diff] [blame] | 1021 | unsigned pg_offset; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1022 | struct nfs_inode *nfsi = NFS_I(ino); |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 1023 | struct nfs_server *server = NFS_SERVER(ino); |
| 1024 | struct nfs_client *clp = server->nfs_client; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1025 | struct pnfs_layout_hdr *lo; |
| 1026 | struct pnfs_layout_segment *lseg = NULL; |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 1027 | bool first = false; |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1028 | |
| 1029 | if (!pnfs_enabled_sb(NFS_SERVER(ino))) |
| 1030 | return NULL; |
Andy Adamson | d23d61c | 2012-05-23 05:02:37 -0400 | [diff] [blame] | 1031 | |
| 1032 | if (pnfs_within_mdsthreshold(ctx, ino, iomode)) |
| 1033 | return NULL; |
| 1034 | |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1035 | spin_lock(&ino->i_lock); |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 1036 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1037 | if (lo == NULL) { |
| 1038 | dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__); |
| 1039 | goto out_unlock; |
| 1040 | } |
| 1041 | |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1042 | /* Do we even need to bother with this? */ |
Trond Myklebust | a59c30a | 2012-03-01 11:17:47 -0500 | [diff] [blame] | 1043 | if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1044 | dprintk("%s matches recall, use MDS\n", __func__); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1045 | goto out_unlock; |
| 1046 | } |
| 1047 | |
| 1048 | /* if LAYOUTGET already failed once we don't try again */ |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 1049 | if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags)) |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1050 | goto out_unlock; |
| 1051 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 1052 | /* Check to see if the layout for the given range already exists */ |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 1053 | lseg = pnfs_find_lseg(lo, &arg); |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 1054 | if (lseg) |
| 1055 | goto out_unlock; |
| 1056 | |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1057 | if (pnfs_layoutgets_blocked(lo, NULL, 0)) |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 1058 | goto out_unlock; |
| 1059 | atomic_inc(&lo->plh_outstanding); |
| 1060 | |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 1061 | pnfs_get_layout_hdr(lo); |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 1062 | if (list_empty(&lo->plh_segs)) |
| 1063 | first = true; |
Andy Adamson | 366d505 | 2012-06-20 15:03:33 -0400 | [diff] [blame] | 1064 | |
| 1065 | /* Enable LAYOUTRETURNs */ |
| 1066 | pnfs_clear_layout_returned(lo); |
| 1067 | |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 1068 | spin_unlock(&ino->i_lock); |
| 1069 | if (first) { |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 1070 | /* The lo must be on the clp list if there is any |
| 1071 | * chance of a CB_LAYOUTRECALL(FILE) coming in. |
| 1072 | */ |
| 1073 | spin_lock(&clp->cl_lock); |
| 1074 | BUG_ON(!list_empty(&lo->plh_layouts)); |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 1075 | list_add_tail(&lo->plh_layouts, &server->layouts); |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 1076 | spin_unlock(&clp->cl_lock); |
| 1077 | } |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1078 | |
Benny Halevy | 707ed5f | 2011-05-22 19:47:46 +0300 | [diff] [blame] | 1079 | pg_offset = arg.offset & ~PAGE_CACHE_MASK; |
| 1080 | if (pg_offset) { |
| 1081 | arg.offset -= pg_offset; |
| 1082 | arg.length += pg_offset; |
| 1083 | } |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 1084 | if (arg.length != NFS4_MAX_UINT64) |
| 1085 | arg.length = PAGE_CACHE_ALIGN(arg.length); |
Benny Halevy | 707ed5f | 2011-05-22 19:47:46 +0300 | [diff] [blame] | 1086 | |
Benny Halevy | fb3296e | 2011-05-22 19:47:26 +0300 | [diff] [blame] | 1087 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); |
Fred Isaman | f49f9ba | 2011-02-03 18:28:52 +0000 | [diff] [blame] | 1088 | if (!lseg && first) { |
| 1089 | spin_lock(&clp->cl_lock); |
| 1090 | list_del_init(&lo->plh_layouts); |
| 1091 | spin_unlock(&clp->cl_lock); |
Fred Isaman | 2130ff6 | 2011-01-06 11:36:26 +0000 | [diff] [blame] | 1092 | } |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 1093 | atomic_dec(&lo->plh_outstanding); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 1094 | pnfs_put_layout_hdr(lo); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1095 | out: |
| 1096 | dprintk("%s end, state 0x%lx lseg %p\n", __func__, |
Andy Adamson | bf9c138 | 2011-03-01 01:34:07 +0000 | [diff] [blame] | 1097 | nfsi->layout ? nfsi->layout->plh_flags : -1, lseg); |
Benny Halevy | e5e9401 | 2010-10-20 00:18:01 -0400 | [diff] [blame] | 1098 | return lseg; |
| 1099 | out_unlock: |
| 1100 | spin_unlock(&ino->i_lock); |
| 1101 | goto out; |
| 1102 | } |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 1103 | EXPORT_SYMBOL_GPL(pnfs_update_layout); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1104 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 1105 | struct pnfs_layout_segment * |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1106 | pnfs_layout_process(struct nfs4_layoutget *lgp) |
| 1107 | { |
| 1108 | struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout; |
| 1109 | struct nfs4_layoutget_res *res = &lgp->res; |
| 1110 | struct pnfs_layout_segment *lseg; |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 1111 | struct inode *ino = lo->plh_inode; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1112 | int status = 0; |
| 1113 | |
| 1114 | /* Inject layout blob into I/O device driver */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 1115 | 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] | 1116 | if (!lseg || IS_ERR(lseg)) { |
| 1117 | if (!lseg) |
| 1118 | status = -ENOMEM; |
| 1119 | else |
| 1120 | status = PTR_ERR(lseg); |
| 1121 | dprintk("%s: Could not allocate layout: error %d\n", |
| 1122 | __func__, status); |
| 1123 | goto out; |
| 1124 | } |
| 1125 | |
| 1126 | spin_lock(&ino->i_lock); |
Trond Myklebust | a59c30a | 2012-03-01 11:17:47 -0500 | [diff] [blame] | 1127 | if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1128 | dprintk("%s forget reply due to recall\n", __func__); |
| 1129 | goto out_forget_reply; |
| 1130 | } |
| 1131 | |
| 1132 | if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) { |
| 1133 | dprintk("%s forget reply due to state\n", __func__); |
| 1134 | goto out_forget_reply; |
| 1135 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1136 | init_lseg(lo, lseg); |
Fred Isaman | 566052c | 2011-01-06 11:36:20 +0000 | [diff] [blame] | 1137 | lseg->pls_range = res->range; |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1138 | pnfs_get_lseg(lseg); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1139 | pnfs_insert_layout(lo, lseg); |
| 1140 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1141 | if (res->return_on_close) { |
| 1142 | set_bit(NFS_LSEG_ROC, &lseg->pls_flags); |
| 1143 | set_bit(NFS_LAYOUT_ROC, &lo->plh_flags); |
| 1144 | } |
| 1145 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1146 | /* Done processing layoutget. Set the layout stateid */ |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1147 | pnfs_set_layout_stateid(lo, &res->stateid, false); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1148 | spin_unlock(&ino->i_lock); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 1149 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1150 | out: |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 1151 | return ERR_PTR(status); |
Fred Isaman | 43f1b3d | 2011-01-06 11:36:30 +0000 | [diff] [blame] | 1152 | |
| 1153 | out_forget_reply: |
| 1154 | spin_unlock(&ino->i_lock); |
| 1155 | lseg->pls_layout = lo; |
| 1156 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); |
| 1157 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1160 | void |
| 1161 | pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1162 | { |
| 1163 | BUG_ON(pgio->pg_lseg != NULL); |
| 1164 | |
Fred Isaman | 1825a0d | 2012-04-20 19:55:31 -0400 | [diff] [blame] | 1165 | if (req->wb_offset != req->wb_pgbase) { |
| 1166 | nfs_pageio_reset_read_mds(pgio); |
| 1167 | return; |
| 1168 | } |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1169 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 1170 | req->wb_context, |
| 1171 | req_offset(req), |
| 1172 | req->wb_bytes, |
| 1173 | IOMODE_READ, |
| 1174 | GFP_KERNEL); |
Trond Myklebust | e885de1 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1175 | /* If no lseg, fall back to read through mds */ |
| 1176 | if (pgio->pg_lseg == NULL) |
Trond Myklebust | 1f94535 | 2011-07-13 15:59:57 -0400 | [diff] [blame] | 1177 | nfs_pageio_reset_read_mds(pgio); |
Trond Myklebust | e885de1 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1178 | |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1179 | } |
| 1180 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_read); |
| 1181 | |
| 1182 | void |
| 1183 | pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1184 | { |
| 1185 | BUG_ON(pgio->pg_lseg != NULL); |
| 1186 | |
Fred Isaman | 1825a0d | 2012-04-20 19:55:31 -0400 | [diff] [blame] | 1187 | if (req->wb_offset != req->wb_pgbase) { |
| 1188 | nfs_pageio_reset_write_mds(pgio); |
| 1189 | return; |
| 1190 | } |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1191 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 1192 | req->wb_context, |
| 1193 | req_offset(req), |
| 1194 | req->wb_bytes, |
| 1195 | IOMODE_RW, |
| 1196 | GFP_NOFS); |
Trond Myklebust | e885de1 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1197 | /* If no lseg, fall back to write through mds */ |
| 1198 | if (pgio->pg_lseg == NULL) |
Trond Myklebust | 1f94535 | 2011-07-13 15:59:57 -0400 | [diff] [blame] | 1199 | nfs_pageio_reset_write_mds(pgio); |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1200 | } |
| 1201 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write); |
| 1202 | |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 1203 | void |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1204 | pnfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, struct inode *inode, |
| 1205 | const struct nfs_pgio_completion_ops *compl_ops) |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1206 | { |
| 1207 | struct nfs_server *server = NFS_SERVER(inode); |
| 1208 | struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld; |
| 1209 | |
| 1210 | if (ld == NULL) |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 1211 | nfs_pageio_init_read(pgio, inode, compl_ops); |
| 1212 | else |
| 1213 | nfs_pageio_init(pgio, inode, ld->pg_read_ops, compl_ops, server->rsize, 0); |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 1216 | void |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1217 | pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, struct inode *inode, |
| 1218 | int ioflags, |
| 1219 | const struct nfs_pgio_completion_ops *compl_ops) |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1220 | { |
| 1221 | struct nfs_server *server = NFS_SERVER(inode); |
| 1222 | struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld; |
| 1223 | |
| 1224 | if (ld == NULL) |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 1225 | nfs_pageio_init_write(pgio, inode, ioflags, compl_ops); |
| 1226 | else |
| 1227 | nfs_pageio_init(pgio, inode, ld->pg_write_ops, compl_ops, server->wsize, ioflags); |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | bool |
Benny Halevy | dfed206 | 2011-05-25 20:25:22 +0300 | [diff] [blame] | 1231 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 1232 | struct nfs_page *req) |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1233 | { |
Trond Myklebust | d8007d4 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1234 | if (pgio->pg_lseg == NULL) |
| 1235 | return nfs_generic_pg_test(pgio, prev, req); |
Benny Halevy | 89a58e3 | 2011-05-25 20:54:40 +0300 | [diff] [blame] | 1236 | |
Trond Myklebust | 19982ba | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1237 | /* |
| 1238 | * Test if a nfs_page is fully contained in the pnfs_layout_range. |
| 1239 | * Note that this test makes several assumptions: |
| 1240 | * - that the previous nfs_page in the struct nfs_pageio_descriptor |
| 1241 | * is known to lie within the range. |
| 1242 | * - that the nfs_page being tested is known to be contiguous with the |
| 1243 | * previous nfs_page. |
| 1244 | * - Layout ranges are page aligned, so we only have to test the |
| 1245 | * start offset of the request. |
| 1246 | * |
| 1247 | * Please also note that 'end_offset' is actually the offset of the |
| 1248 | * first byte that lies outside the pnfs_layout_range. FIXME? |
| 1249 | * |
| 1250 | */ |
| 1251 | return req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset, |
| 1252 | pgio->pg_lseg->pls_range.length); |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1253 | } |
Benny Halevy | 89a58e3 | 2011-05-25 20:54:40 +0300 | [diff] [blame] | 1254 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_test); |
Fred Isaman | bae724e | 2011-03-01 01:34:15 +0000 | [diff] [blame] | 1255 | |
Andy Adamson | e7dd79af | 2012-04-27 17:53:46 -0400 | [diff] [blame] | 1256 | int pnfs_write_done_resend_to_mds(struct inode *inode, |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1257 | struct list_head *head, |
| 1258 | const struct nfs_pgio_completion_ops *compl_ops) |
Trond Myklebust | e2fecb2 | 2012-01-06 08:57:46 -0500 | [diff] [blame] | 1259 | { |
| 1260 | struct nfs_pageio_descriptor pgio; |
| 1261 | LIST_HEAD(failed); |
| 1262 | |
| 1263 | /* Resend all requests through the MDS */ |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 1264 | nfs_pageio_init_write(&pgio, inode, FLUSH_STABLE, compl_ops); |
Trond Myklebust | e2fecb2 | 2012-01-06 08:57:46 -0500 | [diff] [blame] | 1265 | while (!list_empty(head)) { |
| 1266 | struct nfs_page *req = nfs_list_entry(head->next); |
| 1267 | |
| 1268 | nfs_list_remove_request(req); |
| 1269 | if (!nfs_pageio_add_request(&pgio, req)) |
| 1270 | nfs_list_add_request(req, &failed); |
| 1271 | } |
| 1272 | nfs_pageio_complete(&pgio); |
| 1273 | |
| 1274 | if (!list_empty(&failed)) { |
| 1275 | /* For some reason our attempt to resend pages. Mark the |
| 1276 | * overall send request as having failed, and let |
| 1277 | * nfs_writeback_release_full deal with the error. |
| 1278 | */ |
| 1279 | list_move(&failed, head); |
| 1280 | return -EIO; |
| 1281 | } |
| 1282 | return 0; |
| 1283 | } |
Andy Adamson | e7dd79af | 2012-04-27 17:53:46 -0400 | [diff] [blame] | 1284 | EXPORT_SYMBOL_GPL(pnfs_write_done_resend_to_mds); |
Trond Myklebust | e2fecb2 | 2012-01-06 08:57:46 -0500 | [diff] [blame] | 1285 | |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1286 | static void pnfs_ld_handle_write_error(struct nfs_write_data *data) |
| 1287 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1288 | struct nfs_pgio_header *hdr = data->header; |
| 1289 | |
| 1290 | dprintk("pnfs write error = %d\n", hdr->pnfs_error); |
| 1291 | if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags & |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1292 | PNFS_LAYOUTRET_ON_ERROR) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1293 | clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags); |
| 1294 | pnfs_return_layout(hdr->inode); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1295 | } |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1296 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) |
| 1297 | data->task.tk_status = pnfs_write_done_resend_to_mds(hdr->inode, |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1298 | &hdr->pages, |
| 1299 | hdr->completion_ops); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1300 | } |
| 1301 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1302 | /* |
| 1303 | * Called by non rpc-based layout drivers |
| 1304 | */ |
Peng Tao | 8ce160c | 2011-09-22 21:50:14 -0400 | [diff] [blame] | 1305 | void pnfs_ld_write_done(struct nfs_write_data *data) |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 1306 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1307 | struct nfs_pgio_header *hdr = data->header; |
| 1308 | |
| 1309 | if (!hdr->pnfs_error) { |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1310 | pnfs_set_layoutcommit(data); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1311 | hdr->mds_ops->rpc_call_done(&data->task, data); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1312 | } else |
| 1313 | pnfs_ld_handle_write_error(data); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1314 | hdr->mds_ops->rpc_release(data); |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1315 | } |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1316 | EXPORT_SYMBOL_GPL(pnfs_ld_write_done); |
Fred Isaman | 44b8379 | 2011-03-03 15:13:44 +0000 | [diff] [blame] | 1317 | |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1318 | static void |
| 1319 | pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, |
| 1320 | struct nfs_write_data *data) |
| 1321 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1322 | struct nfs_pgio_header *hdr = data->header; |
| 1323 | |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1324 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1325 | list_splice_tail_init(&hdr->pages, &desc->pg_list); |
| 1326 | nfs_pageio_reset_write_mds(desc); |
| 1327 | desc->pg_recoalesce = 1; |
| 1328 | } |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1329 | nfs_writedata_release(data); |
| 1330 | } |
| 1331 | |
| 1332 | static enum pnfs_try_status |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1333 | pnfs_try_to_write_data(struct nfs_write_data *wdata, |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1334 | const struct rpc_call_ops *call_ops, |
| 1335 | struct pnfs_layout_segment *lseg, |
| 1336 | int how) |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1337 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1338 | struct nfs_pgio_header *hdr = wdata->header; |
| 1339 | struct inode *inode = hdr->inode; |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1340 | enum pnfs_try_status trypnfs; |
| 1341 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 1342 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1343 | hdr->mds_ops = call_ops; |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1344 | |
| 1345 | dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__, |
| 1346 | inode->i_ino, wdata->args.count, wdata->args.offset, how); |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1347 | trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1348 | if (trypnfs != PNFS_NOT_ATTEMPTED) |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1349 | nfs_inc_stats(inode, NFSIOS_PNFS_WRITE); |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1350 | dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs); |
| 1351 | return trypnfs; |
| 1352 | } |
| 1353 | |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1354 | static void |
| 1355 | pnfs_do_multiple_writes(struct nfs_pageio_descriptor *desc, struct list_head *head, int how) |
| 1356 | { |
| 1357 | struct nfs_write_data *data; |
| 1358 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; |
| 1359 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1360 | |
| 1361 | desc->pg_lseg = NULL; |
| 1362 | while (!list_empty(head)) { |
| 1363 | enum pnfs_try_status trypnfs; |
| 1364 | |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1365 | data = list_first_entry(head, struct nfs_write_data, list); |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1366 | list_del_init(&data->list); |
| 1367 | |
| 1368 | trypnfs = pnfs_try_to_write_data(data, call_ops, lseg, how); |
| 1369 | if (trypnfs == PNFS_NOT_ATTEMPTED) |
| 1370 | pnfs_write_through_mds(desc, data); |
| 1371 | } |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1372 | pnfs_put_lseg(lseg); |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1373 | } |
| 1374 | |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1375 | static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) |
| 1376 | { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1377 | pnfs_put_lseg(hdr->lseg); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1378 | nfs_writehdr_free(hdr); |
| 1379 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 1380 | EXPORT_SYMBOL_GPL(pnfs_writehdr_free); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1381 | |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1382 | int |
| 1383 | pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) |
| 1384 | { |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1385 | struct nfs_write_header *whdr; |
| 1386 | struct nfs_pgio_header *hdr; |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1387 | int ret; |
| 1388 | |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1389 | whdr = nfs_writehdr_alloc(); |
| 1390 | if (!whdr) { |
Trond Myklebust | 9b5415b | 2012-04-27 14:31:47 -0400 | [diff] [blame] | 1391 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1392 | pnfs_put_lseg(desc->pg_lseg); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1393 | desc->pg_lseg = NULL; |
| 1394 | return -ENOMEM; |
| 1395 | } |
| 1396 | hdr = &whdr->header; |
| 1397 | nfs_pgheader_init(desc, hdr, pnfs_writehdr_free); |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1398 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1399 | atomic_inc(&hdr->refcnt); |
| 1400 | ret = nfs_generic_flush(desc, hdr); |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1401 | if (ret != 0) { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1402 | pnfs_put_lseg(desc->pg_lseg); |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1403 | desc->pg_lseg = NULL; |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1404 | } else |
| 1405 | pnfs_do_multiple_writes(desc, &hdr->rpc_list, desc->pg_ioflags); |
| 1406 | if (atomic_dec_and_test(&hdr->refcnt)) |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1407 | hdr->completion_ops->completion(hdr); |
Fred Isaman | 6c75dc0 | 2012-04-20 14:47:47 -0400 | [diff] [blame] | 1408 | return ret; |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 1409 | } |
| 1410 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); |
| 1411 | |
Andy Adamson | e7dd79af | 2012-04-27 17:53:46 -0400 | [diff] [blame] | 1412 | int pnfs_read_done_resend_to_mds(struct inode *inode, |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1413 | struct list_head *head, |
| 1414 | const struct nfs_pgio_completion_ops *compl_ops) |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1415 | { |
| 1416 | struct nfs_pageio_descriptor pgio; |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1417 | LIST_HEAD(failed); |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1418 | |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1419 | /* Resend all requests through the MDS */ |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 1420 | nfs_pageio_init_read(&pgio, inode, compl_ops); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1421 | while (!list_empty(head)) { |
| 1422 | struct nfs_page *req = nfs_list_entry(head->next); |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1423 | |
| 1424 | nfs_list_remove_request(req); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1425 | if (!nfs_pageio_add_request(&pgio, req)) |
| 1426 | nfs_list_add_request(req, &failed); |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1427 | } |
| 1428 | nfs_pageio_complete(&pgio); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1429 | |
| 1430 | if (!list_empty(&failed)) { |
| 1431 | list_move(&failed, head); |
| 1432 | return -EIO; |
| 1433 | } |
| 1434 | return 0; |
| 1435 | } |
Andy Adamson | e7dd79af | 2012-04-27 17:53:46 -0400 | [diff] [blame] | 1436 | EXPORT_SYMBOL_GPL(pnfs_read_done_resend_to_mds); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1437 | |
| 1438 | static void pnfs_ld_handle_read_error(struct nfs_read_data *data) |
| 1439 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1440 | struct nfs_pgio_header *hdr = data->header; |
| 1441 | |
| 1442 | dprintk("pnfs read error = %d\n", hdr->pnfs_error); |
| 1443 | if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags & |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1444 | PNFS_LAYOUTRET_ON_ERROR) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1445 | clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags); |
| 1446 | pnfs_return_layout(hdr->inode); |
Fred Isaman | 1acbbb4e1 | 2012-04-20 14:47:37 -0400 | [diff] [blame] | 1447 | } |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1448 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) |
| 1449 | data->task.tk_status = pnfs_read_done_resend_to_mds(hdr->inode, |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1450 | &hdr->pages, |
| 1451 | hdr->completion_ops); |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1452 | } |
| 1453 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 1454 | /* |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1455 | * Called by non rpc-based layout drivers |
| 1456 | */ |
Peng Tao | 9b7eecd | 2011-09-22 21:50:15 -0400 | [diff] [blame] | 1457 | void pnfs_ld_read_done(struct nfs_read_data *data) |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1458 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1459 | struct nfs_pgio_header *hdr = data->header; |
| 1460 | |
| 1461 | if (likely(!hdr->pnfs_error)) { |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1462 | __nfs4_read_done_cb(data); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1463 | hdr->mds_ops->rpc_call_done(&data->task, data); |
Trond Myklebust | 62e4a76 | 2011-11-10 14:30:37 -0500 | [diff] [blame] | 1464 | } else |
| 1465 | pnfs_ld_handle_read_error(data); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1466 | hdr->mds_ops->rpc_release(data); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1467 | } |
| 1468 | EXPORT_SYMBOL_GPL(pnfs_ld_read_done); |
| 1469 | |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1470 | static void |
| 1471 | pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, |
| 1472 | struct nfs_read_data *data) |
| 1473 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1474 | struct nfs_pgio_header *hdr = data->header; |
| 1475 | |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1476 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1477 | list_splice_tail_init(&hdr->pages, &desc->pg_list); |
| 1478 | nfs_pageio_reset_read_mds(desc); |
| 1479 | desc->pg_recoalesce = 1; |
| 1480 | } |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1481 | nfs_readdata_release(data); |
| 1482 | } |
| 1483 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 1484 | /* |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1485 | * Call the appropriate parallel I/O subsystem read function. |
| 1486 | */ |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1487 | static enum pnfs_try_status |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1488 | pnfs_try_to_read_data(struct nfs_read_data *rdata, |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1489 | const struct rpc_call_ops *call_ops, |
| 1490 | struct pnfs_layout_segment *lseg) |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1491 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1492 | struct nfs_pgio_header *hdr = rdata->header; |
| 1493 | struct inode *inode = hdr->inode; |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1494 | struct nfs_server *nfss = NFS_SERVER(inode); |
| 1495 | enum pnfs_try_status trypnfs; |
| 1496 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1497 | hdr->mds_ops = call_ops; |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1498 | |
| 1499 | dprintk("%s: Reading ino:%lu %u@%llu\n", |
| 1500 | __func__, inode->i_ino, rdata->args.count, rdata->args.offset); |
| 1501 | |
| 1502 | trypnfs = nfss->pnfs_curr_ld->read_pagelist(rdata); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1503 | if (trypnfs != PNFS_NOT_ATTEMPTED) |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1504 | nfs_inc_stats(inode, NFSIOS_PNFS_READ); |
Andy Adamson | 64419a9 | 2011-03-01 01:34:16 +0000 | [diff] [blame] | 1505 | dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs); |
| 1506 | return trypnfs; |
| 1507 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1508 | |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1509 | static void |
| 1510 | pnfs_do_multiple_reads(struct nfs_pageio_descriptor *desc, struct list_head *head) |
| 1511 | { |
| 1512 | struct nfs_read_data *data; |
| 1513 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; |
| 1514 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1515 | |
| 1516 | desc->pg_lseg = NULL; |
| 1517 | while (!list_empty(head)) { |
| 1518 | enum pnfs_try_status trypnfs; |
| 1519 | |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1520 | data = list_first_entry(head, struct nfs_read_data, list); |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1521 | list_del_init(&data->list); |
| 1522 | |
| 1523 | trypnfs = pnfs_try_to_read_data(data, call_ops, lseg); |
| 1524 | if (trypnfs == PNFS_NOT_ATTEMPTED) |
| 1525 | pnfs_read_through_mds(desc, data); |
| 1526 | } |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1527 | pnfs_put_lseg(lseg); |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1528 | } |
| 1529 | |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1530 | static void pnfs_readhdr_free(struct nfs_pgio_header *hdr) |
| 1531 | { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1532 | pnfs_put_lseg(hdr->lseg); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1533 | nfs_readhdr_free(hdr); |
| 1534 | } |
Bryan Schumaker | 89d77c8 | 2012-07-30 16:05:25 -0400 | [diff] [blame] | 1535 | EXPORT_SYMBOL_GPL(pnfs_readhdr_free); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1536 | |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1537 | int |
| 1538 | pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) |
| 1539 | { |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1540 | struct nfs_read_header *rhdr; |
| 1541 | struct nfs_pgio_header *hdr; |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1542 | int ret; |
| 1543 | |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1544 | rhdr = nfs_readhdr_alloc(); |
| 1545 | if (!rhdr) { |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1546 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1547 | ret = -ENOMEM; |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1548 | pnfs_put_lseg(desc->pg_lseg); |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1549 | desc->pg_lseg = NULL; |
| 1550 | return ret; |
| 1551 | } |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1552 | hdr = &rhdr->header; |
| 1553 | nfs_pgheader_init(desc, hdr, pnfs_readhdr_free); |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1554 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1555 | atomic_inc(&hdr->refcnt); |
| 1556 | ret = nfs_generic_pagein(desc, hdr); |
| 1557 | if (ret != 0) { |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1558 | pnfs_put_lseg(desc->pg_lseg); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1559 | desc->pg_lseg = NULL; |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1560 | } else |
| 1561 | pnfs_do_multiple_reads(desc, &hdr->rpc_list); |
| 1562 | if (atomic_dec_and_test(&hdr->refcnt)) |
Fred Isaman | 061ae2e | 2012-04-20 14:47:48 -0400 | [diff] [blame] | 1563 | hdr->completion_ops->completion(hdr); |
Fred Isaman | 4db6e0b | 2012-04-20 14:47:46 -0400 | [diff] [blame] | 1564 | return ret; |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 1565 | } |
| 1566 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages); |
| 1567 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1568 | /* |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1569 | * There can be multiple RW segments. |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1570 | */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1571 | 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] | 1572 | { |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1573 | struct pnfs_layout_segment *lseg; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1574 | |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1575 | list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) { |
| 1576 | if (lseg->pls_range.iomode == IOMODE_RW && |
| 1577 | test_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags)) |
| 1578 | list_add(&lseg->pls_lc_list, listp); |
| 1579 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Peng Tao | 1b0ae06 | 2011-09-22 21:50:12 -0400 | [diff] [blame] | 1582 | void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg) |
| 1583 | { |
| 1584 | if (lseg->pls_range.iomode == IOMODE_RW) { |
| 1585 | dprintk("%s Setting layout IOMODE_RW fail bit\n", __func__); |
| 1586 | set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); |
| 1587 | } else { |
| 1588 | dprintk("%s Setting layout IOMODE_READ fail bit\n", __func__); |
| 1589 | set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); |
| 1590 | } |
| 1591 | } |
| 1592 | EXPORT_SYMBOL_GPL(pnfs_set_lo_fail); |
| 1593 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1594 | void |
| 1595 | pnfs_set_layoutcommit(struct nfs_write_data *wdata) |
| 1596 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1597 | struct nfs_pgio_header *hdr = wdata->header; |
| 1598 | struct inode *inode = hdr->inode; |
| 1599 | struct nfs_inode *nfsi = NFS_I(inode); |
Vitaliy Gusev | 4b8ee2b | 2011-05-20 01:34:46 +0400 | [diff] [blame] | 1600 | loff_t end_pos = wdata->mds_offset + wdata->res.count; |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1601 | bool mark_as_dirty = false; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1602 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1603 | spin_lock(&inode->i_lock); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1604 | if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1605 | mark_as_dirty = true; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1606 | dprintk("%s: Set layoutcommit for inode %lu ", |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1607 | __func__, inode->i_ino); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1608 | } |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1609 | if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &hdr->lseg->pls_flags)) { |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1610 | /* references matched in nfs4_layoutcommit_release */ |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame^] | 1611 | pnfs_get_lseg(hdr->lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1612 | } |
Peng Tao | acff5880 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1613 | if (end_pos > nfsi->layout->plh_lwb) |
| 1614 | nfsi->layout->plh_lwb = end_pos; |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1615 | spin_unlock(&inode->i_lock); |
Peng Tao | acff5880 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1616 | dprintk("%s: lseg %p end_pos %llu\n", |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1617 | __func__, hdr->lseg, nfsi->layout->plh_lwb); |
Weston Andros Adamson | 79a48a1 | 2011-04-13 10:53:51 -0400 | [diff] [blame] | 1618 | |
| 1619 | /* if pnfs_layoutcommit_inode() runs between inode locks, the next one |
| 1620 | * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */ |
| 1621 | if (mark_as_dirty) |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 1622 | mark_inode_dirty_sync(inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1623 | } |
| 1624 | EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit); |
| 1625 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 1626 | void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data) |
| 1627 | { |
| 1628 | struct nfs_server *nfss = NFS_SERVER(data->args.inode); |
| 1629 | |
| 1630 | if (nfss->pnfs_curr_ld->cleanup_layoutcommit) |
| 1631 | nfss->pnfs_curr_ld->cleanup_layoutcommit(data); |
| 1632 | } |
| 1633 | |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1634 | /* |
| 1635 | * For the LAYOUT4_NFSV4_1_FILES layout type, NFS_DATA_SYNC WRITEs and |
| 1636 | * NFS_UNSTABLE WRITEs with a COMMIT to data servers must store enough |
| 1637 | * data to disk to allow the server to recover the data if it crashes. |
| 1638 | * LAYOUTCOMMIT is only needed when the NFL4_UFLG_COMMIT_THRU_MDS flag |
| 1639 | * is off, and a COMMIT is sent to a data server, or |
| 1640 | * if WRITEs to a data server return NFS_DATA_SYNC. |
| 1641 | */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1642 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 1643 | pnfs_layoutcommit_inode(struct inode *inode, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1644 | { |
| 1645 | struct nfs4_layoutcommit_data *data; |
| 1646 | struct nfs_inode *nfsi = NFS_I(inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1647 | loff_t end_pos; |
| 1648 | int status = 0; |
| 1649 | |
| 1650 | dprintk("--> %s inode %lu\n", __func__, inode->i_ino); |
| 1651 | |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1652 | if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) |
| 1653 | return 0; |
| 1654 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1655 | /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */ |
| 1656 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1657 | if (!data) { |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1658 | status = -ENOMEM; |
| 1659 | goto out; |
| 1660 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1661 | |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 1662 | if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) |
| 1663 | goto out_free; |
| 1664 | |
| 1665 | if (test_and_set_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags)) { |
| 1666 | if (!sync) { |
| 1667 | status = -EAGAIN; |
| 1668 | goto out_free; |
| 1669 | } |
| 1670 | status = wait_on_bit_lock(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING, |
| 1671 | nfs_wait_bit_killable, TASK_KILLABLE); |
| 1672 | if (status) |
| 1673 | goto out_free; |
| 1674 | } |
| 1675 | |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1676 | INIT_LIST_HEAD(&data->lseg_list); |
Andy Adamson | de4b15c | 2011-03-12 02:58:09 -0500 | [diff] [blame] | 1677 | spin_lock(&inode->i_lock); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1678 | if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 1679 | clear_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1680 | spin_unlock(&inode->i_lock); |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 1681 | wake_up_bit(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING); |
| 1682 | goto out_free; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1683 | } |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 1684 | |
| 1685 | pnfs_list_write_lseg(inode, &data->lseg_list); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1686 | |
Peng Tao | acff5880 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1687 | end_pos = nfsi->layout->plh_lwb; |
Peng Tao | acff5880 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 1688 | nfsi->layout->plh_lwb = 0; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1689 | |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1690 | nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1691 | spin_unlock(&inode->i_lock); |
| 1692 | |
| 1693 | data->args.inode = inode; |
Peng Tao | 9fa4075 | 2011-07-30 20:52:32 -0400 | [diff] [blame] | 1694 | data->cred = get_rpccred(nfsi->layout->plh_lc_cred); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1695 | nfs_fattr_init(&data->fattr); |
| 1696 | data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
| 1697 | data->res.fattr = &data->fattr; |
| 1698 | data->args.lastbytewritten = end_pos - 1; |
| 1699 | data->res.server = NFS_SERVER(inode); |
| 1700 | |
| 1701 | status = nfs4_proc_layoutcommit(data, sync); |
| 1702 | out: |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 1703 | if (status) |
| 1704 | mark_inode_dirty_sync(inode); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1705 | dprintk("<-- %s status %d\n", __func__, status); |
| 1706 | return status; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 1707 | out_free: |
| 1708 | kfree(data); |
| 1709 | goto out; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 1710 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1711 | |
| 1712 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) |
| 1713 | { |
| 1714 | struct nfs4_threshold *thp; |
| 1715 | |
| 1716 | thp = kzalloc(sizeof(*thp), GFP_NOFS); |
| 1717 | if (!thp) { |
| 1718 | dprintk("%s mdsthreshold allocation failed\n", __func__); |
| 1719 | return NULL; |
| 1720 | } |
| 1721 | return thp; |
| 1722 | } |