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