blob: b2d3bb5971bbdfbfe769db16a14ba56b2d63f376 [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 Adamsoncbdabc7f2011-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 Adamsoncbdabc7f2011-03-01 01:34:20 +000085static int filelayout_async_handle_error(struct rpc_task *task,
86 struct nfs4_state *state,
87 struct nfs_client *clp,
88 int *reset)
89{
Andy Adamson9cb81962012-03-07 10:49:41 -050090 struct nfs_server *mds_server = NFS_SERVER(state->inode);
91 struct nfs_client *mds_client = mds_server->nfs_client;
92
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +000093 if (task->tk_status >= 0)
94 return 0;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +000095 *reset = 0;
96
97 switch (task->tk_status) {
Andy Adamson9cb81962012-03-07 10:49:41 -050098 /* MDS state errors */
99 case -NFS4ERR_DELEG_REVOKED:
100 case -NFS4ERR_ADMIN_REVOKED:
101 case -NFS4ERR_BAD_STATEID:
102 if (state != NULL)
103 nfs_remove_bad_delegation(state->inode);
104 case -NFS4ERR_OPENMODE:
105 if (state == NULL)
106 break;
107 nfs4_schedule_stateid_recovery(mds_server, state);
108 goto wait_on_recovery;
109 case -NFS4ERR_EXPIRED:
110 if (state != NULL)
111 nfs4_schedule_stateid_recovery(mds_server, state);
112 nfs4_schedule_lease_recovery(mds_client);
113 goto wait_on_recovery;
114 /* DS session errors */
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000115 case -NFS4ERR_BADSESSION:
116 case -NFS4ERR_BADSLOT:
117 case -NFS4ERR_BAD_HIGH_SLOT:
118 case -NFS4ERR_DEADSESSION:
119 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
120 case -NFS4ERR_SEQ_FALSE_RETRY:
121 case -NFS4ERR_SEQ_MISORDERED:
122 dprintk("%s ERROR %d, Reset session. Exchangeid "
123 "flags 0x%x\n", __func__, task->tk_status,
124 clp->cl_exchange_flags);
125 nfs4_schedule_session_recovery(clp->cl_session);
126 break;
127 case -NFS4ERR_DELAY:
128 case -NFS4ERR_GRACE:
129 case -EKEYEXPIRED:
130 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
131 break;
Andy Adamsona8a4ae32011-05-03 13:43:03 -0400132 case -NFS4ERR_RETRY_UNCACHED_REP:
133 break;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000134 default:
135 dprintk("%s DS error. Retry through MDS %d\n", __func__,
136 task->tk_status);
137 *reset = 1;
138 break;
139 }
Andy Adamson9cb81962012-03-07 10:49:41 -0500140out:
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000141 task->tk_status = 0;
142 return -EAGAIN;
Andy Adamson9cb81962012-03-07 10:49:41 -0500143wait_on_recovery:
144 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
145 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
146 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
147 goto out;
148
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000149}
150
151/* NFS_PROTO call done callback routines */
152
153static int filelayout_read_done_cb(struct rpc_task *task,
154 struct nfs_read_data *data)
155{
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000156 int reset = 0;
157
158 dprintk("%s DS read\n", __func__);
159
160 if (filelayout_async_handle_error(task, data->args.context->state,
161 data->ds_clp, &reset) == -EAGAIN) {
162 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
163 __func__, data->ds_clp, data->ds_clp->cl_session);
164 if (reset) {
Peng Tao1b0ae062011-09-22 21:50:12 -0400165 pnfs_set_lo_fail(data->lseg);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000166 nfs4_reset_read(task, data);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000167 }
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700168 rpc_restart_call_prepare(task);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000169 return -EAGAIN;
170 }
171
172 return 0;
173}
174
Andy Adamson16b374c2010-10-20 00:18:04 -0400175/*
Andy Adamson863a3c62011-03-23 13:27:54 +0000176 * We reference the rpc_cred of the first WRITE that triggers the need for
177 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
178 * rfc5661 is not clear about which credential should be used.
179 */
180static void
181filelayout_set_layoutcommit(struct nfs_write_data *wdata)
182{
183 if (FILELAYOUT_LSEG(wdata->lseg)->commit_through_mds ||
184 wdata->res.verf->committed == NFS_FILE_SYNC)
185 return;
186
187 pnfs_set_layoutcommit(wdata);
188 dprintk("%s ionde %lu pls_end_pos %lu\n", __func__, wdata->inode->i_ino,
Peng Taoacff58802011-07-30 20:52:31 -0400189 (unsigned long) NFS_I(wdata->inode)->layout->plh_lwb);
Andy Adamson863a3c62011-03-23 13:27:54 +0000190}
191
192/*
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000193 * Call ops for the async read/write cases
194 * In the case of dense layouts, the offset needs to be reset to its
195 * original value.
196 */
197static void filelayout_read_prepare(struct rpc_task *task, void *data)
198{
199 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
200
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000201 rdata->read_done_cb = filelayout_read_done_cb;
202
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000203 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
204 &rdata->args.seq_args, &rdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500205 task))
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000206 return;
207
208 rpc_call_start(task);
209}
210
211static void filelayout_read_call_done(struct rpc_task *task, void *data)
212{
213 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
214
215 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
216
217 /* Note this may cause RPC to be resent */
218 rdata->mds_ops->rpc_call_done(task, data);
219}
220
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500221static void filelayout_read_count_stats(struct rpc_task *task, void *data)
222{
223 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
224
225 rpc_count_iostats(task, NFS_SERVER(rdata->inode)->client->cl_metrics);
226}
227
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000228static void filelayout_read_release(void *data)
229{
230 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
231
232 rdata->mds_ops->rpc_release(data);
233}
234
Fred Isamana69aef12011-03-03 15:13:47 +0000235static int filelayout_write_done_cb(struct rpc_task *task,
236 struct nfs_write_data *data)
237{
238 int reset = 0;
239
240 if (filelayout_async_handle_error(task, data->args.context->state,
241 data->ds_clp, &reset) == -EAGAIN) {
Fred Isamana69aef12011-03-03 15:13:47 +0000242 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
243 __func__, data->ds_clp, data->ds_clp->cl_session);
244 if (reset) {
Peng Tao1b0ae062011-09-22 21:50:12 -0400245 pnfs_set_lo_fail(data->lseg);
Fred Isamana69aef12011-03-03 15:13:47 +0000246 nfs4_reset_write(task, data);
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700247 }
248 rpc_restart_call_prepare(task);
Fred Isamana69aef12011-03-03 15:13:47 +0000249 return -EAGAIN;
250 }
251
Andy Adamson863a3c62011-03-23 13:27:54 +0000252 filelayout_set_layoutcommit(data);
Fred Isamana69aef12011-03-03 15:13:47 +0000253 return 0;
254}
255
Fred Isamane0c2b382011-03-23 13:27:53 +0000256/* Fake up some data that will cause nfs_commit_release to retry the writes. */
257static void prepare_to_resend_writes(struct nfs_write_data *data)
258{
259 struct nfs_page *first = nfs_list_entry(data->pages.next);
260
261 data->task.tk_status = 0;
262 memcpy(data->verf.verifier, first->wb_verf.verifier,
263 sizeof(first->wb_verf.verifier));
264 data->verf.verifier[0]++; /* ensure verifier mismatch */
265}
266
267static int filelayout_commit_done_cb(struct rpc_task *task,
268 struct nfs_write_data *data)
269{
270 int reset = 0;
271
272 if (filelayout_async_handle_error(task, data->args.context->state,
273 data->ds_clp, &reset) == -EAGAIN) {
274 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
275 __func__, data->ds_clp, data->ds_clp->cl_session);
276 if (reset) {
277 prepare_to_resend_writes(data);
Peng Tao1b0ae062011-09-22 21:50:12 -0400278 pnfs_set_lo_fail(data->lseg);
Fred Isamane0c2b382011-03-23 13:27:53 +0000279 } else
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700280 rpc_restart_call_prepare(task);
Fred Isamane0c2b382011-03-23 13:27:53 +0000281 return -EAGAIN;
282 }
283
284 return 0;
285}
286
Fred Isamana69aef12011-03-03 15:13:47 +0000287static void filelayout_write_prepare(struct rpc_task *task, void *data)
288{
289 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
290
291 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
292 &wdata->args.seq_args, &wdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500293 task))
Fred Isamana69aef12011-03-03 15:13:47 +0000294 return;
295
296 rpc_call_start(task);
297}
298
299static void filelayout_write_call_done(struct rpc_task *task, void *data)
300{
301 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
302
303 /* Note this may cause RPC to be resent */
304 wdata->mds_ops->rpc_call_done(task, data);
305}
306
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500307static void filelayout_write_count_stats(struct rpc_task *task, void *data)
308{
309 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
310
311 rpc_count_iostats(task, NFS_SERVER(wdata->inode)->client->cl_metrics);
312}
313
Fred Isamana69aef12011-03-03 15:13:47 +0000314static void filelayout_write_release(void *data)
315{
316 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
317
318 wdata->mds_ops->rpc_release(data);
319}
320
Fred Isamane0c2b382011-03-23 13:27:53 +0000321static void filelayout_commit_release(void *data)
322{
323 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
324
325 nfs_commit_release_pages(wdata);
326 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding))
327 nfs_commit_clear_lock(NFS_I(wdata->inode));
328 nfs_commitdata_release(wdata);
329}
330
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000331struct rpc_call_ops filelayout_read_call_ops = {
332 .rpc_call_prepare = filelayout_read_prepare,
333 .rpc_call_done = filelayout_read_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500334 .rpc_count_stats = filelayout_read_count_stats,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000335 .rpc_release = filelayout_read_release,
336};
337
Fred Isamana69aef12011-03-03 15:13:47 +0000338struct rpc_call_ops filelayout_write_call_ops = {
339 .rpc_call_prepare = filelayout_write_prepare,
340 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500341 .rpc_count_stats = filelayout_write_count_stats,
Fred Isamana69aef12011-03-03 15:13:47 +0000342 .rpc_release = filelayout_write_release,
343};
344
Fred Isamane0c2b382011-03-23 13:27:53 +0000345struct rpc_call_ops filelayout_commit_call_ops = {
346 .rpc_call_prepare = filelayout_write_prepare,
347 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500348 .rpc_count_stats = filelayout_write_count_stats,
Fred Isamane0c2b382011-03-23 13:27:53 +0000349 .rpc_release = filelayout_commit_release,
350};
351
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000352static enum pnfs_try_status
353filelayout_read_pagelist(struct nfs_read_data *data)
354{
355 struct pnfs_layout_segment *lseg = data->lseg;
356 struct nfs4_pnfs_ds *ds;
357 loff_t offset = data->args.offset;
358 u32 j, idx;
359 struct nfs_fh *fh;
360 int status;
361
362 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
363 __func__, data->inode->i_ino,
364 data->args.pgbase, (size_t)data->args.count, offset);
365
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400366 if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
367 return PNFS_NOT_ATTEMPTED;
368
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000369 /* Retrieve the correct rpc_client for the byte range */
370 j = nfs4_fl_calc_j_index(lseg, offset);
371 idx = nfs4_fl_calc_ds_index(lseg, j);
372 ds = nfs4_fl_prepare_ds(lseg, idx);
373 if (!ds) {
Andy Adamson568e8c42011-03-01 01:34:22 +0000374 /* Either layout fh index faulty, or ds connect failed */
375 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
376 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000377 return PNFS_NOT_ATTEMPTED;
378 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400379 dprintk("%s USE DS: %s\n", __func__, ds->ds_remotestr);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000380
381 /* No multipath support. Use first DS */
382 data->ds_clp = ds->ds_clp;
383 fh = nfs4_fl_select_ds_fh(lseg, j);
384 if (fh)
385 data->args.fh = fh;
386
387 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
388 data->mds_offset = offset;
389
390 /* Perform an asynchronous read to ds */
391 status = nfs_initiate_read(data, ds->ds_clp->cl_rpcclient,
392 &filelayout_read_call_ops);
393 BUG_ON(status != 0);
394 return PNFS_ATTEMPTED;
395}
396
Fred Isamana69aef12011-03-03 15:13:47 +0000397/* Perform async writes. */
Andy Adamson0382b742011-03-03 15:13:45 +0000398static enum pnfs_try_status
399filelayout_write_pagelist(struct nfs_write_data *data, int sync)
400{
Fred Isamana69aef12011-03-03 15:13:47 +0000401 struct pnfs_layout_segment *lseg = data->lseg;
402 struct nfs4_pnfs_ds *ds;
403 loff_t offset = data->args.offset;
404 u32 j, idx;
405 struct nfs_fh *fh;
406 int status;
407
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400408 if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
409 return PNFS_NOT_ATTEMPTED;
410
Fred Isamana69aef12011-03-03 15:13:47 +0000411 /* Retrieve the correct rpc_client for the byte range */
412 j = nfs4_fl_calc_j_index(lseg, offset);
413 idx = nfs4_fl_calc_ds_index(lseg, j);
414 ds = nfs4_fl_prepare_ds(lseg, idx);
415 if (!ds) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500416 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
417 __func__);
Fred Isamana69aef12011-03-03 15:13:47 +0000418 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
419 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
420 return PNFS_NOT_ATTEMPTED;
421 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400422 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s\n", __func__,
Fred Isamana69aef12011-03-03 15:13:47 +0000423 data->inode->i_ino, sync, (size_t) data->args.count, offset,
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400424 ds->ds_remotestr);
Fred Isamana69aef12011-03-03 15:13:47 +0000425
Fred Isamana69aef12011-03-03 15:13:47 +0000426 data->write_done_cb = filelayout_write_done_cb;
427 data->ds_clp = ds->ds_clp;
428 fh = nfs4_fl_select_ds_fh(lseg, j);
429 if (fh)
430 data->args.fh = fh;
431 /*
432 * Get the file offset on the dserver. Set the write offset to
433 * this offset and save the original offset.
434 */
435 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
Fred Isamana69aef12011-03-03 15:13:47 +0000436
437 /* Perform an asynchronous write */
438 status = nfs_initiate_write(data, ds->ds_clp->cl_rpcclient,
439 &filelayout_write_call_ops, sync);
440 BUG_ON(status != 0);
441 return PNFS_ATTEMPTED;
Andy Adamson0382b742011-03-03 15:13:45 +0000442}
443
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000444/*
Andy Adamson16b374c2010-10-20 00:18:04 -0400445 * filelayout_check_layout()
446 *
447 * Make sure layout segment parameters are sane WRT the device.
448 * At this point no generic layer initialization of the lseg has occurred,
449 * and nothing has been added to the layout_hdr cache.
450 *
451 */
452static int
453filelayout_check_layout(struct pnfs_layout_hdr *lo,
454 struct nfs4_filelayout_segment *fl,
455 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400456 struct nfs4_deviceid *id,
457 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400458{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400459 struct nfs4_deviceid_node *d;
Andy Adamson16b374c2010-10-20 00:18:04 -0400460 struct nfs4_file_layout_dsaddr *dsaddr;
461 int status = -EINVAL;
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000462 struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
Andy Adamson16b374c2010-10-20 00:18:04 -0400463
464 dprintk("--> %s\n", __func__);
465
Andy Adamson7c24d942011-06-13 18:22:38 -0400466 /* FIXME: remove this check when layout segment support is added */
467 if (lgr->range.offset != 0 ||
468 lgr->range.length != NFS4_MAX_UINT64) {
469 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
470 __func__);
471 goto out;
472 }
473
Andy Adamson16b374c2010-10-20 00:18:04 -0400474 if (fl->pattern_offset > lgr->range.offset) {
Jim Rees3b6445a2011-02-22 19:31:57 -0500475 dprintk("%s pattern_offset %lld too large\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400476 __func__, fl->pattern_offset);
477 goto out;
478 }
479
Benny Halevy75247af2011-02-22 15:56:01 -0800480 if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) {
481 dprintk("%s Invalid stripe unit (%u)\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400482 __func__, fl->stripe_unit);
483 goto out;
484 }
485
486 /* find and reference the deviceid */
Benny Halevy35c8bb52011-05-24 18:04:02 +0300487 d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode)->pnfs_curr_ld,
488 NFS_SERVER(lo->plh_inode)->nfs_client, id);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400489 if (d == NULL) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400490 dsaddr = get_device_info(lo->plh_inode, id, gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400491 if (dsaddr == NULL)
492 goto out;
Benny Halevya1eaecb2011-05-19 22:14:47 -0400493 } else
494 dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400495 /* Found deviceid is being reaped */
496 if (test_bit(NFS_DEVICEID_INVALID, &dsaddr->id_node.flags))
497 goto out_put;
498
Andy Adamson16b374c2010-10-20 00:18:04 -0400499 fl->dsaddr = dsaddr;
500
Chuck Levere4149662011-10-25 12:18:03 -0400501 if (fl->first_stripe_index >= dsaddr->stripe_count) {
502 dprintk("%s Bad first_stripe_index %u\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400503 __func__, fl->first_stripe_index);
504 goto out_put;
505 }
506
507 if ((fl->stripe_type == STRIPE_SPARSE &&
508 fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
509 (fl->stripe_type == STRIPE_DENSE &&
510 fl->num_fh != dsaddr->stripe_count)) {
511 dprintk("%s num_fh %u not valid for given packing\n",
512 __func__, fl->num_fh);
513 goto out_put;
514 }
515
516 if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) {
517 dprintk("%s Stripe unit (%u) not aligned with rsize %u "
518 "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize,
519 nfss->wsize);
520 }
521
522 status = 0;
523out:
524 dprintk("--> %s returns %d\n", __func__, status);
525 return status;
526out_put:
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000527 nfs4_fl_put_deviceid(dsaddr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400528 goto out;
529}
530
531static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
532{
533 int i;
534
535 for (i = 0; i < fl->num_fh; i++) {
536 if (!fl->fh_array[i])
537 break;
538 kfree(fl->fh_array[i]);
539 }
540 kfree(fl->fh_array);
541 fl->fh_array = NULL;
542}
543
544static void
545_filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
546{
547 filelayout_free_fh_array(fl);
548 kfree(fl);
549}
550
551static int
552filelayout_decode_layout(struct pnfs_layout_hdr *flo,
553 struct nfs4_filelayout_segment *fl,
554 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400555 struct nfs4_deviceid *id,
556 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400557{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400558 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400559 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400560 struct page *scratch;
561 __be32 *p;
Andy Adamson16b374c2010-10-20 00:18:04 -0400562 uint32_t nfl_util;
563 int i;
564
565 dprintk("%s: set_layout_map Begin\n", __func__);
566
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400567 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400568 if (!scratch)
569 return -ENOMEM;
570
Benny Halevyf7da7a12011-05-19 14:16:47 -0400571 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400572 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
573
574 /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
575 * num_fh (4) */
576 p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
577 if (unlikely(!p))
578 goto out_err;
579
Andy Adamson16b374c2010-10-20 00:18:04 -0400580 memcpy(id, p, sizeof(*id));
581 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400582 nfs4_print_deviceid(id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400583
584 nfl_util = be32_to_cpup(p++);
585 if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
586 fl->commit_through_mds = 1;
587 if (nfl_util & NFL4_UFLG_DENSE)
588 fl->stripe_type = STRIPE_DENSE;
589 else
590 fl->stripe_type = STRIPE_SPARSE;
591 fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
592
593 fl->first_stripe_index = be32_to_cpup(p++);
594 p = xdr_decode_hyper(p, &fl->pattern_offset);
595 fl->num_fh = be32_to_cpup(p++);
596
597 dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
598 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
599 fl->pattern_offset);
600
Andy Adamsoncec765c2011-06-13 18:36:17 -0400601 /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
602 * Futher checking is done in filelayout_check_layout */
Chuck Levere4149662011-10-25 12:18:03 -0400603 if (fl->num_fh >
Andy Adamsoncec765c2011-06-13 18:36:17 -0400604 max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400605 goto out_err;
606
Andy Adamsoncec765c2011-06-13 18:36:17 -0400607 if (fl->num_fh > 0) {
608 fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
609 gfp_flags);
610 if (!fl->fh_array)
611 goto out_err;
612 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400613
614 for (i = 0; i < fl->num_fh; i++) {
615 /* Do we want to use a mempool here? */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400616 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400617 if (!fl->fh_array[i])
618 goto out_err_free;
619
620 p = xdr_inline_decode(&stream, 4);
621 if (unlikely(!p))
622 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400623 fl->fh_array[i]->size = be32_to_cpup(p++);
624 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -0500625 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400626 i, fl->fh_array[i]->size);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400627 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400628 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400629
630 p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
631 if (unlikely(!p))
632 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400633 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
Andy Adamson16b374c2010-10-20 00:18:04 -0400634 dprintk("DEBUG: %s: fh len %d\n", __func__,
635 fl->fh_array[i]->size);
636 }
637
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400638 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400639 return 0;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400640
641out_err_free:
642 filelayout_free_fh_array(fl);
643out_err:
644 __free_page(scratch);
645 return -EIO;
Andy Adamson16b374c2010-10-20 00:18:04 -0400646}
647
Fred Isamanc8795132011-03-23 13:27:49 +0000648static void
649filelayout_free_lseg(struct pnfs_layout_segment *lseg)
650{
651 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
652
653 dprintk("--> %s\n", __func__);
654 nfs4_fl_put_deviceid(fl->dsaddr);
Fred Isaman425eb732011-03-23 13:27:50 +0000655 kfree(fl->commit_buckets);
Fred Isamanc8795132011-03-23 13:27:49 +0000656 _filelayout_free_lseg(fl);
657}
658
Andy Adamson16b374c2010-10-20 00:18:04 -0400659static struct pnfs_layout_segment *
660filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400661 struct nfs4_layoutget_res *lgr,
662 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400663{
664 struct nfs4_filelayout_segment *fl;
665 int rc;
666 struct nfs4_deviceid id;
667
668 dprintk("--> %s\n", __func__);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400669 fl = kzalloc(sizeof(*fl), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400670 if (!fl)
671 return NULL;
672
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400673 rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
674 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
Andy Adamson16b374c2010-10-20 00:18:04 -0400675 _filelayout_free_lseg(fl);
676 return NULL;
677 }
Fred Isaman425eb732011-03-23 13:27:50 +0000678
679 /* This assumes there is only one IOMODE_RW lseg. What
680 * we really want to do is have a layout_hdr level
681 * dictionary of <multipath_list4, fh> keys, each
682 * associated with a struct list_head, populated by calls
683 * to filelayout_write_pagelist().
684 * */
685 if ((!fl->commit_through_mds) && (lgr->range.iomode == IOMODE_RW)) {
686 int i;
687 int size = (fl->stripe_type == STRIPE_SPARSE) ?
688 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
689
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400690 fl->commit_buckets = kcalloc(size, sizeof(struct list_head), gfp_flags);
Fred Isaman425eb732011-03-23 13:27:50 +0000691 if (!fl->commit_buckets) {
692 filelayout_free_lseg(&fl->generic_hdr);
693 return NULL;
694 }
695 fl->number_of_buckets = size;
696 for (i = 0; i < size; i++)
697 INIT_LIST_HEAD(&fl->commit_buckets[i]);
698 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400699 return &fl->generic_hdr;
700}
701
Fred Isaman94ad1c82011-03-01 01:34:14 +0000702/*
703 * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
704 *
Benny Halevy18ad0a92011-05-25 21:03:56 +0300705 * return true : coalesce page
706 * return false : don't coalesce page
Fred Isaman94ad1c82011-03-01 01:34:14 +0000707 */
Trond Myklebust1751c362011-06-10 13:30:23 -0400708static bool
Fred Isaman94ad1c82011-03-01 01:34:14 +0000709filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
710 struct nfs_page *req)
711{
712 u64 p_stripe, r_stripe;
713 u32 stripe_unit;
714
Benny Halevy19345cb2011-06-19 18:33:46 -0400715 if (!pnfs_generic_pg_test(pgio, prev, req) ||
716 !nfs_generic_pg_test(pgio, prev, req))
717 return false;
Benny Halevy89a58e32011-05-25 20:54:40 +0300718
Fred Isaman94ad1c82011-03-01 01:34:14 +0000719 p_stripe = (u64)prev->wb_index << PAGE_CACHE_SHIFT;
720 r_stripe = (u64)req->wb_index << PAGE_CACHE_SHIFT;
721 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
722
723 do_div(p_stripe, stripe_unit);
724 do_div(r_stripe, stripe_unit);
725
726 return (p_stripe == r_stripe);
727}
728
Andy Adamson7c24d942011-06-13 18:22:38 -0400729void
730filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
731 struct nfs_page *req)
732{
733 BUG_ON(pgio->pg_lseg != NULL);
734
735 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
736 req->wb_context,
737 0,
738 NFS4_MAX_UINT64,
739 IOMODE_READ,
740 GFP_KERNEL);
741 /* If no lseg, fall back to read through mds */
742 if (pgio->pg_lseg == NULL)
Trond Myklebust1f945352011-07-13 15:59:57 -0400743 nfs_pageio_reset_read_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400744}
745
746void
747filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
748 struct nfs_page *req)
749{
750 BUG_ON(pgio->pg_lseg != NULL);
751
752 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
753 req->wb_context,
754 0,
755 NFS4_MAX_UINT64,
756 IOMODE_RW,
757 GFP_NOFS);
758 /* If no lseg, fall back to write through mds */
759 if (pgio->pg_lseg == NULL)
Trond Myklebust1f945352011-07-13 15:59:57 -0400760 nfs_pageio_reset_write_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400761}
762
Trond Myklebust1751c362011-06-10 13:30:23 -0400763static const struct nfs_pageio_ops filelayout_pg_read_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400764 .pg_init = filelayout_pg_init_read,
Trond Myklebust1751c362011-06-10 13:30:23 -0400765 .pg_test = filelayout_pg_test,
Trond Myklebust493292d2011-07-13 15:58:28 -0400766 .pg_doio = pnfs_generic_pg_readpages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400767};
768
769static const struct nfs_pageio_ops filelayout_pg_write_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400770 .pg_init = filelayout_pg_init_write,
Trond Myklebust1751c362011-06-10 13:30:23 -0400771 .pg_test = filelayout_pg_test,
Trond Myklebustdce81292011-07-13 15:59:19 -0400772 .pg_doio = pnfs_generic_pg_writepages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400773};
774
Fred Isamane0c2b382011-03-23 13:27:53 +0000775static bool filelayout_mark_pnfs_commit(struct pnfs_layout_segment *lseg)
776{
777 return !FILELAYOUT_LSEG(lseg)->commit_through_mds;
778}
779
780static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
781{
782 if (fl->stripe_type == STRIPE_SPARSE)
783 return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
784 else
785 return j;
786}
787
788struct list_head *filelayout_choose_commit_list(struct nfs_page *req)
789{
790 struct pnfs_layout_segment *lseg = req->wb_commit_lseg;
791 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
792 u32 i, j;
793 struct list_head *list;
794
795 /* Note that we are calling nfs4_fl_calc_j_index on each page
796 * that ends up being committed to a data server. An attractive
797 * alternative is to add a field to nfs_write_data and nfs_page
798 * to store the value calculated in filelayout_write_pagelist
799 * and just use that here.
800 */
801 j = nfs4_fl_calc_j_index(lseg,
802 (loff_t)req->wb_index << PAGE_CACHE_SHIFT);
803 i = select_bucket_index(fl, j);
804 list = &fl->commit_buckets[i];
805 if (list_empty(list)) {
806 /* Non-empty buckets hold a reference on the lseg */
807 get_lseg(lseg);
808 }
809 return list;
810}
811
812static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
813{
814 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
815
816 if (flseg->stripe_type == STRIPE_SPARSE)
817 return i;
818 else
819 return nfs4_fl_calc_ds_index(lseg, i);
820}
821
822static struct nfs_fh *
823select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
824{
825 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
826
827 if (flseg->stripe_type == STRIPE_SPARSE) {
828 if (flseg->num_fh == 1)
829 i = 0;
830 else if (flseg->num_fh == 0)
831 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
832 return NULL;
833 }
834 return flseg->fh_array[i];
835}
836
837static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
838{
839 struct pnfs_layout_segment *lseg = data->lseg;
840 struct nfs4_pnfs_ds *ds;
841 u32 idx;
842 struct nfs_fh *fh;
843
844 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
845 ds = nfs4_fl_prepare_ds(lseg, idx);
846 if (!ds) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500847 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
848 __func__);
Fred Isamane0c2b382011-03-23 13:27:53 +0000849 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
850 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
851 prepare_to_resend_writes(data);
852 data->mds_ops->rpc_release(data);
853 return -EAGAIN;
854 }
855 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
856 data->write_done_cb = filelayout_commit_done_cb;
857 data->ds_clp = ds->ds_clp;
858 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
859 if (fh)
860 data->args.fh = fh;
861 return nfs_initiate_commit(data, ds->ds_clp->cl_rpcclient,
862 &filelayout_commit_call_ops, how);
863}
864
865/*
866 * This is only useful while we are using whole file layouts.
867 */
868static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode)
869{
870 struct pnfs_layout_segment *lseg, *rv = NULL;
871
872 spin_lock(&inode->i_lock);
873 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
874 if (lseg->pls_range.iomode == IOMODE_RW)
875 rv = get_lseg(lseg);
876 spin_unlock(&inode->i_lock);
877 return rv;
878}
879
880static int alloc_ds_commits(struct inode *inode, struct list_head *list)
881{
882 struct pnfs_layout_segment *lseg;
883 struct nfs4_filelayout_segment *fl;
884 struct nfs_write_data *data;
885 int i, j;
886
887 /* Won't need this when non-whole file layout segments are supported
888 * instead we will use a pnfs_layout_hdr structure */
889 lseg = find_only_write_lseg(inode);
890 if (!lseg)
891 return 0;
892 fl = FILELAYOUT_LSEG(lseg);
893 for (i = 0; i < fl->number_of_buckets; i++) {
894 if (list_empty(&fl->commit_buckets[i]))
895 continue;
896 data = nfs_commitdata_alloc();
897 if (!data)
898 goto out_bad;
899 data->ds_commit_index = i;
900 data->lseg = lseg;
901 list_add(&data->pages, list);
902 }
903 put_lseg(lseg);
904 return 0;
905
906out_bad:
907 for (j = i; j < fl->number_of_buckets; j++) {
908 if (list_empty(&fl->commit_buckets[i]))
909 continue;
910 nfs_retry_commit(&fl->commit_buckets[i], lseg);
911 put_lseg(lseg); /* associated with emptying bucket */
912 }
913 put_lseg(lseg);
914 /* Caller will clean up entries put on list */
915 return -ENOMEM;
916}
917
918/* This follows nfs_commit_list pretty closely */
919static int
920filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
921 int how)
922{
923 struct nfs_write_data *data, *tmp;
924 LIST_HEAD(list);
925
926 if (!list_empty(mds_pages)) {
927 data = nfs_commitdata_alloc();
928 if (!data)
929 goto out_bad;
930 data->lseg = NULL;
931 list_add(&data->pages, &list);
932 }
933
934 if (alloc_ds_commits(inode, &list))
935 goto out_bad;
936
937 list_for_each_entry_safe(data, tmp, &list, pages) {
938 list_del_init(&data->pages);
939 atomic_inc(&NFS_I(inode)->commits_outstanding);
940 if (!data->lseg) {
941 nfs_init_commit(data, mds_pages, NULL);
942 nfs_initiate_commit(data, NFS_CLIENT(inode),
943 data->mds_ops, how);
944 } else {
945 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index], data->lseg);
946 filelayout_initiate_commit(data, how);
947 }
948 }
949 return 0;
950 out_bad:
951 list_for_each_entry_safe(data, tmp, &list, pages) {
952 nfs_retry_commit(&data->pages, data->lseg);
953 list_del_init(&data->pages);
954 nfs_commit_free(data);
955 }
956 nfs_retry_commit(mds_pages, NULL);
957 nfs_commit_clear_lock(NFS_I(inode));
958 return -ENOMEM;
959}
960
Benny Halevy1775bc32011-05-20 13:47:33 +0200961static void
962filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d)
963{
964 nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
965}
966
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400967static struct pnfs_layoutdriver_type filelayout_type = {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000968 .id = LAYOUT_NFSV4_1_FILES,
969 .name = "LAYOUT_NFSV4_1_FILES",
970 .owner = THIS_MODULE,
971 .alloc_lseg = filelayout_alloc_lseg,
972 .free_lseg = filelayout_free_lseg,
Trond Myklebust1751c362011-06-10 13:30:23 -0400973 .pg_read_ops = &filelayout_pg_read_ops,
974 .pg_write_ops = &filelayout_pg_write_ops,
Fred Isamane0c2b382011-03-23 13:27:53 +0000975 .mark_pnfs_commit = filelayout_mark_pnfs_commit,
976 .choose_commit_list = filelayout_choose_commit_list,
977 .commit_pagelist = filelayout_commit_pagelist,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000978 .read_pagelist = filelayout_read_pagelist,
Andy Adamson0382b742011-03-03 15:13:45 +0000979 .write_pagelist = filelayout_write_pagelist,
Benny Halevy1775bc32011-05-20 13:47:33 +0200980 .free_deviceid_node = filelayout_free_deveiceid_node,
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400981};
982
983static int __init nfs4filelayout_init(void)
984{
985 printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
986 __func__);
987 return pnfs_register_layoutdriver(&filelayout_type);
988}
989
990static void __exit nfs4filelayout_exit(void)
991{
992 printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
993 __func__);
994 pnfs_unregister_layoutdriver(&filelayout_type);
995}
996
J. Bruce Fieldsf85ef692011-07-15 19:18:42 -0400997MODULE_ALIAS("nfs-layouttype4-1");
998
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400999module_init(nfs4filelayout_init);
1000module_exit(nfs4filelayout_exit);