blob: a63062d3882fc3dd40996f70f9149415c47bb458 [file] [log] [blame]
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001/*
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 Halevy19345cb2011-06-19 18:33:46 -040033#include <linux/nfs_page.h>
Paul Gortmaker143cb492011-07-01 14:23:34 -040034#include <linux/module.h>
Andy Adamson16b374c2010-10-20 00:18:04 -040035
Weston Andros Adamson0a702192012-02-17 13:15:24 -050036#include <linux/sunrpc/metrics.h>
37
Andy Adamson16b374c2010-10-20 00:18:04 -040038#include "internal.h"
Andy Adamson9cb81962012-03-07 10:49:41 -050039#include "delegation.h"
Andy Adamson16b374c2010-10-20 00:18:04 -040040#include "nfs4filelayout.h"
Dean Hildebrand7ab672c2010-10-20 00:18:00 -040041
42#define NFSDBG_FACILITY NFSDBG_PNFS_LD
43
44MODULE_LICENSE("GPL");
45MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
46MODULE_DESCRIPTION("The NFSv4 file layout driver");
47
Andy Adamsoncbdabc72011-03-01 01:34:20 +000048#define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
49
Fred Isamancfe7f412011-03-01 01:34:18 +000050static loff_t
51filelayout_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 Metcalf3476f112011-08-11 13:54:28 -070055 u64 stripe_no;
56 u32 rem;
Fred Isamancfe7f412011-03-01 01:34:18 +000057
58 offset -= flseg->pattern_offset;
Chris Metcalf3476f112011-08-11 13:54:28 -070059 stripe_no = div_u64(offset, stripe_width);
60 div_u64_rem(offset, flseg->stripe_unit, &rem);
Fred Isamancfe7f412011-03-01 01:34:18 +000061
Chris Metcalf3476f112011-08-11 13:54:28 -070062 return stripe_no * flseg->stripe_unit + rem;
Fred Isamancfe7f412011-03-01 01:34:18 +000063}
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 */
69static loff_t
70filelayout_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 Adamsone7dd79af2012-04-27 17:53:46 -040085static 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
106static 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 Adamsoncbdabc72011-03-01 01:34:20 +0000127static int filelayout_async_handle_error(struct rpc_task *task,
128 struct nfs4_state *state,
129 struct nfs_client *clp,
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400130 struct pnfs_layout_segment *lseg)
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000131{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400132 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 Adamson9cb81962012-03-07 10:49:41 -0500135 struct nfs_client *mds_client = mds_server->nfs_client;
Andy Adamson671fb892012-04-27 17:53:49 -0400136 struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
Andy Adamson9cb81962012-03-07 10:49:41 -0500137
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000138 if (task->tk_status >= 0)
139 return 0;
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000140
141 switch (task->tk_status) {
Andy Adamson9cb81962012-03-07 10:49:41 -0500142 /* MDS state errors */
143 case -NFS4ERR_DELEG_REVOKED:
144 case -NFS4ERR_ADMIN_REVOKED:
145 case -NFS4ERR_BAD_STATEID:
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400146 if (state == NULL)
147 break;
Andy Adamson2dc31752012-03-08 11:03:53 -0500148 nfs_remove_bad_delegation(state->inode);
Andy Adamson9cb81962012-03-07 10:49:41 -0500149 case -NFS4ERR_OPENMODE:
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400150 if (state == NULL)
151 break;
Andy Adamson9cb81962012-03-07 10:49:41 -0500152 nfs4_schedule_stateid_recovery(mds_server, state);
153 goto wait_on_recovery;
154 case -NFS4ERR_EXPIRED:
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400155 if (state != NULL)
156 nfs4_schedule_stateid_recovery(mds_server, state);
Andy Adamson9cb81962012-03-07 10:49:41 -0500157 nfs4_schedule_lease_recovery(mds_client);
158 goto wait_on_recovery;
159 /* DS session errors */
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000160 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 Adamsona8a4ae32011-05-03 13:43:03 -0400177 case -NFS4ERR_RETRY_UNCACHED_REP:
178 break;
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400179 /* 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 Adamsoncbdabc72011-03-01 01:34:20 +0000188 task->tk_status);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400189 filelayout_mark_devid_invalid(devid);
Andy Adamson671fb892012-04-27 17:53:49 -0400190 rpc_wake_up(&tbl->slot_tbl_waitq);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400191 /* 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 Adamsoncbdabc72011-03-01 01:34:20 +0000196 }
Andy Adamson9cb81962012-03-07 10:49:41 -0500197out:
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000198 task->tk_status = 0;
199 return -EAGAIN;
Andy Adamson9cb81962012-03-07 10:49:41 -0500200wait_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 Adamsoncbdabc72011-03-01 01:34:20 +0000205}
206
207/* NFS_PROTO call done callback routines */
208
209static int filelayout_read_done_cb(struct rpc_task *task,
210 struct nfs_read_data *data)
211{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400212 struct nfs_pgio_header *hdr = data->header;
213 int err;
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000214
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400215 err = filelayout_async_handle_error(task, data->args.context->state,
216 data->ds_clp, hdr->lseg);
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000217
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400218 switch (err) {
219 case -NFS4ERR_RESET_TO_MDS:
220 filelayout_reset_read(data);
221 return task->tk_status;
222 case -EAGAIN:
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700223 rpc_restart_call_prepare(task);
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000224 return -EAGAIN;
225 }
226
227 return 0;
228}
229
Andy Adamson16b374c2010-10-20 00:18:04 -0400230/*
Andy Adamson863a3c62011-03-23 13:27:54 +0000231 * 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 */
235static void
236filelayout_set_layoutcommit(struct nfs_write_data *wdata)
237{
Fred Isamancd841602012-04-20 14:47:44 -0400238 struct nfs_pgio_header *hdr = wdata->header;
239
240 if (FILELAYOUT_LSEG(hdr->lseg)->commit_through_mds ||
Andy Adamson863a3c62011-03-23 13:27:54 +0000241 wdata->res.verf->committed == NFS_FILE_SYNC)
242 return;
243
244 pnfs_set_layoutcommit(wdata);
Fred Isamancd841602012-04-20 14:47:44 -0400245 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 Adamson863a3c62011-03-23 13:27:54 +0000247}
248
249/*
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000250 * 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 */
254static void filelayout_read_prepare(struct rpc_task *task, void *data)
255{
Fred Isamancd12ae32012-04-20 14:47:42 -0400256 struct nfs_read_data *rdata = data;
Andy Adamson0ad2f372012-04-27 17:53:48 -0400257 struct pnfs_layout_segment *lseg = rdata->header->lseg;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000258
Andy Adamson0ad2f372012-04-27 17:53:48 -0400259 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 Adamsoncbdabc72011-03-01 01:34:20 +0000265 rdata->read_done_cb = filelayout_read_done_cb;
266
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000267 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
268 &rdata->args.seq_args, &rdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500269 task))
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000270 return;
271
272 rpc_call_start(task);
273}
274
275static void filelayout_read_call_done(struct rpc_task *task, void *data)
276{
Fred Isamancd12ae32012-04-20 14:47:42 -0400277 struct nfs_read_data *rdata = data;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000278
279 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
280
Andy Adamson0ad2f372012-04-27 17:53:48 -0400281 if (test_bit(NFS_IOHDR_REDO, &rdata->header->flags))
282 return;
283
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000284 /* Note this may cause RPC to be resent */
Fred Isamancd841602012-04-20 14:47:44 -0400285 rdata->header->mds_ops->rpc_call_done(task, data);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000286}
287
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500288static void filelayout_read_count_stats(struct rpc_task *task, void *data)
289{
Fred Isamancd12ae32012-04-20 14:47:42 -0400290 struct nfs_read_data *rdata = data;
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500291
Fred Isamancd841602012-04-20 14:47:44 -0400292 rpc_count_iostats(task, NFS_SERVER(rdata->header->inode)->client->cl_metrics);
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500293}
294
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000295static void filelayout_read_release(void *data)
296{
Fred Isamancd12ae32012-04-20 14:47:42 -0400297 struct nfs_read_data *rdata = data;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000298
Fred Isamancd841602012-04-20 14:47:44 -0400299 rdata->header->mds_ops->rpc_release(data);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000300}
301
Fred Isamana69aef12011-03-03 15:13:47 +0000302static int filelayout_write_done_cb(struct rpc_task *task,
303 struct nfs_write_data *data)
304{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400305 struct nfs_pgio_header *hdr = data->header;
306 int err;
Fred Isamana69aef12011-03-03 15:13:47 +0000307
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400308 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 Myklebustd00c5d42011-10-19 12:17:29 -0700316 rpc_restart_call_prepare(task);
Fred Isamana69aef12011-03-03 15:13:47 +0000317 return -EAGAIN;
318 }
319
Andy Adamson863a3c62011-03-23 13:27:54 +0000320 filelayout_set_layoutcommit(data);
Fred Isamana69aef12011-03-03 15:13:47 +0000321 return 0;
322}
323
Fred Isamane0c2b382011-03-23 13:27:53 +0000324/* Fake up some data that will cause nfs_commit_release to retry the writes. */
Fred Isaman0b7c0152012-04-20 14:47:39 -0400325static void prepare_to_resend_writes(struct nfs_commit_data *data)
Fred Isamane0c2b382011-03-23 13:27:53 +0000326{
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
335static int filelayout_commit_done_cb(struct rpc_task *task,
Fred Isaman0b7c0152012-04-20 14:47:39 -0400336 struct nfs_commit_data *data)
Fred Isamane0c2b382011-03-23 13:27:53 +0000337{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400338 int err;
Fred Isamane0c2b382011-03-23 13:27:53 +0000339
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400340 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 Isamane0c2b382011-03-23 13:27:53 +0000349 return -EAGAIN;
350 }
351
352 return 0;
353}
354
Fred Isamana69aef12011-03-03 15:13:47 +0000355static void filelayout_write_prepare(struct rpc_task *task, void *data)
356{
Fred Isamancd12ae32012-04-20 14:47:42 -0400357 struct nfs_write_data *wdata = data;
Andy Adamson0ad2f372012-04-27 17:53:48 -0400358 struct pnfs_layout_segment *lseg = wdata->header->lseg;
Fred Isamana69aef12011-03-03 15:13:47 +0000359
Andy Adamson0ad2f372012-04-27 17:53:48 -0400360 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 Isamana69aef12011-03-03 15:13:47 +0000366 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
367 &wdata->args.seq_args, &wdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500368 task))
Fred Isamana69aef12011-03-03 15:13:47 +0000369 return;
370
371 rpc_call_start(task);
372}
373
374static void filelayout_write_call_done(struct rpc_task *task, void *data)
375{
Fred Isamancd12ae32012-04-20 14:47:42 -0400376 struct nfs_write_data *wdata = data;
Fred Isamana69aef12011-03-03 15:13:47 +0000377
Andy Adamson0ad2f372012-04-27 17:53:48 -0400378 if (test_bit(NFS_IOHDR_REDO, &wdata->header->flags))
379 return;
380
Fred Isamana69aef12011-03-03 15:13:47 +0000381 /* Note this may cause RPC to be resent */
Fred Isamancd841602012-04-20 14:47:44 -0400382 wdata->header->mds_ops->rpc_call_done(task, data);
Fred Isamana69aef12011-03-03 15:13:47 +0000383}
384
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500385static void filelayout_write_count_stats(struct rpc_task *task, void *data)
386{
Fred Isamancd12ae32012-04-20 14:47:42 -0400387 struct nfs_write_data *wdata = data;
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500388
Fred Isamancd841602012-04-20 14:47:44 -0400389 rpc_count_iostats(task, NFS_SERVER(wdata->header->inode)->client->cl_metrics);
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500390}
391
Fred Isamana69aef12011-03-03 15:13:47 +0000392static void filelayout_write_release(void *data)
393{
Fred Isamancd12ae32012-04-20 14:47:42 -0400394 struct nfs_write_data *wdata = data;
Fred Isamana69aef12011-03-03 15:13:47 +0000395
Fred Isamancd841602012-04-20 14:47:44 -0400396 wdata->header->mds_ops->rpc_release(data);
Fred Isamana69aef12011-03-03 15:13:47 +0000397}
398
Fred Isaman0b7c0152012-04-20 14:47:39 -0400399static void filelayout_commit_prepare(struct rpc_task *task, void *data)
Fred Isamane0c2b382011-03-23 13:27:53 +0000400{
Fred Isaman0b7c0152012-04-20 14:47:39 -0400401 struct nfs_commit_data *wdata = data;
Fred Isamane0c2b382011-03-23 13:27:53 +0000402
Fred Isaman0b7c0152012-04-20 14:47:39 -0400403 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
411static 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
419static 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
426static void filelayout_commit_release(void *calldata)
427{
428 struct nfs_commit_data *data = calldata;
429
Fred Isamanf453a542012-04-20 14:47:54 -0400430 data->completion_ops->completion(data);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400431 put_lseg(data->lseg);
432 nfs_commitdata_release(data);
Fred Isamane0c2b382011-03-23 13:27:53 +0000433}
434
Trond Myklebust17280172012-03-11 13:11:00 -0400435static const struct rpc_call_ops filelayout_read_call_ops = {
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000436 .rpc_call_prepare = filelayout_read_prepare,
437 .rpc_call_done = filelayout_read_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500438 .rpc_count_stats = filelayout_read_count_stats,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000439 .rpc_release = filelayout_read_release,
440};
441
Trond Myklebust17280172012-03-11 13:11:00 -0400442static const struct rpc_call_ops filelayout_write_call_ops = {
Fred Isamana69aef12011-03-03 15:13:47 +0000443 .rpc_call_prepare = filelayout_write_prepare,
444 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500445 .rpc_count_stats = filelayout_write_count_stats,
Fred Isamana69aef12011-03-03 15:13:47 +0000446 .rpc_release = filelayout_write_release,
447};
448
Trond Myklebust17280172012-03-11 13:11:00 -0400449static const struct rpc_call_ops filelayout_commit_call_ops = {
Fred Isaman0b7c0152012-04-20 14:47:39 -0400450 .rpc_call_prepare = filelayout_commit_prepare,
451 .rpc_call_done = filelayout_write_commit_done,
452 .rpc_count_stats = filelayout_commit_count_stats,
Fred Isamane0c2b382011-03-23 13:27:53 +0000453 .rpc_release = filelayout_commit_release,
454};
455
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000456static enum pnfs_try_status
457filelayout_read_pagelist(struct nfs_read_data *data)
458{
Fred Isamancd841602012-04-20 14:47:44 -0400459 struct nfs_pgio_header *hdr = data->header;
460 struct pnfs_layout_segment *lseg = hdr->lseg;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000461 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 Isamancd841602012-04-20 14:47:44 -0400468 __func__, hdr->inode->i_ino,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000469 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 Adamson90fecfc2012-04-27 17:53:43 -0400475 if (!ds)
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000476 return PNFS_NOT_ATTEMPTED;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400477 dprintk("%s USE DS: %s\n", __func__, ds->ds_remotestr);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000478
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 Isamanc5996c42012-04-20 14:47:41 -0400489 status = nfs_initiate_read(ds->ds_clp->cl_rpcclient, data,
Andy Adamson9f0ec1762012-04-27 17:53:44 -0400490 &filelayout_read_call_ops, RPC_TASK_SOFTCONN);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000491 BUG_ON(status != 0);
492 return PNFS_ATTEMPTED;
493}
494
Fred Isamana69aef12011-03-03 15:13:47 +0000495/* Perform async writes. */
Andy Adamson0382b742011-03-03 15:13:45 +0000496static enum pnfs_try_status
497filelayout_write_pagelist(struct nfs_write_data *data, int sync)
498{
Fred Isamancd841602012-04-20 14:47:44 -0400499 struct nfs_pgio_header *hdr = data->header;
500 struct pnfs_layout_segment *lseg = hdr->lseg;
Fred Isamana69aef12011-03-03 15:13:47 +0000501 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 Adamson90fecfc2012-04-27 17:53:43 -0400511 if (!ds)
Fred Isamana69aef12011-03-03 15:13:47 +0000512 return PNFS_NOT_ATTEMPTED;
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400513 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s\n", __func__,
Fred Isamancd841602012-04-20 14:47:44 -0400514 hdr->inode->i_ino, sync, (size_t) data->args.count, offset,
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400515 ds->ds_remotestr);
Fred Isamana69aef12011-03-03 15:13:47 +0000516
Fred Isamana69aef12011-03-03 15:13:47 +0000517 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 Isamana69aef12011-03-03 15:13:47 +0000527
528 /* Perform an asynchronous write */
Fred Isamanc5996c42012-04-20 14:47:41 -0400529 status = nfs_initiate_write(ds->ds_clp->cl_rpcclient, data,
Andy Adamson9f0ec1762012-04-27 17:53:44 -0400530 &filelayout_write_call_ops, sync,
531 RPC_TASK_SOFTCONN);
Fred Isamana69aef12011-03-03 15:13:47 +0000532 BUG_ON(status != 0);
533 return PNFS_ATTEMPTED;
Andy Adamson0382b742011-03-03 15:13:45 +0000534}
535
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000536/*
Andy Adamson16b374c2010-10-20 00:18:04 -0400537 * 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 */
544static int
545filelayout_check_layout(struct pnfs_layout_hdr *lo,
546 struct nfs4_filelayout_segment *fl,
547 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400548 struct nfs4_deviceid *id,
549 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400550{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400551 struct nfs4_deviceid_node *d;
Andy Adamson16b374c2010-10-20 00:18:04 -0400552 struct nfs4_file_layout_dsaddr *dsaddr;
553 int status = -EINVAL;
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000554 struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
Andy Adamson16b374c2010-10-20 00:18:04 -0400555
556 dprintk("--> %s\n", __func__);
557
Andy Adamson7c24d942011-06-13 18:22:38 -0400558 /* 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 Adamson16b374c2010-10-20 00:18:04 -0400566 if (fl->pattern_offset > lgr->range.offset) {
Jim Rees3b6445a2011-02-22 19:31:57 -0500567 dprintk("%s pattern_offset %lld too large\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400568 __func__, fl->pattern_offset);
569 goto out;
570 }
571
Benny Halevy75247af2011-02-22 15:56:01 -0800572 if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) {
573 dprintk("%s Invalid stripe unit (%u)\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400574 __func__, fl->stripe_unit);
575 goto out;
576 }
577
578 /* find and reference the deviceid */
Benny Halevy35c8bb52011-05-24 18:04:02 +0300579 d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode)->pnfs_curr_ld,
580 NFS_SERVER(lo->plh_inode)->nfs_client, id);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400581 if (d == NULL) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400582 dsaddr = get_device_info(lo->plh_inode, id, gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400583 if (dsaddr == NULL)
584 goto out;
Benny Halevya1eaecb2011-05-19 22:14:47 -0400585 } else
586 dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400587 /* Found deviceid is being reaped */
588 if (test_bit(NFS_DEVICEID_INVALID, &dsaddr->id_node.flags))
589 goto out_put;
590
Andy Adamson16b374c2010-10-20 00:18:04 -0400591 fl->dsaddr = dsaddr;
592
Chuck Levere4149662011-10-25 12:18:03 -0400593 if (fl->first_stripe_index >= dsaddr->stripe_count) {
594 dprintk("%s Bad first_stripe_index %u\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400595 __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;
615out:
616 dprintk("--> %s returns %d\n", __func__, status);
617 return status;
618out_put:
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000619 nfs4_fl_put_deviceid(dsaddr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400620 goto out;
621}
622
623static 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
636static void
637_filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
638{
639 filelayout_free_fh_array(fl);
640 kfree(fl);
641}
642
643static int
644filelayout_decode_layout(struct pnfs_layout_hdr *flo,
645 struct nfs4_filelayout_segment *fl,
646 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400647 struct nfs4_deviceid *id,
648 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400649{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400650 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400651 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400652 struct page *scratch;
653 __be32 *p;
Andy Adamson16b374c2010-10-20 00:18:04 -0400654 uint32_t nfl_util;
655 int i;
656
657 dprintk("%s: set_layout_map Begin\n", __func__);
658
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400659 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400660 if (!scratch)
661 return -ENOMEM;
662
Benny Halevyf7da7a12011-05-19 14:16:47 -0400663 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400664 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 Adamson16b374c2010-10-20 00:18:04 -0400672 memcpy(id, p, sizeof(*id));
673 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400674 nfs4_print_deviceid(id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400675
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 Adamsoncec765c2011-06-13 18:36:17 -0400693 /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
694 * Futher checking is done in filelayout_check_layout */
Chuck Levere4149662011-10-25 12:18:03 -0400695 if (fl->num_fh >
Andy Adamsoncec765c2011-06-13 18:36:17 -0400696 max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400697 goto out_err;
698
Andy Adamsoncec765c2011-06-13 18:36:17 -0400699 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 Adamson16b374c2010-10-20 00:18:04 -0400705
706 for (i = 0; i < fl->num_fh; i++) {
707 /* Do we want to use a mempool here? */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400708 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400709 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 Adamson16b374c2010-10-20 00:18:04 -0400715 fl->fh_array[i]->size = be32_to_cpup(p++);
716 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -0500717 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400718 i, fl->fh_array[i]->size);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400719 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400720 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400721
722 p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
723 if (unlikely(!p))
724 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400725 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
Andy Adamson16b374c2010-10-20 00:18:04 -0400726 dprintk("DEBUG: %s: fh len %d\n", __func__,
727 fl->fh_array[i]->size);
728 }
729
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400730 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400731 return 0;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400732
733out_err_free:
734 filelayout_free_fh_array(fl);
735out_err:
736 __free_page(scratch);
737 return -EIO;
Andy Adamson16b374c2010-10-20 00:18:04 -0400738}
739
Fred Isamanc8795132011-03-23 13:27:49 +0000740static void
741filelayout_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 Isaman799ba8d2012-04-20 14:47:38 -0400747 /* 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 Isamanc8795132011-03-23 13:27:49 +0000756 _filelayout_free_lseg(fl);
757}
758
Fred Isaman799ba8d2012-04-20 14:47:38 -0400759static int
760filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
Fred Isamanea2cf222012-04-20 14:47:53 -0400761 struct nfs_commit_info *cinfo,
Fred Isaman799ba8d2012-04-20 14:47:38 -0400762 gfp_t gfp_flags)
763{
764 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
Fred Isamanea2cf222012-04-20 14:47:53 -0400765 struct pnfs_commit_bucket *buckets;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400766 int size;
767
768 if (fl->commit_through_mds)
769 return 0;
Fred Isamanea2cf222012-04-20 14:47:53 -0400770 if (cinfo->ds->nbuckets != 0) {
Fred Isaman799ba8d2012-04-20 14:47:38 -0400771 /* 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 Isamanea2cf222012-04-20 14:47:53 -0400783 buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
Fred Isaman799ba8d2012-04-20 14:47:38 -0400784 gfp_flags);
785 if (!buckets)
786 return -ENOMEM;
787 else {
788 int i;
789
Fred Isamanea2cf222012-04-20 14:47:53 -0400790 spin_lock(cinfo->lock);
791 if (cinfo->ds->nbuckets != 0)
Fred Isaman799ba8d2012-04-20 14:47:38 -0400792 kfree(buckets);
793 else {
Fred Isamanea2cf222012-04-20 14:47:53 -0400794 cinfo->ds->buckets = buckets;
795 cinfo->ds->nbuckets = size;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400796 for (i = 0; i < size; i++) {
797 INIT_LIST_HEAD(&buckets[i].written);
798 INIT_LIST_HEAD(&buckets[i].committing);
799 }
800 }
Fred Isamanea2cf222012-04-20 14:47:53 -0400801 spin_unlock(cinfo->lock);
Fred Isaman799ba8d2012-04-20 14:47:38 -0400802 return 0;
803 }
804}
805
Andy Adamson16b374c2010-10-20 00:18:04 -0400806static struct pnfs_layout_segment *
807filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400808 struct nfs4_layoutget_res *lgr,
809 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400810{
811 struct nfs4_filelayout_segment *fl;
812 int rc;
813 struct nfs4_deviceid id;
814
815 dprintk("--> %s\n", __func__);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400816 fl = kzalloc(sizeof(*fl), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400817 if (!fl)
818 return NULL;
819
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400820 rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
821 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
Andy Adamson16b374c2010-10-20 00:18:04 -0400822 _filelayout_free_lseg(fl);
823 return NULL;
824 }
825 return &fl->generic_hdr;
826}
827
Fred Isaman94ad1c82011-03-01 01:34:14 +0000828/*
829 * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
830 *
Benny Halevy18ad0a92011-05-25 21:03:56 +0300831 * return true : coalesce page
832 * return false : don't coalesce page
Fred Isaman94ad1c82011-03-01 01:34:14 +0000833 */
Trond Myklebust1751c362011-06-10 13:30:23 -0400834static bool
Fred Isaman94ad1c82011-03-01 01:34:14 +0000835filelayout_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 Halevy19345cb2011-06-19 18:33:46 -0400841 if (!pnfs_generic_pg_test(pgio, prev, req) ||
842 !nfs_generic_pg_test(pgio, prev, req))
843 return false;
Benny Halevy89a58e32011-05-25 20:54:40 +0300844
Fred Isamanb5542842012-04-20 14:47:43 -0400845 p_stripe = (u64)req_offset(prev);
846 r_stripe = (u64)req_offset(req);
Fred Isaman94ad1c82011-03-01 01:34:14 +0000847 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 Myklebust17280172012-03-11 13:11:00 -0400855static void
Andy Adamson7c24d942011-06-13 18:22:38 -0400856filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
857 struct nfs_page *req)
858{
859 BUG_ON(pgio->pg_lseg != NULL);
860
Fred Isaman1825a0d2012-04-20 19:55:31 -0400861 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 Adamson7c24d942011-06-13 18:22:38 -0400871 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 Myklebust1f945352011-07-13 15:59:57 -0400879 nfs_pageio_reset_read_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400880}
881
Trond Myklebust17280172012-03-11 13:11:00 -0400882static void
Andy Adamson7c24d942011-06-13 18:22:38 -0400883filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
884 struct nfs_page *req)
885{
Fred Isamanea2cf222012-04-20 14:47:53 -0400886 struct nfs_commit_info cinfo;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400887 int status;
888
Andy Adamson7c24d942011-06-13 18:22:38 -0400889 BUG_ON(pgio->pg_lseg != NULL);
890
Fred Isaman1825a0d2012-04-20 19:55:31 -0400891 if (req->wb_offset != req->wb_pgbase)
892 goto out_mds;
Andy Adamson7c24d942011-06-13 18:22:38 -0400893 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 Isaman799ba8d2012-04-20 14:47:38 -0400901 goto out_mds;
Fred Isamanea2cf222012-04-20 14:47:53 -0400902 nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
903 status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
Fred Isaman799ba8d2012-04-20 14:47:38 -0400904 if (status < 0) {
905 put_lseg(pgio->pg_lseg);
906 pgio->pg_lseg = NULL;
907 goto out_mds;
908 }
909 return;
910out_mds:
911 nfs_pageio_reset_write_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400912}
913
Trond Myklebust1751c362011-06-10 13:30:23 -0400914static const struct nfs_pageio_ops filelayout_pg_read_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400915 .pg_init = filelayout_pg_init_read,
Trond Myklebust1751c362011-06-10 13:30:23 -0400916 .pg_test = filelayout_pg_test,
Trond Myklebust493292d2011-07-13 15:58:28 -0400917 .pg_doio = pnfs_generic_pg_readpages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400918};
919
920static const struct nfs_pageio_ops filelayout_pg_write_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400921 .pg_init = filelayout_pg_init_write,
Trond Myklebust1751c362011-06-10 13:30:23 -0400922 .pg_test = filelayout_pg_test,
Trond Myklebustdce81292011-07-13 15:59:19 -0400923 .pg_doio = pnfs_generic_pg_writepages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400924};
925
Fred Isamane0c2b382011-03-23 13:27:53 +0000926static 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 Isamand6d6dc72012-03-08 17:29:35 -0500934/* 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 Isamand6d6dc72012-03-08 17:29:35 -0500936 */
Trond Myklebust8dd37752012-03-15 17:16:40 -0400937static void
Fred Isamanea2cf222012-04-20 14:47:53 -0400938filelayout_clear_request_commit(struct nfs_page *req,
939 struct nfs_commit_info *cinfo)
Fred Isamane0c2b382011-03-23 13:27:53 +0000940{
Trond Myklebust8dd37752012-03-15 17:16:40 -0400941 struct pnfs_layout_segment *freeme = NULL;
Trond Myklebust8dd37752012-03-15 17:16:40 -0400942
Fred Isamanea2cf222012-04-20 14:47:53 -0400943 spin_lock(cinfo->lock);
Trond Myklebust8dd37752012-03-15 17:16:40 -0400944 if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags))
945 goto out;
Fred Isamanea2cf222012-04-20 14:47:53 -0400946 cinfo->ds->nwritten--;
Fred Isamand6d6dc72012-03-08 17:29:35 -0500947 if (list_is_singular(&req->wb_list)) {
Fred Isamanea2cf222012-04-20 14:47:53 -0400948 struct pnfs_commit_bucket *bucket;
Fred Isamand6d6dc72012-03-08 17:29:35 -0500949
Fred Isaman799ba8d2012-04-20 14:47:38 -0400950 bucket = list_first_entry(&req->wb_list,
Fred Isamanea2cf222012-04-20 14:47:53 -0400951 struct pnfs_commit_bucket,
Fred Isaman799ba8d2012-04-20 14:47:38 -0400952 written);
953 freeme = bucket->wlseg;
954 bucket->wlseg = NULL;
Fred Isamand6d6dc72012-03-08 17:29:35 -0500955 }
Trond Myklebust8dd37752012-03-15 17:16:40 -0400956out:
Fred Isamanea2cf222012-04-20 14:47:53 -0400957 nfs_request_remove_commit_list(req, cinfo);
958 spin_unlock(cinfo->lock);
Trond Myklebust8dd37752012-03-15 17:16:40 -0400959 put_lseg(freeme);
Fred Isamand6d6dc72012-03-08 17:29:35 -0500960}
961
962static struct list_head *
963filelayout_choose_commit_list(struct nfs_page *req,
Fred Isamanea2cf222012-04-20 14:47:53 -0400964 struct pnfs_layout_segment *lseg,
965 struct nfs_commit_info *cinfo)
Fred Isamand6d6dc72012-03-08 17:29:35 -0500966{
Fred Isamane0c2b382011-03-23 13:27:53 +0000967 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
968 u32 i, j;
969 struct list_head *list;
Fred Isamanea2cf222012-04-20 14:47:53 -0400970 struct pnfs_commit_bucket *buckets;
Fred Isamane0c2b382011-03-23 13:27:53 +0000971
Fred Isamand6d6dc72012-03-08 17:29:35 -0500972 if (fl->commit_through_mds)
Fred Isamanea2cf222012-04-20 14:47:53 -0400973 return &cinfo->mds->list;
Fred Isamand6d6dc72012-03-08 17:29:35 -0500974
Fred Isamane0c2b382011-03-23 13:27:53 +0000975 /* 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 Isamanb5542842012-04-20 14:47:43 -0400981 j = nfs4_fl_calc_j_index(lseg, req_offset(req));
Fred Isamane0c2b382011-03-23 13:27:53 +0000982 i = select_bucket_index(fl, j);
Fred Isamanea2cf222012-04-20 14:47:53 -0400983 buckets = cinfo->ds->buckets;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400984 list = &buckets[i].written;
Fred Isamane0c2b382011-03-23 13:27:53 +0000985 if (list_empty(list)) {
Fred Isamand6d6dc72012-03-08 17:29:35 -0500986 /* 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 Isaman799ba8d2012-04-20 14:47:38 -0400990 * filelayout_clear_request_commit
Fred Isamand6d6dc72012-03-08 17:29:35 -0500991 */
Fred Isaman799ba8d2012-04-20 14:47:38 -0400992 buckets[i].wlseg = get_lseg(lseg);
Fred Isamane0c2b382011-03-23 13:27:53 +0000993 }
Trond Myklebust8dd37752012-03-15 17:16:40 -0400994 set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
Fred Isamanea2cf222012-04-20 14:47:53 -0400995 cinfo->ds->nwritten++;
Fred Isamane0c2b382011-03-23 13:27:53 +0000996 return list;
997}
998
Trond Myklebust8dd37752012-03-15 17:16:40 -0400999static void
1000filelayout_mark_request_commit(struct nfs_page *req,
Fred Isamanea2cf222012-04-20 14:47:53 -04001001 struct pnfs_layout_segment *lseg,
1002 struct nfs_commit_info *cinfo)
Trond Myklebust8dd37752012-03-15 17:16:40 -04001003{
1004 struct list_head *list;
1005
Fred Isamanea2cf222012-04-20 14:47:53 -04001006 list = filelayout_choose_commit_list(req, lseg, cinfo);
1007 nfs_request_add_commit_list(req, list, cinfo);
Trond Myklebust8dd37752012-03-15 17:16:40 -04001008}
1009
Fred Isamane0c2b382011-03-23 13:27:53 +00001010static 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
1020static struct nfs_fh *
1021select_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 Isaman0b7c0152012-04-20 14:47:39 -04001035static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
Fred Isamane0c2b382011-03-23 13:27:53 +00001036{
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 Isamane0c2b382011-03-23 13:27:53 +00001045 prepare_to_resend_writes(data);
Trond Myklebust8dd37752012-03-15 17:16:40 -04001046 filelayout_commit_release(data);
Fred Isamane0c2b382011-03-23 13:27:53 +00001047 return -EAGAIN;
1048 }
1049 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
Fred Isaman0b7c0152012-04-20 14:47:39 -04001050 data->commit_done_cb = filelayout_commit_done_cb;
Fred Isamane0c2b382011-03-23 13:27:53 +00001051 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 Isaman0b7c0152012-04-20 14:47:39 -04001055 return nfs_initiate_commit(ds->ds_clp->cl_rpcclient, data,
Andy Adamson9f0ec1762012-04-27 17:53:44 -04001056 &filelayout_commit_call_ops, how,
1057 RPC_TASK_SOFTCONN);
Fred Isamane0c2b382011-03-23 13:27:53 +00001058}
1059
Trond Myklebust8dd37752012-03-15 17:16:40 -04001060static int
Fred Isaman1763da12012-04-20 14:47:57 -04001061transfer_commit_list(struct list_head *src, struct list_head *dst,
1062 struct nfs_commit_info *cinfo, int max)
Trond Myklebust8dd37752012-03-15 17:16:40 -04001063{
Trond Myklebust8dd37752012-03-15 17:16:40 -04001064 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 Isamanea2cf222012-04-20 14:47:53 -04001070 if (cond_resched_lock(cinfo->lock))
Trond Myklebust3b3be882012-03-17 11:59:30 -04001071 list_safe_reset_next(req, tmp, wb_list);
Fred Isamanea2cf222012-04-20 14:47:53 -04001072 nfs_request_remove_commit_list(req, cinfo);
Trond Myklebust8dd37752012-03-15 17:16:40 -04001073 clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
1074 nfs_list_add_request(req, dst);
1075 ret++;
Fred Isaman1763da12012-04-20 14:47:57 -04001076 if ((ret == max) && !cinfo->dreq)
Trond Myklebust8dd37752012-03-15 17:16:40 -04001077 break;
1078 }
Fred Isaman1763da12012-04-20 14:47:57 -04001079 return ret;
1080}
1081
1082static int
1083filelayout_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 Isaman799ba8d2012-04-20 14:47:38 -04001092 if (ret) {
Fred Isamanea2cf222012-04-20 14:47:53 -04001093 cinfo->ds->nwritten -= ret;
1094 cinfo->ds->ncommitting += ret;
Fred Isaman799ba8d2012-04-20 14:47:38 -04001095 bucket->clseg = bucket->wlseg;
1096 if (list_empty(src))
1097 bucket->wlseg = NULL;
1098 else
1099 get_lseg(bucket->clseg);
1100 }
Trond Myklebust8dd37752012-03-15 17:16:40 -04001101 return ret;
1102}
1103
Fred Isamand6d6dc72012-03-08 17:29:35 -05001104/* Move reqs from written to committing lists, returning count of number moved.
Fred Isamanea2cf222012-04-20 14:47:53 -04001105 * Note called with cinfo->lock held.
Fred Isamand6d6dc72012-03-08 17:29:35 -05001106 */
Fred Isamanea2cf222012-04-20 14:47:53 -04001107static int filelayout_scan_commit_lists(struct nfs_commit_info *cinfo,
1108 int max)
Fred Isamand6d6dc72012-03-08 17:29:35 -05001109{
Fred Isamand6d6dc72012-03-08 17:29:35 -05001110 int i, rv = 0, cnt;
1111
Fred Isamanea2cf222012-04-20 14:47:53 -04001112 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 Isamand6d6dc72012-03-08 17:29:35 -05001115 max -= cnt;
1116 rv += cnt;
1117 }
Fred Isamand6d6dc72012-03-08 17:29:35 -05001118 return rv;
1119}
1120
Fred Isaman1763da12012-04-20 14:47:57 -04001121/* Pull everything off the committing lists and dump into @dst */
1122static 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 Myklebust9390f422012-03-16 13:52:45 -04001142static unsigned int
Fred Isamanea2cf222012-04-20 14:47:53 -04001143alloc_ds_commits(struct nfs_commit_info *cinfo, struct list_head *list)
Fred Isamane0c2b382011-03-23 13:27:53 +00001144{
Fred Isamanea2cf222012-04-20 14:47:53 -04001145 struct pnfs_ds_commit_info *fl_cinfo;
1146 struct pnfs_commit_bucket *bucket;
Fred Isaman0b7c0152012-04-20 14:47:39 -04001147 struct nfs_commit_data *data;
Fred Isamane0c2b382011-03-23 13:27:53 +00001148 int i, j;
Trond Myklebust9390f422012-03-16 13:52:45 -04001149 unsigned int nreq = 0;
Fred Isamane0c2b382011-03-23 13:27:53 +00001150
Fred Isamanea2cf222012-04-20 14:47:53 -04001151 fl_cinfo = cinfo->ds;
Fred Isaman799ba8d2012-04-20 14:47:38 -04001152 bucket = fl_cinfo->buckets;
1153 for (i = 0; i < fl_cinfo->nbuckets; i++, bucket++) {
1154 if (list_empty(&bucket->committing))
Fred Isamane0c2b382011-03-23 13:27:53 +00001155 continue;
1156 data = nfs_commitdata_alloc();
1157 if (!data)
Trond Myklebust9390f422012-03-16 13:52:45 -04001158 break;
Fred Isamane0c2b382011-03-23 13:27:53 +00001159 data->ds_commit_index = i;
Fred Isaman799ba8d2012-04-20 14:47:38 -04001160 data->lseg = bucket->clseg;
1161 bucket->clseg = NULL;
Fred Isamane0c2b382011-03-23 13:27:53 +00001162 list_add(&data->pages, list);
Trond Myklebust9390f422012-03-16 13:52:45 -04001163 nreq++;
Fred Isamane0c2b382011-03-23 13:27:53 +00001164 }
Fred Isamane0c2b382011-03-23 13:27:53 +00001165
Trond Myklebust9390f422012-03-16 13:52:45 -04001166 /* Clean up on error */
Fred Isaman799ba8d2012-04-20 14:47:38 -04001167 for (j = i; j < fl_cinfo->nbuckets; j++, bucket++) {
1168 if (list_empty(&bucket->committing))
Fred Isamane0c2b382011-03-23 13:27:53 +00001169 continue;
Fred Isamanea2cf222012-04-20 14:47:53 -04001170 nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo);
Fred Isaman799ba8d2012-04-20 14:47:38 -04001171 put_lseg(bucket->clseg);
1172 bucket->clseg = NULL;
Fred Isamane0c2b382011-03-23 13:27:53 +00001173 }
Fred Isamane0c2b382011-03-23 13:27:53 +00001174 /* Caller will clean up entries put on list */
Trond Myklebust9390f422012-03-16 13:52:45 -04001175 return nreq;
Fred Isamane0c2b382011-03-23 13:27:53 +00001176}
1177
1178/* This follows nfs_commit_list pretty closely */
1179static int
1180filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
Fred Isamanea2cf222012-04-20 14:47:53 -04001181 int how, struct nfs_commit_info *cinfo)
Fred Isamane0c2b382011-03-23 13:27:53 +00001182{
Fred Isaman0b7c0152012-04-20 14:47:39 -04001183 struct nfs_commit_data *data, *tmp;
Fred Isamane0c2b382011-03-23 13:27:53 +00001184 LIST_HEAD(list);
Trond Myklebust9390f422012-03-16 13:52:45 -04001185 unsigned int nreq = 0;
Fred Isamane0c2b382011-03-23 13:27:53 +00001186
1187 if (!list_empty(mds_pages)) {
1188 data = nfs_commitdata_alloc();
Trond Myklebust9390f422012-03-16 13:52:45 -04001189 if (data != NULL) {
1190 data->lseg = NULL;
1191 list_add(&data->pages, &list);
1192 nreq++;
1193 } else
Fred Isamanea2cf222012-04-20 14:47:53 -04001194 nfs_retry_commit(mds_pages, NULL, cinfo);
Fred Isamane0c2b382011-03-23 13:27:53 +00001195 }
1196
Fred Isamanea2cf222012-04-20 14:47:53 -04001197 nreq += alloc_ds_commits(cinfo, &list);
Trond Myklebust9390f422012-03-16 13:52:45 -04001198
1199 if (nreq == 0) {
Fred Isamanf453a542012-04-20 14:47:54 -04001200 cinfo->completion_ops->error_cleanup(NFS_I(inode));
Trond Myklebust9390f422012-03-16 13:52:45 -04001201 goto out;
1202 }
1203
Fred Isamanea2cf222012-04-20 14:47:53 -04001204 atomic_add(nreq, &cinfo->mds->rpcs_out);
Fred Isamane0c2b382011-03-23 13:27:53 +00001205
1206 list_for_each_entry_safe(data, tmp, &list, pages) {
1207 list_del_init(&data->pages);
Fred Isamane0c2b382011-03-23 13:27:53 +00001208 if (!data->lseg) {
Fred Isamanf453a542012-04-20 14:47:54 -04001209 nfs_init_commit(data, mds_pages, NULL, cinfo);
Fred Isaman0b7c0152012-04-20 14:47:39 -04001210 nfs_initiate_commit(NFS_CLIENT(inode), data,
Andy Adamson9f0ec1762012-04-27 17:53:44 -04001211 data->mds_ops, how, 0);
Fred Isamane0c2b382011-03-23 13:27:53 +00001212 } else {
Fred Isamanea2cf222012-04-20 14:47:53 -04001213 struct pnfs_commit_bucket *buckets;
Fred Isaman799ba8d2012-04-20 14:47:38 -04001214
Fred Isamanea2cf222012-04-20 14:47:53 -04001215 buckets = cinfo->ds->buckets;
Fred Isamanf453a542012-04-20 14:47:54 -04001216 nfs_init_commit(data, &buckets[data->ds_commit_index].committing, data->lseg, cinfo);
Fred Isamane0c2b382011-03-23 13:27:53 +00001217 filelayout_initiate_commit(data, how);
1218 }
1219 }
Trond Myklebust9390f422012-03-16 13:52:45 -04001220out:
Fred Isamanea2cf222012-04-20 14:47:53 -04001221 cinfo->ds->ncommitting = 0;
Trond Myklebust9390f422012-03-16 13:52:45 -04001222 return PNFS_ATTEMPTED;
Fred Isamane0c2b382011-03-23 13:27:53 +00001223}
1224
Benny Halevy1775bc32011-05-20 13:47:33 +02001225static void
1226filelayout_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 Isaman799ba8d2012-04-20 14:47:38 -04001231static struct pnfs_layout_hdr *
1232filelayout_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
1240static void
1241filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
1242{
1243 kfree(FILELAYOUT_FROM_HDR(lo));
1244}
1245
Fred Isamanea2cf222012-04-20 14:47:53 -04001246static struct pnfs_ds_commit_info *
1247filelayout_get_ds_info(struct inode *inode)
1248{
Fred Isamandf011742012-04-24 14:50:34 -04001249 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 Isamanea2cf222012-04-20 14:47:53 -04001255}
1256
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001257static struct pnfs_layoutdriver_type filelayout_type = {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +00001258 .id = LAYOUT_NFSV4_1_FILES,
1259 .name = "LAYOUT_NFSV4_1_FILES",
1260 .owner = THIS_MODULE,
Fred Isaman799ba8d2012-04-20 14:47:38 -04001261 .alloc_layout_hdr = filelayout_alloc_layout_hdr,
1262 .free_layout_hdr = filelayout_free_layout_hdr,
Christoph Hellwigea8eecd2011-03-01 01:34:21 +00001263 .alloc_lseg = filelayout_alloc_lseg,
1264 .free_lseg = filelayout_free_lseg,
Trond Myklebust1751c362011-06-10 13:30:23 -04001265 .pg_read_ops = &filelayout_pg_read_ops,
1266 .pg_write_ops = &filelayout_pg_write_ops,
Fred Isamanea2cf222012-04-20 14:47:53 -04001267 .get_ds_info = &filelayout_get_ds_info,
Trond Myklebust8dd37752012-03-15 17:16:40 -04001268 .mark_request_commit = filelayout_mark_request_commit,
1269 .clear_request_commit = filelayout_clear_request_commit,
Fred Isamand6d6dc72012-03-08 17:29:35 -05001270 .scan_commit_lists = filelayout_scan_commit_lists,
Fred Isaman1763da12012-04-20 14:47:57 -04001271 .recover_commit_reqs = filelayout_recover_commit_reqs,
Fred Isamane0c2b382011-03-23 13:27:53 +00001272 .commit_pagelist = filelayout_commit_pagelist,
Andy Adamsondc70d7b2011-03-01 01:34:19 +00001273 .read_pagelist = filelayout_read_pagelist,
Andy Adamson0382b742011-03-03 15:13:45 +00001274 .write_pagelist = filelayout_write_pagelist,
Benny Halevy1775bc32011-05-20 13:47:33 +02001275 .free_deviceid_node = filelayout_free_deveiceid_node,
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001276};
1277
1278static 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
1285static 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 Fieldsf85ef692011-07-15 19:18:42 -04001292MODULE_ALIAS("nfs-layouttype4-1");
1293
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001294module_init(nfs4filelayout_init);
1295module_exit(nfs4filelayout_exit);