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