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