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