blob: a46bf6de9ce455a97ef18275efe4906ac10e12ed [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
Tom Haynesb5968722014-05-12 14:35:52 -070038#include "../nfs4session.h"
39#include "../internal.h"
40#include "../delegation.h"
41#include "filelayout.h"
42#include "../nfs4trace.h"
Dean Hildebrand7ab672c2010-10-20 00:18:00 -040043
44#define NFSDBG_FACILITY NFSDBG_PNFS_LD
45
46MODULE_LICENSE("GPL");
47MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
48MODULE_DESCRIPTION("The NFSv4 file layout driver");
49
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +000050#define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
51
Fred Isamancfe7f412011-03-01 01:34:18 +000052static loff_t
53filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
54 loff_t offset)
55{
56 u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count;
Chris Metcalf3476f112011-08-11 13:54:28 -070057 u64 stripe_no;
58 u32 rem;
Fred Isamancfe7f412011-03-01 01:34:18 +000059
60 offset -= flseg->pattern_offset;
Chris Metcalf3476f112011-08-11 13:54:28 -070061 stripe_no = div_u64(offset, stripe_width);
62 div_u64_rem(offset, flseg->stripe_unit, &rem);
Fred Isamancfe7f412011-03-01 01:34:18 +000063
Chris Metcalf3476f112011-08-11 13:54:28 -070064 return stripe_no * flseg->stripe_unit + rem;
Fred Isamancfe7f412011-03-01 01:34:18 +000065}
66
67/* This function is used by the layout driver to calculate the
68 * offset of the file on the dserver based on whether the
69 * layout type is STRIPE_DENSE or STRIPE_SPARSE
70 */
71static loff_t
72filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset)
73{
74 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
75
76 switch (flseg->stripe_type) {
77 case STRIPE_SPARSE:
78 return offset;
79
80 case STRIPE_DENSE:
81 return filelayout_get_dense_offset(flseg, offset);
82 }
83
84 BUG();
85}
86
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -040087static void filelayout_reset_write(struct nfs_pgio_header *hdr)
Andy Adamsone7dd79af2012-04-27 17:53:46 -040088{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -040089 struct rpc_task *task = &hdr->task;
Andy Adamsone7dd79af2012-04-27 17:53:46 -040090
91 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
92 dprintk("%s Reset task %5u for i/o through MDS "
Niels de Vos1e8968c2013-12-17 18:20:16 +010093 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -040094 hdr->task.tk_pid,
Bryan Schumaker497826a2012-05-22 10:10:03 -040095 hdr->inode->i_sb->s_id,
Niels de Vos1e8968c2013-12-17 18:20:16 +010096 (unsigned long long)NFS_FILEID(hdr->inode),
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -040097 hdr->args.count,
98 (unsigned long long)hdr->args.offset);
Andy Adamsone7dd79af2012-04-27 17:53:46 -040099
Weston Andros Adamson53113ad2014-06-09 11:48:38 -0400100 task->tk_status = pnfs_write_done_resend_to_mds(hdr);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400101 }
102}
103
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400104static void filelayout_reset_read(struct nfs_pgio_header *hdr)
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400105{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400106 struct rpc_task *task = &hdr->task;
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400107
108 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
109 dprintk("%s Reset task %5u for i/o through MDS "
Niels de Vos1e8968c2013-12-17 18:20:16 +0100110 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400111 hdr->task.tk_pid,
Bryan Schumaker497826a2012-05-22 10:10:03 -0400112 hdr->inode->i_sb->s_id,
Niels de Vos1e8968c2013-12-17 18:20:16 +0100113 (unsigned long long)NFS_FILEID(hdr->inode),
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400114 hdr->args.count,
115 (unsigned long long)hdr->args.offset);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400116
Weston Andros Adamson53113ad2014-06-09 11:48:38 -0400117 task->tk_status = pnfs_read_done_resend_to_mds(hdr);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400118 }
119}
120
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000121static int filelayout_async_handle_error(struct rpc_task *task,
122 struct nfs4_state *state,
123 struct nfs_client *clp,
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400124 struct pnfs_layout_segment *lseg)
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000125{
Trond Myklebustd527e5c2012-10-11 13:43:38 -0400126 struct pnfs_layout_hdr *lo = lseg->pls_layout;
127 struct inode *inode = lo->plh_inode;
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400128 struct nfs_server *mds_server = NFS_SERVER(inode);
129 struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
Andy Adamson9cb81962012-03-07 10:49:41 -0500130 struct nfs_client *mds_client = mds_server->nfs_client;
Andy Adamson671fb892012-04-27 17:53:49 -0400131 struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
Andy Adamson9cb81962012-03-07 10:49:41 -0500132
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000133 if (task->tk_status >= 0)
134 return 0;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000135
136 switch (task->tk_status) {
Andy Adamson9cb81962012-03-07 10:49:41 -0500137 /* MDS state errors */
138 case -NFS4ERR_DELEG_REVOKED:
139 case -NFS4ERR_ADMIN_REVOKED:
140 case -NFS4ERR_BAD_STATEID:
Andy Adamson9cb81962012-03-07 10:49:41 -0500141 case -NFS4ERR_OPENMODE:
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400142 if (state == NULL)
143 break;
Trond Myklebust5d422302013-03-14 16:57:48 -0400144 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
145 goto out_bad_stateid;
Andy Adamson9cb81962012-03-07 10:49:41 -0500146 goto wait_on_recovery;
147 case -NFS4ERR_EXPIRED:
Trond Myklebust5d422302013-03-14 16:57:48 -0400148 if (state != NULL) {
149 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
150 goto out_bad_stateid;
151 }
Andy Adamson9cb81962012-03-07 10:49:41 -0500152 nfs4_schedule_lease_recovery(mds_client);
153 goto wait_on_recovery;
154 /* DS session errors */
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000155 case -NFS4ERR_BADSESSION:
156 case -NFS4ERR_BADSLOT:
157 case -NFS4ERR_BAD_HIGH_SLOT:
158 case -NFS4ERR_DEADSESSION:
159 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
160 case -NFS4ERR_SEQ_FALSE_RETRY:
161 case -NFS4ERR_SEQ_MISORDERED:
162 dprintk("%s ERROR %d, Reset session. Exchangeid "
163 "flags 0x%x\n", __func__, task->tk_status,
164 clp->cl_exchange_flags);
Trond Myklebust9f594792012-05-27 13:02:53 -0400165 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000166 break;
167 case -NFS4ERR_DELAY:
168 case -NFS4ERR_GRACE:
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000169 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
170 break;
Andy Adamsona8a4ae32011-05-03 13:43:03 -0400171 case -NFS4ERR_RETRY_UNCACHED_REP:
172 break;
Andy Adamson041245c2012-04-27 17:53:53 -0400173 /* Invalidate Layout errors */
174 case -NFS4ERR_PNFS_NO_LAYOUT:
175 case -ESTALE: /* mapped NFS4ERR_STALE */
176 case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */
177 case -EISDIR: /* mapped NFS4ERR_ISDIR */
178 case -NFS4ERR_FHEXPIRED:
179 case -NFS4ERR_WRONG_TYPE:
180 dprintk("%s Invalid layout error %d\n", __func__,
181 task->tk_status);
182 /*
183 * Destroy layout so new i/o will get a new layout.
184 * Layout will not be destroyed until all current lseg
185 * references are put. Mark layout as invalid to resend failed
186 * i/o and all i/o waiting on the slot table to the MDS until
187 * layout is destroyed and a new valid layout is obtained.
188 */
Andy Adamsond42e7872012-05-22 08:09:28 -0400189 pnfs_destroy_layout(NFS_I(inode));
Andy Adamson041245c2012-04-27 17:53:53 -0400190 rpc_wake_up(&tbl->slot_tbl_waitq);
191 goto reset;
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400192 /* RPC connection errors */
193 case -ECONNREFUSED:
194 case -EHOSTDOWN:
195 case -EHOSTUNREACH:
196 case -ENETUNREACH:
197 case -EIO:
198 case -ETIMEDOUT:
199 case -EPIPE:
200 dprintk("%s DS connection error %d\n", __func__,
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000201 task->tk_status);
Trond Myklebust1dfed272012-09-18 19:51:12 -0400202 nfs4_mark_deviceid_unavailable(devid);
Peng Taoc2201062014-09-06 00:53:29 +0800203 pnfs_error_mark_layout_for_return(inode, lseg);
Andy Adamson671fb892012-04-27 17:53:49 -0400204 rpc_wake_up(&tbl->slot_tbl_waitq);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400205 /* fall through */
206 default:
Andy Adamson041245c2012-04-27 17:53:53 -0400207reset:
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400208 dprintk("%s Retry through MDS. Error %d\n", __func__,
209 task->tk_status);
210 return -NFS4ERR_RESET_TO_MDS;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000211 }
Andy Adamson9cb81962012-03-07 10:49:41 -0500212out:
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000213 task->tk_status = 0;
214 return -EAGAIN;
Trond Myklebust5d422302013-03-14 16:57:48 -0400215out_bad_stateid:
216 task->tk_status = -EIO;
217 return 0;
Andy Adamson9cb81962012-03-07 10:49:41 -0500218wait_on_recovery:
219 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
220 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
221 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
222 goto out;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000223}
224
225/* NFS_PROTO call done callback routines */
226
227static int filelayout_read_done_cb(struct rpc_task *task,
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400228 struct nfs_pgio_header *hdr)
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000229{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400230 int err;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000231
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400232 trace_nfs4_pnfs_read(hdr, task->tk_status);
233 err = filelayout_async_handle_error(task, hdr->args.context->state,
234 hdr->ds_clp, hdr->lseg);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000235
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400236 switch (err) {
237 case -NFS4ERR_RESET_TO_MDS:
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400238 filelayout_reset_read(hdr);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400239 return task->tk_status;
240 case -EAGAIN:
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700241 rpc_restart_call_prepare(task);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000242 return -EAGAIN;
243 }
244
245 return 0;
246}
247
Andy Adamson16b374c2010-10-20 00:18:04 -0400248/*
Andy Adamson863a3c62011-03-23 13:27:54 +0000249 * We reference the rpc_cred of the first WRITE that triggers the need for
250 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
251 * rfc5661 is not clear about which credential should be used.
252 */
253static void
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400254filelayout_set_layoutcommit(struct nfs_pgio_header *hdr)
Andy Adamson863a3c62011-03-23 13:27:54 +0000255{
Fred Isamancd841602012-04-20 14:47:44 -0400256
257 if (FILELAYOUT_LSEG(hdr->lseg)->commit_through_mds ||
Peng Taobc7d4b82014-08-07 10:15:03 +0800258 hdr->res.verf->committed != NFS_DATA_SYNC)
Andy Adamson863a3c62011-03-23 13:27:54 +0000259 return;
260
Trond Myklebust67af7612015-03-25 20:40:38 -0400261 pnfs_set_layoutcommit(hdr->inode, hdr->lseg,
262 hdr->mds_offset + hdr->res.count);
Tom Haynesf383b7e2014-06-04 15:54:57 -0700263 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
Fred Isamancd841602012-04-20 14:47:44 -0400264 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
Andy Adamson863a3c62011-03-23 13:27:54 +0000265}
266
Trond Myklebust1dfed272012-09-18 19:51:12 -0400267bool
268filelayout_test_devid_unavailable(struct nfs4_deviceid_node *node)
269{
270 return filelayout_test_devid_invalid(node) ||
271 nfs4_test_deviceid_unavailable(node);
272}
273
274static bool
275filelayout_reset_to_mds(struct pnfs_layout_segment *lseg)
276{
277 struct nfs4_deviceid_node *node = FILELAYOUT_DEVID_NODE(lseg);
278
Trond Myklebust8006bfb2012-09-21 14:48:04 -0400279 return filelayout_test_devid_unavailable(node);
Trond Myklebust1dfed272012-09-18 19:51:12 -0400280}
281
Andy Adamson863a3c62011-03-23 13:27:54 +0000282/*
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000283 * Call ops for the async read/write cases
284 * In the case of dense layouts, the offset needs to be reset to its
285 * original value.
286 */
287static void filelayout_read_prepare(struct rpc_task *task, void *data)
288{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400289 struct nfs_pgio_header *hdr = data;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000290
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400291 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
Trond Myklebustc58c8442013-03-18 19:45:14 -0400292 rpc_exit(task, -EIO);
293 return;
294 }
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400295 if (filelayout_reset_to_mds(hdr->lseg)) {
Andy Adamson0ad2f372012-04-27 17:53:48 -0400296 dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400297 filelayout_reset_read(hdr);
Andy Adamson0ad2f372012-04-27 17:53:48 -0400298 rpc_exit(task, 0);
299 return;
300 }
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400301 hdr->pgio_done_cb = filelayout_read_done_cb;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000302
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400303 if (nfs41_setup_sequence(hdr->ds_clp->cl_session,
304 &hdr->args.seq_args,
305 &hdr->res.seq_res,
Trond Myklebust9b206142013-03-17 15:52:00 -0400306 task))
307 return;
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400308 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
309 hdr->args.lock_context, FMODE_READ) == -EIO)
Andy Adamson869a9d32014-03-04 12:31:09 -0500310 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000311}
312
313static void filelayout_read_call_done(struct rpc_task *task, void *data)
314{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400315 struct nfs_pgio_header *hdr = data;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000316
317 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
318
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400319 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
Andy Adamsonf9c96fc2014-01-29 11:34:38 -0500320 task->tk_status == 0) {
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400321 nfs41_sequence_done(task, &hdr->res.seq_res);
Andy Adamson0ad2f372012-04-27 17:53:48 -0400322 return;
Andy Adamsonf9c96fc2014-01-29 11:34:38 -0500323 }
Andy Adamson0ad2f372012-04-27 17:53:48 -0400324
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000325 /* Note this may cause RPC to be resent */
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400326 hdr->mds_ops->rpc_call_done(task, data);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000327}
328
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500329static void filelayout_read_count_stats(struct rpc_task *task, void *data)
330{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400331 struct nfs_pgio_header *hdr = data;
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500332
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400333 rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500334}
335
Fred Isamana69aef12011-03-03 15:13:47 +0000336static int filelayout_write_done_cb(struct rpc_task *task,
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400337 struct nfs_pgio_header *hdr)
Fred Isamana69aef12011-03-03 15:13:47 +0000338{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400339 int err;
Fred Isamana69aef12011-03-03 15:13:47 +0000340
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400341 trace_nfs4_pnfs_write(hdr, task->tk_status);
342 err = filelayout_async_handle_error(task, hdr->args.context->state,
343 hdr->ds_clp, hdr->lseg);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400344
345 switch (err) {
346 case -NFS4ERR_RESET_TO_MDS:
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400347 filelayout_reset_write(hdr);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400348 return task->tk_status;
349 case -EAGAIN:
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700350 rpc_restart_call_prepare(task);
Fred Isamana69aef12011-03-03 15:13:47 +0000351 return -EAGAIN;
352 }
353
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400354 filelayout_set_layoutcommit(hdr);
Fred Isamana69aef12011-03-03 15:13:47 +0000355 return 0;
356}
357
Fred Isamane0c2b382011-03-23 13:27:53 +0000358static int filelayout_commit_done_cb(struct rpc_task *task,
Fred Isaman0b7c0152012-04-20 14:47:39 -0400359 struct nfs_commit_data *data)
Fred Isamane0c2b382011-03-23 13:27:53 +0000360{
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400361 int err;
Fred Isamane0c2b382011-03-23 13:27:53 +0000362
Trond Myklebustcc668ab2013-08-14 15:31:28 -0400363 trace_nfs4_pnfs_commit_ds(data, task->tk_status);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400364 err = filelayout_async_handle_error(task, NULL, data->ds_clp,
365 data->lseg);
366
367 switch (err) {
368 case -NFS4ERR_RESET_TO_MDS:
Tom Haynesf54bcf22014-12-11 15:34:59 -0500369 pnfs_generic_prepare_to_resend_writes(data);
Andy Adamsone7dd79af2012-04-27 17:53:46 -0400370 return -EAGAIN;
371 case -EAGAIN:
372 rpc_restart_call_prepare(task);
Fred Isamane0c2b382011-03-23 13:27:53 +0000373 return -EAGAIN;
374 }
375
Peng Taobc7d4b82014-08-07 10:15:03 +0800376 if (data->verf.committed == NFS_UNSTABLE)
Trond Myklebust67af7612015-03-25 20:40:38 -0400377 pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
Peng Taobc7d4b82014-08-07 10:15:03 +0800378
Fred Isamane0c2b382011-03-23 13:27:53 +0000379 return 0;
380}
381
Fred Isamana69aef12011-03-03 15:13:47 +0000382static void filelayout_write_prepare(struct rpc_task *task, void *data)
383{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400384 struct nfs_pgio_header *hdr = data;
Fred Isamana69aef12011-03-03 15:13:47 +0000385
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400386 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
Trond Myklebustc58c8442013-03-18 19:45:14 -0400387 rpc_exit(task, -EIO);
388 return;
389 }
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400390 if (filelayout_reset_to_mds(hdr->lseg)) {
Andy Adamson0ad2f372012-04-27 17:53:48 -0400391 dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400392 filelayout_reset_write(hdr);
Andy Adamson0ad2f372012-04-27 17:53:48 -0400393 rpc_exit(task, 0);
394 return;
395 }
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400396 if (nfs41_setup_sequence(hdr->ds_clp->cl_session,
397 &hdr->args.seq_args,
398 &hdr->res.seq_res,
Trond Myklebust9b206142013-03-17 15:52:00 -0400399 task))
400 return;
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400401 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
402 hdr->args.lock_context, FMODE_WRITE) == -EIO)
Andy Adamson869a9d32014-03-04 12:31:09 -0500403 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
Fred Isamana69aef12011-03-03 15:13:47 +0000404}
405
406static void filelayout_write_call_done(struct rpc_task *task, void *data)
407{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400408 struct nfs_pgio_header *hdr = data;
Fred Isamana69aef12011-03-03 15:13:47 +0000409
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400410 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
Andy Adamsonf9c96fc2014-01-29 11:34:38 -0500411 task->tk_status == 0) {
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400412 nfs41_sequence_done(task, &hdr->res.seq_res);
Andy Adamson0ad2f372012-04-27 17:53:48 -0400413 return;
Andy Adamsonf9c96fc2014-01-29 11:34:38 -0500414 }
Andy Adamson0ad2f372012-04-27 17:53:48 -0400415
Fred Isamana69aef12011-03-03 15:13:47 +0000416 /* Note this may cause RPC to be resent */
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400417 hdr->mds_ops->rpc_call_done(task, data);
Fred Isamana69aef12011-03-03 15:13:47 +0000418}
419
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500420static void filelayout_write_count_stats(struct rpc_task *task, void *data)
421{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400422 struct nfs_pgio_header *hdr = data;
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500423
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400424 rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500425}
426
Fred Isaman0b7c0152012-04-20 14:47:39 -0400427static void filelayout_commit_prepare(struct rpc_task *task, void *data)
Fred Isamane0c2b382011-03-23 13:27:53 +0000428{
Fred Isaman0b7c0152012-04-20 14:47:39 -0400429 struct nfs_commit_data *wdata = data;
Fred Isamane0c2b382011-03-23 13:27:53 +0000430
Trond Myklebustd9afbd12012-10-22 20:28:44 -0400431 nfs41_setup_sequence(wdata->ds_clp->cl_session,
432 &wdata->args.seq_args,
433 &wdata->res.seq_res,
434 task);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400435}
436
Fred Isaman0b7c0152012-04-20 14:47:39 -0400437static void filelayout_commit_count_stats(struct rpc_task *task, void *data)
438{
439 struct nfs_commit_data *cdata = data;
440
441 rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics);
442}
443
Trond Myklebust17280172012-03-11 13:11:00 -0400444static const struct rpc_call_ops filelayout_read_call_ops = {
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000445 .rpc_call_prepare = filelayout_read_prepare,
446 .rpc_call_done = filelayout_read_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500447 .rpc_count_stats = filelayout_read_count_stats,
Tom Haynesf54bcf22014-12-11 15:34:59 -0500448 .rpc_release = pnfs_generic_rw_release,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000449};
450
Trond Myklebust17280172012-03-11 13:11:00 -0400451static const struct rpc_call_ops filelayout_write_call_ops = {
Fred Isamana69aef12011-03-03 15:13:47 +0000452 .rpc_call_prepare = filelayout_write_prepare,
453 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500454 .rpc_count_stats = filelayout_write_count_stats,
Tom Haynesf54bcf22014-12-11 15:34:59 -0500455 .rpc_release = pnfs_generic_rw_release,
Fred Isamana69aef12011-03-03 15:13:47 +0000456};
457
Trond Myklebust17280172012-03-11 13:11:00 -0400458static const struct rpc_call_ops filelayout_commit_call_ops = {
Fred Isaman0b7c0152012-04-20 14:47:39 -0400459 .rpc_call_prepare = filelayout_commit_prepare,
Tom Haynesf54bcf22014-12-11 15:34:59 -0500460 .rpc_call_done = pnfs_generic_write_commit_done,
Fred Isaman0b7c0152012-04-20 14:47:39 -0400461 .rpc_count_stats = filelayout_commit_count_stats,
Tom Haynesf54bcf22014-12-11 15:34:59 -0500462 .rpc_release = pnfs_generic_commit_release,
Fred Isamane0c2b382011-03-23 13:27:53 +0000463};
464
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000465static enum pnfs_try_status
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400466filelayout_read_pagelist(struct nfs_pgio_header *hdr)
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000467{
Fred Isamancd841602012-04-20 14:47:44 -0400468 struct pnfs_layout_segment *lseg = hdr->lseg;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000469 struct nfs4_pnfs_ds *ds;
Andy Adamson0e201622013-09-06 14:14:00 -0400470 struct rpc_clnt *ds_clnt;
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400471 loff_t offset = hdr->args.offset;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000472 u32 j, idx;
473 struct nfs_fh *fh;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000474
475 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
Fred Isamancd841602012-04-20 14:47:44 -0400476 __func__, hdr->inode->i_ino,
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400477 hdr->args.pgbase, (size_t)hdr->args.count, offset);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000478
479 /* Retrieve the correct rpc_client for the byte range */
480 j = nfs4_fl_calc_j_index(lseg, offset);
481 idx = nfs4_fl_calc_ds_index(lseg, j);
482 ds = nfs4_fl_prepare_ds(lseg, idx);
Andy Adamson90fecfc2012-04-27 17:53:43 -0400483 if (!ds)
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000484 return PNFS_NOT_ATTEMPTED;
Andy Adamson0e201622013-09-06 14:14:00 -0400485
486 ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
487 if (IS_ERR(ds_clnt))
488 return PNFS_NOT_ATTEMPTED;
489
Andy Adamson3a7936c2012-04-27 17:53:51 -0400490 dprintk("%s USE DS: %s cl_count %d\n", __func__,
491 ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count));
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000492
493 /* No multipath support. Use first DS */
Andy Adamson3a7936c2012-04-27 17:53:51 -0400494 atomic_inc(&ds->ds_clp->cl_count);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400495 hdr->ds_clp = ds->ds_clp;
Weston Andros Adamson6cccbb62014-09-16 17:35:51 -0400496 hdr->ds_commit_idx = idx;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000497 fh = nfs4_fl_select_ds_fh(lseg, j);
498 if (fh)
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400499 hdr->args.fh = fh;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000500
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400501 hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
502 hdr->mds_offset = offset;
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000503
504 /* Perform an asynchronous read to ds */
Peng Tao46a5ab42014-06-13 23:02:25 +0800505 nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
506 NFS_PROTO(hdr->inode), &filelayout_read_call_ops,
507 0, RPC_TASK_SOFTCONN);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000508 return PNFS_ATTEMPTED;
509}
510
Fred Isamana69aef12011-03-03 15:13:47 +0000511/* Perform async writes. */
Andy Adamson0382b742011-03-03 15:13:45 +0000512static enum pnfs_try_status
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400513filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
Andy Adamson0382b742011-03-03 15:13:45 +0000514{
Fred Isamancd841602012-04-20 14:47:44 -0400515 struct pnfs_layout_segment *lseg = hdr->lseg;
Fred Isamana69aef12011-03-03 15:13:47 +0000516 struct nfs4_pnfs_ds *ds;
Andy Adamson0e201622013-09-06 14:14:00 -0400517 struct rpc_clnt *ds_clnt;
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400518 loff_t offset = hdr->args.offset;
Fred Isamana69aef12011-03-03 15:13:47 +0000519 u32 j, idx;
520 struct nfs_fh *fh;
Fred Isamana69aef12011-03-03 15:13:47 +0000521
522 /* Retrieve the correct rpc_client for the byte range */
523 j = nfs4_fl_calc_j_index(lseg, offset);
524 idx = nfs4_fl_calc_ds_index(lseg, j);
525 ds = nfs4_fl_prepare_ds(lseg, idx);
Andy Adamson90fecfc2012-04-27 17:53:43 -0400526 if (!ds)
Fred Isamana69aef12011-03-03 15:13:47 +0000527 return PNFS_NOT_ATTEMPTED;
Andy Adamson0e201622013-09-06 14:14:00 -0400528
529 ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
530 if (IS_ERR(ds_clnt))
531 return PNFS_NOT_ATTEMPTED;
532
Andy Adamson3a7936c2012-04-27 17:53:51 -0400533 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d\n",
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400534 __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
Andy Adamson3a7936c2012-04-27 17:53:51 -0400535 offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count));
Fred Isamana69aef12011-03-03 15:13:47 +0000536
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400537 hdr->pgio_done_cb = filelayout_write_done_cb;
Andy Adamson3a7936c2012-04-27 17:53:51 -0400538 atomic_inc(&ds->ds_clp->cl_count);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400539 hdr->ds_clp = ds->ds_clp;
Weston Andros Adamson6cccbb62014-09-16 17:35:51 -0400540 hdr->ds_commit_idx = idx;
Fred Isamana69aef12011-03-03 15:13:47 +0000541 fh = nfs4_fl_select_ds_fh(lseg, j);
542 if (fh)
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400543 hdr->args.fh = fh;
544 hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
Fred Isamana69aef12011-03-03 15:13:47 +0000545
546 /* Perform an asynchronous write */
Peng Tao46a5ab42014-06-13 23:02:25 +0800547 nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
548 NFS_PROTO(hdr->inode), &filelayout_write_call_ops,
549 sync, RPC_TASK_SOFTCONN);
Fred Isamana69aef12011-03-03 15:13:47 +0000550 return PNFS_ATTEMPTED;
Andy Adamson0382b742011-03-03 15:13:45 +0000551}
552
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000553/*
Andy Adamson16b374c2010-10-20 00:18:04 -0400554 * filelayout_check_layout()
555 *
556 * Make sure layout segment parameters are sane WRT the device.
557 * At this point no generic layer initialization of the lseg has occurred,
558 * and nothing has been added to the layout_hdr cache.
559 *
560 */
561static int
562filelayout_check_layout(struct pnfs_layout_hdr *lo,
563 struct nfs4_filelayout_segment *fl,
564 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400565 struct nfs4_deviceid *id,
566 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400567{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400568 struct nfs4_deviceid_node *d;
Andy Adamson16b374c2010-10-20 00:18:04 -0400569 struct nfs4_file_layout_dsaddr *dsaddr;
570 int status = -EINVAL;
Andy Adamson16b374c2010-10-20 00:18:04 -0400571
572 dprintk("--> %s\n", __func__);
573
Andy Adamson7c24d942011-06-13 18:22:38 -0400574 /* FIXME: remove this check when layout segment support is added */
575 if (lgr->range.offset != 0 ||
576 lgr->range.length != NFS4_MAX_UINT64) {
577 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
578 __func__);
579 goto out;
580 }
581
Andy Adamson16b374c2010-10-20 00:18:04 -0400582 if (fl->pattern_offset > lgr->range.offset) {
Jim Rees3b6445a2011-02-22 19:31:57 -0500583 dprintk("%s pattern_offset %lld too large\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400584 __func__, fl->pattern_offset);
585 goto out;
586 }
587
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400588 if (!fl->stripe_unit) {
Benny Halevy75247af2011-02-22 15:56:01 -0800589 dprintk("%s Invalid stripe unit (%u)\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400590 __func__, fl->stripe_unit);
591 goto out;
592 }
593
594 /* find and reference the deviceid */
Christoph Hellwig661373b2014-09-02 21:27:57 -0700595 d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), id,
596 lo->plh_lc_cred, gfp_flags);
597 if (d == NULL)
598 goto out;
599
600 dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
Trond Myklebust1dfed272012-09-18 19:51:12 -0400601 /* Found deviceid is unavailable */
602 if (filelayout_test_devid_unavailable(&dsaddr->id_node))
Christoph Hellwig661373b2014-09-02 21:27:57 -0700603 goto out_put;
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400604
Andy Adamson16b374c2010-10-20 00:18:04 -0400605 fl->dsaddr = dsaddr;
606
Chuck Levere4149662011-10-25 12:18:03 -0400607 if (fl->first_stripe_index >= dsaddr->stripe_count) {
608 dprintk("%s Bad first_stripe_index %u\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400609 __func__, fl->first_stripe_index);
610 goto out_put;
611 }
612
613 if ((fl->stripe_type == STRIPE_SPARSE &&
614 fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
615 (fl->stripe_type == STRIPE_DENSE &&
616 fl->num_fh != dsaddr->stripe_count)) {
617 dprintk("%s num_fh %u not valid for given packing\n",
618 __func__, fl->num_fh);
619 goto out_put;
620 }
621
Andy Adamson16b374c2010-10-20 00:18:04 -0400622 status = 0;
623out:
624 dprintk("--> %s returns %d\n", __func__, status);
625 return status;
626out_put:
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000627 nfs4_fl_put_deviceid(dsaddr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400628 goto out;
629}
630
631static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
632{
633 int i;
634
635 for (i = 0; i < fl->num_fh; i++) {
636 if (!fl->fh_array[i])
637 break;
638 kfree(fl->fh_array[i]);
639 }
640 kfree(fl->fh_array);
641 fl->fh_array = NULL;
642}
643
644static void
645_filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
646{
647 filelayout_free_fh_array(fl);
648 kfree(fl);
649}
650
651static int
652filelayout_decode_layout(struct pnfs_layout_hdr *flo,
653 struct nfs4_filelayout_segment *fl,
654 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400655 struct nfs4_deviceid *id,
656 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400657{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400658 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400659 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400660 struct page *scratch;
661 __be32 *p;
Andy Adamson16b374c2010-10-20 00:18:04 -0400662 uint32_t nfl_util;
663 int i;
664
665 dprintk("%s: set_layout_map Begin\n", __func__);
666
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400667 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400668 if (!scratch)
669 return -ENOMEM;
670
Benny Halevyf7da7a12011-05-19 14:16:47 -0400671 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400672 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
673
674 /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
675 * num_fh (4) */
676 p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
677 if (unlikely(!p))
678 goto out_err;
679
Andy Adamson16b374c2010-10-20 00:18:04 -0400680 memcpy(id, p, sizeof(*id));
681 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400682 nfs4_print_deviceid(id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400683
684 nfl_util = be32_to_cpup(p++);
685 if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
686 fl->commit_through_mds = 1;
687 if (nfl_util & NFL4_UFLG_DENSE)
688 fl->stripe_type = STRIPE_DENSE;
689 else
690 fl->stripe_type = STRIPE_SPARSE;
691 fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
692
693 fl->first_stripe_index = be32_to_cpup(p++);
694 p = xdr_decode_hyper(p, &fl->pattern_offset);
695 fl->num_fh = be32_to_cpup(p++);
696
697 dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
698 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
699 fl->pattern_offset);
700
Andy Adamsoncec765c2011-06-13 18:36:17 -0400701 /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
702 * Futher checking is done in filelayout_check_layout */
Chuck Levere4149662011-10-25 12:18:03 -0400703 if (fl->num_fh >
Andy Adamsoncec765c2011-06-13 18:36:17 -0400704 max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400705 goto out_err;
706
Andy Adamsoncec765c2011-06-13 18:36:17 -0400707 if (fl->num_fh > 0) {
Trond Myklebust1813bad2012-10-11 14:36:52 -0400708 fl->fh_array = kcalloc(fl->num_fh, sizeof(fl->fh_array[0]),
Andy Adamsoncec765c2011-06-13 18:36:17 -0400709 gfp_flags);
710 if (!fl->fh_array)
711 goto out_err;
712 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400713
714 for (i = 0; i < fl->num_fh; i++) {
715 /* Do we want to use a mempool here? */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400716 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400717 if (!fl->fh_array[i])
718 goto out_err_free;
719
720 p = xdr_inline_decode(&stream, 4);
721 if (unlikely(!p))
722 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400723 fl->fh_array[i]->size = be32_to_cpup(p++);
724 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -0500725 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400726 i, fl->fh_array[i]->size);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400727 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400728 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400729
730 p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
731 if (unlikely(!p))
732 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400733 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
Andy Adamson16b374c2010-10-20 00:18:04 -0400734 dprintk("DEBUG: %s: fh len %d\n", __func__,
735 fl->fh_array[i]->size);
736 }
737
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400738 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400739 return 0;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400740
741out_err_free:
742 filelayout_free_fh_array(fl);
743out_err:
744 __free_page(scratch);
745 return -EIO;
Andy Adamson16b374c2010-10-20 00:18:04 -0400746}
747
Fred Isamanc8795132011-03-23 13:27:49 +0000748static void
749filelayout_free_lseg(struct pnfs_layout_segment *lseg)
750{
751 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
752
753 dprintk("--> %s\n", __func__);
754 nfs4_fl_put_deviceid(fl->dsaddr);
Fred Isaman799ba8d2012-04-20 14:47:38 -0400755 /* This assumes a single RW lseg */
756 if (lseg->pls_range.iomode == IOMODE_RW) {
757 struct nfs4_filelayout *flo;
758
759 flo = FILELAYOUT_FROM_HDR(lseg->pls_layout);
760 flo->commit_info.nbuckets = 0;
761 kfree(flo->commit_info.buckets);
762 flo->commit_info.buckets = NULL;
763 }
Fred Isamanc8795132011-03-23 13:27:49 +0000764 _filelayout_free_lseg(fl);
765}
766
Fred Isaman799ba8d2012-04-20 14:47:38 -0400767static int
768filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
Fred Isamanea2cf222012-04-20 14:47:53 -0400769 struct nfs_commit_info *cinfo,
Fred Isaman799ba8d2012-04-20 14:47:38 -0400770 gfp_t gfp_flags)
771{
772 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
Fred Isamanea2cf222012-04-20 14:47:53 -0400773 struct pnfs_commit_bucket *buckets;
Weston Andros Adamsondd7663e2014-05-15 11:56:49 -0400774 int size, i;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400775
776 if (fl->commit_through_mds)
777 return 0;
Weston Andros Adamsondd7663e2014-05-15 11:56:49 -0400778
779 size = (fl->stripe_type == STRIPE_SPARSE) ?
780 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
781
782 if (cinfo->ds->nbuckets >= size) {
Fred Isaman799ba8d2012-04-20 14:47:38 -0400783 /* This assumes there is only one IOMODE_RW lseg. What
784 * we really want to do is have a layout_hdr level
785 * dictionary of <multipath_list4, fh> keys, each
786 * associated with a struct list_head, populated by calls
787 * to filelayout_write_pagelist().
788 * */
789 return 0;
790 }
791
Fred Isamanea2cf222012-04-20 14:47:53 -0400792 buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
Fred Isaman799ba8d2012-04-20 14:47:38 -0400793 gfp_flags);
794 if (!buckets)
795 return -ENOMEM;
Weston Andros Adamsondd7663e2014-05-15 11:56:49 -0400796 for (i = 0; i < size; i++) {
797 INIT_LIST_HEAD(&buckets[i].written);
798 INIT_LIST_HEAD(&buckets[i].committing);
Weston Andros Adamson5002c582014-05-15 11:56:54 -0400799 /* mark direct verifier as unset */
800 buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400801 }
Weston Andros Adamsondd7663e2014-05-15 11:56:49 -0400802
803 spin_lock(cinfo->lock);
804 if (cinfo->ds->nbuckets >= size)
805 goto out;
806 for (i = 0; i < cinfo->ds->nbuckets; i++) {
807 list_splice(&cinfo->ds->buckets[i].written,
808 &buckets[i].written);
809 list_splice(&cinfo->ds->buckets[i].committing,
810 &buckets[i].committing);
Weston Andros Adamson5002c582014-05-15 11:56:54 -0400811 buckets[i].direct_verf.committed =
812 cinfo->ds->buckets[i].direct_verf.committed;
Weston Andros Adamsondd7663e2014-05-15 11:56:49 -0400813 buckets[i].wlseg = cinfo->ds->buckets[i].wlseg;
814 buckets[i].clseg = cinfo->ds->buckets[i].clseg;
815 }
816 swap(cinfo->ds->buckets, buckets);
817 cinfo->ds->nbuckets = size;
818out:
819 spin_unlock(cinfo->lock);
820 kfree(buckets);
821 return 0;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400822}
823
Andy Adamson16b374c2010-10-20 00:18:04 -0400824static struct pnfs_layout_segment *
825filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400826 struct nfs4_layoutget_res *lgr,
827 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400828{
829 struct nfs4_filelayout_segment *fl;
830 int rc;
831 struct nfs4_deviceid id;
832
833 dprintk("--> %s\n", __func__);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400834 fl = kzalloc(sizeof(*fl), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400835 if (!fl)
836 return NULL;
837
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400838 rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
839 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
Andy Adamson16b374c2010-10-20 00:18:04 -0400840 _filelayout_free_lseg(fl);
841 return NULL;
842 }
843 return &fl->generic_hdr;
844}
845
Fred Isaman94ad1c82011-03-01 01:34:14 +0000846/*
847 * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
848 *
Weston Andros Adamsonb4fdac12014-05-15 11:56:43 -0400849 * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
850 * of bytes (maximum @req->wb_bytes) that can be coalesced.
Fred Isaman94ad1c82011-03-01 01:34:14 +0000851 */
Weston Andros Adamsonb4fdac12014-05-15 11:56:43 -0400852static size_t
Fred Isaman94ad1c82011-03-01 01:34:14 +0000853filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
854 struct nfs_page *req)
855{
Weston Andros Adamson0f9c4292014-05-15 11:56:51 -0400856 unsigned int size;
Fred Isaman94ad1c82011-03-01 01:34:14 +0000857 u64 p_stripe, r_stripe;
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400858 u32 stripe_offset;
859 u64 segment_offset = pgio->pg_lseg->pls_range.offset;
860 u32 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
Fred Isaman94ad1c82011-03-01 01:34:14 +0000861
Weston Andros Adamson0f9c4292014-05-15 11:56:51 -0400862 /* calls nfs_generic_pg_test */
863 size = pnfs_generic_pg_test(pgio, prev, req);
864 if (!size)
Weston Andros Adamsonb4fdac12014-05-15 11:56:43 -0400865 return 0;
Benny Halevy89a58e32011-05-25 20:54:40 +0300866
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400867 /* see if req and prev are in the same stripe */
Weston Andros Adamson0f9c4292014-05-15 11:56:51 -0400868 if (prev) {
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400869 p_stripe = (u64)req_offset(prev) - segment_offset;
870 r_stripe = (u64)req_offset(req) - segment_offset;
Weston Andros Adamson0f9c4292014-05-15 11:56:51 -0400871 do_div(p_stripe, stripe_unit);
872 do_div(r_stripe, stripe_unit);
Fred Isaman94ad1c82011-03-01 01:34:14 +0000873
Weston Andros Adamson0f9c4292014-05-15 11:56:51 -0400874 if (p_stripe != r_stripe)
875 return 0;
876 }
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400877
878 /* calculate remaining bytes in the current stripe */
879 div_u64_rem((u64)req_offset(req) - segment_offset,
880 stripe_unit,
881 &stripe_offset);
882 WARN_ON_ONCE(stripe_offset > stripe_unit);
883 if (stripe_offset >= stripe_unit)
884 return 0;
885 return min(stripe_unit - (unsigned int)stripe_offset, size);
Fred Isaman94ad1c82011-03-01 01:34:14 +0000886}
887
Trond Myklebust17280172012-03-11 13:11:00 -0400888static void
Andy Adamson7c24d942011-06-13 18:22:38 -0400889filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
890 struct nfs_page *req)
891{
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400892 if (!pgio->pg_lseg)
893 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
Andy Adamson7c24d942011-06-13 18:22:38 -0400894 req->wb_context,
895 0,
896 NFS4_MAX_UINT64,
897 IOMODE_READ,
898 GFP_KERNEL);
899 /* If no lseg, fall back to read through mds */
900 if (pgio->pg_lseg == NULL)
Trond Myklebust1f945352011-07-13 15:59:57 -0400901 nfs_pageio_reset_read_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400902}
903
Trond Myklebust17280172012-03-11 13:11:00 -0400904static void
Andy Adamson7c24d942011-06-13 18:22:38 -0400905filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
906 struct nfs_page *req)
907{
Fred Isamanea2cf222012-04-20 14:47:53 -0400908 struct nfs_commit_info cinfo;
Fred Isaman799ba8d2012-04-20 14:47:38 -0400909 int status;
910
Weston Andros Adamsonc6194272014-05-15 11:56:56 -0400911 if (!pgio->pg_lseg)
912 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
Andy Adamson7c24d942011-06-13 18:22:38 -0400913 req->wb_context,
914 0,
915 NFS4_MAX_UINT64,
916 IOMODE_RW,
917 GFP_NOFS);
918 /* If no lseg, fall back to write through mds */
919 if (pgio->pg_lseg == NULL)
Fred Isaman799ba8d2012-04-20 14:47:38 -0400920 goto out_mds;
Fred Isamanea2cf222012-04-20 14:47:53 -0400921 nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
922 status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
Fred Isaman799ba8d2012-04-20 14:47:38 -0400923 if (status < 0) {
Trond Myklebust9369a432012-09-18 20:57:08 -0400924 pnfs_put_lseg(pgio->pg_lseg);
Fred Isaman799ba8d2012-04-20 14:47:38 -0400925 pgio->pg_lseg = NULL;
926 goto out_mds;
927 }
928 return;
929out_mds:
930 nfs_pageio_reset_write_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400931}
932
Trond Myklebust1751c362011-06-10 13:30:23 -0400933static const struct nfs_pageio_ops filelayout_pg_read_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400934 .pg_init = filelayout_pg_init_read,
Trond Myklebust1751c362011-06-10 13:30:23 -0400935 .pg_test = filelayout_pg_test,
Trond Myklebust493292d2011-07-13 15:58:28 -0400936 .pg_doio = pnfs_generic_pg_readpages,
Weston Andros Adamson180bb5e2014-09-10 15:48:01 -0400937 .pg_cleanup = pnfs_generic_pg_cleanup,
Trond Myklebust1751c362011-06-10 13:30:23 -0400938};
939
940static const struct nfs_pageio_ops filelayout_pg_write_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400941 .pg_init = filelayout_pg_init_write,
Trond Myklebust1751c362011-06-10 13:30:23 -0400942 .pg_test = filelayout_pg_test,
Trond Myklebustdce81292011-07-13 15:59:19 -0400943 .pg_doio = pnfs_generic_pg_writepages,
Weston Andros Adamson180bb5e2014-09-10 15:48:01 -0400944 .pg_cleanup = pnfs_generic_pg_cleanup,
Trond Myklebust1751c362011-06-10 13:30:23 -0400945};
946
Fred Isamane0c2b382011-03-23 13:27:53 +0000947static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
948{
949 if (fl->stripe_type == STRIPE_SPARSE)
950 return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
951 else
952 return j;
953}
954
Peng Taoc8a32922014-07-03 13:07:45 +0800955static void
956filelayout_mark_request_commit(struct nfs_page *req,
957 struct pnfs_layout_segment *lseg,
Weston Andros Adamsonb57ff132014-09-05 18:20:21 -0400958 struct nfs_commit_info *cinfo,
959 u32 ds_commit_idx)
Peng Taoc8a32922014-07-03 13:07:45 +0800960
Fred Isamand6d6dc72012-03-08 17:29:35 -0500961{
Fred Isamane0c2b382011-03-23 13:27:53 +0000962 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
963 u32 i, j;
Fred Isamane0c2b382011-03-23 13:27:53 +0000964
Peng Taoc8a32922014-07-03 13:07:45 +0800965 if (fl->commit_through_mds) {
Tom Haynes338d00c2015-02-17 14:58:15 -0800966 nfs_request_add_commit_list(req, &cinfo->mds->list, cinfo);
967 } else {
968 /* Note that we are calling nfs4_fl_calc_j_index on each page
969 * that ends up being committed to a data server. An attractive
970 * alternative is to add a field to nfs_write_data and nfs_page
971 * to store the value calculated in filelayout_write_pagelist
972 * and just use that here.
Fred Isamand6d6dc72012-03-08 17:29:35 -0500973 */
Tom Haynes338d00c2015-02-17 14:58:15 -0800974 j = nfs4_fl_calc_j_index(lseg, req_offset(req));
975 i = select_bucket_index(fl, j);
976 pnfs_layout_mark_request_commit(req, lseg, cinfo, i);
Fred Isamane0c2b382011-03-23 13:27:53 +0000977 }
Trond Myklebust8dd37752012-03-15 17:16:40 -0400978}
979
Fred Isamane0c2b382011-03-23 13:27:53 +0000980static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
981{
982 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
983
984 if (flseg->stripe_type == STRIPE_SPARSE)
985 return i;
986 else
987 return nfs4_fl_calc_ds_index(lseg, i);
988}
989
990static struct nfs_fh *
991select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
992{
993 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
994
995 if (flseg->stripe_type == STRIPE_SPARSE) {
996 if (flseg->num_fh == 1)
997 i = 0;
998 else if (flseg->num_fh == 0)
999 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
1000 return NULL;
1001 }
1002 return flseg->fh_array[i];
1003}
1004
Fred Isaman0b7c0152012-04-20 14:47:39 -04001005static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
Fred Isamane0c2b382011-03-23 13:27:53 +00001006{
1007 struct pnfs_layout_segment *lseg = data->lseg;
1008 struct nfs4_pnfs_ds *ds;
Andy Adamson0e201622013-09-06 14:14:00 -04001009 struct rpc_clnt *ds_clnt;
Fred Isamane0c2b382011-03-23 13:27:53 +00001010 u32 idx;
1011 struct nfs_fh *fh;
1012
1013 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
1014 ds = nfs4_fl_prepare_ds(lseg, idx);
Andy Adamson0e201622013-09-06 14:14:00 -04001015 if (!ds)
1016 goto out_err;
1017
1018 ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, data->inode);
1019 if (IS_ERR(ds_clnt))
1020 goto out_err;
1021
Andy Adamson3a7936c2012-04-27 17:53:51 -04001022 dprintk("%s ino %lu, how %d cl_count %d\n", __func__,
1023 data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count));
Fred Isaman0b7c0152012-04-20 14:47:39 -04001024 data->commit_done_cb = filelayout_commit_done_cb;
Andy Adamson3a7936c2012-04-27 17:53:51 -04001025 atomic_inc(&ds->ds_clp->cl_count);
Fred Isamane0c2b382011-03-23 13:27:53 +00001026 data->ds_clp = ds->ds_clp;
1027 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
1028 if (fh)
1029 data->args.fh = fh;
Peng Taoc36aae92014-06-09 07:10:14 +08001030 return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode),
Andy Adamson9f0ec1762012-04-27 17:53:44 -04001031 &filelayout_commit_call_ops, how,
1032 RPC_TASK_SOFTCONN);
Andy Adamson0e201622013-09-06 14:14:00 -04001033out_err:
Tom Haynesf54bcf22014-12-11 15:34:59 -05001034 pnfs_generic_prepare_to_resend_writes(data);
1035 pnfs_generic_commit_release(data);
Andy Adamson0e201622013-09-06 14:14:00 -04001036 return -EAGAIN;
Fred Isamane0c2b382011-03-23 13:27:53 +00001037}
1038
Weston Andros Adamson02d14262014-07-17 20:42:17 -04001039/* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest
1040 * for @page
1041 * @cinfo - commit info for current inode
1042 * @page - page to search for matching head request
1043 *
1044 * Returns a the head request if one is found, otherwise returns NULL.
1045 */
1046static struct nfs_page *
1047filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page)
1048{
1049 struct nfs_page *freq, *t;
1050 struct pnfs_commit_bucket *b;
1051 int i;
1052
1053 /* Linearly search the commit lists for each bucket until a matching
1054 * request is found */
1055 for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
1056 list_for_each_entry_safe(freq, t, &b->written, wb_list) {
1057 if (freq->wb_page == page)
1058 return freq->wb_head;
1059 }
1060 list_for_each_entry_safe(freq, t, &b->committing, wb_list) {
1061 if (freq->wb_page == page)
1062 return freq->wb_head;
1063 }
1064 }
1065
1066 return NULL;
1067}
1068
Fred Isamane0c2b382011-03-23 13:27:53 +00001069static int
1070filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
Fred Isamanea2cf222012-04-20 14:47:53 -04001071 int how, struct nfs_commit_info *cinfo)
Fred Isamane0c2b382011-03-23 13:27:53 +00001072{
Tom Haynesf54bcf22014-12-11 15:34:59 -05001073 return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
1074 filelayout_initiate_commit);
Fred Isamane0c2b382011-03-23 13:27:53 +00001075}
Tom Haynesf54bcf22014-12-11 15:34:59 -05001076
Christoph Hellwig661373b2014-09-02 21:27:57 -07001077static struct nfs4_deviceid_node *
1078filelayout_alloc_deviceid_node(struct nfs_server *server,
1079 struct pnfs_device *pdev, gfp_t gfp_flags)
1080{
1081 struct nfs4_file_layout_dsaddr *dsaddr;
1082
1083 dsaddr = nfs4_fl_alloc_deviceid_node(server, pdev, gfp_flags);
1084 if (!dsaddr)
1085 return NULL;
1086 return &dsaddr->id_node;
1087}
Fred Isamane0c2b382011-03-23 13:27:53 +00001088
Benny Halevy1775bc32011-05-20 13:47:33 +02001089static void
Trond Myklebustfc877012015-03-09 17:25:14 -04001090filelayout_free_deviceid_node(struct nfs4_deviceid_node *d)
Benny Halevy1775bc32011-05-20 13:47:33 +02001091{
1092 nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
1093}
1094
Fred Isaman799ba8d2012-04-20 14:47:38 -04001095static struct pnfs_layout_hdr *
1096filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
1097{
1098 struct nfs4_filelayout *flo;
1099
1100 flo = kzalloc(sizeof(*flo), gfp_flags);
Trond Myklebust6df200f2014-05-29 20:06:55 -04001101 return flo != NULL ? &flo->generic_hdr : NULL;
Fred Isaman799ba8d2012-04-20 14:47:38 -04001102}
1103
1104static void
1105filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
1106{
1107 kfree(FILELAYOUT_FROM_HDR(lo));
1108}
1109
Fred Isamanea2cf222012-04-20 14:47:53 -04001110static struct pnfs_ds_commit_info *
1111filelayout_get_ds_info(struct inode *inode)
1112{
Fred Isamandf011742012-04-24 14:50:34 -04001113 struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
1114
1115 if (layout == NULL)
1116 return NULL;
1117 else
1118 return &FILELAYOUT_FROM_HDR(layout)->commit_info;
Fred Isamanea2cf222012-04-20 14:47:53 -04001119}
1120
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001121static struct pnfs_layoutdriver_type filelayout_type = {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +00001122 .id = LAYOUT_NFSV4_1_FILES,
1123 .name = "LAYOUT_NFSV4_1_FILES",
1124 .owner = THIS_MODULE,
Fred Isaman799ba8d2012-04-20 14:47:38 -04001125 .alloc_layout_hdr = filelayout_alloc_layout_hdr,
1126 .free_layout_hdr = filelayout_free_layout_hdr,
Christoph Hellwigea8eecd2011-03-01 01:34:21 +00001127 .alloc_lseg = filelayout_alloc_lseg,
1128 .free_lseg = filelayout_free_lseg,
Trond Myklebust1751c362011-06-10 13:30:23 -04001129 .pg_read_ops = &filelayout_pg_read_ops,
1130 .pg_write_ops = &filelayout_pg_write_ops,
Fred Isamanea2cf222012-04-20 14:47:53 -04001131 .get_ds_info = &filelayout_get_ds_info,
Trond Myklebust8dd37752012-03-15 17:16:40 -04001132 .mark_request_commit = filelayout_mark_request_commit,
Tom Haynesf54bcf22014-12-11 15:34:59 -05001133 .clear_request_commit = pnfs_generic_clear_request_commit,
1134 .scan_commit_lists = pnfs_generic_scan_commit_lists,
1135 .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
Weston Andros Adamson02d14262014-07-17 20:42:17 -04001136 .search_commit_reqs = filelayout_search_commit_reqs,
Fred Isamane0c2b382011-03-23 13:27:53 +00001137 .commit_pagelist = filelayout_commit_pagelist,
Andy Adamsondc70d7b2011-03-01 01:34:19 +00001138 .read_pagelist = filelayout_read_pagelist,
Andy Adamson0382b742011-03-03 15:13:45 +00001139 .write_pagelist = filelayout_write_pagelist,
Christoph Hellwig661373b2014-09-02 21:27:57 -07001140 .alloc_deviceid_node = filelayout_alloc_deviceid_node,
Trond Myklebustfc877012015-03-09 17:25:14 -04001141 .free_deviceid_node = filelayout_free_deviceid_node,
Trond Myklebust5bb89b42015-03-25 14:14:42 -04001142 .sync = pnfs_nfs_generic_sync,
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001143};
1144
1145static int __init nfs4filelayout_init(void)
1146{
1147 printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
1148 __func__);
1149 return pnfs_register_layoutdriver(&filelayout_type);
1150}
1151
1152static void __exit nfs4filelayout_exit(void)
1153{
1154 printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
1155 __func__);
1156 pnfs_unregister_layoutdriver(&filelayout_type);
1157}
1158
J. Bruce Fieldsf85ef692011-07-15 19:18:42 -04001159MODULE_ALIAS("nfs-layouttype4-1");
1160
Dean Hildebrand7ab672c2010-10-20 00:18:00 -04001161module_init(nfs4filelayout_init);
1162module_exit(nfs4filelayout_exit);