]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/nfs/flexfilelayout/flexfilelayout.c
Merge remote-tracking branches 'asoc/topic/rt5659', 'asoc/topic/rt5660', 'asoc/topic...
[mirror_ubuntu-hirsute-kernel.git] / fs / nfs / flexfilelayout / flexfilelayout.c
CommitLineData
d67ae825
TH
1/*
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>
d67ae825
TH
14
15#include "flexfilelayout.h"
16#include "../nfs4session.h"
40c64c26 17#include "../nfs4idmap.h"
d67ae825
TH
18#include "../internal.h"
19#include "../delegation.h"
20#include "../nfs4trace.h"
21#include "../iostat.h"
22#include "../nfs.h"
ad4dc53e 23#include "../nfs42.h"
d67ae825
TH
24
25#define NFSDBG_FACILITY NFSDBG_PNFS_LD
26
27#define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)
28
90a0be00
JL
29static struct group_info *ff_zero_group;
30
d67ae825
TH
31static struct pnfs_layout_hdr *
32ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
33{
34 struct nfs4_flexfile_layout *ffl;
35
36 ffl = kzalloc(sizeof(*ffl), gfp_flags);
37 if (ffl) {
38 INIT_LIST_HEAD(&ffl->error_list);
266d12d4 39 INIT_LIST_HEAD(&ffl->mirrors);
1c8d477a 40 ffl->last_report_time = ktime_get();
d67ae825
TH
41 return &ffl->generic_hdr;
42 } else
43 return NULL;
44}
45
46static void
47ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo)
48{
49 struct nfs4_ff_layout_ds_err *err, *n;
50
51 list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list,
52 list) {
53 list_del(&err->list);
54 kfree(err);
55 }
56 kfree(FF_LAYOUT_FROM_HDR(lo));
57}
58
93b717fd 59static int decode_pnfs_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
d67ae825
TH
60{
61 __be32 *p;
62
63 p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE);
64 if (unlikely(p == NULL))
65 return -ENOBUFS;
93b717fd
TM
66 stateid->type = NFS4_PNFS_DS_STATEID_TYPE;
67 memcpy(stateid->data, p, NFS4_STATEID_SIZE);
d67ae825
TH
68 dprintk("%s: stateid id= [%x%x%x%x]\n", __func__,
69 p[0], p[1], p[2], p[3]);
70 return 0;
71}
72
73static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid)
74{
75 __be32 *p;
76
77 p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
78 if (unlikely(!p))
79 return -ENOBUFS;
80 memcpy(devid, p, NFS4_DEVICEID4_SIZE);
81 nfs4_print_deviceid(devid);
82 return 0;
83}
84
85static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
86{
87 __be32 *p;
88
89 p = xdr_inline_decode(xdr, 4);
90 if (unlikely(!p))
91 return -ENOBUFS;
92 fh->size = be32_to_cpup(p++);
93 if (fh->size > sizeof(struct nfs_fh)) {
94 printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n",
95 fh->size);
96 return -EOVERFLOW;
97 }
98 /* fh.data */
99 p = xdr_inline_decode(xdr, fh->size);
100 if (unlikely(!p))
101 return -ENOBUFS;
102 memcpy(&fh->data, p, fh->size);
103 dprintk("%s: fh len %d\n", __func__, fh->size);
104
105 return 0;
106}
107
108/*
109 * Currently only stringified uids and gids are accepted.
110 * I.e., kerberos is not supported to the DSes, so no pricipals.
111 *
112 * That means that one common function will suffice, but when
113 * principals are added, this should be split to accomodate
114 * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid().
115 */
116static int
117decode_name(struct xdr_stream *xdr, u32 *id)
118{
119 __be32 *p;
120 int len;
121
122 /* opaque_length(4)*/
123 p = xdr_inline_decode(xdr, 4);
124 if (unlikely(!p))
125 return -ENOBUFS;
126 len = be32_to_cpup(p++);
127 if (len < 0)
128 return -EINVAL;
129
130 dprintk("%s: len %u\n", __func__, len);
131
132 /* opaque body */
133 p = xdr_inline_decode(xdr, len);
134 if (unlikely(!p))
135 return -ENOBUFS;
136
137 if (!nfs_map_string_to_numeric((char *)p, len, id))
138 return -EINVAL;
139
140 return 0;
141}
142
266d12d4
TM
143static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
144 const struct nfs4_ff_layout_mirror *m2)
145{
146 int i, j;
147
148 if (m1->fh_versions_cnt != m2->fh_versions_cnt)
149 return false;
150 for (i = 0; i < m1->fh_versions_cnt; i++) {
151 bool found_fh = false;
86fb449b 152 for (j = 0; j < m2->fh_versions_cnt; j++) {
266d12d4
TM
153 if (nfs_compare_fh(&m1->fh_versions[i],
154 &m2->fh_versions[j]) == 0) {
155 found_fh = true;
156 break;
157 }
158 }
159 if (!found_fh)
160 return false;
161 }
162 return true;
163}
164
165static struct nfs4_ff_layout_mirror *
166ff_layout_add_mirror(struct pnfs_layout_hdr *lo,
167 struct nfs4_ff_layout_mirror *mirror)
168{
169 struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
170 struct nfs4_ff_layout_mirror *pos;
171 struct inode *inode = lo->plh_inode;
172
173 spin_lock(&inode->i_lock);
174 list_for_each_entry(pos, &ff_layout->mirrors, mirrors) {
175 if (mirror->mirror_ds != pos->mirror_ds)
176 continue;
177 if (!ff_mirror_match_fh(mirror, pos))
178 continue;
179 if (atomic_inc_not_zero(&pos->ref)) {
180 spin_unlock(&inode->i_lock);
181 return pos;
182 }
183 }
184 list_add(&mirror->mirrors, &ff_layout->mirrors);
185 mirror->layout = lo;
186 spin_unlock(&inode->i_lock);
187 return mirror;
188}
189
e3b1df2d 190static void
266d12d4
TM
191ff_layout_remove_mirror(struct nfs4_ff_layout_mirror *mirror)
192{
193 struct inode *inode;
194 if (mirror->layout == NULL)
195 return;
196 inode = mirror->layout->plh_inode;
197 spin_lock(&inode->i_lock);
198 list_del(&mirror->mirrors);
199 spin_unlock(&inode->i_lock);
200 mirror->layout = NULL;
201}
202
28a0d72c
TM
203static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
204{
205 struct nfs4_ff_layout_mirror *mirror;
206
207 mirror = kzalloc(sizeof(*mirror), gfp_flags);
208 if (mirror != NULL) {
209 spin_lock_init(&mirror->lock);
210 atomic_set(&mirror->ref, 1);
266d12d4 211 INIT_LIST_HEAD(&mirror->mirrors);
28a0d72c
TM
212 }
213 return mirror;
214}
215
216static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
217{
3064b686
JL
218 struct rpc_cred *cred;
219
266d12d4 220 ff_layout_remove_mirror(mirror);
28a0d72c 221 kfree(mirror->fh_versions);
3064b686
JL
222 cred = rcu_access_pointer(mirror->ro_cred);
223 if (cred)
224 put_rpccred(cred);
225 cred = rcu_access_pointer(mirror->rw_cred);
226 if (cred)
227 put_rpccred(cred);
28a0d72c
TM
228 nfs4_ff_layout_put_deviceid(mirror->mirror_ds);
229 kfree(mirror);
230}
231
232static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror *mirror)
233{
234 if (mirror != NULL && atomic_dec_and_test(&mirror->ref))
235 ff_layout_free_mirror(mirror);
236}
237
d67ae825
TH
238static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls)
239{
240 int i;
241
242 if (fls->mirror_array) {
243 for (i = 0; i < fls->mirror_array_cnt; i++) {
244 /* normally mirror_ds is freed in
245 * .free_deviceid_node but we still do it here
246 * for .alloc_lseg error path */
28a0d72c 247 ff_layout_put_mirror(fls->mirror_array[i]);
d67ae825
TH
248 }
249 kfree(fls->mirror_array);
250 fls->mirror_array = NULL;
251 }
252}
253
254static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr)
255{
256 int ret = 0;
257
258 dprintk("--> %s\n", __func__);
259
260 /* FIXME: remove this check when layout segment support is added */
261 if (lgr->range.offset != 0 ||
262 lgr->range.length != NFS4_MAX_UINT64) {
263 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
264 __func__);
265 ret = -EINVAL;
266 }
267
268 dprintk("--> %s returns %d\n", __func__, ret);
269 return ret;
270}
271
272static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls)
273{
274 if (fls) {
275 ff_layout_free_mirror_array(fls);
276 kfree(fls);
277 }
278}
279
0762ed2c
TM
280static bool
281ff_lseg_range_is_after(const struct pnfs_layout_range *l1,
282 const struct pnfs_layout_range *l2)
283{
284 u64 end1, end2;
285
286 if (l1->iomode != l2->iomode)
287 return l1->iomode != IOMODE_READ;
288 end1 = pnfs_calc_offset_end(l1->offset, l1->length);
289 end2 = pnfs_calc_offset_end(l2->offset, l2->length);
290 if (end1 < l2->offset)
291 return false;
292 if (end2 < l1->offset)
293 return true;
294 return l2->offset <= l1->offset;
295}
296
297static bool
298ff_lseg_merge(struct pnfs_layout_segment *new,
299 struct pnfs_layout_segment *old)
300{
301 u64 new_end, old_end;
302
ee26bdd6
JL
303 if (test_bit(NFS_LSEG_LAYOUTRETURN, &old->pls_flags))
304 return false;
0762ed2c
TM
305 if (new->pls_range.iomode != old->pls_range.iomode)
306 return false;
307 old_end = pnfs_calc_offset_end(old->pls_range.offset,
308 old->pls_range.length);
309 if (old_end < new->pls_range.offset)
310 return false;
311 new_end = pnfs_calc_offset_end(new->pls_range.offset,
312 new->pls_range.length);
313 if (new_end < old->pls_range.offset)
314 return false;
315
316 /* Mergeable: copy info from 'old' to 'new' */
317 if (new_end < old_end)
318 new_end = old_end;
319 if (new->pls_range.offset < old->pls_range.offset)
320 new->pls_range.offset = old->pls_range.offset;
321 new->pls_range.length = pnfs_calc_offset_length(new->pls_range.offset,
322 new_end);
323 if (test_bit(NFS_LSEG_ROC, &old->pls_flags))
324 set_bit(NFS_LSEG_ROC, &new->pls_flags);
0762ed2c
TM
325 return true;
326}
327
328static void
329ff_layout_add_lseg(struct pnfs_layout_hdr *lo,
330 struct pnfs_layout_segment *lseg,
331 struct list_head *free_me)
332{
333 pnfs_generic_layout_insert_lseg(lo, lseg,
334 ff_lseg_range_is_after,
335 ff_lseg_merge,
336 free_me);
337}
338
d67ae825
TH
339static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls)
340{
d67ae825
TH
341 int i, j;
342
343 for (i = 0; i < fls->mirror_array_cnt - 1; i++) {
344 for (j = i + 1; j < fls->mirror_array_cnt; j++)
345 if (fls->mirror_array[i]->efficiency <
455b6ee6
FF
346 fls->mirror_array[j]->efficiency)
347 swap(fls->mirror_array[i],
348 fls->mirror_array[j]);
d67ae825
TH
349 }
350}
351
260074cd
TM
352static void ff_layout_mark_devices_valid(struct nfs4_ff_layout_segment *fls)
353{
354 struct nfs4_deviceid_node *node;
355 int i;
356
357 if (!(fls->flags & FF_FLAGS_NO_IO_THRU_MDS))
358 return;
359 for (i = 0; i < fls->mirror_array_cnt; i++) {
360 node = &fls->mirror_array[i]->mirror_ds->id_node;
361 clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
362 }
363}
364
d67ae825
TH
365static struct pnfs_layout_segment *
366ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
367 struct nfs4_layoutget_res *lgr,
368 gfp_t gfp_flags)
369{
370 struct pnfs_layout_segment *ret;
371 struct nfs4_ff_layout_segment *fls = NULL;
372 struct xdr_stream stream;
373 struct xdr_buf buf;
374 struct page *scratch;
375 u64 stripe_unit;
376 u32 mirror_array_cnt;
377 __be32 *p;
378 int i, rc;
379
380 dprintk("--> %s\n", __func__);
381 scratch = alloc_page(gfp_flags);
382 if (!scratch)
383 return ERR_PTR(-ENOMEM);
384
385 xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages,
386 lgr->layoutp->len);
387 xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
388
389 /* stripe unit and mirror_array_cnt */
390 rc = -EIO;
391 p = xdr_inline_decode(&stream, 8 + 4);
392 if (!p)
393 goto out_err_free;
394
395 p = xdr_decode_hyper(p, &stripe_unit);
396 mirror_array_cnt = be32_to_cpup(p++);
397 dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__,
398 stripe_unit, mirror_array_cnt);
399
400 if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT ||
401 mirror_array_cnt == 0)
402 goto out_err_free;
403
404 rc = -ENOMEM;
405 fls = kzalloc(sizeof(*fls), gfp_flags);
406 if (!fls)
407 goto out_err_free;
408
409 fls->mirror_array_cnt = mirror_array_cnt;
410 fls->stripe_unit = stripe_unit;
411 fls->mirror_array = kcalloc(fls->mirror_array_cnt,
412 sizeof(fls->mirror_array[0]), gfp_flags);
413 if (fls->mirror_array == NULL)
414 goto out_err_free;
415
416 for (i = 0; i < fls->mirror_array_cnt; i++) {
266d12d4 417 struct nfs4_ff_layout_mirror *mirror;
d67ae825
TH
418 struct nfs4_deviceid devid;
419 struct nfs4_deviceid_node *idnode;
90a0be00 420 struct auth_cred acred = { .group_info = ff_zero_group };
3064b686 421 struct rpc_cred __rcu *cred;
90a0be00 422 u32 ds_count, fh_count, id;
d67ae825
TH
423 int j;
424
425 rc = -EIO;
426 p = xdr_inline_decode(&stream, 4);
427 if (!p)
428 goto out_err_free;
429 ds_count = be32_to_cpup(p);
430
431 /* FIXME: allow for striping? */
432 if (ds_count != 1)
433 goto out_err_free;
434
28a0d72c 435 fls->mirror_array[i] = ff_layout_alloc_mirror(gfp_flags);
d67ae825
TH
436 if (fls->mirror_array[i] == NULL) {
437 rc = -ENOMEM;
438 goto out_err_free;
439 }
440
d67ae825
TH
441 fls->mirror_array[i]->ds_count = ds_count;
442
443 /* deviceid */
444 rc = decode_deviceid(&stream, &devid);
445 if (rc)
446 goto out_err_free;
447
448 idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode),
449 &devid, lh->plh_lc_cred,
450 gfp_flags);
451 /*
452 * upon success, mirror_ds is allocated by previous
453 * getdeviceinfo, or newly by .alloc_deviceid_node
454 * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure
455 */
456 if (idnode)
457 fls->mirror_array[i]->mirror_ds =
458 FF_LAYOUT_MIRROR_DS(idnode);
459 else
460 goto out_err_free;
461
462 /* efficiency */
463 rc = -EIO;
464 p = xdr_inline_decode(&stream, 4);
465 if (!p)
466 goto out_err_free;
467 fls->mirror_array[i]->efficiency = be32_to_cpup(p);
468
469 /* stateid */
93b717fd 470 rc = decode_pnfs_stateid(&stream, &fls->mirror_array[i]->stateid);
d67ae825
TH
471 if (rc)
472 goto out_err_free;
473
474 /* fh */
475 p = xdr_inline_decode(&stream, 4);
476 if (!p)
477 goto out_err_free;
478 fh_count = be32_to_cpup(p);
479
480 fls->mirror_array[i]->fh_versions =
481 kzalloc(fh_count * sizeof(struct nfs_fh),
482 gfp_flags);
483 if (fls->mirror_array[i]->fh_versions == NULL) {
484 rc = -ENOMEM;
485 goto out_err_free;
486 }
487
488 for (j = 0; j < fh_count; j++) {
489 rc = decode_nfs_fh(&stream,
490 &fls->mirror_array[i]->fh_versions[j]);
491 if (rc)
492 goto out_err_free;
493 }
494
495 fls->mirror_array[i]->fh_versions_cnt = fh_count;
496
497 /* user */
90a0be00 498 rc = decode_name(&stream, &id);
d67ae825
TH
499 if (rc)
500 goto out_err_free;
501
90a0be00
JL
502 acred.uid = make_kuid(&init_user_ns, id);
503
d67ae825 504 /* group */
90a0be00 505 rc = decode_name(&stream, &id);
d67ae825
TH
506 if (rc)
507 goto out_err_free;
508
90a0be00
JL
509 acred.gid = make_kgid(&init_user_ns, id);
510
511 /* find the cred for it */
3064b686 512 rcu_assign_pointer(cred, rpc_lookup_generic_cred(&acred, 0, gfp_flags));
90a0be00
JL
513 if (IS_ERR(cred)) {
514 rc = PTR_ERR(cred);
515 goto out_err_free;
516 }
517
3064b686
JL
518 if (lgr->range.iomode == IOMODE_READ)
519 rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
520 else
521 rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
90a0be00 522
266d12d4
TM
523 mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
524 if (mirror != fls->mirror_array[i]) {
90a0be00 525 /* swap cred ptrs so free_mirror will clean up old */
3064b686
JL
526 if (lgr->range.iomode == IOMODE_READ) {
527 cred = xchg(&mirror->ro_cred, cred);
528 rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
529 } else {
530 cred = xchg(&mirror->rw_cred, cred);
531 rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
532 }
266d12d4
TM
533 ff_layout_free_mirror(fls->mirror_array[i]);
534 fls->mirror_array[i] = mirror;
535 }
536
3064b686
JL
537 dprintk("%s: iomode %s uid %u gid %u\n", __func__,
538 lgr->range.iomode == IOMODE_READ ? "READ" : "RW",
90a0be00
JL
539 from_kuid(&init_user_ns, acred.uid),
540 from_kgid(&init_user_ns, acred.gid));
d67ae825
TH
541 }
542
c0f5f505 543 p = xdr_inline_decode(&stream, 4);
d0379a5d
TM
544 if (!p)
545 goto out_sort_mirrors;
546 fls->flags = be32_to_cpup(p);
547
548 p = xdr_inline_decode(&stream, 4);
549 if (!p)
550 goto out_sort_mirrors;
551 for (i=0; i < fls->mirror_array_cnt; i++)
552 fls->mirror_array[i]->report_interval = be32_to_cpup(p);
c0f5f505 553
d0379a5d 554out_sort_mirrors:
d67ae825
TH
555 ff_layout_sort_mirrors(fls);
556 rc = ff_layout_check_layout(lgr);
557 if (rc)
558 goto out_err_free;
260074cd 559 ff_layout_mark_devices_valid(fls);
d67ae825
TH
560
561 ret = &fls->generic_hdr;
562 dprintk("<-- %s (success)\n", __func__);
563out_free_page:
564 __free_page(scratch);
565 return ret;
566out_err_free:
567 _ff_layout_free_lseg(fls);
568 ret = ERR_PTR(rc);
569 dprintk("<-- %s (%d)\n", __func__, rc);
570 goto out_free_page;
571}
572
573static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout)
574{
575 struct pnfs_layout_segment *lseg;
576
577 list_for_each_entry(lseg, &layout->plh_segs, pls_list)
578 if (lseg->pls_range.iomode == IOMODE_RW)
579 return true;
580
581 return false;
582}
583
584static void
585ff_layout_free_lseg(struct pnfs_layout_segment *lseg)
586{
587 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
d67ae825
TH
588
589 dprintk("--> %s\n", __func__);
590
d67ae825
TH
591 if (lseg->pls_range.iomode == IOMODE_RW) {
592 struct nfs4_flexfile_layout *ffl;
593 struct inode *inode;
594
595 ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout);
596 inode = ffl->generic_hdr.plh_inode;
597 spin_lock(&inode->i_lock);
598 if (!ff_layout_has_rw_segments(lseg->pls_layout)) {
599 ffl->commit_info.nbuckets = 0;
600 kfree(ffl->commit_info.buckets);
601 ffl->commit_info.buckets = NULL;
602 }
603 spin_unlock(&inode->i_lock);
604 }
605 _ff_layout_free_lseg(fls);
606}
607
608/* Return 1 until we have multiple lsegs support */
609static int
610ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls)
611{
612 return 1;
613}
614
abcb7bfc 615static void
e76d28dd 616nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
abcb7bfc 617{
9bbd9bb4
PT
618 /* first IO request? */
619 if (atomic_inc_return(&timer->n_ops) == 1) {
e76d28dd 620 timer->start_time = now;
abcb7bfc
TM
621 }
622}
623
624static ktime_t
e76d28dd 625nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
abcb7bfc 626{
e76d28dd 627 ktime_t start;
abcb7bfc 628
9bbd9bb4
PT
629 if (atomic_dec_return(&timer->n_ops) < 0)
630 WARN_ON_ONCE(1);
631
9bbd9bb4
PT
632 start = timer->start_time;
633 timer->start_time = now;
abcb7bfc
TM
634 return ktime_sub(now, start);
635}
636
97ba375b 637static bool
d983803d 638nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
e76d28dd
TM
639 struct nfs4_ff_layoutstat *layoutstat,
640 ktime_t now)
abcb7bfc 641{
d983803d 642 static const ktime_t notime = {0};
bbf58bf3 643 s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
1c8d477a 644 struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);
d983803d 645
e76d28dd 646 nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
9bbd9bb4
PT
647 if (ktime_equal(mirror->start_time, notime))
648 mirror->start_time = now;
d0379a5d
TM
649 if (mirror->report_interval != 0)
650 report_interval = (s64)mirror->report_interval * 1000LL;
651 else if (layoutstats_timer != 0)
bbf58bf3 652 report_interval = (s64)layoutstats_timer * 1000LL;
1c8d477a 653 if (ktime_to_ms(ktime_sub(now, ffl->last_report_time)) >=
bbf58bf3 654 report_interval) {
1c8d477a 655 ffl->last_report_time = now;
97ba375b
PT
656 return true;
657 }
658
659 return false;
abcb7bfc
TM
660}
661
662static void
663nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat,
664 __u64 requested)
665{
666 struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
667
668 iostat->ops_requested++;
669 iostat->bytes_requested += requested;
670}
671
672static void
673nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat,
674 __u64 requested,
675 __u64 completed,
e76d28dd
TM
676 ktime_t time_completed,
677 ktime_t time_started)
abcb7bfc
TM
678{
679 struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
e76d28dd 680 ktime_t completion_time = ktime_sub(time_completed, time_started);
abcb7bfc
TM
681 ktime_t timer;
682
683 iostat->ops_completed++;
684 iostat->bytes_completed += completed;
685 iostat->bytes_not_delivered += requested - completed;
686
e76d28dd 687 timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer, time_completed);
abcb7bfc
TM
688 iostat->total_busy_time =
689 ktime_add(iostat->total_busy_time, timer);
690 iostat->aggregate_completion_time =
e76d28dd
TM
691 ktime_add(iostat->aggregate_completion_time,
692 completion_time);
abcb7bfc
TM
693}
694
695static void
0b7baf94
TM
696nfs4_ff_layout_stat_io_start_read(struct inode *inode,
697 struct nfs4_ff_layout_mirror *mirror,
e76d28dd 698 __u64 requested, ktime_t now)
abcb7bfc 699{
97ba375b
PT
700 bool report;
701
abcb7bfc 702 spin_lock(&mirror->lock);
e76d28dd 703 report = nfs4_ff_layoutstat_start_io(mirror, &mirror->read_stat, now);
abcb7bfc
TM
704 nfs4_ff_layout_stat_io_update_requested(&mirror->read_stat, requested);
705 spin_unlock(&mirror->lock);
97ba375b
PT
706
707 if (report)
0b7baf94 708 pnfs_report_layoutstat(inode, GFP_KERNEL);
abcb7bfc
TM
709}
710
711static void
712nfs4_ff_layout_stat_io_end_read(struct rpc_task *task,
713 struct nfs4_ff_layout_mirror *mirror,
714 __u64 requested,
715 __u64 completed)
716{
717 spin_lock(&mirror->lock);
718 nfs4_ff_layout_stat_io_update_completed(&mirror->read_stat,
719 requested, completed,
e76d28dd 720 ktime_get(), task->tk_start);
abcb7bfc
TM
721 spin_unlock(&mirror->lock);
722}
723
724static void
0b7baf94
TM
725nfs4_ff_layout_stat_io_start_write(struct inode *inode,
726 struct nfs4_ff_layout_mirror *mirror,
e76d28dd 727 __u64 requested, ktime_t now)
abcb7bfc 728{
97ba375b
PT
729 bool report;
730
abcb7bfc 731 spin_lock(&mirror->lock);
e76d28dd 732 report = nfs4_ff_layoutstat_start_io(mirror , &mirror->write_stat, now);
abcb7bfc
TM
733 nfs4_ff_layout_stat_io_update_requested(&mirror->write_stat, requested);
734 spin_unlock(&mirror->lock);
97ba375b
PT
735
736 if (report)
0b7baf94 737 pnfs_report_layoutstat(inode, GFP_NOIO);
abcb7bfc
TM
738}
739
740static void
741nfs4_ff_layout_stat_io_end_write(struct rpc_task *task,
742 struct nfs4_ff_layout_mirror *mirror,
743 __u64 requested,
744 __u64 completed,
745 enum nfs3_stable_how committed)
746{
747 if (committed == NFS_UNSTABLE)
748 requested = completed = 0;
749
750 spin_lock(&mirror->lock);
751 nfs4_ff_layout_stat_io_update_completed(&mirror->write_stat,
e76d28dd 752 requested, completed, ktime_get(), task->tk_start);
abcb7bfc
TM
753 spin_unlock(&mirror->lock);
754}
755
d67ae825
TH
756static int
757ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg,
758 struct nfs_commit_info *cinfo,
759 gfp_t gfp_flags)
760{
761 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
762 struct pnfs_commit_bucket *buckets;
763 int size;
764
765 if (cinfo->ds->nbuckets != 0) {
766 /* This assumes there is only one RW lseg per file.
767 * To support multiple lseg per file, we need to
768 * change struct pnfs_commit_bucket to allow dynamic
769 * increasing nbuckets.
770 */
771 return 0;
772 }
773
774 size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg);
775
776 buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
777 gfp_flags);
778 if (!buckets)
779 return -ENOMEM;
780 else {
781 int i;
782
fe238e60 783 spin_lock(&cinfo->inode->i_lock);
d67ae825
TH
784 if (cinfo->ds->nbuckets != 0)
785 kfree(buckets);
786 else {
787 cinfo->ds->buckets = buckets;
788 cinfo->ds->nbuckets = size;
789 for (i = 0; i < size; i++) {
790 INIT_LIST_HEAD(&buckets[i].written);
791 INIT_LIST_HEAD(&buckets[i].committing);
792 /* mark direct verifier as unset */
793 buckets[i].direct_verf.committed =
794 NFS_INVALID_STABLE_HOW;
795 }
796 }
fe238e60 797 spin_unlock(&cinfo->inode->i_lock);
d67ae825
TH
798 return 0;
799 }
800}
801
802static struct nfs4_pnfs_ds *
13544412
TM
803ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
804 int start_idx,
d67ae825
TH
805 int *best_idx)
806{
13544412 807 struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
d67ae825 808 struct nfs4_pnfs_ds *ds;
3dc14735 809 bool fail_return = false;
d67ae825
TH
810 int idx;
811
d67ae825 812 /* mirrors are sorted by efficiency */
13544412 813 for (idx = start_idx; idx < fls->mirror_array_cnt; idx++) {
3dc14735
TM
814 if (idx+1 == fls->mirror_array_cnt)
815 fail_return = true;
816 ds = nfs4_ff_layout_prepare_ds(lseg, idx, fail_return);
d67ae825
TH
817 if (ds) {
818 *best_idx = idx;
819 return ds;
820 }
821 }
822
823 return NULL;
824}
825
c7d73af2
TH
826static void
827ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio,
828 struct nfs_page *req,
829 bool strict_iomode)
830{
831retry_strict:
832 pnfs_put_lseg(pgio->pg_lseg);
833 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
834 req->wb_context,
835 0,
836 NFS4_MAX_UINT64,
837 IOMODE_READ,
838 strict_iomode,
839 GFP_KERNEL);
840 if (IS_ERR(pgio->pg_lseg)) {
841 pgio->pg_error = PTR_ERR(pgio->pg_lseg);
842 pgio->pg_lseg = NULL;
843 }
844
845 /* If we don't have checking, do get a IOMODE_RW
846 * segment, and the server wants to avoid READs
847 * there, then retry!
848 */
849 if (pgio->pg_lseg && !strict_iomode &&
850 ff_layout_avoid_read_on_rw(pgio->pg_lseg)) {
851 strict_iomode = true;
852 goto retry_strict;
853 }
854}
855
d67ae825
TH
856static void
857ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
858 struct nfs_page *req)
859{
860 struct nfs_pgio_mirror *pgm;
861 struct nfs4_ff_layout_mirror *mirror;
862 struct nfs4_pnfs_ds *ds;
863 int ds_idx;
864
3dc14735 865retry:
d67ae825 866 /* Use full layout for now */
c7d73af2
TH
867 if (!pgio->pg_lseg)
868 ff_layout_pg_get_read(pgio, req, false);
869 else if (ff_layout_avoid_read_on_rw(pgio->pg_lseg))
870 ff_layout_pg_get_read(pgio, req, true);
602c4cd4 871
d67ae825
TH
872 /* If no lseg, fall back to read through mds */
873 if (pgio->pg_lseg == NULL)
874 goto out_mds;
875
13544412 876 ds = ff_layout_choose_best_ds_for_read(pgio->pg_lseg, 0, &ds_idx);
446ca219 877 if (!ds) {
3dc14735 878 if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
446ca219 879 goto out_mds;
3dc14735
TM
880 pnfs_put_lseg(pgio->pg_lseg);
881 pgio->pg_lseg = NULL;
882 /* Sleep for 1 second before retrying */
883 ssleep(1);
884 goto retry;
446ca219
TH
885 }
886
d67ae825
TH
887 mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx);
888
889 pgio->pg_mirror_idx = ds_idx;
890
891 /* read always uses only one mirror - idx 0 for pgio layer */
892 pgm = &pgio->pg_mirrors[0];
893 pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize;
894
895 return;
896out_mds:
897 pnfs_put_lseg(pgio->pg_lseg);
898 pgio->pg_lseg = NULL;
899 nfs_pageio_reset_read_mds(pgio);
900}
901
902static void
903ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
904 struct nfs_page *req)
905{
906 struct nfs4_ff_layout_mirror *mirror;
907 struct nfs_pgio_mirror *pgm;
908 struct nfs_commit_info cinfo;
909 struct nfs4_pnfs_ds *ds;
910 int i;
911 int status;
912
3dc14735 913retry:
d600ad1f 914 if (!pgio->pg_lseg) {
d67ae825
TH
915 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
916 req->wb_context,
917 0,
918 NFS4_MAX_UINT64,
919 IOMODE_RW,
c7d73af2 920 false,
d67ae825 921 GFP_NOFS);
d600ad1f
PT
922 if (IS_ERR(pgio->pg_lseg)) {
923 pgio->pg_error = PTR_ERR(pgio->pg_lseg);
924 pgio->pg_lseg = NULL;
925 return;
926 }
927 }
d67ae825
TH
928 /* If no lseg, fall back to write through mds */
929 if (pgio->pg_lseg == NULL)
930 goto out_mds;
931
932 nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
933 status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
934 if (status < 0)
935 goto out_mds;
936
937 /* Use a direct mapping of ds_idx to pgio mirror_idx */
938 if (WARN_ON_ONCE(pgio->pg_mirror_count !=
939 FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg)))
940 goto out_mds;
941
942 for (i = 0; i < pgio->pg_mirror_count; i++) {
943 ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true);
446ca219 944 if (!ds) {
3dc14735 945 if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
446ca219 946 goto out_mds;
3dc14735
TM
947 pnfs_put_lseg(pgio->pg_lseg);
948 pgio->pg_lseg = NULL;
949 /* Sleep for 1 second before retrying */
950 ssleep(1);
951 goto retry;
446ca219 952 }
d67ae825
TH
953 pgm = &pgio->pg_mirrors[i];
954 mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i);
955 pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize;
956 }
957
958 return;
959
960out_mds:
961 pnfs_put_lseg(pgio->pg_lseg);
962 pgio->pg_lseg = NULL;
963 nfs_pageio_reset_write_mds(pgio);
964}
965
966static unsigned int
967ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
968 struct nfs_page *req)
969{
d600ad1f 970 if (!pgio->pg_lseg) {
d67ae825
TH
971 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
972 req->wb_context,
973 0,
974 NFS4_MAX_UINT64,
975 IOMODE_RW,
c7d73af2 976 false,
d67ae825 977 GFP_NOFS);
d600ad1f
PT
978 if (IS_ERR(pgio->pg_lseg)) {
979 pgio->pg_error = PTR_ERR(pgio->pg_lseg);
980 pgio->pg_lseg = NULL;
981 goto out;
982 }
983 }
d67ae825
TH
984 if (pgio->pg_lseg)
985 return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg);
986
987 /* no lseg means that pnfs is not in use, so no mirroring here */
d67ae825 988 nfs_pageio_reset_write_mds(pgio);
d600ad1f 989out:
d67ae825
TH
990 return 1;
991}
992
993static const struct nfs_pageio_ops ff_layout_pg_read_ops = {
994 .pg_init = ff_layout_pg_init_read,
995 .pg_test = pnfs_generic_pg_test,
996 .pg_doio = pnfs_generic_pg_readpages,
997 .pg_cleanup = pnfs_generic_pg_cleanup,
998};
999
1000static const struct nfs_pageio_ops ff_layout_pg_write_ops = {
1001 .pg_init = ff_layout_pg_init_write,
1002 .pg_test = pnfs_generic_pg_test,
1003 .pg_doio = pnfs_generic_pg_writepages,
1004 .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write,
1005 .pg_cleanup = pnfs_generic_pg_cleanup,
1006};
1007
1008static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs)
1009{
1010 struct rpc_task *task = &hdr->task;
1011
1012 pnfs_layoutcommit_inode(hdr->inode, false);
1013
1014 if (retry_pnfs) {
1015 dprintk("%s Reset task %5u for i/o through pNFS "
1016 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
1017 hdr->task.tk_pid,
1018 hdr->inode->i_sb->s_id,
1019 (unsigned long long)NFS_FILEID(hdr->inode),
1020 hdr->args.count,
1021 (unsigned long long)hdr->args.offset);
1022
dc602dd7 1023 hdr->completion_ops->reschedule_io(hdr);
d67ae825
TH
1024 return;
1025 }
1026
1027 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
1028 dprintk("%s Reset task %5u for i/o through MDS "
1029 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
1030 hdr->task.tk_pid,
1031 hdr->inode->i_sb->s_id,
1032 (unsigned long long)NFS_FILEID(hdr->inode),
1033 hdr->args.count,
1034 (unsigned long long)hdr->args.offset);
1035
1036 task->tk_status = pnfs_write_done_resend_to_mds(hdr);
1037 }
1038}
1039
1040static void ff_layout_reset_read(struct nfs_pgio_header *hdr)
1041{
1042 struct rpc_task *task = &hdr->task;
1043
1044 pnfs_layoutcommit_inode(hdr->inode, false);
1045
1046 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
1047 dprintk("%s Reset task %5u for i/o through MDS "
1048 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
1049 hdr->task.tk_pid,
1050 hdr->inode->i_sb->s_id,
1051 (unsigned long long)NFS_FILEID(hdr->inode),
1052 hdr->args.count,
1053 (unsigned long long)hdr->args.offset);
1054
1055 task->tk_status = pnfs_read_done_resend_to_mds(hdr);
1056 }
1057}
1058
1059static int ff_layout_async_handle_error_v4(struct rpc_task *task,
1060 struct nfs4_state *state,
1061 struct nfs_client *clp,
1062 struct pnfs_layout_segment *lseg,
1063 int idx)
1064{
1065 struct pnfs_layout_hdr *lo = lseg->pls_layout;
1066 struct inode *inode = lo->plh_inode;
1067 struct nfs_server *mds_server = NFS_SERVER(inode);
1068
1069 struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
1070 struct nfs_client *mds_client = mds_server->nfs_client;
1071 struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
1072
1073 if (task->tk_status >= 0)
1074 return 0;
1075
1076 switch (task->tk_status) {
1077 /* MDS state errors */
1078 case -NFS4ERR_DELEG_REVOKED:
1079 case -NFS4ERR_ADMIN_REVOKED:
1080 case -NFS4ERR_BAD_STATEID:
1081 if (state == NULL)
1082 break;
1083 nfs_remove_bad_delegation(state->inode);
1084 case -NFS4ERR_OPENMODE:
1085 if (state == NULL)
1086 break;
1087 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
1088 goto out_bad_stateid;
1089 goto wait_on_recovery;
1090 case -NFS4ERR_EXPIRED:
1091 if (state != NULL) {
1092 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
1093 goto out_bad_stateid;
1094 }
1095 nfs4_schedule_lease_recovery(mds_client);
1096 goto wait_on_recovery;
1097 /* DS session errors */
1098 case -NFS4ERR_BADSESSION:
1099 case -NFS4ERR_BADSLOT:
1100 case -NFS4ERR_BAD_HIGH_SLOT:
1101 case -NFS4ERR_DEADSESSION:
1102 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1103 case -NFS4ERR_SEQ_FALSE_RETRY:
1104 case -NFS4ERR_SEQ_MISORDERED:
1105 dprintk("%s ERROR %d, Reset session. Exchangeid "
1106 "flags 0x%x\n", __func__, task->tk_status,
1107 clp->cl_exchange_flags);
1108 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
1109 break;
1110 case -NFS4ERR_DELAY:
1111 case -NFS4ERR_GRACE:
1112 rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX);
1113 break;
1114 case -NFS4ERR_RETRY_UNCACHED_REP:
1115 break;
1116 /* Invalidate Layout errors */
1117 case -NFS4ERR_PNFS_NO_LAYOUT:
1118 case -ESTALE: /* mapped NFS4ERR_STALE */
1119 case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */
1120 case -EISDIR: /* mapped NFS4ERR_ISDIR */
1121 case -NFS4ERR_FHEXPIRED:
1122 case -NFS4ERR_WRONG_TYPE:
1123 dprintk("%s Invalid layout error %d\n", __func__,
1124 task->tk_status);
1125 /*
1126 * Destroy layout so new i/o will get a new layout.
1127 * Layout will not be destroyed until all current lseg
1128 * references are put. Mark layout as invalid to resend failed
1129 * i/o and all i/o waiting on the slot table to the MDS until
1130 * layout is destroyed and a new valid layout is obtained.
1131 */
1132 pnfs_destroy_layout(NFS_I(inode));
1133 rpc_wake_up(&tbl->slot_tbl_waitq);
1134 goto reset;
1135 /* RPC connection errors */
1136 case -ECONNREFUSED:
1137 case -EHOSTDOWN:
1138 case -EHOSTUNREACH:
1139 case -ENETUNREACH:
1140 case -EIO:
1141 case -ETIMEDOUT:
1142 case -EPIPE:
1143 dprintk("%s DS connection error %d\n", __func__,
1144 task->tk_status);
1145 nfs4_mark_deviceid_unavailable(devid);
1146 rpc_wake_up(&tbl->slot_tbl_waitq);
1147 /* fall through */
1148 default:
3b13b4b3 1149 if (ff_layout_avoid_mds_available_ds(lseg))
d67ae825
TH
1150 return -NFS4ERR_RESET_TO_PNFS;
1151reset:
1152 dprintk("%s Retry through MDS. Error %d\n", __func__,
1153 task->tk_status);
1154 return -NFS4ERR_RESET_TO_MDS;
1155 }
1156out:
1157 task->tk_status = 0;
1158 return -EAGAIN;
1159out_bad_stateid:
1160 task->tk_status = -EIO;
1161 return 0;
1162wait_on_recovery:
1163 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
1164 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
1165 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
1166 goto out;
1167}
1168
1169/* Retry all errors through either pNFS or MDS except for -EJUKEBOX */
1170static int ff_layout_async_handle_error_v3(struct rpc_task *task,
1171 struct pnfs_layout_segment *lseg,
1172 int idx)
1173{
1174 struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
1175
1176 if (task->tk_status >= 0)
1177 return 0;
1178
90816d1d
TM
1179 switch (task->tk_status) {
1180 /* File access problems. Don't mark the device as unavailable */
1181 case -EACCES:
1182 case -ESTALE:
1183 case -EISDIR:
1184 case -EBADHANDLE:
1185 case -ELOOP:
1186 case -ENOSPC:
1187 break;
1188 case -EJUKEBOX:
1189 nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
1190 goto out_retry;
1191 default:
d67ae825
TH
1192 dprintk("%s DS connection error %d\n", __func__,
1193 task->tk_status);
1194 nfs4_mark_deviceid_unavailable(devid);
d67ae825 1195 }
90816d1d
TM
1196 /* FIXME: Need to prevent infinite looping here. */
1197 return -NFS4ERR_RESET_TO_PNFS;
1198out_retry:
d67ae825 1199 task->tk_status = 0;
7eeea167 1200 rpc_restart_call_prepare(task);
d67ae825
TH
1201 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
1202 return -EAGAIN;
1203}
1204
1205static int ff_layout_async_handle_error(struct rpc_task *task,
1206 struct nfs4_state *state,
1207 struct nfs_client *clp,
1208 struct pnfs_layout_segment *lseg,
1209 int idx)
1210{
1211 int vers = clp->cl_nfs_mod->rpc_vers->number;
1212
1213 switch (vers) {
1214 case 3:
1215 return ff_layout_async_handle_error_v3(task, lseg, idx);
1216 case 4:
1217 return ff_layout_async_handle_error_v4(task, state, clp,
1218 lseg, idx);
1219 default:
1220 /* should never happen */
1221 WARN_ON_ONCE(1);
1222 return 0;
1223 }
1224}
1225
1226static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
1227 int idx, u64 offset, u64 length,
dd52128a 1228 u32 status, int opnum, int error)
d67ae825
TH
1229{
1230 struct nfs4_ff_layout_mirror *mirror;
1231 int err;
1232
dd52128a
TM
1233 if (status == 0) {
1234 switch (error) {
1235 case -ETIMEDOUT:
1236 case -EPFNOSUPPORT:
1237 case -EPROTONOSUPPORT:
1238 case -EOPNOTSUPP:
1239 case -ECONNREFUSED:
1240 case -ECONNRESET:
1241 case -EHOSTDOWN:
1242 case -EHOSTUNREACH:
1243 case -ENETUNREACH:
1244 case -EADDRINUSE:
1245 case -ENOBUFS:
1246 case -EPIPE:
1247 case -EPERM:
1248 status = NFS4ERR_NXIO;
1249 break;
1250 case -EACCES:
1251 status = NFS4ERR_ACCESS;
1252 break;
1253 default:
1254 return;
1255 }
1256 }
1257
c22eeb86
PT
1258 switch (status) {
1259 case NFS4ERR_DELAY:
1260 case NFS4ERR_GRACE:
1261 return;
1262 default:
1263 break;
1264 }
1265
d67ae825
TH
1266 mirror = FF_LAYOUT_COMP(lseg, idx);
1267 err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
1268 mirror, offset, length, status, opnum,
1269 GFP_NOIO);
f95c03b2 1270 pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode, lseg);
d67ae825
TH
1271 dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status);
1272}
1273
1274/* NFS_PROTO call done callback routines */
d67ae825
TH
1275static int ff_layout_read_done_cb(struct rpc_task *task,
1276 struct nfs_pgio_header *hdr)
1277{
d67ae825
TH
1278 int err;
1279
1280 trace_nfs4_pnfs_read(hdr, task->tk_status);
dd52128a 1281 if (task->tk_status < 0)
d67ae825
TH
1282 ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
1283 hdr->args.offset, hdr->args.count,
dd52128a
TM
1284 hdr->res.op_status, OP_READ,
1285 task->tk_status);
d67ae825
TH
1286 err = ff_layout_async_handle_error(task, hdr->args.context->state,
1287 hdr->ds_clp, hdr->lseg,
1288 hdr->pgio_mirror_idx);
1289
1290 switch (err) {
1291 case -NFS4ERR_RESET_TO_PNFS:
13544412
TM
1292 if (ff_layout_choose_best_ds_for_read(hdr->lseg,
1293 hdr->pgio_mirror_idx + 1,
1294 &hdr->pgio_mirror_idx))
1295 goto out_eagain;
d67ae825
TH
1296 pnfs_read_resend_pnfs(hdr);
1297 return task->tk_status;
1298 case -NFS4ERR_RESET_TO_MDS:
d67ae825
TH
1299 ff_layout_reset_read(hdr);
1300 return task->tk_status;
1301 case -EAGAIN:
13544412 1302 goto out_eagain;
d67ae825
TH
1303 }
1304
1305 return 0;
13544412
TM
1306out_eagain:
1307 rpc_restart_call_prepare(task);
1308 return -EAGAIN;
d67ae825
TH
1309}
1310
c0f5f505
TM
1311static bool
1312ff_layout_need_layoutcommit(struct pnfs_layout_segment *lseg)
1313{
1314 return !(FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_LAYOUTCOMMIT);
1315}
1316
d67ae825
TH
1317/*
1318 * We reference the rpc_cred of the first WRITE that triggers the need for
1319 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
1320 * rfc5661 is not clear about which credential should be used.
1321 *
1322 * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so
1323 * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751
1324 * we always send layoutcommit after DS writes.
1325 */
1326static void
bc28e1c2
TM
1327ff_layout_set_layoutcommit(struct inode *inode,
1328 struct pnfs_layout_segment *lseg,
1329 loff_t end_offset)
d67ae825 1330{
bc28e1c2 1331 if (!ff_layout_need_layoutcommit(lseg))
c0f5f505
TM
1332 return;
1333
bc28e1c2
TM
1334 pnfs_set_layoutcommit(inode, lseg, end_offset);
1335 dprintk("%s inode %lu pls_end_pos %llu\n", __func__, inode->i_ino,
1336 (unsigned long long) NFS_I(inode)->layout->plh_lwb);
d67ae825
TH
1337}
1338
1339static bool
75bf47eb 1340ff_layout_device_unavailable(struct pnfs_layout_segment *lseg, int idx)
d67ae825
TH
1341{
1342 /* No mirroring for now */
1343 struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx);
1344
1345 return ff_layout_test_devid_unavailable(node);
1346}
1347
37e9ed22
TM
1348static void ff_layout_read_record_layoutstats_start(struct rpc_task *task,
1349 struct nfs_pgio_header *hdr)
d67ae825 1350{
37e9ed22
TM
1351 if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
1352 return;
0b7baf94 1353 nfs4_ff_layout_stat_io_start_read(hdr->inode,
abcb7bfc 1354 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
e76d28dd
TM
1355 hdr->args.count,
1356 task->tk_start);
37e9ed22
TM
1357}
1358
1359static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
1360 struct nfs_pgio_header *hdr)
1361{
1362 if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
1363 return;
1364 nfs4_ff_layout_stat_io_end_read(task,
1365 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
1366 hdr->args.count,
1367 hdr->res.count);
1368}
abcb7bfc 1369
37e9ed22
TM
1370static int ff_layout_read_prepare_common(struct rpc_task *task,
1371 struct nfs_pgio_header *hdr)
1372{
d67ae825
TH
1373 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
1374 rpc_exit(task, -EIO);
1375 return -EIO;
1376 }
75bf47eb
TM
1377 if (ff_layout_device_unavailable(hdr->lseg, hdr->pgio_mirror_idx)) {
1378 rpc_exit(task, -EHOSTDOWN);
d67ae825
TH
1379 return -EAGAIN;
1380 }
d67ae825 1381
37e9ed22 1382 ff_layout_read_record_layoutstats_start(task, hdr);
d67ae825
TH
1383 return 0;
1384}
1385
1386/*
1387 * Call ops for the async read/write cases
1388 * In the case of dense layouts, the offset needs to be reset to its
1389 * original value.
1390 */
1391static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data)
1392{
1393 struct nfs_pgio_header *hdr = data;
1394
1395 if (ff_layout_read_prepare_common(task, hdr))
1396 return;
1397
1398 rpc_call_start(task);
1399}
1400
1401static int ff_layout_setup_sequence(struct nfs_client *ds_clp,
1402 struct nfs4_sequence_args *args,
1403 struct nfs4_sequence_res *res,
1404 struct rpc_task *task)
1405{
1406 if (ds_clp->cl_session)
1407 return nfs41_setup_sequence(ds_clp->cl_session,
1408 args,
1409 res,
1410 task);
1411 return nfs40_setup_sequence(ds_clp->cl_slot_tbl,
1412 args,
1413 res,
1414 task);
1415}
1416
1417static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data)
1418{
1419 struct nfs_pgio_header *hdr = data;
1420
d67ae825
TH
1421 if (ff_layout_setup_sequence(hdr->ds_clp,
1422 &hdr->args.seq_args,
1423 &hdr->res.seq_res,
1424 task))
1425 return;
1426
abcb7bfc
TM
1427 if (ff_layout_read_prepare_common(task, hdr))
1428 return;
1429
d67ae825
TH
1430 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
1431 hdr->args.lock_context, FMODE_READ) == -EIO)
1432 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
1433}
1434
1435static void ff_layout_read_call_done(struct rpc_task *task, void *data)
1436{
1437 struct nfs_pgio_header *hdr = data;
1438
1439 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
1440
1441 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
1442 task->tk_status == 0) {
1443 nfs4_sequence_done(task, &hdr->res.seq_res);
1444 return;
1445 }
1446
1447 /* Note this may cause RPC to be resent */
1448 hdr->mds_ops->rpc_call_done(task, hdr);
1449}
1450
1451static void ff_layout_read_count_stats(struct rpc_task *task, void *data)
1452{
1453 struct nfs_pgio_header *hdr = data;
1454
37e9ed22 1455 ff_layout_read_record_layoutstats_done(task, hdr);
d67ae825
TH
1456 rpc_count_iostats_metrics(task,
1457 &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]);
1458}
1459
4d0ac221
TM
1460static void ff_layout_read_release(void *data)
1461{
1462 struct nfs_pgio_header *hdr = data;
1463
1464 ff_layout_read_record_layoutstats_done(&hdr->task, hdr);
1465 pnfs_generic_rw_release(data);
1466}
1467
1468
d67ae825
TH
1469static int ff_layout_write_done_cb(struct rpc_task *task,
1470 struct nfs_pgio_header *hdr)
1471{
2e18d4d8 1472 loff_t end_offs = 0;
d67ae825
TH
1473 int err;
1474
1475 trace_nfs4_pnfs_write(hdr, task->tk_status);
dd52128a 1476 if (task->tk_status < 0)
d67ae825
TH
1477 ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx,
1478 hdr->args.offset, hdr->args.count,
dd52128a
TM
1479 hdr->res.op_status, OP_WRITE,
1480 task->tk_status);
d67ae825
TH
1481 err = ff_layout_async_handle_error(task, hdr->args.context->state,
1482 hdr->ds_clp, hdr->lseg,
1483 hdr->pgio_mirror_idx);
1484
1485 switch (err) {
1486 case -NFS4ERR_RESET_TO_PNFS:
7cc8c5cd
TM
1487 ff_layout_reset_write(hdr, true);
1488 return task->tk_status;
d67ae825 1489 case -NFS4ERR_RESET_TO_MDS:
7cc8c5cd 1490 ff_layout_reset_write(hdr, false);
d67ae825
TH
1491 return task->tk_status;
1492 case -EAGAIN:
d67ae825
TH
1493 return -EAGAIN;
1494 }
1495
1496 if (hdr->res.verf->committed == NFS_FILE_SYNC ||
1497 hdr->res.verf->committed == NFS_DATA_SYNC)
2e18d4d8
TM
1498 end_offs = hdr->mds_offset + (loff_t)hdr->res.count;
1499
1500 /* Note: if the write is unstable, don't set end_offs until commit */
1501 ff_layout_set_layoutcommit(hdr->inode, hdr->lseg, end_offs);
d67ae825 1502
54204010
PT
1503 /* zero out fattr since we don't care DS attr at all */
1504 hdr->fattr.valid = 0;
69f230d9
PT
1505 if (task->tk_status >= 0)
1506 nfs_writeback_update_inode(hdr);
1507
d67ae825
TH
1508 return 0;
1509}
1510
1511static int ff_layout_commit_done_cb(struct rpc_task *task,
1512 struct nfs_commit_data *data)
1513{
d67ae825
TH
1514 int err;
1515
1516 trace_nfs4_pnfs_commit_ds(data, task->tk_status);
dd52128a 1517 if (task->tk_status < 0)
d67ae825
TH
1518 ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index,
1519 data->args.offset, data->args.count,
dd52128a
TM
1520 data->res.op_status, OP_COMMIT,
1521 task->tk_status);
d67ae825
TH
1522 err = ff_layout_async_handle_error(task, NULL, data->ds_clp,
1523 data->lseg, data->ds_commit_index);
1524
1525 switch (err) {
1526 case -NFS4ERR_RESET_TO_PNFS:
7cc8c5cd
TM
1527 pnfs_generic_prepare_to_resend_writes(data);
1528 return -EAGAIN;
d67ae825 1529 case -NFS4ERR_RESET_TO_MDS:
d67ae825
TH
1530 pnfs_generic_prepare_to_resend_writes(data);
1531 return -EAGAIN;
1532 case -EAGAIN:
1533 rpc_restart_call_prepare(task);
1534 return -EAGAIN;
1535 }
1536
bc28e1c2 1537 ff_layout_set_layoutcommit(data->inode, data->lseg, data->lwb);
d67ae825
TH
1538
1539 return 0;
1540}
1541
37e9ed22
TM
1542static void ff_layout_write_record_layoutstats_start(struct rpc_task *task,
1543 struct nfs_pgio_header *hdr)
d67ae825 1544{
37e9ed22
TM
1545 if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
1546 return;
0b7baf94 1547 nfs4_ff_layout_stat_io_start_write(hdr->inode,
abcb7bfc 1548 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
e76d28dd
TM
1549 hdr->args.count,
1550 task->tk_start);
37e9ed22
TM
1551}
1552
1553static void ff_layout_write_record_layoutstats_done(struct rpc_task *task,
1554 struct nfs_pgio_header *hdr)
1555{
1556 if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
1557 return;
1558 nfs4_ff_layout_stat_io_end_write(task,
1559 FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
1560 hdr->args.count, hdr->res.count,
1561 hdr->res.verf->committed);
1562}
abcb7bfc 1563
37e9ed22
TM
1564static int ff_layout_write_prepare_common(struct rpc_task *task,
1565 struct nfs_pgio_header *hdr)
1566{
d67ae825
TH
1567 if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
1568 rpc_exit(task, -EIO);
1569 return -EIO;
1570 }
1571
75bf47eb
TM
1572 if (ff_layout_device_unavailable(hdr->lseg, hdr->pgio_mirror_idx)) {
1573 rpc_exit(task, -EHOSTDOWN);
d67ae825
TH
1574 return -EAGAIN;
1575 }
1576
37e9ed22 1577 ff_layout_write_record_layoutstats_start(task, hdr);
d67ae825
TH
1578 return 0;
1579}
1580
1581static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data)
1582{
1583 struct nfs_pgio_header *hdr = data;
1584
1585 if (ff_layout_write_prepare_common(task, hdr))
1586 return;
1587
1588 rpc_call_start(task);
1589}
1590
1591static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data)
1592{
1593 struct nfs_pgio_header *hdr = data;
1594
d67ae825
TH
1595 if (ff_layout_setup_sequence(hdr->ds_clp,
1596 &hdr->args.seq_args,
1597 &hdr->res.seq_res,
1598 task))
1599 return;
1600
abcb7bfc
TM
1601 if (ff_layout_write_prepare_common(task, hdr))
1602 return;
1603
d67ae825
TH
1604 if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
1605 hdr->args.lock_context, FMODE_WRITE) == -EIO)
1606 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
1607}
1608
1609static void ff_layout_write_call_done(struct rpc_task *task, void *data)
1610{
1611 struct nfs_pgio_header *hdr = data;
1612
1613 if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
1614 task->tk_status == 0) {
1615 nfs4_sequence_done(task, &hdr->res.seq_res);
1616 return;
1617 }
1618
1619 /* Note this may cause RPC to be resent */
1620 hdr->mds_ops->rpc_call_done(task, hdr);
1621}
1622
1623static void ff_layout_write_count_stats(struct rpc_task *task, void *data)
1624{
1625 struct nfs_pgio_header *hdr = data;
1626
37e9ed22 1627 ff_layout_write_record_layoutstats_done(task, hdr);
d67ae825
TH
1628 rpc_count_iostats_metrics(task,
1629 &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]);
1630}
1631
4d0ac221
TM
1632static void ff_layout_write_release(void *data)
1633{
1634 struct nfs_pgio_header *hdr = data;
1635
1636 ff_layout_write_record_layoutstats_done(&hdr->task, hdr);
1637 pnfs_generic_rw_release(data);
1638}
1639
37e9ed22 1640static void ff_layout_commit_record_layoutstats_start(struct rpc_task *task,
abcb7bfc
TM
1641 struct nfs_commit_data *cdata)
1642{
37e9ed22
TM
1643 if (test_and_set_bit(NFS_IOHDR_STAT, &cdata->flags))
1644 return;
0b7baf94 1645 nfs4_ff_layout_stat_io_start_write(cdata->inode,
abcb7bfc 1646 FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
e76d28dd 1647 0, task->tk_start);
abcb7bfc
TM
1648}
1649
37e9ed22
TM
1650static void ff_layout_commit_record_layoutstats_done(struct rpc_task *task,
1651 struct nfs_commit_data *cdata)
1652{
1653 struct nfs_page *req;
1654 __u64 count = 0;
1655
1656 if (!test_and_clear_bit(NFS_IOHDR_STAT, &cdata->flags))
1657 return;
1658
1659 if (task->tk_status == 0) {
1660 list_for_each_entry(req, &cdata->pages, wb_list)
1661 count += req->wb_bytes;
1662 }
1663 nfs4_ff_layout_stat_io_end_write(task,
1664 FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
1665 count, count, NFS_FILE_SYNC);
1666}
1667
1668static void ff_layout_commit_prepare_common(struct rpc_task *task,
1669 struct nfs_commit_data *cdata)
1670{
1671 ff_layout_commit_record_layoutstats_start(task, cdata);
1672}
1673
d67ae825
TH
1674static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data)
1675{
abcb7bfc 1676 ff_layout_commit_prepare_common(task, data);
d67ae825
TH
1677 rpc_call_start(task);
1678}
1679
1680static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data)
1681{
1682 struct nfs_commit_data *wdata = data;
1683
abcb7bfc 1684 if (ff_layout_setup_sequence(wdata->ds_clp,
d67ae825
TH
1685 &wdata->args.seq_args,
1686 &wdata->res.seq_res,
abcb7bfc
TM
1687 task))
1688 return;
1689 ff_layout_commit_prepare_common(task, data);
1690}
1691
1692static void ff_layout_commit_done(struct rpc_task *task, void *data)
141b9b59
PT
1693{
1694 pnfs_generic_write_commit_done(task, data);
1695}
1696
1697static void ff_layout_commit_count_stats(struct rpc_task *task, void *data)
abcb7bfc
TM
1698{
1699 struct nfs_commit_data *cdata = data;
abcb7bfc 1700
37e9ed22 1701 ff_layout_commit_record_layoutstats_done(task, cdata);
d67ae825
TH
1702 rpc_count_iostats_metrics(task,
1703 &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]);
1704}
1705
4d0ac221
TM
1706static void ff_layout_commit_release(void *data)
1707{
1708 struct nfs_commit_data *cdata = data;
1709
1710 ff_layout_commit_record_layoutstats_done(&cdata->task, cdata);
1711 pnfs_generic_commit_release(data);
1712}
1713
d67ae825
TH
1714static const struct rpc_call_ops ff_layout_read_call_ops_v3 = {
1715 .rpc_call_prepare = ff_layout_read_prepare_v3,
1716 .rpc_call_done = ff_layout_read_call_done,
1717 .rpc_count_stats = ff_layout_read_count_stats,
4d0ac221 1718 .rpc_release = ff_layout_read_release,
d67ae825
TH
1719};
1720
1721static const struct rpc_call_ops ff_layout_read_call_ops_v4 = {
1722 .rpc_call_prepare = ff_layout_read_prepare_v4,
1723 .rpc_call_done = ff_layout_read_call_done,
1724 .rpc_count_stats = ff_layout_read_count_stats,
4d0ac221 1725 .rpc_release = ff_layout_read_release,
d67ae825
TH
1726};
1727
1728static const struct rpc_call_ops ff_layout_write_call_ops_v3 = {
1729 .rpc_call_prepare = ff_layout_write_prepare_v3,
1730 .rpc_call_done = ff_layout_write_call_done,
1731 .rpc_count_stats = ff_layout_write_count_stats,
4d0ac221 1732 .rpc_release = ff_layout_write_release,
d67ae825
TH
1733};
1734
1735static const struct rpc_call_ops ff_layout_write_call_ops_v4 = {
1736 .rpc_call_prepare = ff_layout_write_prepare_v4,
1737 .rpc_call_done = ff_layout_write_call_done,
1738 .rpc_count_stats = ff_layout_write_count_stats,
4d0ac221 1739 .rpc_release = ff_layout_write_release,
d67ae825
TH
1740};
1741
1742static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = {
1743 .rpc_call_prepare = ff_layout_commit_prepare_v3,
abcb7bfc 1744 .rpc_call_done = ff_layout_commit_done,
d67ae825 1745 .rpc_count_stats = ff_layout_commit_count_stats,
4d0ac221 1746 .rpc_release = ff_layout_commit_release,
d67ae825
TH
1747};
1748
1749static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = {
1750 .rpc_call_prepare = ff_layout_commit_prepare_v4,
abcb7bfc 1751 .rpc_call_done = ff_layout_commit_done,
d67ae825 1752 .rpc_count_stats = ff_layout_commit_count_stats,
4d0ac221 1753 .rpc_release = ff_layout_commit_release,
d67ae825
TH
1754};
1755
1756static enum pnfs_try_status
1757ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1758{
1759 struct pnfs_layout_segment *lseg = hdr->lseg;
1760 struct nfs4_pnfs_ds *ds;
1761 struct rpc_clnt *ds_clnt;
1762 struct rpc_cred *ds_cred;
1763 loff_t offset = hdr->args.offset;
1764 u32 idx = hdr->pgio_mirror_idx;
1765 int vers;
1766 struct nfs_fh *fh;
1767
1768 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
1769 __func__, hdr->inode->i_ino,
1770 hdr->args.pgbase, (size_t)hdr->args.count, offset);
1771
1772 ds = nfs4_ff_layout_prepare_ds(lseg, idx, false);
1773 if (!ds)
1774 goto out_failed;
1775
1776 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1777 hdr->inode);
1778 if (IS_ERR(ds_clnt))
1779 goto out_failed;
1780
1781 ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
57f3f4c0 1782 if (!ds_cred)
d67ae825
TH
1783 goto out_failed;
1784
1785 vers = nfs4_ff_layout_ds_version(lseg, idx);
1786
1787 dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__,
1788 ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers);
1789
75bf47eb 1790 hdr->pgio_done_cb = ff_layout_read_done_cb;
d67ae825
TH
1791 atomic_inc(&ds->ds_clp->cl_count);
1792 hdr->ds_clp = ds->ds_clp;
1793 fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
1794 if (fh)
1795 hdr->args.fh = fh;
d67ae825
TH
1796 /*
1797 * Note that if we ever decide to split across DSes,
1798 * then we may need to handle dense-like offsets.
1799 */
1800 hdr->args.offset = offset;
1801 hdr->mds_offset = offset;
1802
1803 /* Perform an asynchronous read to ds */
1804 nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
1805 vers == 3 ? &ff_layout_read_call_ops_v3 :
1806 &ff_layout_read_call_ops_v4,
1807 0, RPC_TASK_SOFTCONN);
57f3f4c0 1808 put_rpccred(ds_cred);
d67ae825
TH
1809 return PNFS_ATTEMPTED;
1810
1811out_failed:
3b13b4b3 1812 if (ff_layout_avoid_mds_available_ds(lseg))
d67ae825
TH
1813 return PNFS_TRY_AGAIN;
1814 return PNFS_NOT_ATTEMPTED;
1815}
1816
1817/* Perform async writes. */
1818static enum pnfs_try_status
1819ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1820{
1821 struct pnfs_layout_segment *lseg = hdr->lseg;
1822 struct nfs4_pnfs_ds *ds;
1823 struct rpc_clnt *ds_clnt;
1824 struct rpc_cred *ds_cred;
1825 loff_t offset = hdr->args.offset;
1826 int vers;
1827 struct nfs_fh *fh;
1828 int idx = hdr->pgio_mirror_idx;
1829
1830 ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
1831 if (!ds)
1832 return PNFS_NOT_ATTEMPTED;
1833
1834 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1835 hdr->inode);
1836 if (IS_ERR(ds_clnt))
1837 return PNFS_NOT_ATTEMPTED;
1838
1839 ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred);
57f3f4c0 1840 if (!ds_cred)
d67ae825
TH
1841 return PNFS_NOT_ATTEMPTED;
1842
1843 vers = nfs4_ff_layout_ds_version(lseg, idx);
1844
1845 dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n",
1846 __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
1847 offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count),
1848 vers);
1849
1850 hdr->pgio_done_cb = ff_layout_write_done_cb;
1851 atomic_inc(&ds->ds_clp->cl_count);
1852 hdr->ds_clp = ds->ds_clp;
1853 hdr->ds_commit_idx = idx;
1854 fh = nfs4_ff_layout_select_ds_fh(lseg, idx);
1855 if (fh)
1856 hdr->args.fh = fh;
1857
1858 /*
1859 * Note that if we ever decide to split across DSes,
1860 * then we may need to handle dense-like offsets.
1861 */
1862 hdr->args.offset = offset;
1863
1864 /* Perform an asynchronous write */
1865 nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
1866 vers == 3 ? &ff_layout_write_call_ops_v3 :
1867 &ff_layout_write_call_ops_v4,
1868 sync, RPC_TASK_SOFTCONN);
57f3f4c0 1869 put_rpccred(ds_cred);
d67ae825
TH
1870 return PNFS_ATTEMPTED;
1871}
1872
d67ae825
TH
1873static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1874{
1875 return i;
1876}
1877
1878static struct nfs_fh *
1879select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1880{
1881 struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
1882
1883 /* FIXME: Assume that there is only one NFS version available
1884 * for the DS.
1885 */
1886 return &flseg->mirror_array[i]->fh_versions[0];
1887}
1888
1889static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1890{
1891 struct pnfs_layout_segment *lseg = data->lseg;
1892 struct nfs4_pnfs_ds *ds;
1893 struct rpc_clnt *ds_clnt;
1894 struct rpc_cred *ds_cred;
1895 u32 idx;
57f3f4c0 1896 int vers, ret;
d67ae825
TH
1897 struct nfs_fh *fh;
1898
1899 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
1900 ds = nfs4_ff_layout_prepare_ds(lseg, idx, true);
1901 if (!ds)
1902 goto out_err;
1903
1904 ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp,
1905 data->inode);
1906 if (IS_ERR(ds_clnt))
1907 goto out_err;
1908
1909 ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred);
57f3f4c0 1910 if (!ds_cred)
d67ae825
TH
1911 goto out_err;
1912
1913 vers = nfs4_ff_layout_ds_version(lseg, idx);
1914
1915 dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__,
1916 data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count),
1917 vers);
1918 data->commit_done_cb = ff_layout_commit_done_cb;
1919 data->cred = ds_cred;
1920 atomic_inc(&ds->ds_clp->cl_count);
1921 data->ds_clp = ds->ds_clp;
1922 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
1923 if (fh)
1924 data->args.fh = fh;
abcb7bfc 1925
57f3f4c0 1926 ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
d67ae825
TH
1927 vers == 3 ? &ff_layout_commit_call_ops_v3 :
1928 &ff_layout_commit_call_ops_v4,
1929 how, RPC_TASK_SOFTCONN);
57f3f4c0
JL
1930 put_rpccred(ds_cred);
1931 return ret;
d67ae825
TH
1932out_err:
1933 pnfs_generic_prepare_to_resend_writes(data);
1934 pnfs_generic_commit_release(data);
1935 return -EAGAIN;
1936}
1937
1938static int
1939ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
1940 int how, struct nfs_commit_info *cinfo)
1941{
1942 return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
1943 ff_layout_initiate_commit);
1944}
1945
1946static struct pnfs_ds_commit_info *
1947ff_layout_get_ds_info(struct inode *inode)
1948{
1949 struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
1950
1951 if (layout == NULL)
1952 return NULL;
1953
1954 return &FF_LAYOUT_FROM_HDR(layout)->commit_info;
1955}
1956
1957static void
fc87701b 1958ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d)
d67ae825
TH
1959{
1960 nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds,
1961 id_node));
1962}
1963
1964static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo,
1965 struct xdr_stream *xdr,
1966 const struct nfs4_layoutreturn_args *args)
1967{
1968 struct pnfs_layout_hdr *hdr = &flo->generic_hdr;
1969 __be32 *start;
1970 int count = 0, ret = 0;
1971
1972 start = xdr_reserve_space(xdr, 4);
1973 if (unlikely(!start))
1974 return -E2BIG;
1975
1976 /* This assume we always return _ALL_ layouts */
1977 spin_lock(&hdr->plh_inode->i_lock);
1978 ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range);
1979 spin_unlock(&hdr->plh_inode->i_lock);
1980
1981 *start = cpu_to_be32(count);
1982
1983 return ret;
1984}
1985
1986/* report nothing for now */
1987static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo,
1988 struct xdr_stream *xdr,
1989 const struct nfs4_layoutreturn_args *args)
1990{
1991 __be32 *p;
1992
1993 p = xdr_reserve_space(xdr, 4);
1994 if (likely(p))
1995 *p = cpu_to_be32(0);
1996}
1997
1998static struct nfs4_deviceid_node *
1999ff_layout_alloc_deviceid_node(struct nfs_server *server,
2000 struct pnfs_device *pdev, gfp_t gfp_flags)
2001{
2002 struct nfs4_ff_layout_ds *dsaddr;
2003
2004 dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags);
2005 if (!dsaddr)
2006 return NULL;
2007 return &dsaddr->id_node;
2008}
2009
2010static void
2011ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo,
2012 struct xdr_stream *xdr,
2013 const struct nfs4_layoutreturn_args *args)
2014{
2015 struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo);
2016 __be32 *start;
2017
2018 dprintk("%s: Begin\n", __func__);
2019 start = xdr_reserve_space(xdr, 4);
2020 BUG_ON(!start);
2021
082fa37d 2022 ff_layout_encode_ioerr(flo, xdr, args);
d67ae825 2023 ff_layout_encode_iostats(flo, xdr, args);
082fa37d 2024
d67ae825
TH
2025 *start = cpu_to_be32((xdr->p - start - 1) * 4);
2026 dprintk("%s: Return\n", __func__);
2027}
2028
27c43064
PT
2029static int
2030ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen)
2031{
2032 const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
2033
2034 return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
2035}
2036
2037static size_t
2038ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf,
2039 const int buflen)
2040{
2041 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
2042 const struct in6_addr *addr = &sin6->sin6_addr;
2043
2044 /*
2045 * RFC 4291, Section 2.2.2
2046 *
2047 * Shorthanded ANY address
2048 */
2049 if (ipv6_addr_any(addr))
2050 return snprintf(buf, buflen, "::");
2051
2052 /*
2053 * RFC 4291, Section 2.2.2
2054 *
2055 * Shorthanded loopback address
2056 */
2057 if (ipv6_addr_loopback(addr))
2058 return snprintf(buf, buflen, "::1");
2059
2060 /*
2061 * RFC 4291, Section 2.2.3
2062 *
2063 * Special presentation address format for mapped v4
2064 * addresses.
2065 */
2066 if (ipv6_addr_v4mapped(addr))
2067 return snprintf(buf, buflen, "::ffff:%pI4",
2068 &addr->s6_addr32[3]);
2069
2070 /*
2071 * RFC 4291, Section 2.2.1
2072 */
2073 return snprintf(buf, buflen, "%pI6c", addr);
2074}
2075
2076/* Derived from rpc_sockaddr2uaddr */
2077static void
2078ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da)
2079{
2080 struct sockaddr *sap = (struct sockaddr *)&da->da_addr;
2081 char portbuf[RPCBIND_MAXUADDRPLEN];
2082 char addrbuf[RPCBIND_MAXUADDRLEN];
2083 char *netid;
2084 unsigned short port;
2085 int len, netid_len;
2086 __be32 *p;
2087
2088 switch (sap->sa_family) {
2089 case AF_INET:
2090 if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
2091 return;
2092 port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2093 netid = "tcp";
2094 netid_len = 3;
2095 break;
2096 case AF_INET6:
2097 if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
2098 return;
2099 port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
2100 netid = "tcp6";
2101 netid_len = 4;
2102 break;
2103 default:
2104 /* we only support tcp and tcp6 */
2105 WARN_ON_ONCE(1);
2106 return;
2107 }
2108
2109 snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff);
2110 len = strlcat(addrbuf, portbuf, sizeof(addrbuf));
2111
2112 p = xdr_reserve_space(xdr, 4 + netid_len);
2113 xdr_encode_opaque(p, netid, netid_len);
2114
2115 p = xdr_reserve_space(xdr, 4 + len);
2116 xdr_encode_opaque(p, addrbuf, len);
2117}
2118
2119static void
2120ff_layout_encode_nfstime(struct xdr_stream *xdr,
2121 ktime_t t)
2122{
2123 struct timespec64 ts;
2124 __be32 *p;
2125
2126 p = xdr_reserve_space(xdr, 12);
2127 ts = ktime_to_timespec64(t);
2128 p = xdr_encode_hyper(p, ts.tv_sec);
2129 *p++ = cpu_to_be32(ts.tv_nsec);
2130}
2131
2132static void
2133ff_layout_encode_io_latency(struct xdr_stream *xdr,
2134 struct nfs4_ff_io_stat *stat)
2135{
2136 __be32 *p;
2137
2138 p = xdr_reserve_space(xdr, 5 * 8);
2139 p = xdr_encode_hyper(p, stat->ops_requested);
2140 p = xdr_encode_hyper(p, stat->bytes_requested);
2141 p = xdr_encode_hyper(p, stat->ops_completed);
2142 p = xdr_encode_hyper(p, stat->bytes_completed);
2143 p = xdr_encode_hyper(p, stat->bytes_not_delivered);
2144 ff_layout_encode_nfstime(xdr, stat->total_busy_time);
2145 ff_layout_encode_nfstime(xdr, stat->aggregate_completion_time);
2146}
2147
2148static void
2149ff_layout_encode_layoutstats(struct xdr_stream *xdr,
2150 struct nfs42_layoutstat_args *args,
2151 struct nfs42_layoutstat_devinfo *devinfo)
2152{
2153 struct nfs4_ff_layout_mirror *mirror = devinfo->layout_private;
2154 struct nfs4_pnfs_ds_addr *da;
2155 struct nfs4_pnfs_ds *ds = mirror->mirror_ds->ds;
2156 struct nfs_fh *fh = &mirror->fh_versions[0];
2157 __be32 *p, *start;
2158
2159 da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node);
2160 dprintk("%s: DS %s: encoding address %s\n",
2161 __func__, ds->ds_remotestr, da->da_remotestr);
2162 /* layoutupdate length */
2163 start = xdr_reserve_space(xdr, 4);
2164 /* netaddr4 */
2165 ff_layout_encode_netaddr(xdr, da);
2166 /* nfs_fh4 */
2167 p = xdr_reserve_space(xdr, 4 + fh->size);
2168 xdr_encode_opaque(p, fh->data, fh->size);
2169 /* ff_io_latency4 read */
2170 spin_lock(&mirror->lock);
2171 ff_layout_encode_io_latency(xdr, &mirror->read_stat.io_stat);
2172 /* ff_io_latency4 write */
2173 ff_layout_encode_io_latency(xdr, &mirror->write_stat.io_stat);
2174 spin_unlock(&mirror->lock);
2175 /* nfstime4 */
2176 ff_layout_encode_nfstime(xdr, ktime_sub(ktime_get(), mirror->start_time));
2177 /* bool */
2178 p = xdr_reserve_space(xdr, 4);
2179 *p = cpu_to_be32(false);
2180
2181 *start = cpu_to_be32((xdr->p - start - 1) * 4);
2182}
2183
266d12d4 2184static int
ad4dc53e 2185ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args *args,
266d12d4
TM
2186 struct pnfs_layout_hdr *lo,
2187 int dev_limit)
ad4dc53e 2188{
266d12d4 2189 struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
ad4dc53e
PT
2190 struct nfs4_ff_layout_mirror *mirror;
2191 struct nfs4_deviceid_node *dev;
2192 struct nfs42_layoutstat_devinfo *devinfo;
266d12d4 2193 int i = 0;
ad4dc53e 2194
266d12d4
TM
2195 list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
2196 if (i >= dev_limit)
ad4dc53e 2197 break;
266d12d4 2198 if (!mirror->mirror_ds)
27c43064 2199 continue;
266d12d4
TM
2200 /* mirror refcount put in cleanup_layoutstats */
2201 if (!atomic_inc_not_zero(&mirror->ref))
2202 continue;
2203 dev = &mirror->mirror_ds->id_node;
2204 devinfo = &args->devinfo[i];
ad4dc53e 2205 memcpy(&devinfo->dev_id, &dev->deviceid, NFS4_DEVICEID4_SIZE);
266d12d4
TM
2206 devinfo->offset = 0;
2207 devinfo->length = NFS4_MAX_UINT64;
d099d7b8 2208 devinfo->read_count = mirror->read_stat.io_stat.ops_completed;
ad4dc53e 2209 devinfo->read_bytes = mirror->read_stat.io_stat.bytes_completed;
d099d7b8 2210 devinfo->write_count = mirror->write_stat.io_stat.ops_completed;
ad4dc53e
PT
2211 devinfo->write_bytes = mirror->write_stat.io_stat.bytes_completed;
2212 devinfo->layout_type = LAYOUT_FLEX_FILES;
27c43064
PT
2213 devinfo->layoutstats_encode = ff_layout_encode_layoutstats;
2214 devinfo->layout_private = mirror;
ad4dc53e 2215
266d12d4 2216 i++;
ad4dc53e 2217 }
266d12d4 2218 return i;
ad4dc53e
PT
2219}
2220
2221static int
2222ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
2223{
266d12d4
TM
2224 struct nfs4_flexfile_layout *ff_layout;
2225 struct nfs4_ff_layout_mirror *mirror;
ad4dc53e
PT
2226 int dev_count = 0;
2227
2228 spin_lock(&args->inode->i_lock);
266d12d4
TM
2229 ff_layout = FF_LAYOUT_FROM_HDR(NFS_I(args->inode)->layout);
2230 list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
2231 if (atomic_read(&mirror->ref) != 0)
2232 dev_count ++;
ad4dc53e
PT
2233 }
2234 spin_unlock(&args->inode->i_lock);
2235 /* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */
2236 if (dev_count > PNFS_LAYOUTSTATS_MAXDEV) {
2237 dprintk("%s: truncating devinfo to limit (%d:%d)\n",
2238 __func__, dev_count, PNFS_LAYOUTSTATS_MAXDEV);
2239 dev_count = PNFS_LAYOUTSTATS_MAXDEV;
2240 }
266d12d4 2241 args->devinfo = kmalloc_array(dev_count, sizeof(*args->devinfo), GFP_NOIO);
ad4dc53e
PT
2242 if (!args->devinfo)
2243 return -ENOMEM;
2244
ad4dc53e 2245 spin_lock(&args->inode->i_lock);
266d12d4
TM
2246 args->num_dev = ff_layout_mirror_prepare_stats(args,
2247 &ff_layout->generic_hdr, dev_count);
ad4dc53e 2248 spin_unlock(&args->inode->i_lock);
ad4dc53e
PT
2249
2250 return 0;
2251}
2252
27c43064
PT
2253static void
2254ff_layout_cleanup_layoutstats(struct nfs42_layoutstat_data *data)
2255{
2256 struct nfs4_ff_layout_mirror *mirror;
2257 int i;
2258
2259 for (i = 0; i < data->args.num_dev; i++) {
2260 mirror = data->args.devinfo[i].layout_private;
2261 data->args.devinfo[i].layout_private = NULL;
0b7baf94 2262 ff_layout_put_mirror(mirror);
27c43064
PT
2263 }
2264}
2265
d67ae825
TH
2266static struct pnfs_layoutdriver_type flexfilelayout_type = {
2267 .id = LAYOUT_FLEX_FILES,
2268 .name = "LAYOUT_FLEX_FILES",
2269 .owner = THIS_MODULE,
2270 .alloc_layout_hdr = ff_layout_alloc_layout_hdr,
2271 .free_layout_hdr = ff_layout_free_layout_hdr,
2272 .alloc_lseg = ff_layout_alloc_lseg,
2273 .free_lseg = ff_layout_free_lseg,
0762ed2c 2274 .add_lseg = ff_layout_add_lseg,
d67ae825
TH
2275 .pg_read_ops = &ff_layout_pg_read_ops,
2276 .pg_write_ops = &ff_layout_pg_write_ops,
2277 .get_ds_info = ff_layout_get_ds_info,
fc87701b 2278 .free_deviceid_node = ff_layout_free_deviceid_node,
338d00cf 2279 .mark_request_commit = pnfs_layout_mark_request_commit,
d67ae825
TH
2280 .clear_request_commit = pnfs_generic_clear_request_commit,
2281 .scan_commit_lists = pnfs_generic_scan_commit_lists,
2282 .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
2283 .commit_pagelist = ff_layout_commit_pagelist,
2284 .read_pagelist = ff_layout_read_pagelist,
2285 .write_pagelist = ff_layout_write_pagelist,
2286 .alloc_deviceid_node = ff_layout_alloc_deviceid_node,
2287 .encode_layoutreturn = ff_layout_encode_layoutreturn,
5bb89b47 2288 .sync = pnfs_nfs_generic_sync,
ad4dc53e 2289 .prepare_layoutstats = ff_layout_prepare_layoutstats,
27c43064 2290 .cleanup_layoutstats = ff_layout_cleanup_layoutstats,
d67ae825
TH
2291};
2292
2293static int __init nfs4flexfilelayout_init(void)
2294{
2295 printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n",
2296 __func__);
90a0be00
JL
2297 if (!ff_zero_group) {
2298 ff_zero_group = groups_alloc(0);
2299 if (!ff_zero_group)
2300 return -ENOMEM;
2301 }
d67ae825
TH
2302 return pnfs_register_layoutdriver(&flexfilelayout_type);
2303}
2304
2305static void __exit nfs4flexfilelayout_exit(void)
2306{
2307 printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n",
2308 __func__);
2309 pnfs_unregister_layoutdriver(&flexfilelayout_type);
90a0be00
JL
2310 if (ff_zero_group) {
2311 put_group_info(ff_zero_group);
2312 ff_zero_group = NULL;
2313 }
d67ae825
TH
2314}
2315
2316MODULE_ALIAS("nfs-layouttype4-4");
2317
2318MODULE_LICENSE("GPL");
2319MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");
2320
2321module_init(nfs4flexfilelayout_init);
2322module_exit(nfs4flexfilelayout_exit);