Dean Hildebrand | 7ab672c | 2010-10-20 00:18:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Module for the pnfs nfs4 file layout driver. |
| 3 | * Defines all I/O and Policy interface operations, plus code |
| 4 | * to register itself with the pNFS client. |
| 5 | * |
| 6 | * Copyright (c) 2002 |
| 7 | * The Regents of the University of Michigan |
| 8 | * All Rights Reserved |
| 9 | * |
| 10 | * Dean Hildebrand <dhildebz@umich.edu> |
| 11 | * |
| 12 | * Permission is granted to use, copy, create derivative works, and |
| 13 | * redistribute this software and such derivative works for any purpose, |
| 14 | * so long as the name of the University of Michigan is not used in |
| 15 | * any advertising or publicity pertaining to the use or distribution |
| 16 | * of this software without specific, written prior authorization. If |
| 17 | * the above copyright notice or any other identification of the |
| 18 | * University of Michigan is included in any copy of any portion of |
| 19 | * this software, then the disclaimer below must also be included. |
| 20 | * |
| 21 | * This software is provided as is, without representation or warranty |
| 22 | * of any kind either express or implied, including without limitation |
| 23 | * the implied warranties of merchantability, fitness for a particular |
| 24 | * purpose, or noninfringement. The Regents of the University of |
| 25 | * Michigan shall not be liable for any damages, including special, |
| 26 | * indirect, incidental, or consequential damages, with respect to any |
| 27 | * claim arising out of or in connection with the use of the software, |
| 28 | * even if it has been or is hereafter advised of the possibility of |
| 29 | * such damages. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/nfs_fs.h> |
Benny Halevy | 19345cb | 2011-06-19 18:33:46 -0400 | [diff] [blame] | 33 | #include <linux/nfs_page.h> |
Paul Gortmaker | 143cb49 | 2011-07-01 14:23:34 -0400 | [diff] [blame] | 34 | #include <linux/module.h> |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 35 | |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 36 | #include <linux/sunrpc/metrics.h> |
| 37 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 38 | #include "internal.h" |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 39 | #include "delegation.h" |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 40 | #include "nfs4filelayout.h" |
Dean Hildebrand | 7ab672c | 2010-10-20 00:18:00 -0400 | [diff] [blame] | 41 | |
| 42 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 43 | |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>"); |
| 46 | MODULE_DESCRIPTION("The NFSv4 file layout driver"); |
| 47 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 48 | #define FILELAYOUT_POLL_RETRY_MAX (15*HZ) |
| 49 | |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 50 | static loff_t |
| 51 | filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg, |
| 52 | loff_t offset) |
| 53 | { |
| 54 | u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count; |
Chris Metcalf | 3476f11 | 2011-08-11 13:54:28 -0700 | [diff] [blame] | 55 | u64 stripe_no; |
| 56 | u32 rem; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 57 | |
| 58 | offset -= flseg->pattern_offset; |
Chris Metcalf | 3476f11 | 2011-08-11 13:54:28 -0700 | [diff] [blame] | 59 | stripe_no = div_u64(offset, stripe_width); |
| 60 | div_u64_rem(offset, flseg->stripe_unit, &rem); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 61 | |
Chris Metcalf | 3476f11 | 2011-08-11 13:54:28 -0700 | [diff] [blame] | 62 | return stripe_no * flseg->stripe_unit + rem; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* This function is used by the layout driver to calculate the |
| 66 | * offset of the file on the dserver based on whether the |
| 67 | * layout type is STRIPE_DENSE or STRIPE_SPARSE |
| 68 | */ |
| 69 | static loff_t |
| 70 | filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset) |
| 71 | { |
| 72 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 73 | |
| 74 | switch (flseg->stripe_type) { |
| 75 | case STRIPE_SPARSE: |
| 76 | return offset; |
| 77 | |
| 78 | case STRIPE_DENSE: |
| 79 | return filelayout_get_dense_offset(flseg, offset); |
| 80 | } |
| 81 | |
| 82 | BUG(); |
| 83 | } |
| 84 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 85 | static int filelayout_async_handle_error(struct rpc_task *task, |
| 86 | struct nfs4_state *state, |
| 87 | struct nfs_client *clp, |
| 88 | int *reset) |
| 89 | { |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 90 | struct nfs_server *mds_server = NFS_SERVER(state->inode); |
| 91 | struct nfs_client *mds_client = mds_server->nfs_client; |
| 92 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 93 | if (task->tk_status >= 0) |
| 94 | return 0; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 95 | *reset = 0; |
| 96 | |
| 97 | switch (task->tk_status) { |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 98 | /* MDS state errors */ |
| 99 | case -NFS4ERR_DELEG_REVOKED: |
| 100 | case -NFS4ERR_ADMIN_REVOKED: |
| 101 | case -NFS4ERR_BAD_STATEID: |
Andy Adamson | 2dc3175 | 2012-03-08 11:03:53 -0500 | [diff] [blame] | 102 | nfs_remove_bad_delegation(state->inode); |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 103 | case -NFS4ERR_OPENMODE: |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 104 | nfs4_schedule_stateid_recovery(mds_server, state); |
| 105 | goto wait_on_recovery; |
| 106 | case -NFS4ERR_EXPIRED: |
Andy Adamson | 2dc3175 | 2012-03-08 11:03:53 -0500 | [diff] [blame] | 107 | nfs4_schedule_stateid_recovery(mds_server, state); |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 108 | nfs4_schedule_lease_recovery(mds_client); |
| 109 | goto wait_on_recovery; |
| 110 | /* DS session errors */ |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 111 | case -NFS4ERR_BADSESSION: |
| 112 | case -NFS4ERR_BADSLOT: |
| 113 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 114 | case -NFS4ERR_DEADSESSION: |
| 115 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 116 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 117 | case -NFS4ERR_SEQ_MISORDERED: |
| 118 | dprintk("%s ERROR %d, Reset session. Exchangeid " |
| 119 | "flags 0x%x\n", __func__, task->tk_status, |
| 120 | clp->cl_exchange_flags); |
| 121 | nfs4_schedule_session_recovery(clp->cl_session); |
| 122 | break; |
| 123 | case -NFS4ERR_DELAY: |
| 124 | case -NFS4ERR_GRACE: |
| 125 | case -EKEYEXPIRED: |
| 126 | rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX); |
| 127 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 128 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 129 | break; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 130 | default: |
| 131 | dprintk("%s DS error. Retry through MDS %d\n", __func__, |
| 132 | task->tk_status); |
| 133 | *reset = 1; |
| 134 | break; |
| 135 | } |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 136 | out: |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 137 | task->tk_status = 0; |
| 138 | return -EAGAIN; |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 139 | wait_on_recovery: |
| 140 | rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL); |
| 141 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0) |
| 142 | rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task); |
| 143 | goto out; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* NFS_PROTO call done callback routines */ |
| 147 | |
| 148 | static int filelayout_read_done_cb(struct rpc_task *task, |
| 149 | struct nfs_read_data *data) |
| 150 | { |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 151 | int reset = 0; |
| 152 | |
| 153 | dprintk("%s DS read\n", __func__); |
| 154 | |
| 155 | if (filelayout_async_handle_error(task, data->args.context->state, |
| 156 | data->ds_clp, &reset) == -EAGAIN) { |
| 157 | dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n", |
| 158 | __func__, data->ds_clp, data->ds_clp->cl_session); |
| 159 | if (reset) { |
Peng Tao | 1b0ae06 | 2011-09-22 21:50:12 -0400 | [diff] [blame] | 160 | pnfs_set_lo_fail(data->lseg); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 161 | nfs4_reset_read(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 162 | } |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 163 | rpc_restart_call_prepare(task); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 164 | return -EAGAIN; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 170 | /* |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 171 | * We reference the rpc_cred of the first WRITE that triggers the need for |
| 172 | * a LAYOUTCOMMIT, and use it to send the layoutcommit compound. |
| 173 | * rfc5661 is not clear about which credential should be used. |
| 174 | */ |
| 175 | static void |
| 176 | filelayout_set_layoutcommit(struct nfs_write_data *wdata) |
| 177 | { |
| 178 | if (FILELAYOUT_LSEG(wdata->lseg)->commit_through_mds || |
| 179 | wdata->res.verf->committed == NFS_FILE_SYNC) |
| 180 | return; |
| 181 | |
| 182 | pnfs_set_layoutcommit(wdata); |
| 183 | dprintk("%s ionde %lu pls_end_pos %lu\n", __func__, wdata->inode->i_ino, |
Peng Tao | acff5880 | 2011-07-30 20:52:31 -0400 | [diff] [blame] | 184 | (unsigned long) NFS_I(wdata->inode)->layout->plh_lwb); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 188 | * Call ops for the async read/write cases |
| 189 | * In the case of dense layouts, the offset needs to be reset to its |
| 190 | * original value. |
| 191 | */ |
| 192 | static void filelayout_read_prepare(struct rpc_task *task, void *data) |
| 193 | { |
| 194 | struct nfs_read_data *rdata = (struct nfs_read_data *)data; |
| 195 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 196 | rdata->read_done_cb = filelayout_read_done_cb; |
| 197 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 198 | if (nfs41_setup_sequence(rdata->ds_clp->cl_session, |
| 199 | &rdata->args.seq_args, &rdata->res.seq_res, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 200 | task)) |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 201 | return; |
| 202 | |
| 203 | rpc_call_start(task); |
| 204 | } |
| 205 | |
| 206 | static void filelayout_read_call_done(struct rpc_task *task, void *data) |
| 207 | { |
| 208 | struct nfs_read_data *rdata = (struct nfs_read_data *)data; |
| 209 | |
| 210 | dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status); |
| 211 | |
| 212 | /* Note this may cause RPC to be resent */ |
| 213 | rdata->mds_ops->rpc_call_done(task, data); |
| 214 | } |
| 215 | |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 216 | static void filelayout_read_count_stats(struct rpc_task *task, void *data) |
| 217 | { |
| 218 | struct nfs_read_data *rdata = (struct nfs_read_data *)data; |
| 219 | |
| 220 | rpc_count_iostats(task, NFS_SERVER(rdata->inode)->client->cl_metrics); |
| 221 | } |
| 222 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 223 | static void filelayout_read_release(void *data) |
| 224 | { |
| 225 | struct nfs_read_data *rdata = (struct nfs_read_data *)data; |
| 226 | |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 227 | put_lseg(rdata->lseg); |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 228 | rdata->mds_ops->rpc_release(data); |
| 229 | } |
| 230 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 231 | static int filelayout_write_done_cb(struct rpc_task *task, |
| 232 | struct nfs_write_data *data) |
| 233 | { |
| 234 | int reset = 0; |
| 235 | |
| 236 | if (filelayout_async_handle_error(task, data->args.context->state, |
| 237 | data->ds_clp, &reset) == -EAGAIN) { |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 238 | dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n", |
| 239 | __func__, data->ds_clp, data->ds_clp->cl_session); |
| 240 | if (reset) { |
Peng Tao | 1b0ae06 | 2011-09-22 21:50:12 -0400 | [diff] [blame] | 241 | pnfs_set_lo_fail(data->lseg); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 242 | nfs4_reset_write(task, data); |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 243 | } |
| 244 | rpc_restart_call_prepare(task); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 245 | return -EAGAIN; |
| 246 | } |
| 247 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 248 | filelayout_set_layoutcommit(data); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 252 | /* Fake up some data that will cause nfs_commit_release to retry the writes. */ |
| 253 | static void prepare_to_resend_writes(struct nfs_write_data *data) |
| 254 | { |
| 255 | struct nfs_page *first = nfs_list_entry(data->pages.next); |
| 256 | |
| 257 | data->task.tk_status = 0; |
| 258 | memcpy(data->verf.verifier, first->wb_verf.verifier, |
| 259 | sizeof(first->wb_verf.verifier)); |
| 260 | data->verf.verifier[0]++; /* ensure verifier mismatch */ |
| 261 | } |
| 262 | |
| 263 | static int filelayout_commit_done_cb(struct rpc_task *task, |
| 264 | struct nfs_write_data *data) |
| 265 | { |
| 266 | int reset = 0; |
| 267 | |
| 268 | if (filelayout_async_handle_error(task, data->args.context->state, |
| 269 | data->ds_clp, &reset) == -EAGAIN) { |
| 270 | dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n", |
| 271 | __func__, data->ds_clp, data->ds_clp->cl_session); |
| 272 | if (reset) { |
| 273 | prepare_to_resend_writes(data); |
Peng Tao | 1b0ae06 | 2011-09-22 21:50:12 -0400 | [diff] [blame] | 274 | pnfs_set_lo_fail(data->lseg); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 275 | } else |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 276 | rpc_restart_call_prepare(task); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 277 | return -EAGAIN; |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 283 | static void filelayout_write_prepare(struct rpc_task *task, void *data) |
| 284 | { |
| 285 | struct nfs_write_data *wdata = (struct nfs_write_data *)data; |
| 286 | |
| 287 | if (nfs41_setup_sequence(wdata->ds_clp->cl_session, |
| 288 | &wdata->args.seq_args, &wdata->res.seq_res, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 289 | task)) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 290 | return; |
| 291 | |
| 292 | rpc_call_start(task); |
| 293 | } |
| 294 | |
| 295 | static void filelayout_write_call_done(struct rpc_task *task, void *data) |
| 296 | { |
| 297 | struct nfs_write_data *wdata = (struct nfs_write_data *)data; |
| 298 | |
| 299 | /* Note this may cause RPC to be resent */ |
| 300 | wdata->mds_ops->rpc_call_done(task, data); |
| 301 | } |
| 302 | |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 303 | static void filelayout_write_count_stats(struct rpc_task *task, void *data) |
| 304 | { |
| 305 | struct nfs_write_data *wdata = (struct nfs_write_data *)data; |
| 306 | |
| 307 | rpc_count_iostats(task, NFS_SERVER(wdata->inode)->client->cl_metrics); |
| 308 | } |
| 309 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 310 | static void filelayout_write_release(void *data) |
| 311 | { |
| 312 | struct nfs_write_data *wdata = (struct nfs_write_data *)data; |
| 313 | |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 314 | put_lseg(wdata->lseg); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 315 | wdata->mds_ops->rpc_release(data); |
| 316 | } |
| 317 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 318 | static void filelayout_commit_release(void *data) |
| 319 | { |
| 320 | struct nfs_write_data *wdata = (struct nfs_write_data *)data; |
| 321 | |
| 322 | nfs_commit_release_pages(wdata); |
| 323 | if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding)) |
| 324 | nfs_commit_clear_lock(NFS_I(wdata->inode)); |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 325 | put_lseg(wdata->lseg); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 326 | nfs_commitdata_release(wdata); |
| 327 | } |
| 328 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 329 | static const struct rpc_call_ops filelayout_read_call_ops = { |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 330 | .rpc_call_prepare = filelayout_read_prepare, |
| 331 | .rpc_call_done = filelayout_read_call_done, |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 332 | .rpc_count_stats = filelayout_read_count_stats, |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 333 | .rpc_release = filelayout_read_release, |
| 334 | }; |
| 335 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 336 | static const struct rpc_call_ops filelayout_write_call_ops = { |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 337 | .rpc_call_prepare = filelayout_write_prepare, |
| 338 | .rpc_call_done = filelayout_write_call_done, |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 339 | .rpc_count_stats = filelayout_write_count_stats, |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 340 | .rpc_release = filelayout_write_release, |
| 341 | }; |
| 342 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 343 | static const struct rpc_call_ops filelayout_commit_call_ops = { |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 344 | .rpc_call_prepare = filelayout_write_prepare, |
| 345 | .rpc_call_done = filelayout_write_call_done, |
Weston Andros Adamson | 0a70219 | 2012-02-17 13:15:24 -0500 | [diff] [blame] | 346 | .rpc_count_stats = filelayout_write_count_stats, |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 347 | .rpc_release = filelayout_commit_release, |
| 348 | }; |
| 349 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 350 | static enum pnfs_try_status |
| 351 | filelayout_read_pagelist(struct nfs_read_data *data) |
| 352 | { |
| 353 | struct pnfs_layout_segment *lseg = data->lseg; |
| 354 | struct nfs4_pnfs_ds *ds; |
| 355 | loff_t offset = data->args.offset; |
| 356 | u32 j, idx; |
| 357 | struct nfs_fh *fh; |
| 358 | int status; |
| 359 | |
| 360 | dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n", |
| 361 | __func__, data->inode->i_ino, |
| 362 | data->args.pgbase, (size_t)data->args.count, offset); |
| 363 | |
Andy Adamson | c47abcf | 2011-06-15 17:52:40 -0400 | [diff] [blame] | 364 | if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags)) |
| 365 | return PNFS_NOT_ATTEMPTED; |
| 366 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 367 | /* Retrieve the correct rpc_client for the byte range */ |
| 368 | j = nfs4_fl_calc_j_index(lseg, offset); |
| 369 | idx = nfs4_fl_calc_ds_index(lseg, j); |
| 370 | ds = nfs4_fl_prepare_ds(lseg, idx); |
| 371 | if (!ds) { |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 372 | /* Either layout fh index faulty, or ds connect failed */ |
| 373 | set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); |
| 374 | set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 375 | return PNFS_NOT_ATTEMPTED; |
| 376 | } |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 377 | dprintk("%s USE DS: %s\n", __func__, ds->ds_remotestr); |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 378 | |
| 379 | /* No multipath support. Use first DS */ |
| 380 | data->ds_clp = ds->ds_clp; |
| 381 | fh = nfs4_fl_select_ds_fh(lseg, j); |
| 382 | if (fh) |
| 383 | data->args.fh = fh; |
| 384 | |
| 385 | data->args.offset = filelayout_get_dserver_offset(lseg, offset); |
| 386 | data->mds_offset = offset; |
| 387 | |
| 388 | /* Perform an asynchronous read to ds */ |
| 389 | status = nfs_initiate_read(data, ds->ds_clp->cl_rpcclient, |
| 390 | &filelayout_read_call_ops); |
| 391 | BUG_ON(status != 0); |
| 392 | return PNFS_ATTEMPTED; |
| 393 | } |
| 394 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 395 | /* Perform async writes. */ |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 396 | static enum pnfs_try_status |
| 397 | filelayout_write_pagelist(struct nfs_write_data *data, int sync) |
| 398 | { |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 399 | struct pnfs_layout_segment *lseg = data->lseg; |
| 400 | struct nfs4_pnfs_ds *ds; |
| 401 | loff_t offset = data->args.offset; |
| 402 | u32 j, idx; |
| 403 | struct nfs_fh *fh; |
| 404 | int status; |
| 405 | |
Andy Adamson | c47abcf | 2011-06-15 17:52:40 -0400 | [diff] [blame] | 406 | if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags)) |
| 407 | return PNFS_NOT_ATTEMPTED; |
| 408 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 409 | /* Retrieve the correct rpc_client for the byte range */ |
| 410 | j = nfs4_fl_calc_j_index(lseg, offset); |
| 411 | idx = nfs4_fl_calc_ds_index(lseg, j); |
| 412 | ds = nfs4_fl_prepare_ds(lseg, idx); |
| 413 | if (!ds) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 414 | printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n", |
| 415 | __func__); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 416 | set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); |
| 417 | set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); |
| 418 | return PNFS_NOT_ATTEMPTED; |
| 419 | } |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 420 | dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s\n", __func__, |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 421 | data->inode->i_ino, sync, (size_t) data->args.count, offset, |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 422 | ds->ds_remotestr); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 423 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 424 | data->write_done_cb = filelayout_write_done_cb; |
| 425 | data->ds_clp = ds->ds_clp; |
| 426 | fh = nfs4_fl_select_ds_fh(lseg, j); |
| 427 | if (fh) |
| 428 | data->args.fh = fh; |
| 429 | /* |
| 430 | * Get the file offset on the dserver. Set the write offset to |
| 431 | * this offset and save the original offset. |
| 432 | */ |
| 433 | data->args.offset = filelayout_get_dserver_offset(lseg, offset); |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 434 | |
| 435 | /* Perform an asynchronous write */ |
| 436 | status = nfs_initiate_write(data, ds->ds_clp->cl_rpcclient, |
| 437 | &filelayout_write_call_ops, sync); |
| 438 | BUG_ON(status != 0); |
| 439 | return PNFS_ATTEMPTED; |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 442 | /* |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 443 | * filelayout_check_layout() |
| 444 | * |
| 445 | * Make sure layout segment parameters are sane WRT the device. |
| 446 | * At this point no generic layer initialization of the lseg has occurred, |
| 447 | * and nothing has been added to the layout_hdr cache. |
| 448 | * |
| 449 | */ |
| 450 | static int |
| 451 | filelayout_check_layout(struct pnfs_layout_hdr *lo, |
| 452 | struct nfs4_filelayout_segment *fl, |
| 453 | struct nfs4_layoutget_res *lgr, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 454 | struct nfs4_deviceid *id, |
| 455 | gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 456 | { |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 457 | struct nfs4_deviceid_node *d; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 458 | struct nfs4_file_layout_dsaddr *dsaddr; |
| 459 | int status = -EINVAL; |
Fred Isaman | b7edfaa | 2011-01-06 11:36:21 +0000 | [diff] [blame] | 460 | struct nfs_server *nfss = NFS_SERVER(lo->plh_inode); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 461 | |
| 462 | dprintk("--> %s\n", __func__); |
| 463 | |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 464 | /* FIXME: remove this check when layout segment support is added */ |
| 465 | if (lgr->range.offset != 0 || |
| 466 | lgr->range.length != NFS4_MAX_UINT64) { |
| 467 | dprintk("%s Only whole file layouts supported. Use MDS i/o\n", |
| 468 | __func__); |
| 469 | goto out; |
| 470 | } |
| 471 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 472 | if (fl->pattern_offset > lgr->range.offset) { |
Jim Rees | 3b6445a | 2011-02-22 19:31:57 -0500 | [diff] [blame] | 473 | dprintk("%s pattern_offset %lld too large\n", |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 474 | __func__, fl->pattern_offset); |
| 475 | goto out; |
| 476 | } |
| 477 | |
Benny Halevy | 75247af | 2011-02-22 15:56:01 -0800 | [diff] [blame] | 478 | if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) { |
| 479 | dprintk("%s Invalid stripe unit (%u)\n", |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 480 | __func__, fl->stripe_unit); |
| 481 | goto out; |
| 482 | } |
| 483 | |
| 484 | /* find and reference the deviceid */ |
Benny Halevy | 35c8bb5 | 2011-05-24 18:04:02 +0300 | [diff] [blame] | 485 | d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode)->pnfs_curr_ld, |
| 486 | NFS_SERVER(lo->plh_inode)->nfs_client, id); |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 487 | if (d == NULL) { |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 488 | dsaddr = get_device_info(lo->plh_inode, id, gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 489 | if (dsaddr == NULL) |
| 490 | goto out; |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 491 | } else |
| 492 | dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node); |
Andy Adamson | c47abcf | 2011-06-15 17:52:40 -0400 | [diff] [blame] | 493 | /* Found deviceid is being reaped */ |
| 494 | if (test_bit(NFS_DEVICEID_INVALID, &dsaddr->id_node.flags)) |
| 495 | goto out_put; |
| 496 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 497 | fl->dsaddr = dsaddr; |
| 498 | |
Chuck Lever | e414966 | 2011-10-25 12:18:03 -0400 | [diff] [blame] | 499 | if (fl->first_stripe_index >= dsaddr->stripe_count) { |
| 500 | dprintk("%s Bad first_stripe_index %u\n", |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 501 | __func__, fl->first_stripe_index); |
| 502 | goto out_put; |
| 503 | } |
| 504 | |
| 505 | if ((fl->stripe_type == STRIPE_SPARSE && |
| 506 | fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) || |
| 507 | (fl->stripe_type == STRIPE_DENSE && |
| 508 | fl->num_fh != dsaddr->stripe_count)) { |
| 509 | dprintk("%s num_fh %u not valid for given packing\n", |
| 510 | __func__, fl->num_fh); |
| 511 | goto out_put; |
| 512 | } |
| 513 | |
| 514 | if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) { |
| 515 | dprintk("%s Stripe unit (%u) not aligned with rsize %u " |
| 516 | "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize, |
| 517 | nfss->wsize); |
| 518 | } |
| 519 | |
| 520 | status = 0; |
| 521 | out: |
| 522 | dprintk("--> %s returns %d\n", __func__, status); |
| 523 | return status; |
| 524 | out_put: |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 525 | nfs4_fl_put_deviceid(dsaddr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 526 | goto out; |
| 527 | } |
| 528 | |
| 529 | static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl) |
| 530 | { |
| 531 | int i; |
| 532 | |
| 533 | for (i = 0; i < fl->num_fh; i++) { |
| 534 | if (!fl->fh_array[i]) |
| 535 | break; |
| 536 | kfree(fl->fh_array[i]); |
| 537 | } |
| 538 | kfree(fl->fh_array); |
| 539 | fl->fh_array = NULL; |
| 540 | } |
| 541 | |
| 542 | static void |
| 543 | _filelayout_free_lseg(struct nfs4_filelayout_segment *fl) |
| 544 | { |
| 545 | filelayout_free_fh_array(fl); |
| 546 | kfree(fl); |
| 547 | } |
| 548 | |
| 549 | static int |
| 550 | filelayout_decode_layout(struct pnfs_layout_hdr *flo, |
| 551 | struct nfs4_filelayout_segment *fl, |
| 552 | struct nfs4_layoutget_res *lgr, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 553 | struct nfs4_deviceid *id, |
| 554 | gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 555 | { |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 556 | struct xdr_stream stream; |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 557 | struct xdr_buf buf; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 558 | struct page *scratch; |
| 559 | __be32 *p; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 560 | uint32_t nfl_util; |
| 561 | int i; |
| 562 | |
| 563 | dprintk("%s: set_layout_map Begin\n", __func__); |
| 564 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 565 | scratch = alloc_page(gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 566 | if (!scratch) |
| 567 | return -ENOMEM; |
| 568 | |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 569 | xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 570 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
| 571 | |
| 572 | /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8), |
| 573 | * num_fh (4) */ |
| 574 | p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20); |
| 575 | if (unlikely(!p)) |
| 576 | goto out_err; |
| 577 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 578 | memcpy(id, p, sizeof(*id)); |
| 579 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 580 | nfs4_print_deviceid(id); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 581 | |
| 582 | nfl_util = be32_to_cpup(p++); |
| 583 | if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS) |
| 584 | fl->commit_through_mds = 1; |
| 585 | if (nfl_util & NFL4_UFLG_DENSE) |
| 586 | fl->stripe_type = STRIPE_DENSE; |
| 587 | else |
| 588 | fl->stripe_type = STRIPE_SPARSE; |
| 589 | fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK; |
| 590 | |
| 591 | fl->first_stripe_index = be32_to_cpup(p++); |
| 592 | p = xdr_decode_hyper(p, &fl->pattern_offset); |
| 593 | fl->num_fh = be32_to_cpup(p++); |
| 594 | |
| 595 | dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n", |
| 596 | __func__, nfl_util, fl->num_fh, fl->first_stripe_index, |
| 597 | fl->pattern_offset); |
| 598 | |
Andy Adamson | cec765c | 2011-06-13 18:36:17 -0400 | [diff] [blame] | 599 | /* Note that a zero value for num_fh is legal for STRIPE_SPARSE. |
| 600 | * Futher checking is done in filelayout_check_layout */ |
Chuck Lever | e414966 | 2011-10-25 12:18:03 -0400 | [diff] [blame] | 601 | if (fl->num_fh > |
Andy Adamson | cec765c | 2011-06-13 18:36:17 -0400 | [diff] [blame] | 602 | max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT)) |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 603 | goto out_err; |
| 604 | |
Andy Adamson | cec765c | 2011-06-13 18:36:17 -0400 | [diff] [blame] | 605 | if (fl->num_fh > 0) { |
| 606 | fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *), |
| 607 | gfp_flags); |
| 608 | if (!fl->fh_array) |
| 609 | goto out_err; |
| 610 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 611 | |
| 612 | for (i = 0; i < fl->num_fh; i++) { |
| 613 | /* Do we want to use a mempool here? */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 614 | fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 615 | if (!fl->fh_array[i]) |
| 616 | goto out_err_free; |
| 617 | |
| 618 | p = xdr_inline_decode(&stream, 4); |
| 619 | if (unlikely(!p)) |
| 620 | goto out_err_free; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 621 | fl->fh_array[i]->size = be32_to_cpup(p++); |
| 622 | if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) { |
Weston Andros Adamson | f9fd2d9 | 2012-01-26 13:32:22 -0500 | [diff] [blame] | 623 | printk(KERN_ERR "NFS: Too big fh %d received %d\n", |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 624 | i, fl->fh_array[i]->size); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 625 | goto out_err_free; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 626 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 627 | |
| 628 | p = xdr_inline_decode(&stream, fl->fh_array[i]->size); |
| 629 | if (unlikely(!p)) |
| 630 | goto out_err_free; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 631 | memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 632 | dprintk("DEBUG: %s: fh len %d\n", __func__, |
| 633 | fl->fh_array[i]->size); |
| 634 | } |
| 635 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 636 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 637 | return 0; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 638 | |
| 639 | out_err_free: |
| 640 | filelayout_free_fh_array(fl); |
| 641 | out_err: |
| 642 | __free_page(scratch); |
| 643 | return -EIO; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 644 | } |
| 645 | |
Fred Isaman | c879513 | 2011-03-23 13:27:49 +0000 | [diff] [blame] | 646 | static void |
| 647 | filelayout_free_lseg(struct pnfs_layout_segment *lseg) |
| 648 | { |
| 649 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); |
| 650 | |
| 651 | dprintk("--> %s\n", __func__); |
| 652 | nfs4_fl_put_deviceid(fl->dsaddr); |
Fred Isaman | 425eb73 | 2011-03-23 13:27:50 +0000 | [diff] [blame] | 653 | kfree(fl->commit_buckets); |
Fred Isaman | c879513 | 2011-03-23 13:27:49 +0000 | [diff] [blame] | 654 | _filelayout_free_lseg(fl); |
| 655 | } |
| 656 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 657 | static struct pnfs_layout_segment * |
| 658 | filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 659 | struct nfs4_layoutget_res *lgr, |
| 660 | gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 661 | { |
| 662 | struct nfs4_filelayout_segment *fl; |
| 663 | int rc; |
| 664 | struct nfs4_deviceid id; |
| 665 | |
| 666 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 667 | fl = kzalloc(sizeof(*fl), gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 668 | if (!fl) |
| 669 | return NULL; |
| 670 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 671 | rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags); |
| 672 | if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) { |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 673 | _filelayout_free_lseg(fl); |
| 674 | return NULL; |
| 675 | } |
Fred Isaman | 425eb73 | 2011-03-23 13:27:50 +0000 | [diff] [blame] | 676 | |
| 677 | /* This assumes there is only one IOMODE_RW lseg. What |
| 678 | * we really want to do is have a layout_hdr level |
| 679 | * dictionary of <multipath_list4, fh> keys, each |
| 680 | * associated with a struct list_head, populated by calls |
| 681 | * to filelayout_write_pagelist(). |
| 682 | * */ |
| 683 | if ((!fl->commit_through_mds) && (lgr->range.iomode == IOMODE_RW)) { |
| 684 | int i; |
| 685 | int size = (fl->stripe_type == STRIPE_SPARSE) ? |
| 686 | fl->dsaddr->ds_num : fl->dsaddr->stripe_count; |
| 687 | |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 688 | fl->commit_buckets = kcalloc(size, sizeof(struct nfs4_fl_commit_bucket), gfp_flags); |
Fred Isaman | 425eb73 | 2011-03-23 13:27:50 +0000 | [diff] [blame] | 689 | if (!fl->commit_buckets) { |
| 690 | filelayout_free_lseg(&fl->generic_hdr); |
| 691 | return NULL; |
| 692 | } |
| 693 | fl->number_of_buckets = size; |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 694 | for (i = 0; i < size; i++) { |
| 695 | INIT_LIST_HEAD(&fl->commit_buckets[i].written); |
| 696 | INIT_LIST_HEAD(&fl->commit_buckets[i].committing); |
| 697 | } |
Fred Isaman | 425eb73 | 2011-03-23 13:27:50 +0000 | [diff] [blame] | 698 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 699 | return &fl->generic_hdr; |
| 700 | } |
| 701 | |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 702 | /* |
| 703 | * filelayout_pg_test(). Called by nfs_can_coalesce_requests() |
| 704 | * |
Benny Halevy | 18ad0a9 | 2011-05-25 21:03:56 +0300 | [diff] [blame] | 705 | * return true : coalesce page |
| 706 | * return false : don't coalesce page |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 707 | */ |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 708 | static bool |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 709 | filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 710 | struct nfs_page *req) |
| 711 | { |
| 712 | u64 p_stripe, r_stripe; |
| 713 | u32 stripe_unit; |
| 714 | |
Benny Halevy | 19345cb | 2011-06-19 18:33:46 -0400 | [diff] [blame] | 715 | if (!pnfs_generic_pg_test(pgio, prev, req) || |
| 716 | !nfs_generic_pg_test(pgio, prev, req)) |
| 717 | return false; |
Benny Halevy | 89a58e3 | 2011-05-25 20:54:40 +0300 | [diff] [blame] | 718 | |
Fred Isaman | 94ad1c8 | 2011-03-01 01:34:14 +0000 | [diff] [blame] | 719 | p_stripe = (u64)prev->wb_index << PAGE_CACHE_SHIFT; |
| 720 | r_stripe = (u64)req->wb_index << PAGE_CACHE_SHIFT; |
| 721 | stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit; |
| 722 | |
| 723 | do_div(p_stripe, stripe_unit); |
| 724 | do_div(r_stripe, stripe_unit); |
| 725 | |
| 726 | return (p_stripe == r_stripe); |
| 727 | } |
| 728 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 729 | static void |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 730 | filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, |
| 731 | struct nfs_page *req) |
| 732 | { |
| 733 | BUG_ON(pgio->pg_lseg != NULL); |
| 734 | |
| 735 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 736 | req->wb_context, |
| 737 | 0, |
| 738 | NFS4_MAX_UINT64, |
| 739 | IOMODE_READ, |
| 740 | GFP_KERNEL); |
| 741 | /* If no lseg, fall back to read through mds */ |
| 742 | if (pgio->pg_lseg == NULL) |
Trond Myklebust | 1f94535 | 2011-07-13 15:59:57 -0400 | [diff] [blame] | 743 | nfs_pageio_reset_read_mds(pgio); |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 746 | static void |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 747 | filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio, |
| 748 | struct nfs_page *req) |
| 749 | { |
| 750 | BUG_ON(pgio->pg_lseg != NULL); |
| 751 | |
| 752 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 753 | req->wb_context, |
| 754 | 0, |
| 755 | NFS4_MAX_UINT64, |
| 756 | IOMODE_RW, |
| 757 | GFP_NOFS); |
| 758 | /* If no lseg, fall back to write through mds */ |
| 759 | if (pgio->pg_lseg == NULL) |
Trond Myklebust | 1f94535 | 2011-07-13 15:59:57 -0400 | [diff] [blame] | 760 | nfs_pageio_reset_write_mds(pgio); |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 763 | static const struct nfs_pageio_ops filelayout_pg_read_ops = { |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 764 | .pg_init = filelayout_pg_init_read, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 765 | .pg_test = filelayout_pg_test, |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 766 | .pg_doio = pnfs_generic_pg_readpages, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | static const struct nfs_pageio_ops filelayout_pg_write_ops = { |
Andy Adamson | 7c24d94 | 2011-06-13 18:22:38 -0400 | [diff] [blame] | 770 | .pg_init = filelayout_pg_init_write, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 771 | .pg_test = filelayout_pg_test, |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 772 | .pg_doio = pnfs_generic_pg_writepages, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 773 | }; |
| 774 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 775 | static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) |
| 776 | { |
| 777 | if (fl->stripe_type == STRIPE_SPARSE) |
| 778 | return nfs4_fl_calc_ds_index(&fl->generic_hdr, j); |
| 779 | else |
| 780 | return j; |
| 781 | } |
| 782 | |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 783 | /* The generic layer is about to remove the req from the commit list. |
| 784 | * If this will make the bucket empty, it will need to put the lseg reference. |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 785 | */ |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 786 | static void |
| 787 | filelayout_clear_request_commit(struct nfs_page *req) |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 788 | { |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 789 | struct pnfs_layout_segment *freeme = NULL; |
| 790 | struct inode *inode = req->wb_context->dentry->d_inode; |
| 791 | |
| 792 | spin_lock(&inode->i_lock); |
| 793 | if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags)) |
| 794 | goto out; |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 795 | if (list_is_singular(&req->wb_list)) { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 796 | struct pnfs_layout_segment *lseg; |
| 797 | |
| 798 | /* From here we can find the bucket, but for the moment, |
| 799 | * since there is only one relevant lseg... |
| 800 | */ |
| 801 | list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) { |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 802 | if (lseg->pls_range.iomode == IOMODE_RW) { |
| 803 | freeme = lseg; |
| 804 | break; |
| 805 | } |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 806 | } |
| 807 | } |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 808 | out: |
| 809 | nfs_request_remove_commit_list(req); |
| 810 | spin_unlock(&inode->i_lock); |
| 811 | put_lseg(freeme); |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static struct list_head * |
| 815 | filelayout_choose_commit_list(struct nfs_page *req, |
| 816 | struct pnfs_layout_segment *lseg) |
| 817 | { |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 818 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); |
| 819 | u32 i, j; |
| 820 | struct list_head *list; |
| 821 | |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 822 | if (fl->commit_through_mds) |
| 823 | return &NFS_I(req->wb_context->dentry->d_inode)->commit_list; |
| 824 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 825 | /* Note that we are calling nfs4_fl_calc_j_index on each page |
| 826 | * that ends up being committed to a data server. An attractive |
| 827 | * alternative is to add a field to nfs_write_data and nfs_page |
| 828 | * to store the value calculated in filelayout_write_pagelist |
| 829 | * and just use that here. |
| 830 | */ |
| 831 | j = nfs4_fl_calc_j_index(lseg, |
| 832 | (loff_t)req->wb_index << PAGE_CACHE_SHIFT); |
| 833 | i = select_bucket_index(fl, j); |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 834 | list = &fl->commit_buckets[i].written; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 835 | if (list_empty(list)) { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 836 | /* Non-empty buckets hold a reference on the lseg. That ref |
| 837 | * is normally transferred to the COMMIT call and released |
| 838 | * there. It could also be released if the last req is pulled |
| 839 | * off due to a rewrite, in which case it will be done in |
| 840 | * filelayout_remove_commit_req |
| 841 | */ |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 842 | get_lseg(lseg); |
| 843 | } |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 844 | set_bit(PG_COMMIT_TO_DS, &req->wb_flags); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 845 | return list; |
| 846 | } |
| 847 | |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 848 | static void |
| 849 | filelayout_mark_request_commit(struct nfs_page *req, |
| 850 | struct pnfs_layout_segment *lseg) |
| 851 | { |
| 852 | struct list_head *list; |
| 853 | |
| 854 | list = filelayout_choose_commit_list(req, lseg); |
| 855 | nfs_request_add_commit_list(req, list); |
| 856 | } |
| 857 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 858 | static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) |
| 859 | { |
| 860 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 861 | |
| 862 | if (flseg->stripe_type == STRIPE_SPARSE) |
| 863 | return i; |
| 864 | else |
| 865 | return nfs4_fl_calc_ds_index(lseg, i); |
| 866 | } |
| 867 | |
| 868 | static struct nfs_fh * |
| 869 | select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i) |
| 870 | { |
| 871 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 872 | |
| 873 | if (flseg->stripe_type == STRIPE_SPARSE) { |
| 874 | if (flseg->num_fh == 1) |
| 875 | i = 0; |
| 876 | else if (flseg->num_fh == 0) |
| 877 | /* Use the MDS OPEN fh set in nfs_read_rpcsetup */ |
| 878 | return NULL; |
| 879 | } |
| 880 | return flseg->fh_array[i]; |
| 881 | } |
| 882 | |
| 883 | static int filelayout_initiate_commit(struct nfs_write_data *data, int how) |
| 884 | { |
| 885 | struct pnfs_layout_segment *lseg = data->lseg; |
| 886 | struct nfs4_pnfs_ds *ds; |
| 887 | u32 idx; |
| 888 | struct nfs_fh *fh; |
| 889 | |
| 890 | idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); |
| 891 | ds = nfs4_fl_prepare_ds(lseg, idx); |
| 892 | if (!ds) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 893 | printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n", |
| 894 | __func__); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 895 | set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); |
| 896 | set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); |
| 897 | prepare_to_resend_writes(data); |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 898 | filelayout_commit_release(data); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 899 | return -EAGAIN; |
| 900 | } |
| 901 | dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how); |
| 902 | data->write_done_cb = filelayout_commit_done_cb; |
| 903 | data->ds_clp = ds->ds_clp; |
| 904 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); |
| 905 | if (fh) |
| 906 | data->args.fh = fh; |
| 907 | return nfs_initiate_commit(data, ds->ds_clp->cl_rpcclient, |
| 908 | &filelayout_commit_call_ops, how); |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * This is only useful while we are using whole file layouts. |
| 913 | */ |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 914 | static struct pnfs_layout_segment * |
| 915 | find_only_write_lseg_locked(struct inode *inode) |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 916 | { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 917 | struct pnfs_layout_segment *lseg; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 918 | |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 919 | list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) |
| 920 | if (lseg->pls_range.iomode == IOMODE_RW) |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 921 | return lseg; |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 922 | return NULL; |
| 923 | } |
| 924 | |
| 925 | static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode) |
| 926 | { |
| 927 | struct pnfs_layout_segment *rv; |
| 928 | |
| 929 | spin_lock(&inode->i_lock); |
| 930 | rv = find_only_write_lseg_locked(inode); |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 931 | if (rv) |
| 932 | get_lseg(rv); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 933 | spin_unlock(&inode->i_lock); |
| 934 | return rv; |
| 935 | } |
| 936 | |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 937 | static int |
Trond Myklebust | 3b3be88 | 2012-03-17 11:59:30 -0400 | [diff] [blame] | 938 | filelayout_scan_ds_commit_list(struct nfs4_fl_commit_bucket *bucket, int max, |
| 939 | spinlock_t *lock) |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 940 | { |
| 941 | struct list_head *src = &bucket->written; |
| 942 | struct list_head *dst = &bucket->committing; |
| 943 | struct nfs_page *req, *tmp; |
| 944 | int ret = 0; |
| 945 | |
| 946 | list_for_each_entry_safe(req, tmp, src, wb_list) { |
| 947 | if (!nfs_lock_request(req)) |
| 948 | continue; |
Trond Myklebust | 3b3be88 | 2012-03-17 11:59:30 -0400 | [diff] [blame] | 949 | if (cond_resched_lock(lock)) |
| 950 | list_safe_reset_next(req, tmp, wb_list); |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 951 | nfs_request_remove_commit_list(req); |
| 952 | clear_bit(PG_COMMIT_TO_DS, &req->wb_flags); |
| 953 | nfs_list_add_request(req, dst); |
| 954 | ret++; |
| 955 | if (ret == max) |
| 956 | break; |
| 957 | } |
| 958 | return ret; |
| 959 | } |
| 960 | |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 961 | /* Move reqs from written to committing lists, returning count of number moved. |
| 962 | * Note called with i_lock held. |
| 963 | */ |
Trond Myklebust | 3b3be88 | 2012-03-17 11:59:30 -0400 | [diff] [blame] | 964 | static int filelayout_scan_commit_lists(struct inode *inode, int max, |
| 965 | spinlock_t *lock) |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 966 | { |
| 967 | struct pnfs_layout_segment *lseg; |
| 968 | struct nfs4_filelayout_segment *fl; |
| 969 | int i, rv = 0, cnt; |
| 970 | |
| 971 | lseg = find_only_write_lseg_locked(inode); |
| 972 | if (!lseg) |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 973 | goto out_done; |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 974 | fl = FILELAYOUT_LSEG(lseg); |
| 975 | if (fl->commit_through_mds) |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 976 | goto out_done; |
| 977 | for (i = 0; i < fl->number_of_buckets && max != 0; i++) { |
Trond Myklebust | 3b3be88 | 2012-03-17 11:59:30 -0400 | [diff] [blame] | 978 | cnt = filelayout_scan_ds_commit_list(&fl->commit_buckets[i], |
| 979 | max, lock); |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 980 | max -= cnt; |
| 981 | rv += cnt; |
| 982 | } |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 983 | out_done: |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 984 | return rv; |
| 985 | } |
| 986 | |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 987 | static unsigned int |
| 988 | alloc_ds_commits(struct inode *inode, struct list_head *list) |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 989 | { |
| 990 | struct pnfs_layout_segment *lseg; |
| 991 | struct nfs4_filelayout_segment *fl; |
| 992 | struct nfs_write_data *data; |
| 993 | int i, j; |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 994 | unsigned int nreq = 0; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 995 | |
| 996 | /* Won't need this when non-whole file layout segments are supported |
| 997 | * instead we will use a pnfs_layout_hdr structure */ |
| 998 | lseg = find_only_write_lseg(inode); |
| 999 | if (!lseg) |
| 1000 | return 0; |
| 1001 | fl = FILELAYOUT_LSEG(lseg); |
| 1002 | for (i = 0; i < fl->number_of_buckets; i++) { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 1003 | if (list_empty(&fl->commit_buckets[i].committing)) |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1004 | continue; |
| 1005 | data = nfs_commitdata_alloc(); |
| 1006 | if (!data) |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1007 | break; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1008 | data->ds_commit_index = i; |
| 1009 | data->lseg = lseg; |
| 1010 | list_add(&data->pages, list); |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1011 | nreq++; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1012 | } |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1013 | |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1014 | /* Clean up on error */ |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1015 | for (j = i; j < fl->number_of_buckets; j++) { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 1016 | if (list_empty(&fl->commit_buckets[i].committing)) |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1017 | continue; |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 1018 | nfs_retry_commit(&fl->commit_buckets[i].committing, lseg); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1019 | put_lseg(lseg); /* associated with emptying bucket */ |
| 1020 | } |
| 1021 | put_lseg(lseg); |
| 1022 | /* Caller will clean up entries put on list */ |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1023 | return nreq; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /* This follows nfs_commit_list pretty closely */ |
| 1027 | static int |
| 1028 | filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, |
| 1029 | int how) |
| 1030 | { |
| 1031 | struct nfs_write_data *data, *tmp; |
| 1032 | LIST_HEAD(list); |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1033 | unsigned int nreq = 0; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1034 | |
| 1035 | if (!list_empty(mds_pages)) { |
| 1036 | data = nfs_commitdata_alloc(); |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1037 | if (data != NULL) { |
| 1038 | data->lseg = NULL; |
| 1039 | list_add(&data->pages, &list); |
| 1040 | nreq++; |
| 1041 | } else |
| 1042 | nfs_retry_commit(mds_pages, NULL); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1045 | nreq += alloc_ds_commits(inode, &list); |
| 1046 | |
| 1047 | if (nreq == 0) { |
| 1048 | nfs_commit_clear_lock(NFS_I(inode)); |
| 1049 | goto out; |
| 1050 | } |
| 1051 | |
| 1052 | atomic_add(nreq, &NFS_I(inode)->commits_outstanding); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1053 | |
| 1054 | list_for_each_entry_safe(data, tmp, &list, pages) { |
| 1055 | list_del_init(&data->pages); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1056 | if (!data->lseg) { |
| 1057 | nfs_init_commit(data, mds_pages, NULL); |
| 1058 | nfs_initiate_commit(data, NFS_CLIENT(inode), |
| 1059 | data->mds_ops, how); |
| 1060 | } else { |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 1061 | nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index].committing, data->lseg); |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1062 | filelayout_initiate_commit(data, how); |
| 1063 | } |
| 1064 | } |
Trond Myklebust | 9390f42 | 2012-03-16 13:52:45 -0400 | [diff] [blame] | 1065 | out: |
| 1066 | return PNFS_ATTEMPTED; |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 1069 | static void |
| 1070 | filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d) |
| 1071 | { |
| 1072 | nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node)); |
| 1073 | } |
| 1074 | |
Dean Hildebrand | 7ab672c | 2010-10-20 00:18:00 -0400 | [diff] [blame] | 1075 | static struct pnfs_layoutdriver_type filelayout_type = { |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 1076 | .id = LAYOUT_NFSV4_1_FILES, |
| 1077 | .name = "LAYOUT_NFSV4_1_FILES", |
| 1078 | .owner = THIS_MODULE, |
| 1079 | .alloc_lseg = filelayout_alloc_lseg, |
| 1080 | .free_lseg = filelayout_free_lseg, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 1081 | .pg_read_ops = &filelayout_pg_read_ops, |
| 1082 | .pg_write_ops = &filelayout_pg_write_ops, |
Trond Myklebust | 8dd3775 | 2012-03-15 17:16:40 -0400 | [diff] [blame] | 1083 | .mark_request_commit = filelayout_mark_request_commit, |
| 1084 | .clear_request_commit = filelayout_clear_request_commit, |
Fred Isaman | d6d6dc7 | 2012-03-08 17:29:35 -0500 | [diff] [blame] | 1085 | .scan_commit_lists = filelayout_scan_commit_lists, |
Fred Isaman | e0c2b38 | 2011-03-23 13:27:53 +0000 | [diff] [blame] | 1086 | .commit_pagelist = filelayout_commit_pagelist, |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 1087 | .read_pagelist = filelayout_read_pagelist, |
Andy Adamson | 0382b74 | 2011-03-03 15:13:45 +0000 | [diff] [blame] | 1088 | .write_pagelist = filelayout_write_pagelist, |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 1089 | .free_deviceid_node = filelayout_free_deveiceid_node, |
Dean Hildebrand | 7ab672c | 2010-10-20 00:18:00 -0400 | [diff] [blame] | 1090 | }; |
| 1091 | |
| 1092 | static int __init nfs4filelayout_init(void) |
| 1093 | { |
| 1094 | printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n", |
| 1095 | __func__); |
| 1096 | return pnfs_register_layoutdriver(&filelayout_type); |
| 1097 | } |
| 1098 | |
| 1099 | static void __exit nfs4filelayout_exit(void) |
| 1100 | { |
| 1101 | printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n", |
| 1102 | __func__); |
| 1103 | pnfs_unregister_layoutdriver(&filelayout_type); |
| 1104 | } |
| 1105 | |
J. Bruce Fields | f85ef69 | 2011-07-15 19:18:42 -0400 | [diff] [blame] | 1106 | MODULE_ALIAS("nfs-layouttype4-1"); |
| 1107 | |
Dean Hildebrand | 7ab672c | 2010-10-20 00:18:00 -0400 | [diff] [blame] | 1108 | module_init(nfs4filelayout_init); |
| 1109 | module_exit(nfs4filelayout_exit); |