blob: 768f6f86c9f0e844c87984a1def1def4f361dea5 [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:
Andy Adamson2dc31752012-03-08 11:03:53 -0500102 nfs_remove_bad_delegation(state->inode);
Andy Adamson9cb81962012-03-07 10:49:41 -0500103 case -NFS4ERR_OPENMODE:
Andy Adamson9cb81962012-03-07 10:49:41 -0500104 nfs4_schedule_stateid_recovery(mds_server, state);
105 goto wait_on_recovery;
106 case -NFS4ERR_EXPIRED:
Andy Adamson2dc31752012-03-08 11:03:53 -0500107 nfs4_schedule_stateid_recovery(mds_server, state);
Andy Adamson9cb81962012-03-07 10:49:41 -0500108 nfs4_schedule_lease_recovery(mds_client);
109 goto wait_on_recovery;
110 /* DS session errors */
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000111 case -NFS4ERR_BADSESSION:
112 case -NFS4ERR_BADSLOT:
113 case -NFS4ERR_BAD_HIGH_SLOT:
114 case -NFS4ERR_DEADSESSION:
115 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
116 case -NFS4ERR_SEQ_FALSE_RETRY:
117 case -NFS4ERR_SEQ_MISORDERED:
118 dprintk("%s ERROR %d, Reset session. Exchangeid "
119 "flags 0x%x\n", __func__, task->tk_status,
120 clp->cl_exchange_flags);
121 nfs4_schedule_session_recovery(clp->cl_session);
122 break;
123 case -NFS4ERR_DELAY:
124 case -NFS4ERR_GRACE:
125 case -EKEYEXPIRED:
126 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
127 break;
Andy Adamsona8a4ae32011-05-03 13:43:03 -0400128 case -NFS4ERR_RETRY_UNCACHED_REP:
129 break;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000130 default:
131 dprintk("%s DS error. Retry through MDS %d\n", __func__,
132 task->tk_status);
133 *reset = 1;
134 break;
135 }
Andy Adamson9cb81962012-03-07 10:49:41 -0500136out:
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000137 task->tk_status = 0;
138 return -EAGAIN;
Andy Adamson9cb81962012-03-07 10:49:41 -0500139wait_on_recovery:
140 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
141 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
142 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
143 goto out;
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000144}
145
146/* NFS_PROTO call done callback routines */
147
148static int filelayout_read_done_cb(struct rpc_task *task,
149 struct nfs_read_data *data)
150{
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000151 int reset = 0;
152
153 dprintk("%s DS read\n", __func__);
154
155 if (filelayout_async_handle_error(task, data->args.context->state,
156 data->ds_clp, &reset) == -EAGAIN) {
157 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
158 __func__, data->ds_clp, data->ds_clp->cl_session);
159 if (reset) {
Peng Tao1b0ae062011-09-22 21:50:12 -0400160 pnfs_set_lo_fail(data->lseg);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000161 nfs4_reset_read(task, data);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000162 }
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700163 rpc_restart_call_prepare(task);
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000164 return -EAGAIN;
165 }
166
167 return 0;
168}
169
Andy Adamson16b374c2010-10-20 00:18:04 -0400170/*
Andy Adamson863a3c62011-03-23 13:27:54 +0000171 * We reference the rpc_cred of the first WRITE that triggers the need for
172 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
173 * rfc5661 is not clear about which credential should be used.
174 */
175static void
176filelayout_set_layoutcommit(struct nfs_write_data *wdata)
177{
178 if (FILELAYOUT_LSEG(wdata->lseg)->commit_through_mds ||
179 wdata->res.verf->committed == NFS_FILE_SYNC)
180 return;
181
182 pnfs_set_layoutcommit(wdata);
183 dprintk("%s ionde %lu pls_end_pos %lu\n", __func__, wdata->inode->i_ino,
Peng Taoacff58802011-07-30 20:52:31 -0400184 (unsigned long) NFS_I(wdata->inode)->layout->plh_lwb);
Andy Adamson863a3c62011-03-23 13:27:54 +0000185}
186
187/*
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000188 * Call ops for the async read/write cases
189 * In the case of dense layouts, the offset needs to be reset to its
190 * original value.
191 */
192static void filelayout_read_prepare(struct rpc_task *task, void *data)
193{
194 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
195
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000196 rdata->read_done_cb = filelayout_read_done_cb;
197
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000198 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
199 &rdata->args.seq_args, &rdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500200 task))
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000201 return;
202
203 rpc_call_start(task);
204}
205
206static void filelayout_read_call_done(struct rpc_task *task, void *data)
207{
208 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
209
210 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
211
212 /* Note this may cause RPC to be resent */
213 rdata->mds_ops->rpc_call_done(task, data);
214}
215
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500216static void filelayout_read_count_stats(struct rpc_task *task, void *data)
217{
218 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
219
220 rpc_count_iostats(task, NFS_SERVER(rdata->inode)->client->cl_metrics);
221}
222
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000223static void filelayout_read_release(void *data)
224{
225 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
226
227 rdata->mds_ops->rpc_release(data);
228}
229
Fred Isamana69aef12011-03-03 15:13:47 +0000230static int filelayout_write_done_cb(struct rpc_task *task,
231 struct nfs_write_data *data)
232{
233 int reset = 0;
234
235 if (filelayout_async_handle_error(task, data->args.context->state,
236 data->ds_clp, &reset) == -EAGAIN) {
Fred Isamana69aef12011-03-03 15:13:47 +0000237 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
238 __func__, data->ds_clp, data->ds_clp->cl_session);
239 if (reset) {
Peng Tao1b0ae062011-09-22 21:50:12 -0400240 pnfs_set_lo_fail(data->lseg);
Fred Isamana69aef12011-03-03 15:13:47 +0000241 nfs4_reset_write(task, data);
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700242 }
243 rpc_restart_call_prepare(task);
Fred Isamana69aef12011-03-03 15:13:47 +0000244 return -EAGAIN;
245 }
246
Andy Adamson863a3c62011-03-23 13:27:54 +0000247 filelayout_set_layoutcommit(data);
Fred Isamana69aef12011-03-03 15:13:47 +0000248 return 0;
249}
250
Fred Isamane0c2b382011-03-23 13:27:53 +0000251/* Fake up some data that will cause nfs_commit_release to retry the writes. */
252static void prepare_to_resend_writes(struct nfs_write_data *data)
253{
254 struct nfs_page *first = nfs_list_entry(data->pages.next);
255
256 data->task.tk_status = 0;
257 memcpy(data->verf.verifier, first->wb_verf.verifier,
258 sizeof(first->wb_verf.verifier));
259 data->verf.verifier[0]++; /* ensure verifier mismatch */
260}
261
262static int filelayout_commit_done_cb(struct rpc_task *task,
263 struct nfs_write_data *data)
264{
265 int reset = 0;
266
267 if (filelayout_async_handle_error(task, data->args.context->state,
268 data->ds_clp, &reset) == -EAGAIN) {
269 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
270 __func__, data->ds_clp, data->ds_clp->cl_session);
271 if (reset) {
272 prepare_to_resend_writes(data);
Peng Tao1b0ae062011-09-22 21:50:12 -0400273 pnfs_set_lo_fail(data->lseg);
Fred Isamane0c2b382011-03-23 13:27:53 +0000274 } else
Trond Myklebustd00c5d42011-10-19 12:17:29 -0700275 rpc_restart_call_prepare(task);
Fred Isamane0c2b382011-03-23 13:27:53 +0000276 return -EAGAIN;
277 }
278
279 return 0;
280}
281
Fred Isamana69aef12011-03-03 15:13:47 +0000282static void filelayout_write_prepare(struct rpc_task *task, void *data)
283{
284 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
285
286 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
287 &wdata->args.seq_args, &wdata->res.seq_res,
Trond Myklebust9d12b212012-01-17 22:04:25 -0500288 task))
Fred Isamana69aef12011-03-03 15:13:47 +0000289 return;
290
291 rpc_call_start(task);
292}
293
294static void filelayout_write_call_done(struct rpc_task *task, void *data)
295{
296 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
297
298 /* Note this may cause RPC to be resent */
299 wdata->mds_ops->rpc_call_done(task, data);
300}
301
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500302static void filelayout_write_count_stats(struct rpc_task *task, void *data)
303{
304 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
305
306 rpc_count_iostats(task, NFS_SERVER(wdata->inode)->client->cl_metrics);
307}
308
Fred Isamana69aef12011-03-03 15:13:47 +0000309static void filelayout_write_release(void *data)
310{
311 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
312
313 wdata->mds_ops->rpc_release(data);
314}
315
Fred Isamane0c2b382011-03-23 13:27:53 +0000316static void filelayout_commit_release(void *data)
317{
318 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
319
320 nfs_commit_release_pages(wdata);
321 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding))
322 nfs_commit_clear_lock(NFS_I(wdata->inode));
323 nfs_commitdata_release(wdata);
324}
325
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000326struct rpc_call_ops filelayout_read_call_ops = {
327 .rpc_call_prepare = filelayout_read_prepare,
328 .rpc_call_done = filelayout_read_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500329 .rpc_count_stats = filelayout_read_count_stats,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000330 .rpc_release = filelayout_read_release,
331};
332
Fred Isamana69aef12011-03-03 15:13:47 +0000333struct rpc_call_ops filelayout_write_call_ops = {
334 .rpc_call_prepare = filelayout_write_prepare,
335 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500336 .rpc_count_stats = filelayout_write_count_stats,
Fred Isamana69aef12011-03-03 15:13:47 +0000337 .rpc_release = filelayout_write_release,
338};
339
Fred Isamane0c2b382011-03-23 13:27:53 +0000340struct rpc_call_ops filelayout_commit_call_ops = {
341 .rpc_call_prepare = filelayout_write_prepare,
342 .rpc_call_done = filelayout_write_call_done,
Weston Andros Adamson0a702192012-02-17 13:15:24 -0500343 .rpc_count_stats = filelayout_write_count_stats,
Fred Isamane0c2b382011-03-23 13:27:53 +0000344 .rpc_release = filelayout_commit_release,
345};
346
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000347static enum pnfs_try_status
348filelayout_read_pagelist(struct nfs_read_data *data)
349{
350 struct pnfs_layout_segment *lseg = data->lseg;
351 struct nfs4_pnfs_ds *ds;
352 loff_t offset = data->args.offset;
353 u32 j, idx;
354 struct nfs_fh *fh;
355 int status;
356
357 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
358 __func__, data->inode->i_ino,
359 data->args.pgbase, (size_t)data->args.count, offset);
360
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400361 if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
362 return PNFS_NOT_ATTEMPTED;
363
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000364 /* Retrieve the correct rpc_client for the byte range */
365 j = nfs4_fl_calc_j_index(lseg, offset);
366 idx = nfs4_fl_calc_ds_index(lseg, j);
367 ds = nfs4_fl_prepare_ds(lseg, idx);
368 if (!ds) {
Andy Adamson568e8c42011-03-01 01:34:22 +0000369 /* Either layout fh index faulty, or ds connect failed */
370 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
371 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000372 return PNFS_NOT_ATTEMPTED;
373 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400374 dprintk("%s USE DS: %s\n", __func__, ds->ds_remotestr);
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000375
376 /* No multipath support. Use first DS */
377 data->ds_clp = ds->ds_clp;
378 fh = nfs4_fl_select_ds_fh(lseg, j);
379 if (fh)
380 data->args.fh = fh;
381
382 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
383 data->mds_offset = offset;
384
385 /* Perform an asynchronous read to ds */
386 status = nfs_initiate_read(data, ds->ds_clp->cl_rpcclient,
387 &filelayout_read_call_ops);
388 BUG_ON(status != 0);
389 return PNFS_ATTEMPTED;
390}
391
Fred Isamana69aef12011-03-03 15:13:47 +0000392/* Perform async writes. */
Andy Adamson0382b742011-03-03 15:13:45 +0000393static enum pnfs_try_status
394filelayout_write_pagelist(struct nfs_write_data *data, int sync)
395{
Fred Isamana69aef12011-03-03 15:13:47 +0000396 struct pnfs_layout_segment *lseg = data->lseg;
397 struct nfs4_pnfs_ds *ds;
398 loff_t offset = data->args.offset;
399 u32 j, idx;
400 struct nfs_fh *fh;
401 int status;
402
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400403 if (test_bit(NFS_DEVICEID_INVALID, &FILELAYOUT_DEVID_NODE(lseg)->flags))
404 return PNFS_NOT_ATTEMPTED;
405
Fred Isamana69aef12011-03-03 15:13:47 +0000406 /* Retrieve the correct rpc_client for the byte range */
407 j = nfs4_fl_calc_j_index(lseg, offset);
408 idx = nfs4_fl_calc_ds_index(lseg, j);
409 ds = nfs4_fl_prepare_ds(lseg, idx);
410 if (!ds) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500411 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
412 __func__);
Fred Isamana69aef12011-03-03 15:13:47 +0000413 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
414 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
415 return PNFS_NOT_ATTEMPTED;
416 }
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400417 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s\n", __func__,
Fred Isamana69aef12011-03-03 15:13:47 +0000418 data->inode->i_ino, sync, (size_t) data->args.count, offset,
Weston Andros Adamsonc9895cb2011-05-31 18:48:56 -0400419 ds->ds_remotestr);
Fred Isamana69aef12011-03-03 15:13:47 +0000420
Fred Isamana69aef12011-03-03 15:13:47 +0000421 data->write_done_cb = filelayout_write_done_cb;
422 data->ds_clp = ds->ds_clp;
423 fh = nfs4_fl_select_ds_fh(lseg, j);
424 if (fh)
425 data->args.fh = fh;
426 /*
427 * Get the file offset on the dserver. Set the write offset to
428 * this offset and save the original offset.
429 */
430 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
Fred Isamana69aef12011-03-03 15:13:47 +0000431
432 /* Perform an asynchronous write */
433 status = nfs_initiate_write(data, ds->ds_clp->cl_rpcclient,
434 &filelayout_write_call_ops, sync);
435 BUG_ON(status != 0);
436 return PNFS_ATTEMPTED;
Andy Adamson0382b742011-03-03 15:13:45 +0000437}
438
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000439/*
Andy Adamson16b374c2010-10-20 00:18:04 -0400440 * filelayout_check_layout()
441 *
442 * Make sure layout segment parameters are sane WRT the device.
443 * At this point no generic layer initialization of the lseg has occurred,
444 * and nothing has been added to the layout_hdr cache.
445 *
446 */
447static int
448filelayout_check_layout(struct pnfs_layout_hdr *lo,
449 struct nfs4_filelayout_segment *fl,
450 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400451 struct nfs4_deviceid *id,
452 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400453{
Benny Halevya1eaecb2011-05-19 22:14:47 -0400454 struct nfs4_deviceid_node *d;
Andy Adamson16b374c2010-10-20 00:18:04 -0400455 struct nfs4_file_layout_dsaddr *dsaddr;
456 int status = -EINVAL;
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000457 struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
Andy Adamson16b374c2010-10-20 00:18:04 -0400458
459 dprintk("--> %s\n", __func__);
460
Andy Adamson7c24d942011-06-13 18:22:38 -0400461 /* FIXME: remove this check when layout segment support is added */
462 if (lgr->range.offset != 0 ||
463 lgr->range.length != NFS4_MAX_UINT64) {
464 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
465 __func__);
466 goto out;
467 }
468
Andy Adamson16b374c2010-10-20 00:18:04 -0400469 if (fl->pattern_offset > lgr->range.offset) {
Jim Rees3b6445a2011-02-22 19:31:57 -0500470 dprintk("%s pattern_offset %lld too large\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400471 __func__, fl->pattern_offset);
472 goto out;
473 }
474
Benny Halevy75247af2011-02-22 15:56:01 -0800475 if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) {
476 dprintk("%s Invalid stripe unit (%u)\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400477 __func__, fl->stripe_unit);
478 goto out;
479 }
480
481 /* find and reference the deviceid */
Benny Halevy35c8bb52011-05-24 18:04:02 +0300482 d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode)->pnfs_curr_ld,
483 NFS_SERVER(lo->plh_inode)->nfs_client, id);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400484 if (d == NULL) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400485 dsaddr = get_device_info(lo->plh_inode, id, gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400486 if (dsaddr == NULL)
487 goto out;
Benny Halevya1eaecb2011-05-19 22:14:47 -0400488 } else
489 dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400490 /* Found deviceid is being reaped */
491 if (test_bit(NFS_DEVICEID_INVALID, &dsaddr->id_node.flags))
492 goto out_put;
493
Andy Adamson16b374c2010-10-20 00:18:04 -0400494 fl->dsaddr = dsaddr;
495
Chuck Levere4149662011-10-25 12:18:03 -0400496 if (fl->first_stripe_index >= dsaddr->stripe_count) {
497 dprintk("%s Bad first_stripe_index %u\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400498 __func__, fl->first_stripe_index);
499 goto out_put;
500 }
501
502 if ((fl->stripe_type == STRIPE_SPARSE &&
503 fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
504 (fl->stripe_type == STRIPE_DENSE &&
505 fl->num_fh != dsaddr->stripe_count)) {
506 dprintk("%s num_fh %u not valid for given packing\n",
507 __func__, fl->num_fh);
508 goto out_put;
509 }
510
511 if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) {
512 dprintk("%s Stripe unit (%u) not aligned with rsize %u "
513 "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize,
514 nfss->wsize);
515 }
516
517 status = 0;
518out:
519 dprintk("--> %s returns %d\n", __func__, status);
520 return status;
521out_put:
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000522 nfs4_fl_put_deviceid(dsaddr);
Andy Adamson16b374c2010-10-20 00:18:04 -0400523 goto out;
524}
525
526static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
527{
528 int i;
529
530 for (i = 0; i < fl->num_fh; i++) {
531 if (!fl->fh_array[i])
532 break;
533 kfree(fl->fh_array[i]);
534 }
535 kfree(fl->fh_array);
536 fl->fh_array = NULL;
537}
538
539static void
540_filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
541{
542 filelayout_free_fh_array(fl);
543 kfree(fl);
544}
545
546static int
547filelayout_decode_layout(struct pnfs_layout_hdr *flo,
548 struct nfs4_filelayout_segment *fl,
549 struct nfs4_layoutget_res *lgr,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400550 struct nfs4_deviceid *id,
551 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400552{
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400553 struct xdr_stream stream;
Benny Halevyf7da7a12011-05-19 14:16:47 -0400554 struct xdr_buf buf;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400555 struct page *scratch;
556 __be32 *p;
Andy Adamson16b374c2010-10-20 00:18:04 -0400557 uint32_t nfl_util;
558 int i;
559
560 dprintk("%s: set_layout_map Begin\n", __func__);
561
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400562 scratch = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400563 if (!scratch)
564 return -ENOMEM;
565
Benny Halevyf7da7a12011-05-19 14:16:47 -0400566 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400567 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
568
569 /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
570 * num_fh (4) */
571 p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
572 if (unlikely(!p))
573 goto out_err;
574
Andy Adamson16b374c2010-10-20 00:18:04 -0400575 memcpy(id, p, sizeof(*id));
576 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
Benny Halevya1eaecb2011-05-19 22:14:47 -0400577 nfs4_print_deviceid(id);
Andy Adamson16b374c2010-10-20 00:18:04 -0400578
579 nfl_util = be32_to_cpup(p++);
580 if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
581 fl->commit_through_mds = 1;
582 if (nfl_util & NFL4_UFLG_DENSE)
583 fl->stripe_type = STRIPE_DENSE;
584 else
585 fl->stripe_type = STRIPE_SPARSE;
586 fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
587
588 fl->first_stripe_index = be32_to_cpup(p++);
589 p = xdr_decode_hyper(p, &fl->pattern_offset);
590 fl->num_fh = be32_to_cpup(p++);
591
592 dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
593 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
594 fl->pattern_offset);
595
Andy Adamsoncec765c2011-06-13 18:36:17 -0400596 /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
597 * Futher checking is done in filelayout_check_layout */
Chuck Levere4149662011-10-25 12:18:03 -0400598 if (fl->num_fh >
Andy Adamsoncec765c2011-06-13 18:36:17 -0400599 max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400600 goto out_err;
601
Andy Adamsoncec765c2011-06-13 18:36:17 -0400602 if (fl->num_fh > 0) {
603 fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
604 gfp_flags);
605 if (!fl->fh_array)
606 goto out_err;
607 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400608
609 for (i = 0; i < fl->num_fh; i++) {
610 /* Do we want to use a mempool here? */
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400611 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400612 if (!fl->fh_array[i])
613 goto out_err_free;
614
615 p = xdr_inline_decode(&stream, 4);
616 if (unlikely(!p))
617 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400618 fl->fh_array[i]->size = be32_to_cpup(p++);
619 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -0500620 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
Andy Adamson16b374c2010-10-20 00:18:04 -0400621 i, fl->fh_array[i]->size);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400622 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400623 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400624
625 p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
626 if (unlikely(!p))
627 goto out_err_free;
Andy Adamson16b374c2010-10-20 00:18:04 -0400628 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
Andy Adamson16b374c2010-10-20 00:18:04 -0400629 dprintk("DEBUG: %s: fh len %d\n", __func__,
630 fl->fh_array[i]->size);
631 }
632
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400633 __free_page(scratch);
Andy Adamson16b374c2010-10-20 00:18:04 -0400634 return 0;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400635
636out_err_free:
637 filelayout_free_fh_array(fl);
638out_err:
639 __free_page(scratch);
640 return -EIO;
Andy Adamson16b374c2010-10-20 00:18:04 -0400641}
642
Fred Isamanc8795132011-03-23 13:27:49 +0000643static void
644filelayout_free_lseg(struct pnfs_layout_segment *lseg)
645{
646 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
647
648 dprintk("--> %s\n", __func__);
649 nfs4_fl_put_deviceid(fl->dsaddr);
Fred Isaman425eb732011-03-23 13:27:50 +0000650 kfree(fl->commit_buckets);
Fred Isamanc8795132011-03-23 13:27:49 +0000651 _filelayout_free_lseg(fl);
652}
653
Andy Adamson16b374c2010-10-20 00:18:04 -0400654static struct pnfs_layout_segment *
655filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400656 struct nfs4_layoutget_res *lgr,
657 gfp_t gfp_flags)
Andy Adamson16b374c2010-10-20 00:18:04 -0400658{
659 struct nfs4_filelayout_segment *fl;
660 int rc;
661 struct nfs4_deviceid id;
662
663 dprintk("--> %s\n", __func__);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400664 fl = kzalloc(sizeof(*fl), gfp_flags);
Andy Adamson16b374c2010-10-20 00:18:04 -0400665 if (!fl)
666 return NULL;
667
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400668 rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
669 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
Andy Adamson16b374c2010-10-20 00:18:04 -0400670 _filelayout_free_lseg(fl);
671 return NULL;
672 }
Fred Isaman425eb732011-03-23 13:27:50 +0000673
674 /* This assumes there is only one IOMODE_RW lseg. What
675 * we really want to do is have a layout_hdr level
676 * dictionary of <multipath_list4, fh> keys, each
677 * associated with a struct list_head, populated by calls
678 * to filelayout_write_pagelist().
679 * */
680 if ((!fl->commit_through_mds) && (lgr->range.iomode == IOMODE_RW)) {
681 int i;
682 int size = (fl->stripe_type == STRIPE_SPARSE) ?
683 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
684
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400685 fl->commit_buckets = kcalloc(size, sizeof(struct list_head), gfp_flags);
Fred Isaman425eb732011-03-23 13:27:50 +0000686 if (!fl->commit_buckets) {
687 filelayout_free_lseg(&fl->generic_hdr);
688 return NULL;
689 }
690 fl->number_of_buckets = size;
691 for (i = 0; i < size; i++)
692 INIT_LIST_HEAD(&fl->commit_buckets[i]);
693 }
Andy Adamson16b374c2010-10-20 00:18:04 -0400694 return &fl->generic_hdr;
695}
696
Fred Isaman94ad1c82011-03-01 01:34:14 +0000697/*
698 * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
699 *
Benny Halevy18ad0a92011-05-25 21:03:56 +0300700 * return true : coalesce page
701 * return false : don't coalesce page
Fred Isaman94ad1c82011-03-01 01:34:14 +0000702 */
Trond Myklebust1751c362011-06-10 13:30:23 -0400703static bool
Fred Isaman94ad1c82011-03-01 01:34:14 +0000704filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
705 struct nfs_page *req)
706{
707 u64 p_stripe, r_stripe;
708 u32 stripe_unit;
709
Benny Halevy19345cb2011-06-19 18:33:46 -0400710 if (!pnfs_generic_pg_test(pgio, prev, req) ||
711 !nfs_generic_pg_test(pgio, prev, req))
712 return false;
Benny Halevy89a58e32011-05-25 20:54:40 +0300713
Fred Isaman94ad1c82011-03-01 01:34:14 +0000714 p_stripe = (u64)prev->wb_index << PAGE_CACHE_SHIFT;
715 r_stripe = (u64)req->wb_index << PAGE_CACHE_SHIFT;
716 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
717
718 do_div(p_stripe, stripe_unit);
719 do_div(r_stripe, stripe_unit);
720
721 return (p_stripe == r_stripe);
722}
723
Andy Adamson7c24d942011-06-13 18:22:38 -0400724void
725filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
726 struct nfs_page *req)
727{
728 BUG_ON(pgio->pg_lseg != NULL);
729
730 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
731 req->wb_context,
732 0,
733 NFS4_MAX_UINT64,
734 IOMODE_READ,
735 GFP_KERNEL);
736 /* If no lseg, fall back to read through mds */
737 if (pgio->pg_lseg == NULL)
Trond Myklebust1f945352011-07-13 15:59:57 -0400738 nfs_pageio_reset_read_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400739}
740
741void
742filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
743 struct nfs_page *req)
744{
745 BUG_ON(pgio->pg_lseg != NULL);
746
747 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
748 req->wb_context,
749 0,
750 NFS4_MAX_UINT64,
751 IOMODE_RW,
752 GFP_NOFS);
753 /* If no lseg, fall back to write through mds */
754 if (pgio->pg_lseg == NULL)
Trond Myklebust1f945352011-07-13 15:59:57 -0400755 nfs_pageio_reset_write_mds(pgio);
Andy Adamson7c24d942011-06-13 18:22:38 -0400756}
757
Trond Myklebust1751c362011-06-10 13:30:23 -0400758static const struct nfs_pageio_ops filelayout_pg_read_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400759 .pg_init = filelayout_pg_init_read,
Trond Myklebust1751c362011-06-10 13:30:23 -0400760 .pg_test = filelayout_pg_test,
Trond Myklebust493292d2011-07-13 15:58:28 -0400761 .pg_doio = pnfs_generic_pg_readpages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400762};
763
764static const struct nfs_pageio_ops filelayout_pg_write_ops = {
Andy Adamson7c24d942011-06-13 18:22:38 -0400765 .pg_init = filelayout_pg_init_write,
Trond Myklebust1751c362011-06-10 13:30:23 -0400766 .pg_test = filelayout_pg_test,
Trond Myklebustdce81292011-07-13 15:59:19 -0400767 .pg_doio = pnfs_generic_pg_writepages,
Trond Myklebust1751c362011-06-10 13:30:23 -0400768};
769
Fred Isamane0c2b382011-03-23 13:27:53 +0000770static bool filelayout_mark_pnfs_commit(struct pnfs_layout_segment *lseg)
771{
772 return !FILELAYOUT_LSEG(lseg)->commit_through_mds;
773}
774
775static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
776{
777 if (fl->stripe_type == STRIPE_SPARSE)
778 return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
779 else
780 return j;
781}
782
783struct list_head *filelayout_choose_commit_list(struct nfs_page *req)
784{
785 struct pnfs_layout_segment *lseg = req->wb_commit_lseg;
786 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
787 u32 i, j;
788 struct list_head *list;
789
790 /* Note that we are calling nfs4_fl_calc_j_index on each page
791 * that ends up being committed to a data server. An attractive
792 * alternative is to add a field to nfs_write_data and nfs_page
793 * to store the value calculated in filelayout_write_pagelist
794 * and just use that here.
795 */
796 j = nfs4_fl_calc_j_index(lseg,
797 (loff_t)req->wb_index << PAGE_CACHE_SHIFT);
798 i = select_bucket_index(fl, j);
799 list = &fl->commit_buckets[i];
800 if (list_empty(list)) {
801 /* Non-empty buckets hold a reference on the lseg */
802 get_lseg(lseg);
803 }
804 return list;
805}
806
807static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
808{
809 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
810
811 if (flseg->stripe_type == STRIPE_SPARSE)
812 return i;
813 else
814 return nfs4_fl_calc_ds_index(lseg, i);
815}
816
817static struct nfs_fh *
818select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
819{
820 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
821
822 if (flseg->stripe_type == STRIPE_SPARSE) {
823 if (flseg->num_fh == 1)
824 i = 0;
825 else if (flseg->num_fh == 0)
826 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
827 return NULL;
828 }
829 return flseg->fh_array[i];
830}
831
832static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
833{
834 struct pnfs_layout_segment *lseg = data->lseg;
835 struct nfs4_pnfs_ds *ds;
836 u32 idx;
837 struct nfs_fh *fh;
838
839 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
840 ds = nfs4_fl_prepare_ds(lseg, idx);
841 if (!ds) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -0500842 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
843 __func__);
Fred Isamane0c2b382011-03-23 13:27:53 +0000844 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
845 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
846 prepare_to_resend_writes(data);
847 data->mds_ops->rpc_release(data);
848 return -EAGAIN;
849 }
850 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
851 data->write_done_cb = filelayout_commit_done_cb;
852 data->ds_clp = ds->ds_clp;
853 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
854 if (fh)
855 data->args.fh = fh;
856 return nfs_initiate_commit(data, ds->ds_clp->cl_rpcclient,
857 &filelayout_commit_call_ops, how);
858}
859
860/*
861 * This is only useful while we are using whole file layouts.
862 */
863static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode)
864{
865 struct pnfs_layout_segment *lseg, *rv = NULL;
866
867 spin_lock(&inode->i_lock);
868 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
869 if (lseg->pls_range.iomode == IOMODE_RW)
870 rv = get_lseg(lseg);
871 spin_unlock(&inode->i_lock);
872 return rv;
873}
874
875static int alloc_ds_commits(struct inode *inode, struct list_head *list)
876{
877 struct pnfs_layout_segment *lseg;
878 struct nfs4_filelayout_segment *fl;
879 struct nfs_write_data *data;
880 int i, j;
881
882 /* Won't need this when non-whole file layout segments are supported
883 * instead we will use a pnfs_layout_hdr structure */
884 lseg = find_only_write_lseg(inode);
885 if (!lseg)
886 return 0;
887 fl = FILELAYOUT_LSEG(lseg);
888 for (i = 0; i < fl->number_of_buckets; i++) {
889 if (list_empty(&fl->commit_buckets[i]))
890 continue;
891 data = nfs_commitdata_alloc();
892 if (!data)
893 goto out_bad;
894 data->ds_commit_index = i;
895 data->lseg = lseg;
896 list_add(&data->pages, list);
897 }
898 put_lseg(lseg);
899 return 0;
900
901out_bad:
902 for (j = i; j < fl->number_of_buckets; j++) {
903 if (list_empty(&fl->commit_buckets[i]))
904 continue;
905 nfs_retry_commit(&fl->commit_buckets[i], lseg);
906 put_lseg(lseg); /* associated with emptying bucket */
907 }
908 put_lseg(lseg);
909 /* Caller will clean up entries put on list */
910 return -ENOMEM;
911}
912
913/* This follows nfs_commit_list pretty closely */
914static int
915filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
916 int how)
917{
918 struct nfs_write_data *data, *tmp;
919 LIST_HEAD(list);
920
921 if (!list_empty(mds_pages)) {
922 data = nfs_commitdata_alloc();
923 if (!data)
924 goto out_bad;
925 data->lseg = NULL;
926 list_add(&data->pages, &list);
927 }
928
929 if (alloc_ds_commits(inode, &list))
930 goto out_bad;
931
932 list_for_each_entry_safe(data, tmp, &list, pages) {
933 list_del_init(&data->pages);
934 atomic_inc(&NFS_I(inode)->commits_outstanding);
935 if (!data->lseg) {
936 nfs_init_commit(data, mds_pages, NULL);
937 nfs_initiate_commit(data, NFS_CLIENT(inode),
938 data->mds_ops, how);
939 } else {
940 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index], data->lseg);
941 filelayout_initiate_commit(data, how);
942 }
943 }
944 return 0;
945 out_bad:
946 list_for_each_entry_safe(data, tmp, &list, pages) {
947 nfs_retry_commit(&data->pages, data->lseg);
948 list_del_init(&data->pages);
949 nfs_commit_free(data);
950 }
951 nfs_retry_commit(mds_pages, NULL);
952 nfs_commit_clear_lock(NFS_I(inode));
953 return -ENOMEM;
954}
955
Benny Halevy1775bc32011-05-20 13:47:33 +0200956static void
957filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d)
958{
959 nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
960}
961
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400962static struct pnfs_layoutdriver_type filelayout_type = {
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000963 .id = LAYOUT_NFSV4_1_FILES,
964 .name = "LAYOUT_NFSV4_1_FILES",
965 .owner = THIS_MODULE,
966 .alloc_lseg = filelayout_alloc_lseg,
967 .free_lseg = filelayout_free_lseg,
Trond Myklebust1751c362011-06-10 13:30:23 -0400968 .pg_read_ops = &filelayout_pg_read_ops,
969 .pg_write_ops = &filelayout_pg_write_ops,
Fred Isamane0c2b382011-03-23 13:27:53 +0000970 .mark_pnfs_commit = filelayout_mark_pnfs_commit,
971 .choose_commit_list = filelayout_choose_commit_list,
972 .commit_pagelist = filelayout_commit_pagelist,
Andy Adamsondc70d7b2011-03-01 01:34:19 +0000973 .read_pagelist = filelayout_read_pagelist,
Andy Adamson0382b742011-03-03 15:13:45 +0000974 .write_pagelist = filelayout_write_pagelist,
Benny Halevy1775bc32011-05-20 13:47:33 +0200975 .free_deviceid_node = filelayout_free_deveiceid_node,
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400976};
977
978static int __init nfs4filelayout_init(void)
979{
980 printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
981 __func__);
982 return pnfs_register_layoutdriver(&filelayout_type);
983}
984
985static void __exit nfs4filelayout_exit(void)
986{
987 printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
988 __func__);
989 pnfs_unregister_layoutdriver(&filelayout_type);
990}
991
J. Bruce Fieldsf85ef692011-07-15 19:18:42 -0400992MODULE_ALIAS("nfs-layouttype4-1");
993
Dean Hildebrand7ab672c2010-10-20 00:18:00 -0400994module_init(nfs4filelayout_init);
995module_exit(nfs4filelayout_exit);