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