blob: 7fc14b90886e746be3338faf7cec58e10f831fae [file] [log] [blame]
Tom Haynesd67ae822014-12-11 17:02:04 -05001/*
2 * Module for pnfs flexfile layout driver.
3 *
4 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
5 *
6 * Tao Peng <bergwolf@primarydata.com>
7 */
8
9#include <linux/nfs_fs.h>
10#include <linux/nfs_page.h>
11#include <linux/module.h>
12
13#include <linux/sunrpc/metrics.h>
Tom Haynesd67ae822014-12-11 17:02:04 -050014
15#include "flexfilelayout.h"
16#include "../nfs4session.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040017#include "../nfs4idmap.h"
Tom Haynesd67ae822014-12-11 17:02:04 -050018#include "../internal.h"
19#include "../delegation.h"
20#include "../nfs4trace.h"
21#include "../iostat.h"
22#include "../nfs.h"
Peng Taoad4dc53e2015-06-23 19:52:01 +080023#include "../nfs42.h"
Tom Haynesd67ae822014-12-11 17:02:04 -050024
25#define NFSDBG_FACILITY NFSDBG_PNFS_LD
26
27#define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)
28
29static struct pnfs_layout_hdr *
30ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
31{
32 struct nfs4_flexfile_layout *ffl;
33
34 ffl = kzalloc(sizeof(*ffl), gfp_flags);
35 if (ffl) {
36 INIT_LIST_HEAD(&ffl->error_list);
Trond Myklebust266d12d2015-08-24 20:03:17 -040037 INIT_LIST_HEAD(&ffl->mirrors);
Tom Haynesd67ae822014-12-11 17:02:04 -050038 return &ffl->generic_hdr;
39 } else
40 return NULL;
41}
42
43static void
44ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo)
45{
46 struct nfs4_ff_layout_ds_err *err, *n;
47
48 list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list,
49 list) {
50 list_del(&err->list);
51 kfree(err);
52 }
53 kfree(FF_LAYOUT_FROM_HDR(lo));
54}
55
56static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
57{
58 __be32 *p;
59
60 p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE);
61 if (unlikely(p == NULL))
62 return -ENOBUFS;
63 memcpy(stateid, p, NFS4_STATEID_SIZE);
64 dprintk("%s: stateid id= [%x%x%x%x]\n", __func__,
65 p[0], p[1], p[2], p[3]);
66 return 0;
67}
68
69static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid)
70{
71 __be32 *p;
72
73 p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
74 if (unlikely(!p))
75 return -ENOBUFS;
76 memcpy(devid, p, NFS4_DEVICEID4_SIZE);
77 nfs4_print_deviceid(devid);
78 return 0;
79}
80
81static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
82{
83 __be32 *p;
84
85 p = xdr_inline_decode(xdr, 4);
86 if (unlikely(!p))
87 return -ENOBUFS;
88 fh->size = be32_to_cpup(p++);
89 if (fh->size > sizeof(struct nfs_fh)) {
90 printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n",
91 fh->size);
92 return -EOVERFLOW;
93 }
94 /* fh.data */
95 p = xdr_inline_decode(xdr, fh->size);
96 if (unlikely(!p))
97 return -ENOBUFS;
98 memcpy(&fh->data, p, fh->size);
99 dprintk("%s: fh len %d\n", __func__, fh->size);
100
101 return 0;
102}
103
104/*
105 * Currently only stringified uids and gids are accepted.
106 * I.e., kerberos is not supported to the DSes, so no pricipals.
107 *
108 * That means that one common function will suffice, but when
109 * principals are added, this should be split to accomodate
110 * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid().
111 */
112static int
113decode_name(struct xdr_stream *xdr, u32 *id)
114{
115 __be32 *p;
116 int len;
117
118 /* opaque_length(4)*/
119 p = xdr_inline_decode(xdr, 4);
120 if (unlikely(!p))
121 return -ENOBUFS;
122 len = be32_to_cpup(p++);
123 if (len < 0)
124 return -EINVAL;
125
126 dprintk("%s: len %u\n", __func__, len);
127
128 /* opaque body */
129 p = xdr_inline_decode(xdr, len);
130 if (unlikely(!p))
131 return -ENOBUFS;
132
133 if (!nfs_map_string_to_numeric((char *)p, len, id))
134 return -EINVAL;
135
136 return 0;
137}
138
Trond Myklebust266d12d2015-08-24 20:03:17 -0400139static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
140 const struct nfs4_ff_layout_mirror *m2)
141{
142 int i, j;
143
144 if (m1->fh_versions_cnt != m2->fh_versions_cnt)
145 return false;
146 for (i = 0; i < m1->fh_versions_cnt; i++) {
147 bool found_fh = false;
148 for (j = 0; j < m2->fh_versions_cnt; i++) {
149 if (nfs_compare_fh(&m1->fh_versions[i],
150 &m2->fh_versions[j]) == 0) {
151 found_fh = true;
152 break;
153 }
154 }
155 if (!found_fh)
156 return false;
157 }
158 return true;
159}
160
161static struct nfs4_ff_layout_mirror *
162ff_layout_add_mirror(struct pnfs_layout_hdr *lo,
163 struct nfs4_ff_layout_mirror *mirror)
164{
165 struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
166 struct nfs4_ff_layout_mirror *pos;
167 struct inode *inode = lo->plh_inode;
168
169 spin_lock(&inode->i_lock);
170 list_for_each_entry(pos, &ff_layout->mirrors, mirrors) {
171 if (mirror->mirror_ds != pos->mirror_ds)
172 continue;
173 if (!ff_mirror_match_fh(mirror, pos))
174 continue;
175 if (atomic_inc_not_zero(&pos->ref)) {
176 spin_unlock(&inode->i_lock);
177 return pos;
178 }
179 }
180 list_add(&mirror->mirrors, &ff_layout->mirrors);
181 mirror->layout = lo;
182 spin_unlock(&inode->i_lock);
183 return mirror;
184}
185
kbuild test robote3b1df22015-08-25 11:19:25 +0800186static void
Trond Myklebust266d12d2015-08-24 20:03:17 -0400187ff_layout_remove_mirror(struct nfs4_ff_layout_mirror *mirror)
188{
189 struct inode *inode;
190 if (mirror->layout == NULL)
191 return;
192 inode = mirror->layout->plh_inode;
193 spin_lock(&inode->i_lock);
194 list_del(&mirror->mirrors);
195 spin_unlock(&inode->i_lock);
196 mirror->layout = NULL;
197}
198
Trond Myklebust28a0d722015-08-24 18:08:30 -0400199static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
200{
201 struct nfs4_ff_layout_mirror *mirror;
202
203 mirror = kzalloc(sizeof(*mirror), gfp_flags);
204 if (mirror != NULL) {
205 spin_lock_init(&mirror->lock);
206 atomic_set(&mirror->ref, 1);
Trond Myklebust266d12d2015-08-24 20:03:17 -0400207 INIT_LIST_HEAD(&mirror->mirrors);
Trond Myklebust28a0d722015-08-24 18:08:30 -0400208 }
209 return mirror;
210}
211
212static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
213{
Trond Myklebust266d12d2015-08-24 20:03:17 -0400214 ff_layout_remove_mirror(mirror);
Trond Myklebust28a0d722015-08-24 18:08:30 -0400215 kfree(mirror->fh_versions);
Trond Myklebust972398f2015-09-01 12:03:56 -0700216 if (mirror->cred)
217 put_rpccred(mirror->cred);
Trond Myklebust28a0d722015-08-24 18:08:30 -0400218 nfs4_ff_layout_put_deviceid(mirror->mirror_ds);
219 kfree(mirror);
220}
221
222static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror *mirror)
223{
224 if (mirror != NULL && atomic_dec_and_test(&mirror->ref))
225 ff_layout_free_mirror(mirror);
226}
227
Tom Haynesd67ae822014-12-11 17:02:04 -0500228static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls)
229{
230 int i;
231
232 if (fls->mirror_array) {
233 for (i = 0; i < fls->mirror_array_cnt; i++) {
234 /* normally mirror_ds is freed in
235 * .free_deviceid_node but we still do it here
236 * for .alloc_lseg error path */
Trond Myklebust28a0d722015-08-24 18:08:30 -0400237 ff_layout_put_mirror(fls->mirror_array[i]);
Tom Haynesd67ae822014-12-11 17:02:04 -0500238 }
239 kfree(fls->mirror_array);
240 fls->mirror_array = NULL;
241 }
242}
243
244static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr)
245{
246 int ret = 0;
247
248 dprintk("--> %s\n", __func__);
249
250 /* FIXME: remove this check when layout segment support is added */
251 if (lgr->range.offset != 0 ||
252 lgr->range.length != NFS4_MAX_UINT64) {
253 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
254 __func__);
255 ret = -EINVAL;
256 }
257
258 dprintk("--> %s returns %d\n", __func__, ret);
259 return ret;
260}
261
262static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls)
263{
264 if (fls) {
265 ff_layout_free_mirror_array(fls);
266 kfree(fls);
267 }
268}
269
Trond Myklebust0762ed22015-08-25 17:38:25 -0400270static bool
271ff_lseg_range_is_after(const struct pnfs_layout_range *l1,
272 const struct pnfs_layout_range *l2)
273{
274 u64 end1, end2;
275
276 if (l1->iomode != l2->iomode)
277 return l1->iomode != IOMODE_READ;
278 end1 = pnfs_calc_offset_end(l1->offset, l1->length);
279 end2 = pnfs_calc_offset_end(l2->offset, l2->length);
280 if (end1 < l2->offset)
281 return false;
282 if (end2 < l1->offset)
283 return true;
284 return l2->offset <= l1->offset;
285}
286
287static bool
288ff_lseg_merge(struct pnfs_layout_segment *new,
289 struct pnfs_layout_segment *old)
290{
291 u64 new_end, old_end;
292
293 if (new->pls_range.iomode != old->pls_range.iomode)
294 return false;
295 old_end = pnfs_calc_offset_end(old->pls_range.offset,
296 old->pls_range.length);
297 if (old_end < new->pls_range.offset)
298 return false;
299 new_end = pnfs_calc_offset_end(new->pls_range.offset,
300 new->pls_range.length);
301 if (new_end < old->pls_range.offset)
302 return false;
303
304 /* Mergeable: copy info from 'old' to 'new' */
305 if (new_end < old_end)
306 new_end = old_end;
307 if (new->pls_range.offset < old->pls_range.offset)
308 new->pls_range.offset = old->pls_range.offset;
309 new->pls_range.length = pnfs_calc_offset_length(new->pls_range.offset,
310 new_end);
311 if (test_bit(NFS_LSEG_ROC, &old->pls_flags))
312 set_bit(NFS_LSEG_ROC, &new->pls_flags);
313 if (test_bit(NFS_LSEG_LAYOUTRETURN, &old->pls_flags))
314 set_bit(NFS_LSEG_LAYOUTRETURN, &new->pls_flags);
315 return true;
316}
317
318static void
319ff_layout_add_lseg(struct pnfs_layout_hdr *lo,
320 struct pnfs_layout_segment *lseg,
321 struct list_head *free_me)
322{
323 pnfs_generic_layout_insert_lseg(lo, lseg,
324 ff_lseg_range_is_after,
325 ff_lseg_merge,
326 free_me);
327}
328
Tom Haynesd67ae822014-12-11 17:02:04 -0500329static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls)
330{
Tom Haynesd67ae822014-12-11 17:02:04 -0500331 int i, j;
332
333 for (i = 0; i < fls->mirror_array_cnt - 1; i++) {
334 for (j = i + 1; j < fls->mirror_array_cnt; j++)
335 if (fls->mirror_array[i]->efficiency <
Fabian Frederick455b6ee2015-06-12 18:58:50 +0200336 fls->mirror_array[j]->efficiency)
337 swap(fls->mirror_array[i],
338 fls->mirror_array[j]);
Tom Haynesd67ae822014-12-11 17:02:04 -0500339 }
340}
341
342static struct pnfs_layout_segment *
343ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
344 struct nfs4_layoutget_res *lgr,
345 gfp_t gfp_flags)
346{
347 struct pnfs_layout_segment *ret;
348 struct nfs4_ff_layout_segment *fls = NULL;
349 struct xdr_stream stream;
350 struct xdr_buf buf;
351 struct page *scratch;
352 u64 stripe_unit;
353 u32 mirror_array_cnt;
354 __be32 *p;
355 int i, rc;
356
357 dprintk("--> %s\n", __func__);
358 scratch = alloc_page(gfp_flags);
359 if (!scratch)
360 return ERR_PTR(-ENOMEM);
361
362 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages,
363 lgr->layoutp->len);
364 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
365
366 /* stripe unit and mirror_array_cnt */
367 rc = -EIO;
368 p = xdr_inline_decode(&stream, 8 + 4);
369 if (!p)
370 goto out_err_free;
371
372 p = xdr_decode_hyper(p, &stripe_unit);
373 mirror_array_cnt = be32_to_cpup(p++);
374 dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__,
375 stripe_unit, mirror_array_cnt);
376
377 if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT ||
378 mirror_array_cnt == 0)
379 goto out_err_free;
380
381 rc = -ENOMEM;
382 fls = kzalloc(sizeof(*fls), gfp_flags);
383 if (!fls)
384 goto out_err_free;
385
386 fls->mirror_array_cnt = mirror_array_cnt;
387 fls->stripe_unit = stripe_unit;
388 fls->mirror_array = kcalloc(fls->mirror_array_cnt,
389 sizeof(fls->mirror_array[0]), gfp_flags);
390 if (fls->mirror_array == NULL)
391 goto out_err_free;
392
393 for (i = 0; i < fls->mirror_array_cnt; i++) {
Trond Myklebust266d12d2015-08-24 20:03:17 -0400394 struct nfs4_ff_layout_mirror *mirror;
Tom Haynesd67ae822014-12-11 17:02:04 -0500395 struct nfs4_deviceid devid;
396 struct nfs4_deviceid_node *idnode;
397 u32 ds_count;
398 u32 fh_count;
399 int j;
400
401 rc = -EIO;
402 p = xdr_inline_decode(&stream, 4);
403 if (!p)
404 goto out_err_free;
405 ds_count = be32_to_cpup(p);
406
407 /* FIXME: allow for striping? */
408 if (ds_count != 1)
409 goto out_err_free;
410
Trond Myklebust28a0d722015-08-24 18:08:30 -0400411 fls->mirror_array[i] = ff_layout_alloc_mirror(gfp_flags);
Tom Haynesd67ae822014-12-11 17:02:04 -0500412 if (fls->mirror_array[i] == NULL) {
413 rc = -ENOMEM;
414 goto out_err_free;
415 }
416
Tom Haynesd67ae822014-12-11 17:02:04 -0500417 fls->mirror_array[i]->ds_count = ds_count;
418
419 /* deviceid */
420 rc = decode_deviceid(&stream, &devid);
421 if (rc)
422 goto out_err_free;
423
424 idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode),
425 &devid, lh->plh_lc_cred,
426 gfp_flags);
427 /*
428 * upon success, mirror_ds is allocated by previous
429 * getdeviceinfo, or newly by .alloc_deviceid_node
430 * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure
431 */
432 if (idnode)
433 fls->mirror_array[i]->mirror_ds =
434 FF_LAYOUT_MIRROR_DS(idnode);
435 else
436 goto out_err_free;
437
438 /* efficiency */
439 rc = -EIO;
440 p = xdr_inline_decode(&stream, 4);
441 if (!p)
442 goto out_err_free;
443 fls->mirror_array[i]->efficiency = be32_to_cpup(p);
444
445 /* stateid */
446 rc = decode_stateid(&stream, &fls->mirror_array[i]->stateid);
447 if (rc)
448 goto out_err_free;
449
450 /* fh */
451 p = xdr_inline_decode(&stream, 4);
452 if (!p)
453 goto out_err_free;
454 fh_count = be32_to_cpup(p);
455
456 fls->mirror_array[i]->fh_versions =
457 kzalloc(fh_count * sizeof(struct nfs_fh),
458 gfp_flags);
459 if (fls->mirror_array[i]->fh_versions == NULL) {
460 rc = -ENOMEM;
461 goto out_err_free;
462 }
463
464 for (j = 0; j < fh_count; j++) {
465 rc = decode_nfs_fh(&stream,
466 &fls->mirror_array[i]->fh_versions[j]);
467 if (rc)
468 goto out_err_free;
469 }
470
471 fls->mirror_array[i]->fh_versions_cnt = fh_count;
472
473 /* user */
474 rc = decode_name(&stream, &fls->mirror_array[i]->uid);
475 if (rc)
476 goto out_err_free;
477
478 /* group */
479 rc = decode_name(&stream, &fls->mirror_array[i]->gid);
480 if (rc)
481 goto out_err_free;
482
Trond Myklebust266d12d2015-08-24 20:03:17 -0400483 mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
484 if (mirror != fls->mirror_array[i]) {
485 ff_layout_free_mirror(fls->mirror_array[i]);
486 fls->mirror_array[i] = mirror;
487 }
488
Tom Haynesd67ae822014-12-11 17:02:04 -0500489 dprintk("%s: uid %d gid %d\n", __func__,
490 fls->mirror_array[i]->uid,
491 fls->mirror_array[i]->gid);
492 }
493
Trond Myklebustc0f5f502015-06-26 14:51:32 -0400494 p = xdr_inline_decode(&stream, 4);
495 if (p)
496 fls->flags = be32_to_cpup(p);
497
Tom Haynesd67ae822014-12-11 17:02:04 -0500498 ff_layout_sort_mirrors(fls);
499 rc = ff_layout_check_layout(lgr);
500 if (rc)
501 goto out_err_free;
502
503 ret = &fls->generic_hdr;
504 dprintk("<-- %s (success)\n", __func__);
505out_free_page:
506 __free_page(scratch);
507 return ret;
508out_err_free:
509 _ff_layout_free_lseg(fls);
510 ret = ERR_PTR(rc);
511 dprintk("<-- %s (%d)\n", __func__, rc);
512 goto out_free_page;
513}
514
515static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
516{
517 struct pnfs_layout_segment *lseg;
518
519 list_for_each_entry(lseg, &layout->plh_segs, pls_list)
520 if (lseg->pls_range.iomode == IOMODE_RW)
521 return true;
522
523 return false;
524}
525
526static void
527ff_layout_free_lseg(struct pnfs_layout_segment *lseg)
528{
529 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
Tom Haynesd67ae822014-12-11 17:02:04 -0500530
531 dprintk("--> %s\n", __func__);
532
Tom Haynesd67ae822014-12-11 17:02:04 -0500533 if (lseg->pls_range.iomode == IOMODE_RW) {
534 struct nfs4_flexfile_layout *ffl;
535 struct inode *inode;
536
537 ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout);
538 inode = ffl->generic_hdr.plh_inode;
539 spin_lock(&inode->i_lock);
540 if (!ff_layout_has_rw_segments(lseg->pls_layout)) {
541 ffl->commit_info.nbuckets = 0;
542 kfree(ffl->commit_info.buckets);
543 ffl->commit_info.buckets = NULL;
544 }
545 spin_unlock(&inode->i_lock);
546 }
547 _ff_layout_free_lseg(fls);
548}
549
550/* Return 1 until we have multiple lsegs support */
551static int
552ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls)
553{
554 return 1;
555}
556
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800557static void
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500558nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800559{
Peng Tao9bbd9bb2015-06-26 09:45:49 +0800560 /* first IO request? */
561 if (atomic_inc_return(&timer->n_ops) == 1) {
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500562 timer->start_time = now;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800563 }
564}
565
566static ktime_t
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500567nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800568{
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500569 ktime_t start;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800570
Peng Tao9bbd9bb2015-06-26 09:45:49 +0800571 if (atomic_dec_return(&timer->n_ops) < 0)
572 WARN_ON_ONCE(1);
573
Peng Tao9bbd9bb2015-06-26 09:45:49 +0800574 start = timer->start_time;
575 timer->start_time = now;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800576 return ktime_sub(now, start);
577}
578
Peng Tao97ba3752015-06-23 19:52:04 +0800579static bool
Peng Taod9838032015-06-23 19:52:00 +0800580nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500581 struct nfs4_ff_layoutstat *layoutstat,
582 ktime_t now)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800583{
Peng Taod9838032015-06-23 19:52:00 +0800584 static const ktime_t notime = {0};
Trond Myklebustbbf58bf2015-08-24 20:39:18 -0400585 s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
Peng Taod9838032015-06-23 19:52:00 +0800586
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500587 nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
Peng Tao9bbd9bb2015-06-26 09:45:49 +0800588 if (ktime_equal(mirror->start_time, notime))
589 mirror->start_time = now;
590 if (ktime_equal(mirror->last_report_time, notime))
591 mirror->last_report_time = now;
Trond Myklebustbbf58bf2015-08-24 20:39:18 -0400592 if (layoutstats_timer != 0)
593 report_interval = (s64)layoutstats_timer * 1000LL;
Peng Tao97ba3752015-06-23 19:52:04 +0800594 if (ktime_to_ms(ktime_sub(now, mirror->last_report_time)) >=
Trond Myklebustbbf58bf2015-08-24 20:39:18 -0400595 report_interval) {
Peng Tao97ba3752015-06-23 19:52:04 +0800596 mirror->last_report_time = now;
597 return true;
598 }
599
600 return false;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800601}
602
603static void
604nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat,
605 __u64 requested)
606{
607 struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
608
609 iostat->ops_requested++;
610 iostat->bytes_requested += requested;
611}
612
613static void
614nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat,
615 __u64 requested,
616 __u64 completed,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500617 ktime_t time_completed,
618 ktime_t time_started)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800619{
620 struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500621 ktime_t completion_time = ktime_sub(time_completed, time_started);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800622 ktime_t timer;
623
624 iostat->ops_completed++;
625 iostat->bytes_completed += completed;
626 iostat->bytes_not_delivered += requested - completed;
627
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500628 timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer, time_completed);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800629 iostat->total_busy_time =
630 ktime_add(iostat->total_busy_time, timer);
631 iostat->aggregate_completion_time =
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500632 ktime_add(iostat->aggregate_completion_time,
633 completion_time);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800634}
635
636static void
Trond Myklebust0b7baf92015-08-24 18:22:28 -0400637nfs4_ff_layout_stat_io_start_read(struct inode *inode,
638 struct nfs4_ff_layout_mirror *mirror,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500639 __u64 requested, ktime_t now)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800640{
Peng Tao97ba3752015-06-23 19:52:04 +0800641 bool report;
642
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800643 spin_lock(&mirror->lock);
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500644 report = nfs4_ff_layoutstat_start_io(mirror, &mirror->read_stat, now);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800645 nfs4_ff_layout_stat_io_update_requested(&mirror->read_stat, requested);
646 spin_unlock(&mirror->lock);
Peng Tao97ba3752015-06-23 19:52:04 +0800647
648 if (report)
Trond Myklebust0b7baf92015-08-24 18:22:28 -0400649 pnfs_report_layoutstat(inode, GFP_KERNEL);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800650}
651
652static void
653nfs4_ff_layout_stat_io_end_read(struct rpc_task *task,
654 struct nfs4_ff_layout_mirror *mirror,
655 __u64 requested,
656 __u64 completed)
657{
658 spin_lock(&mirror->lock);
659 nfs4_ff_layout_stat_io_update_completed(&mirror->read_stat,
660 requested, completed,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500661 ktime_get(), task->tk_start);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800662 spin_unlock(&mirror->lock);
663}
664
665static void
Trond Myklebust0b7baf92015-08-24 18:22:28 -0400666nfs4_ff_layout_stat_io_start_write(struct inode *inode,
667 struct nfs4_ff_layout_mirror *mirror,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500668 __u64 requested, ktime_t now)
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800669{
Peng Tao97ba3752015-06-23 19:52:04 +0800670 bool report;
671
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800672 spin_lock(&mirror->lock);
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500673 report = nfs4_ff_layoutstat_start_io(mirror , &mirror->write_stat, now);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800674 nfs4_ff_layout_stat_io_update_requested(&mirror->write_stat, requested);
675 spin_unlock(&mirror->lock);
Peng Tao97ba3752015-06-23 19:52:04 +0800676
677 if (report)
Trond Myklebust0b7baf92015-08-24 18:22:28 -0400678 pnfs_report_layoutstat(inode, GFP_NOIO);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800679}
680
681static void
682nfs4_ff_layout_stat_io_end_write(struct rpc_task *task,
683 struct nfs4_ff_layout_mirror *mirror,
684 __u64 requested,
685 __u64 completed,
686 enum nfs3_stable_how committed)
687{
688 if (committed == NFS_UNSTABLE)
689 requested = completed = 0;
690
691 spin_lock(&mirror->lock);
692 nfs4_ff_layout_stat_io_update_completed(&mirror->write_stat,
Trond Myklebuste76d28d2015-08-20 13:12:51 -0500693 requested, completed, ktime_get(), task->tk_start);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +0800694 spin_unlock(&mirror->lock);
695}
696
Tom Haynesd67ae822014-12-11 17:02:04 -0500697static int
698ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg,
699 struct nfs_commit_info *cinfo,
700 gfp_t gfp_flags)
701{
702 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
703 struct pnfs_commit_bucket *buckets;
704 int size;
705
706 if (cinfo->ds->nbuckets != 0) {
707 /* This assumes there is only one RW lseg per file.
708 * To support multiple lseg per file, we need to
709 * change struct pnfs_commit_bucket to allow dynamic
710 * increasing nbuckets.
711 */
712 return 0;
713 }
714
715 size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg);
716
717 buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
718 gfp_flags);
719 if (!buckets)
720 return -ENOMEM;
721 else {
722 int i;
723
724 spin_lock(cinfo->lock);
725 if (cinfo->ds->nbuckets != 0)
726 kfree(buckets);
727 else {
728 cinfo->ds->buckets = buckets;
729 cinfo->ds->nbuckets = size;
730 for (i = 0; i < size; i++) {
731 INIT_LIST_HEAD(&buckets[i].written);
732 INIT_LIST_HEAD(&buckets[i].committing);
733 /* mark direct verifier as unset */
734 buckets[i].direct_verf.committed =
735 NFS_INVALID_STABLE_HOW;
736 }
737 }
738 spin_unlock(cinfo->lock);
739 return 0;
740 }
741}
742
743static struct nfs4_pnfs_ds *
Trond Myklebust13544412015-11-02 10:11:17 -0500744ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
745 int start_idx,
Tom Haynesd67ae822014-12-11 17:02:04 -0500746 int *best_idx)
747{
Trond Myklebust13544412015-11-02 10:11:17 -0500748 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
Tom Haynesd67ae822014-12-11 17:02:04 -0500749 struct nfs4_pnfs_ds *ds;
750 int idx;
751
Tom Haynesd67ae822014-12-11 17:02:04 -0500752 /* mirrors are sorted by efficiency */
Trond Myklebust13544412015-11-02 10:11:17 -0500753 for (idx = start_idx; idx < fls->mirror_array_cnt; idx++) {
754 ds = nfs4_ff_layout_prepare_ds(lseg, idx, false);
Tom Haynesd67ae822014-12-11 17:02:04 -0500755 if (ds) {
756 *best_idx = idx;
757 return ds;
758 }
759 }
760
761 return NULL;
762}
763
764static void
765ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
766 struct nfs_page *req)
767{
768 struct nfs_pgio_mirror *pgm;
769 struct nfs4_ff_layout_mirror *mirror;
770 struct nfs4_pnfs_ds *ds;
771 int ds_idx;
772
773 /* Use full layout for now */
774 if (!pgio->pg_lseg)
775 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
776 req->wb_context,
777 0,
778 NFS4_MAX_UINT64,
779 IOMODE_READ,
780 GFP_KERNEL);
781 /* If no lseg, fall back to read through mds */
782 if (pgio->pg_lseg == NULL)
783 goto out_mds;
784
Trond Myklebust13544412015-11-02 10:11:17 -0500785 ds = ff_layout_choose_best_ds_for_read(pgio->pg_lseg, 0, &ds_idx);
Tom Haynesd67ae822014-12-11 17:02:04 -0500786 if (!ds)
787 goto out_mds;
788 mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx);
789
790 pgio->pg_mirror_idx = ds_idx;
791
792 /* read always uses only one mirror - idx 0 for pgio layer */
793 pgm = &pgio->pg_mirrors[0];
794 pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize;
795
796 return;
797out_mds:
798 pnfs_put_lseg(pgio->pg_lseg);
799 pgio->pg_lseg = NULL;
800 nfs_pageio_reset_read_mds(pgio);
801}
802
803static void
804ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
805 struct nfs_page *req)
806{
807 struct nfs4_ff_layout_mirror *mirror;
808 struct nfs_pgio_mirror *pgm;
809 struct nfs_commit_info cinfo;
810 struct nfs4_pnfs_ds *ds;
811 int i;
812 int status;
813
814 if (!pgio->pg_lseg)
815 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
816 req->wb_context,
817 0,
818 NFS4_MAX_UINT64,
819 IOMODE_RW,
820 GFP_NOFS);
821 /* If no lseg, fall back to write through mds */
822 if (pgio->pg_lseg == NULL)
823 goto out_mds;
824
825 nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
826 status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
827 if (status < 0)
828 goto out_mds;
829
830 /* Use a direct mapping of ds_idx to pgio mirror_idx */
831 if (WARN_ON_ONCE(pgio->pg_mirror_count !=
832 FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg)))
833 goto out_mds;
834
835 for (i = 0; i < pgio->pg_mirror_count; i++) {
836 ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true);
837 if (!ds)
838 goto out_mds;
839 pgm = &pgio->pg_mirrors[i];
840 mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i);
841 pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize;
842 }
843
844 return;
845
846out_mds:
847 pnfs_put_lseg(pgio->pg_lseg);
848 pgio->pg_lseg = NULL;
849 nfs_pageio_reset_write_mds(pgio);
850}
851
852static unsigned int
853ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
854 struct nfs_page *req)
855{
856 if (!pgio->pg_lseg)
857 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
858 req->wb_context,
859 0,
860 NFS4_MAX_UINT64,
861 IOMODE_RW,
862 GFP_NOFS);
863 if (pgio->pg_lseg)
864 return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg);
865
866 /* no lseg means that pnfs is not in use, so no mirroring here */
Tom Haynesd67ae822014-12-11 17:02:04 -0500867 nfs_pageio_reset_write_mds(pgio);
868 return 1;
869}
870
871static const struct nfs_pageio_ops ff_layout_pg_read_ops = {
872 .pg_init = ff_layout_pg_init_read,
873 .pg_test = pnfs_generic_pg_test,
874 .pg_doio = pnfs_generic_pg_readpages,
875 .pg_cleanup = pnfs_generic_pg_cleanup,
876};
877
878static const struct nfs_pageio_ops ff_layout_pg_write_ops = {
879 .pg_init = ff_layout_pg_init_write,
880 .pg_test = pnfs_generic_pg_test,
881 .pg_doio = pnfs_generic_pg_writepages,
882 .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write,
883 .pg_cleanup = pnfs_generic_pg_cleanup,
884};
885
886static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs)
887{
888 struct rpc_task *task = &hdr->task;
889
890 pnfs_layoutcommit_inode(hdr->inode, false);
891
892 if (retry_pnfs) {
893 dprintk("%s Reset task %5u for i/o through pNFS "
894 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
895 hdr->task.tk_pid,
896 hdr->inode->i_sb->s_id,
897 (unsigned long long)NFS_FILEID(hdr->inode),
898 hdr->args.count,
899 (unsigned long long)hdr->args.offset);
900
901 if (!hdr->dreq) {
902 struct nfs_open_context *ctx;
903
904 ctx = nfs_list_entry(hdr->pages.next)->wb_context;
905 set_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags);
906 hdr->completion_ops->error_cleanup(&hdr->pages);
907 } else {
908 nfs_direct_set_resched_writes(hdr->dreq);
909 /* fake unstable write to let common nfs resend pages */
910 hdr->verf.committed = NFS_UNSTABLE;
Trond Myklebustd6208762015-06-26 15:37:58 -0400911 hdr->good_bytes = hdr->args.count;
Tom Haynesd67ae822014-12-11 17:02:04 -0500912 }
913 return;
914 }
915
916 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
917 dprintk("%s Reset task %5u for i/o through MDS "
918 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
919 hdr->task.tk_pid,
920 hdr->inode->i_sb->s_id,
921 (unsigned long long)NFS_FILEID(hdr->inode),
922 hdr->args.count,
923 (unsigned long long)hdr->args.offset);
924
925 task->tk_status = pnfs_write_done_resend_to_mds(hdr);
926 }
927}
928
929static void ff_layout_reset_read(struct nfs_pgio_header *hdr)
930{
931 struct rpc_task *task = &hdr->task;
932
933 pnfs_layoutcommit_inode(hdr->inode, false);
934
935 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
936 dprintk("%s Reset task %5u for i/o through MDS "
937 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
938 hdr->task.tk_pid,
939 hdr->inode->i_sb->s_id,
940 (unsigned long long)NFS_FILEID(hdr->inode),
941 hdr->args.count,
942 (unsigned long long)hdr->args.offset);
943
944 task->tk_status = pnfs_read_done_resend_to_mds(hdr);
945 }
946}
947
948static int ff_layout_async_handle_error_v4(struct rpc_task *task,
949 struct nfs4_state *state,
950 struct nfs_client *clp,
951 struct pnfs_layout_segment *lseg,
952 int idx)
953{
954 struct pnfs_layout_hdr *lo = lseg->pls_layout;
955 struct inode *inode = lo->plh_inode;
956 struct nfs_server *mds_server = NFS_SERVER(inode);
957
958 struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
959 struct nfs_client *mds_client = mds_server->nfs_client;
960 struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
961
962 if (task->tk_status >= 0)
963 return 0;
964
965 switch (task->tk_status) {
966 /* MDS state errors */
967 case -NFS4ERR_DELEG_REVOKED:
968 case -NFS4ERR_ADMIN_REVOKED:
969 case -NFS4ERR_BAD_STATEID:
970 if (state == NULL)
971 break;
972 nfs_remove_bad_delegation(state->inode);
973 case -NFS4ERR_OPENMODE:
974 if (state == NULL)
975 break;
976 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
977 goto out_bad_stateid;
978 goto wait_on_recovery;
979 case -NFS4ERR_EXPIRED:
980 if (state != NULL) {
981 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
982 goto out_bad_stateid;
983 }
984 nfs4_schedule_lease_recovery(mds_client);
985 goto wait_on_recovery;
986 /* DS session errors */
987 case -NFS4ERR_BADSESSION:
988 case -NFS4ERR_BADSLOT:
989 case -NFS4ERR_BAD_HIGH_SLOT:
990 case -NFS4ERR_DEADSESSION:
991 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
992 case -NFS4ERR_SEQ_FALSE_RETRY:
993 case -NFS4ERR_SEQ_MISORDERED:
994 dprintk("%s ERROR %d, Reset session. Exchangeid "
995 "flags 0x%x\n", __func__, task->tk_status,
996 clp->cl_exchange_flags);
997 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
998 break;
999 case -NFS4ERR_DELAY:
1000 case -NFS4ERR_GRACE:
1001 rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX);
1002 break;
1003 case -NFS4ERR_RETRY_UNCACHED_REP:
1004 break;
1005 /* Invalidate Layout errors */
1006 case -NFS4ERR_PNFS_NO_LAYOUT:
1007 case -ESTALE: /* mapped NFS4ERR_STALE */
1008 case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */
1009 case -EISDIR: /* mapped NFS4ERR_ISDIR */
1010 case -NFS4ERR_FHEXPIRED:
1011 case -NFS4ERR_WRONG_TYPE:
1012 dprintk("%s Invalid layout error %d\n", __func__,
1013 task->tk_status);
1014 /*
1015 * Destroy layout so new i/o will get a new layout.
1016 * Layout will not be destroyed until all current lseg
1017 * references are put. Mark layout as invalid to resend failed
1018 * i/o and all i/o waiting on the slot table to the MDS until
1019 * layout is destroyed and a new valid layout is obtained.
1020 */
1021 pnfs_destroy_layout(NFS_I(inode));
1022 rpc_wake_up(&tbl->slot_tbl_waitq);
1023 goto reset;
1024 /* RPC connection errors */
1025 case -ECONNREFUSED:
1026 case -EHOSTDOWN:
1027 case -EHOSTUNREACH:
1028 case -ENETUNREACH:
1029 case -EIO:
1030 case -ETIMEDOUT:
1031 case -EPIPE:
1032 dprintk("%s DS connection error %d\n", __func__,
1033 task->tk_status);
1034 nfs4_mark_deviceid_unavailable(devid);
1035 rpc_wake_up(&tbl->slot_tbl_waitq);
1036 /* fall through */
1037 default:
1038 if (ff_layout_has_available_ds(lseg))
1039 return -NFS4ERR_RESET_TO_PNFS;
1040reset:
1041 dprintk("%s Retry through MDS. Error %d\n", __func__,
1042 task->tk_status);
1043 return -NFS4ERR_RESET_TO_MDS;
1044 }
1045out:
1046 task->tk_status = 0;
1047 return -EAGAIN;
1048out_bad_stateid:
1049 task->tk_status = -EIO;
1050 return 0;
1051wait_on_recovery:
1052 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
1053 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
1054 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
1055 goto out;
1056}
1057
1058/* Retry all errors through either pNFS or MDS except for -EJUKEBOX */
1059static int ff_layout_async_handle_error_v3(struct rpc_task *task,
1060 struct pnfs_layout_segment *lseg,
1061 int idx)
1062{
1063 struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
1064
1065 if (task->tk_status >= 0)
1066 return 0;
1067
Trond Myklebust90816d12015-08-30 09:53:06 -07001068 switch (task->tk_status) {
1069 /* File access problems. Don't mark the device as unavailable */
1070 case -EACCES:
1071 case -ESTALE:
1072 case -EISDIR:
1073 case -EBADHANDLE:
1074 case -ELOOP:
1075 case -ENOSPC:
1076 break;
1077 case -EJUKEBOX:
1078 nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
1079 goto out_retry;
1080 default:
Tom Haynesd67ae822014-12-11 17:02:04 -05001081 dprintk("%s DS connection error %d\n", __func__,
1082 task->tk_status);
1083 nfs4_mark_deviceid_unavailable(devid);
Tom Haynesd67ae822014-12-11 17:02:04 -05001084 }
Trond Myklebust90816d12015-08-30 09:53:06 -07001085 /* FIXME: Need to prevent infinite looping here. */
1086 return -NFS4ERR_RESET_TO_PNFS;
1087out_retry:
Tom Haynesd67ae822014-12-11 17:02:04 -05001088 task->tk_status = 0;
1089 rpc_restart_call(task);
1090 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
1091 return -EAGAIN;
1092}
1093
1094static int ff_layout_async_handle_error(struct rpc_task *task,
1095 struct nfs4_state *state,
1096 struct nfs_client *clp,
1097 struct pnfs_layout_segment *lseg,
1098 int idx)
1099{
1100 int vers = clp->cl_nfs_mod->rpc_vers->number;
1101
1102 switch (vers) {
1103 case 3:
1104 return ff_layout_async_handle_error_v3(task, lseg, idx);
1105 case 4:
1106 return ff_layout_async_handle_error_v4(task, state, clp,
1107 lseg, idx);
1108 default:
1109 /* should never happen */
1110 WARN_ON_ONCE(1);
1111 return 0;
1112 }
1113}
1114
1115static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
1116 int idx, u64 offset, u64 length,
Trond Myklebustdd521282015-08-20 17:59:49 -05001117 u32 status, int opnum, int error)
Tom Haynesd67ae822014-12-11 17:02:04 -05001118{
1119 struct nfs4_ff_layout_mirror *mirror;
1120 int err;
1121
Trond Myklebustdd521282015-08-20 17:59:49 -05001122 if (status == 0) {
1123 switch (error) {
1124 case -ETIMEDOUT:
1125 case -EPFNOSUPPORT:
1126 case -EPROTONOSUPPORT:
1127 case -EOPNOTSUPP:
1128 case -ECONNREFUSED:
1129 case -ECONNRESET:
1130 case -EHOSTDOWN:
1131 case -EHOSTUNREACH:
1132 case -ENETUNREACH:
1133 case -EADDRINUSE:
1134 case -ENOBUFS:
1135 case -EPIPE:
1136 case -EPERM:
1137 status = NFS4ERR_NXIO;
1138 break;
1139 case -EACCES:
1140 status = NFS4ERR_ACCESS;
1141 break;
1142 default:
1143 return;
1144 }
1145 }
1146
Tom Haynesd67ae822014-12-11 17:02:04 -05001147 mirror = FF_LAYOUT_COMP(lseg, idx);
1148 err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
1149 mirror, offset, length, status, opnum,
1150 GFP_NOIO);
Trond Myklebustf95c03b2015-09-02 15:15:11 -07001151 pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode, lseg);
Tom Haynesd67ae822014-12-11 17:02:04 -05001152 dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status);
1153}
1154
1155/* NFS_PROTO call done callback routines */
1156
1157static int ff_layout_read_done_cb(struct rpc_task *task,
1158 struct nfs_pgio_header *hdr)
1159{
Tom Haynesd67ae822014-12-11 17:02:04 -05001160 int err;
1161
1162 trace_nfs4_pnfs_read(hdr, task->tk_status);
Trond Myklebustdd521282015-08-20 17:59:49 -05001163 if (task->tk_status < 0)
Tom Haynesd67ae822014-12-11 17:02:04 -05001164 ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
1165 hdr->args.offset, hdr->args.count,
Trond Myklebustdd521282015-08-20 17:59:49 -05001166 hdr->res.op_status, OP_READ,
1167 task->tk_status);
Tom Haynesd67ae822014-12-11 17:02:04 -05001168 err = ff_layout_async_handle_error(task, hdr->args.context->state,
1169 hdr->ds_clp, hdr->lseg,
1170 hdr->pgio_mirror_idx);
1171
1172 switch (err) {
1173 case -NFS4ERR_RESET_TO_PNFS:
Trond Myklebust13544412015-11-02 10:11:17 -05001174 if (ff_layout_choose_best_ds_for_read(hdr->lseg,
1175 hdr->pgio_mirror_idx + 1,
1176 &hdr->pgio_mirror_idx))
1177 goto out_eagain;
Tom Haynesd67ae822014-12-11 17:02:04 -05001178 set_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE,
1179 &hdr->lseg->pls_layout->plh_flags);
1180 pnfs_read_resend_pnfs(hdr);
1181 return task->tk_status;
1182 case -NFS4ERR_RESET_TO_MDS:
Tom Haynesd67ae822014-12-11 17:02:04 -05001183 ff_layout_reset_read(hdr);
1184 return task->tk_status;
1185 case -EAGAIN:
Trond Myklebust13544412015-11-02 10:11:17 -05001186 goto out_eagain;
Tom Haynesd67ae822014-12-11 17:02:04 -05001187 }
1188
1189 return 0;
Trond Myklebust13544412015-11-02 10:11:17 -05001190out_eagain:
1191 rpc_restart_call_prepare(task);
1192 return -EAGAIN;
Tom Haynesd67ae822014-12-11 17:02:04 -05001193}
1194
Trond Myklebustc0f5f502015-06-26 14:51:32 -04001195static bool
1196ff_layout_need_layoutcommit(struct pnfs_layout_segment *lseg)
1197{
1198 return !(FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_LAYOUTCOMMIT);
1199}
1200
Tom Haynesd67ae822014-12-11 17:02:04 -05001201/*
1202 * We reference the rpc_cred of the first WRITE that triggers the need for
1203 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
1204 * rfc5661 is not clear about which credential should be used.
1205 *
1206 * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so
1207 * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751
1208 * we always send layoutcommit after DS writes.
1209 */
1210static void
1211ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr)
1212{
Trond Myklebustc0f5f502015-06-26 14:51:32 -04001213 if (!ff_layout_need_layoutcommit(hdr->lseg))
1214 return;
1215
Trond Myklebust67af7612015-03-25 20:40:38 -04001216 pnfs_set_layoutcommit(hdr->inode, hdr->lseg,
1217 hdr->mds_offset + hdr->res.count);
Tom Haynesd67ae822014-12-11 17:02:04 -05001218 dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
1219 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
1220}
1221
1222static bool
1223ff_layout_reset_to_mds(struct pnfs_layout_segment *lseg, int idx)
1224{
1225 /* No mirroring for now */
1226 struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx);
1227
1228 return ff_layout_test_devid_unavailable(node);
1229}
1230
1231static int ff_layout_read_prepare_common(struct rpc_task *task,
1232 struct nfs_pgio_header *hdr)
1233{
Trond Myklebust0b7baf92015-08-24 18:22:28 -04001234 nfs4_ff_layout_stat_io_start_read(hdr->inode,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001235 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
Trond Myklebuste76d28d2015-08-20 13:12:51 -05001236 hdr->args.count,
1237 task->tk_start);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001238
Tom Haynesd67ae822014-12-11 17:02:04 -05001239 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
1240 rpc_exit(task, -EIO);
1241 return -EIO;
1242 }
1243 if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) {
1244 dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
1245 if (ff_layout_has_available_ds(hdr->lseg))
1246 pnfs_read_resend_pnfs(hdr);
1247 else
1248 ff_layout_reset_read(hdr);
1249 rpc_exit(task, 0);
1250 return -EAGAIN;
1251 }
1252 hdr->pgio_done_cb = ff_layout_read_done_cb;
1253
1254 return 0;
1255}
1256
1257/*
1258 * Call ops for the async read/write cases
1259 * In the case of dense layouts, the offset needs to be reset to its
1260 * original value.
1261 */
1262static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data)
1263{
1264 struct nfs_pgio_header *hdr = data;
1265
1266 if (ff_layout_read_prepare_common(task, hdr))
1267 return;
1268
1269 rpc_call_start(task);
1270}
1271
1272static int ff_layout_setup_sequence(struct nfs_client *ds_clp,
1273 struct nfs4_sequence_args *args,
1274 struct nfs4_sequence_res *res,
1275 struct rpc_task *task)
1276{
1277 if (ds_clp->cl_session)
1278 return nfs41_setup_sequence(ds_clp->cl_session,
1279 args,
1280 res,
1281 task);
1282 return nfs40_setup_sequence(ds_clp->cl_slot_tbl,
1283 args,
1284 res,
1285 task);
1286}
1287
1288static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data)
1289{
1290 struct nfs_pgio_header *hdr = data;
1291
Tom Haynesd67ae822014-12-11 17:02:04 -05001292 if (ff_layout_setup_sequence(hdr->ds_clp,
1293 &hdr->args.seq_args,
1294 &hdr->res.seq_res,
1295 task))
1296 return;
1297
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001298 if (ff_layout_read_prepare_common(task, hdr))
1299 return;
1300
Tom Haynesd67ae822014-12-11 17:02:04 -05001301 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
1302 hdr->args.lock_context, FMODE_READ) == -EIO)
1303 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
1304}
1305
1306static void ff_layout_read_call_done(struct rpc_task *task, void *data)
1307{
1308 struct nfs_pgio_header *hdr = data;
1309
1310 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
1311
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001312 nfs4_ff_layout_stat_io_end_read(task,
1313 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
1314 hdr->args.count, hdr->res.count);
1315
Tom Haynesd67ae822014-12-11 17:02:04 -05001316 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
1317 task->tk_status == 0) {
1318 nfs4_sequence_done(task, &hdr->res.seq_res);
1319 return;
1320 }
1321
1322 /* Note this may cause RPC to be resent */
1323 hdr->mds_ops->rpc_call_done(task, hdr);
1324}
1325
1326static void ff_layout_read_count_stats(struct rpc_task *task, void *data)
1327{
1328 struct nfs_pgio_header *hdr = data;
1329
1330 rpc_count_iostats_metrics(task,
1331 &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]);
1332}
1333
1334static int ff_layout_write_done_cb(struct rpc_task *task,
1335 struct nfs_pgio_header *hdr)
1336{
Tom Haynesd67ae822014-12-11 17:02:04 -05001337 int err;
1338
1339 trace_nfs4_pnfs_write(hdr, task->tk_status);
Trond Myklebustdd521282015-08-20 17:59:49 -05001340 if (task->tk_status < 0)
Tom Haynesd67ae822014-12-11 17:02:04 -05001341 ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
1342 hdr->args.offset, hdr->args.count,
Trond Myklebustdd521282015-08-20 17:59:49 -05001343 hdr->res.op_status, OP_WRITE,
1344 task->tk_status);
Tom Haynesd67ae822014-12-11 17:02:04 -05001345 err = ff_layout_async_handle_error(task, hdr->args.context->state,
1346 hdr->ds_clp, hdr->lseg,
1347 hdr->pgio_mirror_idx);
1348
1349 switch (err) {
1350 case -NFS4ERR_RESET_TO_PNFS:
Trond Myklebust7cc8c5c2015-09-02 15:22:48 -07001351 pnfs_set_retry_layoutget(hdr->lseg->pls_layout);
1352 ff_layout_reset_write(hdr, true);
1353 return task->tk_status;
Tom Haynesd67ae822014-12-11 17:02:04 -05001354 case -NFS4ERR_RESET_TO_MDS:
Trond Myklebust7cc8c5c2015-09-02 15:22:48 -07001355 pnfs_clear_retry_layoutget(hdr->lseg->pls_layout);
1356 ff_layout_reset_write(hdr, false);
Tom Haynesd67ae822014-12-11 17:02:04 -05001357 return task->tk_status;
1358 case -EAGAIN:
1359 rpc_restart_call_prepare(task);
1360 return -EAGAIN;
1361 }
1362
1363 if (hdr->res.verf->committed == NFS_FILE_SYNC ||
1364 hdr->res.verf->committed == NFS_DATA_SYNC)
1365 ff_layout_set_layoutcommit(hdr);
1366
Peng Tao54204012015-08-22 06:40:00 +08001367 /* zero out fattr since we don't care DS attr at all */
1368 hdr->fattr.valid = 0;
Peng Tao69f230d2015-08-20 01:52:59 +08001369 if (task->tk_status >= 0)
1370 nfs_writeback_update_inode(hdr);
1371
Tom Haynesd67ae822014-12-11 17:02:04 -05001372 return 0;
1373}
1374
1375static int ff_layout_commit_done_cb(struct rpc_task *task,
1376 struct nfs_commit_data *data)
1377{
Tom Haynesd67ae822014-12-11 17:02:04 -05001378 int err;
1379
1380 trace_nfs4_pnfs_commit_ds(data, task->tk_status);
Trond Myklebustdd521282015-08-20 17:59:49 -05001381 if (task->tk_status < 0)
Tom Haynesd67ae822014-12-11 17:02:04 -05001382 ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index,
1383 data->args.offset, data->args.count,
Trond Myklebustdd521282015-08-20 17:59:49 -05001384 data->res.op_status, OP_COMMIT,
1385 task->tk_status);
Tom Haynesd67ae822014-12-11 17:02:04 -05001386 err = ff_layout_async_handle_error(task, NULL, data->ds_clp,
1387 data->lseg, data->ds_commit_index);
1388
1389 switch (err) {
1390 case -NFS4ERR_RESET_TO_PNFS:
Trond Myklebust7cc8c5c2015-09-02 15:22:48 -07001391 pnfs_set_retry_layoutget(data->lseg->pls_layout);
1392 pnfs_generic_prepare_to_resend_writes(data);
1393 return -EAGAIN;
Tom Haynesd67ae822014-12-11 17:02:04 -05001394 case -NFS4ERR_RESET_TO_MDS:
Trond Myklebust7cc8c5c2015-09-02 15:22:48 -07001395 pnfs_clear_retry_layoutget(data->lseg->pls_layout);
Tom Haynesd67ae822014-12-11 17:02:04 -05001396 pnfs_generic_prepare_to_resend_writes(data);
1397 return -EAGAIN;
1398 case -EAGAIN:
1399 rpc_restart_call_prepare(task);
1400 return -EAGAIN;
1401 }
1402
Trond Myklebustc0f5f502015-06-26 14:51:32 -04001403 if (data->verf.committed == NFS_UNSTABLE
1404 && ff_layout_need_layoutcommit(data->lseg))
Trond Myklebust67af7612015-03-25 20:40:38 -04001405 pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
Tom Haynesd67ae822014-12-11 17:02:04 -05001406
1407 return 0;
1408}
1409
1410static int ff_layout_write_prepare_common(struct rpc_task *task,
1411 struct nfs_pgio_header *hdr)
1412{
Trond Myklebust0b7baf92015-08-24 18:22:28 -04001413 nfs4_ff_layout_stat_io_start_write(hdr->inode,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001414 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
Trond Myklebuste76d28d2015-08-20 13:12:51 -05001415 hdr->args.count,
1416 task->tk_start);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001417
Tom Haynesd67ae822014-12-11 17:02:04 -05001418 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
1419 rpc_exit(task, -EIO);
1420 return -EIO;
1421 }
1422
1423 if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) {
1424 bool retry_pnfs;
1425
1426 retry_pnfs = ff_layout_has_available_ds(hdr->lseg);
1427 dprintk("%s task %u reset io to %s\n", __func__,
1428 task->tk_pid, retry_pnfs ? "pNFS" : "MDS");
1429 ff_layout_reset_write(hdr, retry_pnfs);
1430 rpc_exit(task, 0);
1431 return -EAGAIN;
1432 }
1433
1434 return 0;
1435}
1436
1437static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data)
1438{
1439 struct nfs_pgio_header *hdr = data;
1440
1441 if (ff_layout_write_prepare_common(task, hdr))
1442 return;
1443
1444 rpc_call_start(task);
1445}
1446
1447static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data)
1448{
1449 struct nfs_pgio_header *hdr = data;
1450
Tom Haynesd67ae822014-12-11 17:02:04 -05001451 if (ff_layout_setup_sequence(hdr->ds_clp,
1452 &hdr->args.seq_args,
1453 &hdr->res.seq_res,
1454 task))
1455 return;
1456
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001457 if (ff_layout_write_prepare_common(task, hdr))
1458 return;
1459
Tom Haynesd67ae822014-12-11 17:02:04 -05001460 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
1461 hdr->args.lock_context, FMODE_WRITE) == -EIO)
1462 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
1463}
1464
1465static void ff_layout_write_call_done(struct rpc_task *task, void *data)
1466{
1467 struct nfs_pgio_header *hdr = data;
1468
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001469 nfs4_ff_layout_stat_io_end_write(task,
1470 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
1471 hdr->args.count, hdr->res.count,
1472 hdr->res.verf->committed);
1473
Tom Haynesd67ae822014-12-11 17:02:04 -05001474 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
1475 task->tk_status == 0) {
1476 nfs4_sequence_done(task, &hdr->res.seq_res);
1477 return;
1478 }
1479
1480 /* Note this may cause RPC to be resent */
1481 hdr->mds_ops->rpc_call_done(task, hdr);
1482}
1483
1484static void ff_layout_write_count_stats(struct rpc_task *task, void *data)
1485{
1486 struct nfs_pgio_header *hdr = data;
1487
1488 rpc_count_iostats_metrics(task,
1489 &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]);
1490}
1491
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001492static void ff_layout_commit_prepare_common(struct rpc_task *task,
1493 struct nfs_commit_data *cdata)
1494{
Trond Myklebust0b7baf92015-08-24 18:22:28 -04001495 nfs4_ff_layout_stat_io_start_write(cdata->inode,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001496 FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
Trond Myklebuste76d28d2015-08-20 13:12:51 -05001497 0, task->tk_start);
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001498}
1499
Tom Haynesd67ae822014-12-11 17:02:04 -05001500static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data)
1501{
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001502 ff_layout_commit_prepare_common(task, data);
Tom Haynesd67ae822014-12-11 17:02:04 -05001503 rpc_call_start(task);
1504}
1505
1506static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data)
1507{
1508 struct nfs_commit_data *wdata = data;
1509
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001510 if (ff_layout_setup_sequence(wdata->ds_clp,
Tom Haynesd67ae822014-12-11 17:02:04 -05001511 &wdata->args.seq_args,
1512 &wdata->res.seq_res,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001513 task))
1514 return;
1515 ff_layout_commit_prepare_common(task, data);
1516}
1517
1518static void ff_layout_commit_done(struct rpc_task *task, void *data)
1519{
1520 struct nfs_commit_data *cdata = data;
1521 struct nfs_page *req;
1522 __u64 count = 0;
1523
1524 if (task->tk_status == 0) {
1525 list_for_each_entry(req, &cdata->pages, wb_list)
1526 count += req->wb_bytes;
1527 }
1528
1529 nfs4_ff_layout_stat_io_end_write(task,
1530 FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
1531 count, count, NFS_FILE_SYNC);
1532
1533 pnfs_generic_write_commit_done(task, data);
Tom Haynesd67ae822014-12-11 17:02:04 -05001534}
1535
1536static void ff_layout_commit_count_stats(struct rpc_task *task, void *data)
1537{
1538 struct nfs_commit_data *cdata = data;
1539
1540 rpc_count_iostats_metrics(task,
1541 &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]);
1542}
1543
1544static const struct rpc_call_ops ff_layout_read_call_ops_v3 = {
1545 .rpc_call_prepare = ff_layout_read_prepare_v3,
1546 .rpc_call_done = ff_layout_read_call_done,
1547 .rpc_count_stats = ff_layout_read_count_stats,
1548 .rpc_release = pnfs_generic_rw_release,
1549};
1550
1551static const struct rpc_call_ops ff_layout_read_call_ops_v4 = {
1552 .rpc_call_prepare = ff_layout_read_prepare_v4,
1553 .rpc_call_done = ff_layout_read_call_done,
1554 .rpc_count_stats = ff_layout_read_count_stats,
1555 .rpc_release = pnfs_generic_rw_release,
1556};
1557
1558static const struct rpc_call_ops ff_layout_write_call_ops_v3 = {
1559 .rpc_call_prepare = ff_layout_write_prepare_v3,
1560 .rpc_call_done = ff_layout_write_call_done,
1561 .rpc_count_stats = ff_layout_write_count_stats,
1562 .rpc_release = pnfs_generic_rw_release,
1563};
1564
1565static const struct rpc_call_ops ff_layout_write_call_ops_v4 = {
1566 .rpc_call_prepare = ff_layout_write_prepare_v4,
1567 .rpc_call_done = ff_layout_write_call_done,
1568 .rpc_count_stats = ff_layout_write_count_stats,
1569 .rpc_release = pnfs_generic_rw_release,
1570};
1571
1572static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = {
1573 .rpc_call_prepare = ff_layout_commit_prepare_v3,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001574 .rpc_call_done = ff_layout_commit_done,
Tom Haynesd67ae822014-12-11 17:02:04 -05001575 .rpc_count_stats = ff_layout_commit_count_stats,
1576 .rpc_release = pnfs_generic_commit_release,
1577};
1578
1579static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = {
1580 .rpc_call_prepare = ff_layout_commit_prepare_v4,
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001581 .rpc_call_done = ff_layout_commit_done,
Tom Haynesd67ae822014-12-11 17:02:04 -05001582 .rpc_count_stats = ff_layout_commit_count_stats,
1583 .rpc_release = pnfs_generic_commit_release,
1584};
1585
1586static enum pnfs_try_status
1587ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1588{
1589 struct pnfs_layout_segment *lseg = hdr->lseg;
1590 struct nfs4_pnfs_ds *ds;
1591 struct rpc_clnt *ds_clnt;
1592 struct rpc_cred *ds_cred;
1593 loff_t offset = hdr->args.offset;
1594 u32 idx = hdr->pgio_mirror_idx;
1595 int vers;
1596 struct nfs_fh *fh;
1597
1598 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
1599 __func__, hdr->inode->i_ino,
1600 hdr->args.pgbase, (size_t)hdr->args.count, offset);
1601
1602 ds = nfs4_ff_layout_prepare_ds(lseg, idx, false);
1603 if (!ds)
1604 goto out_failed;
1605
1606 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1607 hdr->inode);
1608 if (IS_ERR(ds_clnt))
1609 goto out_failed;
1610
1611 ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
1612 if (IS_ERR(ds_cred))
1613 goto out_failed;
1614
1615 vers = nfs4_ff_layout_ds_version(lseg, idx);
1616
1617 dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__,
1618 ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers);
1619
1620 atomic_inc(&ds->ds_clp->cl_count);
1621 hdr->ds_clp = ds->ds_clp;
1622 fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
1623 if (fh)
1624 hdr->args.fh = fh;
Tom Haynesd67ae822014-12-11 17:02:04 -05001625 /*
1626 * Note that if we ever decide to split across DSes,
1627 * then we may need to handle dense-like offsets.
1628 */
1629 hdr->args.offset = offset;
1630 hdr->mds_offset = offset;
1631
1632 /* Perform an asynchronous read to ds */
1633 nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
1634 vers == 3 ? &ff_layout_read_call_ops_v3 :
1635 &ff_layout_read_call_ops_v4,
1636 0, RPC_TASK_SOFTCONN);
1637
1638 return PNFS_ATTEMPTED;
1639
1640out_failed:
1641 if (ff_layout_has_available_ds(lseg))
1642 return PNFS_TRY_AGAIN;
1643 return PNFS_NOT_ATTEMPTED;
1644}
1645
1646/* Perform async writes. */
1647static enum pnfs_try_status
1648ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1649{
1650 struct pnfs_layout_segment *lseg = hdr->lseg;
1651 struct nfs4_pnfs_ds *ds;
1652 struct rpc_clnt *ds_clnt;
1653 struct rpc_cred *ds_cred;
1654 loff_t offset = hdr->args.offset;
1655 int vers;
1656 struct nfs_fh *fh;
1657 int idx = hdr->pgio_mirror_idx;
1658
1659 ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
1660 if (!ds)
1661 return PNFS_NOT_ATTEMPTED;
1662
1663 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1664 hdr->inode);
1665 if (IS_ERR(ds_clnt))
1666 return PNFS_NOT_ATTEMPTED;
1667
1668 ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
1669 if (IS_ERR(ds_cred))
1670 return PNFS_NOT_ATTEMPTED;
1671
1672 vers = nfs4_ff_layout_ds_version(lseg, idx);
1673
1674 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n",
1675 __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
1676 offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count),
1677 vers);
1678
1679 hdr->pgio_done_cb = ff_layout_write_done_cb;
1680 atomic_inc(&ds->ds_clp->cl_count);
1681 hdr->ds_clp = ds->ds_clp;
1682 hdr->ds_commit_idx = idx;
1683 fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
1684 if (fh)
1685 hdr->args.fh = fh;
1686
1687 /*
1688 * Note that if we ever decide to split across DSes,
1689 * then we may need to handle dense-like offsets.
1690 */
1691 hdr->args.offset = offset;
1692
1693 /* Perform an asynchronous write */
1694 nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
1695 vers == 3 ? &ff_layout_write_call_ops_v3 :
1696 &ff_layout_write_call_ops_v4,
1697 sync, RPC_TASK_SOFTCONN);
1698 return PNFS_ATTEMPTED;
1699}
1700
Tom Haynesd67ae822014-12-11 17:02:04 -05001701static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1702{
1703 return i;
1704}
1705
1706static struct nfs_fh *
1707select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1708{
1709 struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
1710
1711 /* FIXME: Assume that there is only one NFS version available
1712 * for the DS.
1713 */
1714 return &flseg->mirror_array[i]->fh_versions[0];
1715}
1716
1717static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1718{
1719 struct pnfs_layout_segment *lseg = data->lseg;
1720 struct nfs4_pnfs_ds *ds;
1721 struct rpc_clnt *ds_clnt;
1722 struct rpc_cred *ds_cred;
1723 u32 idx;
1724 int vers;
1725 struct nfs_fh *fh;
1726
1727 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
1728 ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
1729 if (!ds)
1730 goto out_err;
1731
1732 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1733 data->inode);
1734 if (IS_ERR(ds_clnt))
1735 goto out_err;
1736
1737 ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred);
1738 if (IS_ERR(ds_cred))
1739 goto out_err;
1740
1741 vers = nfs4_ff_layout_ds_version(lseg, idx);
1742
1743 dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__,
1744 data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count),
1745 vers);
1746 data->commit_done_cb = ff_layout_commit_done_cb;
1747 data->cred = ds_cred;
1748 atomic_inc(&ds->ds_clp->cl_count);
1749 data->ds_clp = ds->ds_clp;
1750 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
1751 if (fh)
1752 data->args.fh = fh;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +08001753
Tom Haynesd67ae822014-12-11 17:02:04 -05001754 return nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
1755 vers == 3 ? &ff_layout_commit_call_ops_v3 :
1756 &ff_layout_commit_call_ops_v4,
1757 how, RPC_TASK_SOFTCONN);
1758out_err:
1759 pnfs_generic_prepare_to_resend_writes(data);
1760 pnfs_generic_commit_release(data);
1761 return -EAGAIN;
1762}
1763
1764static int
1765ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
1766 int how, struct nfs_commit_info *cinfo)
1767{
1768 return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
1769 ff_layout_initiate_commit);
1770}
1771
1772static struct pnfs_ds_commit_info *
1773ff_layout_get_ds_info(struct inode *inode)
1774{
1775 struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
1776
1777 if (layout == NULL)
1778 return NULL;
1779
1780 return &FF_LAYOUT_FROM_HDR(layout)->commit_info;
1781}
1782
1783static void
Trond Myklebustfc877012015-03-09 17:25:14 -04001784ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d)
Tom Haynesd67ae822014-12-11 17:02:04 -05001785{
1786 nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds,
1787 id_node));
1788}
1789
1790static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo,
1791 struct xdr_stream *xdr,
1792 const struct nfs4_layoutreturn_args *args)
1793{
1794 struct pnfs_layout_hdr *hdr = &flo->generic_hdr;
1795 __be32 *start;
1796 int count = 0, ret = 0;
1797
1798 start = xdr_reserve_space(xdr, 4);
1799 if (unlikely(!start))
1800 return -E2BIG;
1801
1802 /* This assume we always return _ALL_ layouts */
1803 spin_lock(&hdr->plh_inode->i_lock);
1804 ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range);
1805 spin_unlock(&hdr->plh_inode->i_lock);
1806
1807 *start = cpu_to_be32(count);
1808
1809 return ret;
1810}
1811
1812/* report nothing for now */
1813static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo,
1814 struct xdr_stream *xdr,
1815 const struct nfs4_layoutreturn_args *args)
1816{
1817 __be32 *p;
1818
1819 p = xdr_reserve_space(xdr, 4);
1820 if (likely(p))
1821 *p = cpu_to_be32(0);
1822}
1823
1824static struct nfs4_deviceid_node *
1825ff_layout_alloc_deviceid_node(struct nfs_server *server,
1826 struct pnfs_device *pdev, gfp_t gfp_flags)
1827{
1828 struct nfs4_ff_layout_ds *dsaddr;
1829
1830 dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags);
1831 if (!dsaddr)
1832 return NULL;
1833 return &dsaddr->id_node;
1834}
1835
1836static void
1837ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo,
1838 struct xdr_stream *xdr,
1839 const struct nfs4_layoutreturn_args *args)
1840{
1841 struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo);
1842 __be32 *start;
1843
1844 dprintk("%s: Begin\n", __func__);
1845 start = xdr_reserve_space(xdr, 4);
1846 BUG_ON(!start);
1847
1848 if (ff_layout_encode_ioerr(flo, xdr, args))
1849 goto out;
1850
1851 ff_layout_encode_iostats(flo, xdr, args);
1852out:
1853 *start = cpu_to_be32((xdr->p - start - 1) * 4);
1854 dprintk("%s: Return\n", __func__);
1855}
1856
Peng Tao27c43062015-06-23 19:52:02 +08001857static int
1858ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen)
1859{
1860 const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
1861
1862 return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
1863}
1864
1865static size_t
1866ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf,
1867 const int buflen)
1868{
1869 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
1870 const struct in6_addr *addr = &sin6->sin6_addr;
1871
1872 /*
1873 * RFC 4291, Section 2.2.2
1874 *
1875 * Shorthanded ANY address
1876 */
1877 if (ipv6_addr_any(addr))
1878 return snprintf(buf, buflen, "::");
1879
1880 /*
1881 * RFC 4291, Section 2.2.2
1882 *
1883 * Shorthanded loopback address
1884 */
1885 if (ipv6_addr_loopback(addr))
1886 return snprintf(buf, buflen, "::1");
1887
1888 /*
1889 * RFC 4291, Section 2.2.3
1890 *
1891 * Special presentation address format for mapped v4
1892 * addresses.
1893 */
1894 if (ipv6_addr_v4mapped(addr))
1895 return snprintf(buf, buflen, "::ffff:%pI4",
1896 &addr->s6_addr32[3]);
1897
1898 /*
1899 * RFC 4291, Section 2.2.1
1900 */
1901 return snprintf(buf, buflen, "%pI6c", addr);
1902}
1903
1904/* Derived from rpc_sockaddr2uaddr */
1905static void
1906ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da)
1907{
1908 struct sockaddr *sap = (struct sockaddr *)&da->da_addr;
1909 char portbuf[RPCBIND_MAXUADDRPLEN];
1910 char addrbuf[RPCBIND_MAXUADDRLEN];
1911 char *netid;
1912 unsigned short port;
1913 int len, netid_len;
1914 __be32 *p;
1915
1916 switch (sap->sa_family) {
1917 case AF_INET:
1918 if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
1919 return;
1920 port = ntohs(((struct sockaddr_in *)sap)->sin_port);
1921 netid = "tcp";
1922 netid_len = 3;
1923 break;
1924 case AF_INET6:
1925 if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
1926 return;
1927 port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
1928 netid = "tcp6";
1929 netid_len = 4;
1930 break;
1931 default:
1932 /* we only support tcp and tcp6 */
1933 WARN_ON_ONCE(1);
1934 return;
1935 }
1936
1937 snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff);
1938 len = strlcat(addrbuf, portbuf, sizeof(addrbuf));
1939
1940 p = xdr_reserve_space(xdr, 4 + netid_len);
1941 xdr_encode_opaque(p, netid, netid_len);
1942
1943 p = xdr_reserve_space(xdr, 4 + len);
1944 xdr_encode_opaque(p, addrbuf, len);
1945}
1946
1947static void
1948ff_layout_encode_nfstime(struct xdr_stream *xdr,
1949 ktime_t t)
1950{
1951 struct timespec64 ts;
1952 __be32 *p;
1953
1954 p = xdr_reserve_space(xdr, 12);
1955 ts = ktime_to_timespec64(t);
1956 p = xdr_encode_hyper(p, ts.tv_sec);
1957 *p++ = cpu_to_be32(ts.tv_nsec);
1958}
1959
1960static void
1961ff_layout_encode_io_latency(struct xdr_stream *xdr,
1962 struct nfs4_ff_io_stat *stat)
1963{
1964 __be32 *p;
1965
1966 p = xdr_reserve_space(xdr, 5 * 8);
1967 p = xdr_encode_hyper(p, stat->ops_requested);
1968 p = xdr_encode_hyper(p, stat->bytes_requested);
1969 p = xdr_encode_hyper(p, stat->ops_completed);
1970 p = xdr_encode_hyper(p, stat->bytes_completed);
1971 p = xdr_encode_hyper(p, stat->bytes_not_delivered);
1972 ff_layout_encode_nfstime(xdr, stat->total_busy_time);
1973 ff_layout_encode_nfstime(xdr, stat->aggregate_completion_time);
1974}
1975
1976static void
1977ff_layout_encode_layoutstats(struct xdr_stream *xdr,
1978 struct nfs42_layoutstat_args *args,
1979 struct nfs42_layoutstat_devinfo *devinfo)
1980{
1981 struct nfs4_ff_layout_mirror *mirror = devinfo->layout_private;
1982 struct nfs4_pnfs_ds_addr *da;
1983 struct nfs4_pnfs_ds *ds = mirror->mirror_ds->ds;
1984 struct nfs_fh *fh = &mirror->fh_versions[0];
1985 __be32 *p, *start;
1986
1987 da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node);
1988 dprintk("%s: DS %s: encoding address %s\n",
1989 __func__, ds->ds_remotestr, da->da_remotestr);
1990 /* layoutupdate length */
1991 start = xdr_reserve_space(xdr, 4);
1992 /* netaddr4 */
1993 ff_layout_encode_netaddr(xdr, da);
1994 /* nfs_fh4 */
1995 p = xdr_reserve_space(xdr, 4 + fh->size);
1996 xdr_encode_opaque(p, fh->data, fh->size);
1997 /* ff_io_latency4 read */
1998 spin_lock(&mirror->lock);
1999 ff_layout_encode_io_latency(xdr, &mirror->read_stat.io_stat);
2000 /* ff_io_latency4 write */
2001 ff_layout_encode_io_latency(xdr, &mirror->write_stat.io_stat);
2002 spin_unlock(&mirror->lock);
2003 /* nfstime4 */
2004 ff_layout_encode_nfstime(xdr, ktime_sub(ktime_get(), mirror->start_time));
2005 /* bool */
2006 p = xdr_reserve_space(xdr, 4);
2007 *p = cpu_to_be32(false);
2008
2009 *start = cpu_to_be32((xdr->p - start - 1) * 4);
2010}
2011
Trond Myklebust266d12d2015-08-24 20:03:17 -04002012static int
Peng Taoad4dc53e2015-06-23 19:52:01 +08002013ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args *args,
Trond Myklebust266d12d2015-08-24 20:03:17 -04002014 struct pnfs_layout_hdr *lo,
2015 int dev_limit)
Peng Taoad4dc53e2015-06-23 19:52:01 +08002016{
Trond Myklebust266d12d2015-08-24 20:03:17 -04002017 struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
Peng Taoad4dc53e2015-06-23 19:52:01 +08002018 struct nfs4_ff_layout_mirror *mirror;
2019 struct nfs4_deviceid_node *dev;
2020 struct nfs42_layoutstat_devinfo *devinfo;
Trond Myklebust266d12d2015-08-24 20:03:17 -04002021 int i = 0;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002022
Trond Myklebust266d12d2015-08-24 20:03:17 -04002023 list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
2024 if (i >= dev_limit)
Peng Taoad4dc53e2015-06-23 19:52:01 +08002025 break;
Trond Myklebust266d12d2015-08-24 20:03:17 -04002026 if (!mirror->mirror_ds)
Peng Tao27c43062015-06-23 19:52:02 +08002027 continue;
Trond Myklebust266d12d2015-08-24 20:03:17 -04002028 /* mirror refcount put in cleanup_layoutstats */
2029 if (!atomic_inc_not_zero(&mirror->ref))
2030 continue;
2031 dev = &mirror->mirror_ds->id_node;
2032 devinfo = &args->devinfo[i];
Peng Taoad4dc53e2015-06-23 19:52:01 +08002033 memcpy(&devinfo->dev_id, &dev->deviceid, NFS4_DEVICEID4_SIZE);
Trond Myklebust266d12d2015-08-24 20:03:17 -04002034 devinfo->offset = 0;
2035 devinfo->length = NFS4_MAX_UINT64;
Peng Taod099d7b2015-08-10 16:47:32 +08002036 devinfo->read_count = mirror->read_stat.io_stat.ops_completed;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002037 devinfo->read_bytes = mirror->read_stat.io_stat.bytes_completed;
Peng Taod099d7b2015-08-10 16:47:32 +08002038 devinfo->write_count = mirror->write_stat.io_stat.ops_completed;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002039 devinfo->write_bytes = mirror->write_stat.io_stat.bytes_completed;
2040 devinfo->layout_type = LAYOUT_FLEX_FILES;
Peng Tao27c43062015-06-23 19:52:02 +08002041 devinfo->layoutstats_encode = ff_layout_encode_layoutstats;
2042 devinfo->layout_private = mirror;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002043
Trond Myklebust266d12d2015-08-24 20:03:17 -04002044 i++;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002045 }
Trond Myklebust266d12d2015-08-24 20:03:17 -04002046 return i;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002047}
2048
2049static int
2050ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
2051{
Trond Myklebust266d12d2015-08-24 20:03:17 -04002052 struct nfs4_flexfile_layout *ff_layout;
2053 struct nfs4_ff_layout_mirror *mirror;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002054 int dev_count = 0;
2055
2056 spin_lock(&args->inode->i_lock);
Trond Myklebust266d12d2015-08-24 20:03:17 -04002057 ff_layout = FF_LAYOUT_FROM_HDR(NFS_I(args->inode)->layout);
2058 list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
2059 if (atomic_read(&mirror->ref) != 0)
2060 dev_count ++;
Peng Taoad4dc53e2015-06-23 19:52:01 +08002061 }
2062 spin_unlock(&args->inode->i_lock);
2063 /* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */
2064 if (dev_count > PNFS_LAYOUTSTATS_MAXDEV) {
2065 dprintk("%s: truncating devinfo to limit (%d:%d)\n",
2066 __func__, dev_count, PNFS_LAYOUTSTATS_MAXDEV);
2067 dev_count = PNFS_LAYOUTSTATS_MAXDEV;
2068 }
Trond Myklebust266d12d2015-08-24 20:03:17 -04002069 args->devinfo = kmalloc_array(dev_count, sizeof(*args->devinfo), GFP_NOIO);
Peng Taoad4dc53e2015-06-23 19:52:01 +08002070 if (!args->devinfo)
2071 return -ENOMEM;
2072
Peng Taoad4dc53e2015-06-23 19:52:01 +08002073 spin_lock(&args->inode->i_lock);
Trond Myklebust266d12d2015-08-24 20:03:17 -04002074 args->num_dev = ff_layout_mirror_prepare_stats(args,
2075 &ff_layout->generic_hdr, dev_count);
Peng Taoad4dc53e2015-06-23 19:52:01 +08002076 spin_unlock(&args->inode->i_lock);
Peng Taoad4dc53e2015-06-23 19:52:01 +08002077
2078 return 0;
2079}
2080
Peng Tao27c43062015-06-23 19:52:02 +08002081static void
2082ff_layout_cleanup_layoutstats(struct nfs42_layoutstat_data *data)
2083{
2084 struct nfs4_ff_layout_mirror *mirror;
2085 int i;
2086
2087 for (i = 0; i < data->args.num_dev; i++) {
2088 mirror = data->args.devinfo[i].layout_private;
2089 data->args.devinfo[i].layout_private = NULL;
Trond Myklebust0b7baf92015-08-24 18:22:28 -04002090 ff_layout_put_mirror(mirror);
Peng Tao27c43062015-06-23 19:52:02 +08002091 }
2092}
2093
Tom Haynesd67ae822014-12-11 17:02:04 -05002094static struct pnfs_layoutdriver_type flexfilelayout_type = {
2095 .id = LAYOUT_FLEX_FILES,
2096 .name = "LAYOUT_FLEX_FILES",
2097 .owner = THIS_MODULE,
2098 .alloc_layout_hdr = ff_layout_alloc_layout_hdr,
2099 .free_layout_hdr = ff_layout_free_layout_hdr,
2100 .alloc_lseg = ff_layout_alloc_lseg,
2101 .free_lseg = ff_layout_free_lseg,
Trond Myklebust0762ed22015-08-25 17:38:25 -04002102 .add_lseg = ff_layout_add_lseg,
Tom Haynesd67ae822014-12-11 17:02:04 -05002103 .pg_read_ops = &ff_layout_pg_read_ops,
2104 .pg_write_ops = &ff_layout_pg_write_ops,
2105 .get_ds_info = ff_layout_get_ds_info,
Trond Myklebustfc877012015-03-09 17:25:14 -04002106 .free_deviceid_node = ff_layout_free_deviceid_node,
Tom Haynes338d00c2015-02-17 14:58:15 -08002107 .mark_request_commit = pnfs_layout_mark_request_commit,
Tom Haynesd67ae822014-12-11 17:02:04 -05002108 .clear_request_commit = pnfs_generic_clear_request_commit,
2109 .scan_commit_lists = pnfs_generic_scan_commit_lists,
2110 .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
2111 .commit_pagelist = ff_layout_commit_pagelist,
2112 .read_pagelist = ff_layout_read_pagelist,
2113 .write_pagelist = ff_layout_write_pagelist,
2114 .alloc_deviceid_node = ff_layout_alloc_deviceid_node,
2115 .encode_layoutreturn = ff_layout_encode_layoutreturn,
Trond Myklebust5bb89b42015-03-25 14:14:42 -04002116 .sync = pnfs_nfs_generic_sync,
Peng Taoad4dc53e2015-06-23 19:52:01 +08002117 .prepare_layoutstats = ff_layout_prepare_layoutstats,
Peng Tao27c43062015-06-23 19:52:02 +08002118 .cleanup_layoutstats = ff_layout_cleanup_layoutstats,
Tom Haynesd67ae822014-12-11 17:02:04 -05002119};
2120
2121static int __init nfs4flexfilelayout_init(void)
2122{
2123 printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n",
2124 __func__);
2125 return pnfs_register_layoutdriver(&flexfilelayout_type);
2126}
2127
2128static void __exit nfs4flexfilelayout_exit(void)
2129{
2130 printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n",
2131 __func__);
2132 pnfs_unregister_layoutdriver(&flexfilelayout_type);
2133}
2134
2135MODULE_ALIAS("nfs-layouttype4-4");
2136
2137MODULE_LICENSE("GPL");
2138MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");
2139
2140module_init(nfs4flexfilelayout_init);
2141module_exit(nfs4flexfilelayout_exit);