2 * Module for pnfs flexfile layout driver.
4 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
6 * Tao Peng <bergwolf@primarydata.com>
9 #include <linux/nfs_fs.h>
10 #include <linux/nfs_page.h>
11 #include <linux/module.h>
13 #include <linux/sunrpc/metrics.h>
15 #include "flexfilelayout.h"
16 #include "../nfs4session.h"
17 #include "../nfs4idmap.h"
18 #include "../internal.h"
19 #include "../delegation.h"
20 #include "../nfs4trace.h"
21 #include "../iostat.h"
25 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
27 #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)
29 static struct group_info
*ff_zero_group
;
31 static struct pnfs_layout_hdr
*
32 ff_layout_alloc_layout_hdr(struct inode
*inode
, gfp_t gfp_flags
)
34 struct nfs4_flexfile_layout
*ffl
;
36 ffl
= kzalloc(sizeof(*ffl
), gfp_flags
);
38 INIT_LIST_HEAD(&ffl
->error_list
);
39 INIT_LIST_HEAD(&ffl
->mirrors
);
40 ffl
->last_report_time
= ktime_get();
41 return &ffl
->generic_hdr
;
47 ff_layout_free_layout_hdr(struct pnfs_layout_hdr
*lo
)
49 struct nfs4_ff_layout_ds_err
*err
, *n
;
51 list_for_each_entry_safe(err
, n
, &FF_LAYOUT_FROM_HDR(lo
)->error_list
,
56 kfree(FF_LAYOUT_FROM_HDR(lo
));
59 static int decode_pnfs_stateid(struct xdr_stream
*xdr
, nfs4_stateid
*stateid
)
63 p
= xdr_inline_decode(xdr
, NFS4_STATEID_SIZE
);
64 if (unlikely(p
== NULL
))
66 stateid
->type
= NFS4_PNFS_DS_STATEID_TYPE
;
67 memcpy(stateid
->data
, p
, NFS4_STATEID_SIZE
);
68 dprintk("%s: stateid id= [%x%x%x%x]\n", __func__
,
69 p
[0], p
[1], p
[2], p
[3]);
73 static int decode_deviceid(struct xdr_stream
*xdr
, struct nfs4_deviceid
*devid
)
77 p
= xdr_inline_decode(xdr
, NFS4_DEVICEID4_SIZE
);
80 memcpy(devid
, p
, NFS4_DEVICEID4_SIZE
);
81 nfs4_print_deviceid(devid
);
85 static int decode_nfs_fh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
89 p
= xdr_inline_decode(xdr
, 4);
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",
99 p
= xdr_inline_decode(xdr
, fh
->size
);
102 memcpy(&fh
->data
, p
, fh
->size
);
103 dprintk("%s: fh len %d\n", __func__
, fh
->size
);
109 * Currently only stringified uids and gids are accepted.
110 * I.e., kerberos is not supported to the DSes, so no pricipals.
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().
117 decode_name(struct xdr_stream
*xdr
, u32
*id
)
122 /* opaque_length(4)*/
123 p
= xdr_inline_decode(xdr
, 4);
126 len
= be32_to_cpup(p
++);
130 dprintk("%s: len %u\n", __func__
, len
);
133 p
= xdr_inline_decode(xdr
, len
);
137 if (!nfs_map_string_to_numeric((char *)p
, len
, id
))
143 static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror
*m1
,
144 const struct nfs4_ff_layout_mirror
*m2
)
148 if (m1
->fh_versions_cnt
!= m2
->fh_versions_cnt
)
150 for (i
= 0; i
< m1
->fh_versions_cnt
; i
++) {
151 bool found_fh
= false;
152 for (j
= 0; j
< m2
->fh_versions_cnt
; j
++) {
153 if (nfs_compare_fh(&m1
->fh_versions
[i
],
154 &m2
->fh_versions
[j
]) == 0) {
165 static struct nfs4_ff_layout_mirror
*
166 ff_layout_add_mirror(struct pnfs_layout_hdr
*lo
,
167 struct nfs4_ff_layout_mirror
*mirror
)
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
;
173 spin_lock(&inode
->i_lock
);
174 list_for_each_entry(pos
, &ff_layout
->mirrors
, mirrors
) {
175 if (mirror
->mirror_ds
!= pos
->mirror_ds
)
177 if (!ff_mirror_match_fh(mirror
, pos
))
179 if (atomic_inc_not_zero(&pos
->ref
)) {
180 spin_unlock(&inode
->i_lock
);
184 list_add(&mirror
->mirrors
, &ff_layout
->mirrors
);
186 spin_unlock(&inode
->i_lock
);
191 ff_layout_remove_mirror(struct nfs4_ff_layout_mirror
*mirror
)
194 if (mirror
->layout
== NULL
)
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
;
203 static struct nfs4_ff_layout_mirror
*ff_layout_alloc_mirror(gfp_t gfp_flags
)
205 struct nfs4_ff_layout_mirror
*mirror
;
207 mirror
= kzalloc(sizeof(*mirror
), gfp_flags
);
208 if (mirror
!= NULL
) {
209 spin_lock_init(&mirror
->lock
);
210 atomic_set(&mirror
->ref
, 1);
211 INIT_LIST_HEAD(&mirror
->mirrors
);
216 static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror
*mirror
)
218 struct rpc_cred
*cred
;
220 ff_layout_remove_mirror(mirror
);
221 kfree(mirror
->fh_versions
);
222 cred
= rcu_access_pointer(mirror
->ro_cred
);
225 cred
= rcu_access_pointer(mirror
->rw_cred
);
228 nfs4_ff_layout_put_deviceid(mirror
->mirror_ds
);
232 static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror
*mirror
)
234 if (mirror
!= NULL
&& atomic_dec_and_test(&mirror
->ref
))
235 ff_layout_free_mirror(mirror
);
238 static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment
*fls
)
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 */
247 ff_layout_put_mirror(fls
->mirror_array
[i
]);
249 kfree(fls
->mirror_array
);
250 fls
->mirror_array
= NULL
;
254 static int ff_layout_check_layout(struct nfs4_layoutget_res
*lgr
)
258 dprintk("--> %s\n", __func__
);
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",
268 dprintk("--> %s returns %d\n", __func__
, ret
);
272 static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment
*fls
)
275 ff_layout_free_mirror_array(fls
);
281 ff_lseg_range_is_after(const struct pnfs_layout_range
*l1
,
282 const struct pnfs_layout_range
*l2
)
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
)
292 if (end2
< l1
->offset
)
294 return l2
->offset
<= l1
->offset
;
298 ff_lseg_merge(struct pnfs_layout_segment
*new,
299 struct pnfs_layout_segment
*old
)
301 u64 new_end
, old_end
;
303 if (test_bit(NFS_LSEG_LAYOUTRETURN
, &old
->pls_flags
))
305 if (new->pls_range
.iomode
!= old
->pls_range
.iomode
)
307 old_end
= pnfs_calc_offset_end(old
->pls_range
.offset
,
308 old
->pls_range
.length
);
309 if (old_end
< new->pls_range
.offset
)
311 new_end
= pnfs_calc_offset_end(new->pls_range
.offset
,
312 new->pls_range
.length
);
313 if (new_end
< old
->pls_range
.offset
)
316 /* Mergeable: copy info from 'old' to 'new' */
317 if (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
,
323 if (test_bit(NFS_LSEG_ROC
, &old
->pls_flags
))
324 set_bit(NFS_LSEG_ROC
, &new->pls_flags
);
329 ff_layout_add_lseg(struct pnfs_layout_hdr
*lo
,
330 struct pnfs_layout_segment
*lseg
,
331 struct list_head
*free_me
)
333 pnfs_generic_layout_insert_lseg(lo
, lseg
,
334 ff_lseg_range_is_after
,
339 static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment
*fls
)
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
<
346 fls
->mirror_array
[j
]->efficiency
)
347 swap(fls
->mirror_array
[i
],
348 fls
->mirror_array
[j
]);
352 static void ff_layout_mark_devices_valid(struct nfs4_ff_layout_segment
*fls
)
354 struct nfs4_deviceid_node
*node
;
357 if (!(fls
->flags
& FF_FLAGS_NO_IO_THRU_MDS
))
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
);
365 static struct pnfs_layout_segment
*
366 ff_layout_alloc_lseg(struct pnfs_layout_hdr
*lh
,
367 struct nfs4_layoutget_res
*lgr
,
370 struct pnfs_layout_segment
*ret
;
371 struct nfs4_ff_layout_segment
*fls
= NULL
;
372 struct xdr_stream stream
;
374 struct page
*scratch
;
376 u32 mirror_array_cnt
;
380 dprintk("--> %s\n", __func__
);
381 scratch
= alloc_page(gfp_flags
);
383 return ERR_PTR(-ENOMEM
);
385 xdr_init_decode_pages(&stream
, &buf
, lgr
->layoutp
->pages
,
387 xdr_set_scratch_buffer(&stream
, page_address(scratch
), PAGE_SIZE
);
389 /* stripe unit and mirror_array_cnt */
391 p
= xdr_inline_decode(&stream
, 8 + 4);
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
);
400 if (mirror_array_cnt
> NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT
||
401 mirror_array_cnt
== 0)
405 fls
= kzalloc(sizeof(*fls
), gfp_flags
);
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
)
416 for (i
= 0; i
< fls
->mirror_array_cnt
; i
++) {
417 struct nfs4_ff_layout_mirror
*mirror
;
418 struct nfs4_deviceid devid
;
419 struct nfs4_deviceid_node
*idnode
;
420 struct auth_cred acred
= { .group_info
= ff_zero_group
};
421 struct rpc_cred __rcu
*cred
;
422 u32 ds_count
, fh_count
, id
;
426 p
= xdr_inline_decode(&stream
, 4);
429 ds_count
= be32_to_cpup(p
);
431 /* FIXME: allow for striping? */
435 fls
->mirror_array
[i
] = ff_layout_alloc_mirror(gfp_flags
);
436 if (fls
->mirror_array
[i
] == NULL
) {
441 fls
->mirror_array
[i
]->ds_count
= ds_count
;
444 rc
= decode_deviceid(&stream
, &devid
);
448 idnode
= nfs4_find_get_deviceid(NFS_SERVER(lh
->plh_inode
),
449 &devid
, lh
->plh_lc_cred
,
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
457 fls
->mirror_array
[i
]->mirror_ds
=
458 FF_LAYOUT_MIRROR_DS(idnode
);
464 p
= xdr_inline_decode(&stream
, 4);
467 fls
->mirror_array
[i
]->efficiency
= be32_to_cpup(p
);
470 rc
= decode_pnfs_stateid(&stream
, &fls
->mirror_array
[i
]->stateid
);
475 p
= xdr_inline_decode(&stream
, 4);
478 fh_count
= be32_to_cpup(p
);
480 fls
->mirror_array
[i
]->fh_versions
=
481 kzalloc(fh_count
* sizeof(struct nfs_fh
),
483 if (fls
->mirror_array
[i
]->fh_versions
== NULL
) {
488 for (j
= 0; j
< fh_count
; j
++) {
489 rc
= decode_nfs_fh(&stream
,
490 &fls
->mirror_array
[i
]->fh_versions
[j
]);
495 fls
->mirror_array
[i
]->fh_versions_cnt
= fh_count
;
498 rc
= decode_name(&stream
, &id
);
502 acred
.uid
= make_kuid(&init_user_ns
, id
);
505 rc
= decode_name(&stream
, &id
);
509 acred
.gid
= make_kgid(&init_user_ns
, id
);
511 /* find the cred for it */
512 rcu_assign_pointer(cred
, rpc_lookup_generic_cred(&acred
, 0, gfp_flags
));
518 if (lgr
->range
.iomode
== IOMODE_READ
)
519 rcu_assign_pointer(fls
->mirror_array
[i
]->ro_cred
, cred
);
521 rcu_assign_pointer(fls
->mirror_array
[i
]->rw_cred
, cred
);
523 mirror
= ff_layout_add_mirror(lh
, fls
->mirror_array
[i
]);
524 if (mirror
!= fls
->mirror_array
[i
]) {
525 /* swap cred ptrs so free_mirror will clean up old */
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
);
530 cred
= xchg(&mirror
->rw_cred
, cred
);
531 rcu_assign_pointer(fls
->mirror_array
[i
]->rw_cred
, cred
);
533 ff_layout_free_mirror(fls
->mirror_array
[i
]);
534 fls
->mirror_array
[i
] = mirror
;
537 dprintk("%s: iomode %s uid %u gid %u\n", __func__
,
538 lgr
->range
.iomode
== IOMODE_READ
? "READ" : "RW",
539 from_kuid(&init_user_ns
, acred
.uid
),
540 from_kgid(&init_user_ns
, acred
.gid
));
543 p
= xdr_inline_decode(&stream
, 4);
545 goto out_sort_mirrors
;
546 fls
->flags
= be32_to_cpup(p
);
548 p
= xdr_inline_decode(&stream
, 4);
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
);
555 ff_layout_sort_mirrors(fls
);
556 rc
= ff_layout_check_layout(lgr
);
559 ff_layout_mark_devices_valid(fls
);
561 ret
= &fls
->generic_hdr
;
562 dprintk("<-- %s (success)\n", __func__
);
564 __free_page(scratch
);
567 _ff_layout_free_lseg(fls
);
569 dprintk("<-- %s (%d)\n", __func__
, rc
);
573 static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr
*layout
)
575 struct pnfs_layout_segment
*lseg
;
577 list_for_each_entry(lseg
, &layout
->plh_segs
, pls_list
)
578 if (lseg
->pls_range
.iomode
== IOMODE_RW
)
585 ff_layout_free_lseg(struct pnfs_layout_segment
*lseg
)
587 struct nfs4_ff_layout_segment
*fls
= FF_LAYOUT_LSEG(lseg
);
589 dprintk("--> %s\n", __func__
);
591 if (lseg
->pls_range
.iomode
== IOMODE_RW
) {
592 struct nfs4_flexfile_layout
*ffl
;
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
;
603 spin_unlock(&inode
->i_lock
);
605 _ff_layout_free_lseg(fls
);
608 /* Return 1 until we have multiple lsegs support */
610 ff_layout_get_lseg_count(struct nfs4_ff_layout_segment
*fls
)
616 nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer
*timer
, ktime_t now
)
618 /* first IO request? */
619 if (atomic_inc_return(&timer
->n_ops
) == 1) {
620 timer
->start_time
= now
;
625 nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer
*timer
, ktime_t now
)
629 if (atomic_dec_return(&timer
->n_ops
) < 0)
632 start
= timer
->start_time
;
633 timer
->start_time
= now
;
634 return ktime_sub(now
, start
);
638 nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror
*mirror
,
639 struct nfs4_ff_layoutstat
*layoutstat
,
642 static const ktime_t notime
= {0};
643 s64 report_interval
= FF_LAYOUTSTATS_REPORT_INTERVAL
;
644 struct nfs4_flexfile_layout
*ffl
= FF_LAYOUT_FROM_HDR(mirror
->layout
);
646 nfs4_ff_start_busy_timer(&layoutstat
->busy_timer
, now
);
647 if (ktime_equal(mirror
->start_time
, notime
))
648 mirror
->start_time
= now
;
649 if (mirror
->report_interval
!= 0)
650 report_interval
= (s64
)mirror
->report_interval
* 1000LL;
651 else if (layoutstats_timer
!= 0)
652 report_interval
= (s64
)layoutstats_timer
* 1000LL;
653 if (ktime_to_ms(ktime_sub(now
, ffl
->last_report_time
)) >=
655 ffl
->last_report_time
= now
;
663 nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat
*layoutstat
,
666 struct nfs4_ff_io_stat
*iostat
= &layoutstat
->io_stat
;
668 iostat
->ops_requested
++;
669 iostat
->bytes_requested
+= requested
;
673 nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat
*layoutstat
,
676 ktime_t time_completed
,
677 ktime_t time_started
)
679 struct nfs4_ff_io_stat
*iostat
= &layoutstat
->io_stat
;
680 ktime_t completion_time
= ktime_sub(time_completed
, time_started
);
683 iostat
->ops_completed
++;
684 iostat
->bytes_completed
+= completed
;
685 iostat
->bytes_not_delivered
+= requested
- completed
;
687 timer
= nfs4_ff_end_busy_timer(&layoutstat
->busy_timer
, time_completed
);
688 iostat
->total_busy_time
=
689 ktime_add(iostat
->total_busy_time
, timer
);
690 iostat
->aggregate_completion_time
=
691 ktime_add(iostat
->aggregate_completion_time
,
696 nfs4_ff_layout_stat_io_start_read(struct inode
*inode
,
697 struct nfs4_ff_layout_mirror
*mirror
,
698 __u64 requested
, ktime_t now
)
702 spin_lock(&mirror
->lock
);
703 report
= nfs4_ff_layoutstat_start_io(mirror
, &mirror
->read_stat
, now
);
704 nfs4_ff_layout_stat_io_update_requested(&mirror
->read_stat
, requested
);
705 spin_unlock(&mirror
->lock
);
708 pnfs_report_layoutstat(inode
, GFP_KERNEL
);
712 nfs4_ff_layout_stat_io_end_read(struct rpc_task
*task
,
713 struct nfs4_ff_layout_mirror
*mirror
,
717 spin_lock(&mirror
->lock
);
718 nfs4_ff_layout_stat_io_update_completed(&mirror
->read_stat
,
719 requested
, completed
,
720 ktime_get(), task
->tk_start
);
721 spin_unlock(&mirror
->lock
);
725 nfs4_ff_layout_stat_io_start_write(struct inode
*inode
,
726 struct nfs4_ff_layout_mirror
*mirror
,
727 __u64 requested
, ktime_t now
)
731 spin_lock(&mirror
->lock
);
732 report
= nfs4_ff_layoutstat_start_io(mirror
, &mirror
->write_stat
, now
);
733 nfs4_ff_layout_stat_io_update_requested(&mirror
->write_stat
, requested
);
734 spin_unlock(&mirror
->lock
);
737 pnfs_report_layoutstat(inode
, GFP_NOIO
);
741 nfs4_ff_layout_stat_io_end_write(struct rpc_task
*task
,
742 struct nfs4_ff_layout_mirror
*mirror
,
745 enum nfs3_stable_how committed
)
747 if (committed
== NFS_UNSTABLE
)
748 requested
= completed
= 0;
750 spin_lock(&mirror
->lock
);
751 nfs4_ff_layout_stat_io_update_completed(&mirror
->write_stat
,
752 requested
, completed
, ktime_get(), task
->tk_start
);
753 spin_unlock(&mirror
->lock
);
757 ff_layout_alloc_commit_info(struct pnfs_layout_segment
*lseg
,
758 struct nfs_commit_info
*cinfo
,
761 struct nfs4_ff_layout_segment
*fls
= FF_LAYOUT_LSEG(lseg
);
762 struct pnfs_commit_bucket
*buckets
;
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.
774 size
= ff_layout_get_lseg_count(fls
) * FF_LAYOUT_MIRROR_COUNT(lseg
);
776 buckets
= kcalloc(size
, sizeof(struct pnfs_commit_bucket
),
783 spin_lock(&cinfo
->inode
->i_lock
);
784 if (cinfo
->ds
->nbuckets
!= 0)
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
;
797 spin_unlock(&cinfo
->inode
->i_lock
);
802 static struct nfs4_pnfs_ds
*
803 ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment
*lseg
,
807 struct nfs4_ff_layout_segment
*fls
= FF_LAYOUT_LSEG(lseg
);
808 struct nfs4_pnfs_ds
*ds
;
809 bool fail_return
= false;
812 /* mirrors are sorted by efficiency */
813 for (idx
= start_idx
; idx
< fls
->mirror_array_cnt
; idx
++) {
814 if (idx
+1 == fls
->mirror_array_cnt
)
816 ds
= nfs4_ff_layout_prepare_ds(lseg
, idx
, fail_return
);
827 ff_layout_pg_get_read(struct nfs_pageio_descriptor
*pgio
,
828 struct nfs_page
*req
,
832 pnfs_put_lseg(pgio
->pg_lseg
);
833 pgio
->pg_lseg
= pnfs_update_layout(pgio
->pg_inode
,
840 if (IS_ERR(pgio
->pg_lseg
)) {
841 pgio
->pg_error
= PTR_ERR(pgio
->pg_lseg
);
842 pgio
->pg_lseg
= NULL
;
845 /* If we don't have checking, do get a IOMODE_RW
846 * segment, and the server wants to avoid READs
849 if (pgio
->pg_lseg
&& !strict_iomode
&&
850 ff_layout_avoid_read_on_rw(pgio
->pg_lseg
)) {
851 strict_iomode
= true;
857 ff_layout_pg_init_read(struct nfs_pageio_descriptor
*pgio
,
858 struct nfs_page
*req
)
860 struct nfs_pgio_mirror
*pgm
;
861 struct nfs4_ff_layout_mirror
*mirror
;
862 struct nfs4_pnfs_ds
*ds
;
866 /* Use full layout for now */
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);
872 /* If no lseg, fall back to read through mds */
873 if (pgio
->pg_lseg
== NULL
)
876 ds
= ff_layout_choose_best_ds_for_read(pgio
->pg_lseg
, 0, &ds_idx
);
878 if (!ff_layout_no_fallback_to_mds(pgio
->pg_lseg
))
880 pnfs_put_lseg(pgio
->pg_lseg
);
881 pgio
->pg_lseg
= NULL
;
882 /* Sleep for 1 second before retrying */
887 mirror
= FF_LAYOUT_COMP(pgio
->pg_lseg
, ds_idx
);
889 pgio
->pg_mirror_idx
= ds_idx
;
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
;
897 pnfs_put_lseg(pgio
->pg_lseg
);
898 pgio
->pg_lseg
= NULL
;
899 nfs_pageio_reset_read_mds(pgio
);
903 ff_layout_pg_init_write(struct nfs_pageio_descriptor
*pgio
,
904 struct nfs_page
*req
)
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
;
914 if (!pgio
->pg_lseg
) {
915 pgio
->pg_lseg
= pnfs_update_layout(pgio
->pg_inode
,
922 if (IS_ERR(pgio
->pg_lseg
)) {
923 pgio
->pg_error
= PTR_ERR(pgio
->pg_lseg
);
924 pgio
->pg_lseg
= NULL
;
928 /* If no lseg, fall back to write through mds */
929 if (pgio
->pg_lseg
== NULL
)
932 nfs_init_cinfo(&cinfo
, pgio
->pg_inode
, pgio
->pg_dreq
);
933 status
= ff_layout_alloc_commit_info(pgio
->pg_lseg
, &cinfo
, GFP_NOFS
);
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
)))
942 for (i
= 0; i
< pgio
->pg_mirror_count
; i
++) {
943 ds
= nfs4_ff_layout_prepare_ds(pgio
->pg_lseg
, i
, true);
945 if (!ff_layout_no_fallback_to_mds(pgio
->pg_lseg
))
947 pnfs_put_lseg(pgio
->pg_lseg
);
948 pgio
->pg_lseg
= NULL
;
949 /* Sleep for 1 second before retrying */
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
;
961 pnfs_put_lseg(pgio
->pg_lseg
);
962 pgio
->pg_lseg
= NULL
;
963 nfs_pageio_reset_write_mds(pgio
);
967 ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor
*pgio
,
968 struct nfs_page
*req
)
970 if (!pgio
->pg_lseg
) {
971 pgio
->pg_lseg
= pnfs_update_layout(pgio
->pg_inode
,
978 if (IS_ERR(pgio
->pg_lseg
)) {
979 pgio
->pg_error
= PTR_ERR(pgio
->pg_lseg
);
980 pgio
->pg_lseg
= NULL
;
985 return FF_LAYOUT_MIRROR_COUNT(pgio
->pg_lseg
);
987 /* no lseg means that pnfs is not in use, so no mirroring here */
988 nfs_pageio_reset_write_mds(pgio
);
993 static 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
,
1000 static 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
,
1008 static void ff_layout_reset_write(struct nfs_pgio_header
*hdr
, bool retry_pnfs
)
1010 struct rpc_task
*task
= &hdr
->task
;
1012 pnfs_layoutcommit_inode(hdr
->inode
, false);
1015 dprintk("%s Reset task %5u for i/o through pNFS "
1016 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__
,
1018 hdr
->inode
->i_sb
->s_id
,
1019 (unsigned long long)NFS_FILEID(hdr
->inode
),
1021 (unsigned long long)hdr
->args
.offset
);
1023 hdr
->completion_ops
->reschedule_io(hdr
);
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__
,
1031 hdr
->inode
->i_sb
->s_id
,
1032 (unsigned long long)NFS_FILEID(hdr
->inode
),
1034 (unsigned long long)hdr
->args
.offset
);
1036 task
->tk_status
= pnfs_write_done_resend_to_mds(hdr
);
1040 static void ff_layout_reset_read(struct nfs_pgio_header
*hdr
)
1042 struct rpc_task
*task
= &hdr
->task
;
1044 pnfs_layoutcommit_inode(hdr
->inode
, false);
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__
,
1050 hdr
->inode
->i_sb
->s_id
,
1051 (unsigned long long)NFS_FILEID(hdr
->inode
),
1053 (unsigned long long)hdr
->args
.offset
);
1055 task
->tk_status
= pnfs_read_done_resend_to_mds(hdr
);
1059 static 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
,
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
);
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
;
1073 if (task
->tk_status
>= 0)
1076 switch (task
->tk_status
) {
1077 /* MDS state errors */
1078 case -NFS4ERR_DELEG_REVOKED
:
1079 case -NFS4ERR_ADMIN_REVOKED
:
1080 case -NFS4ERR_BAD_STATEID
:
1083 nfs_remove_bad_delegation(state
->inode
);
1084 case -NFS4ERR_OPENMODE
:
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
;
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
);
1110 case -NFS4ERR_DELAY
:
1111 case -NFS4ERR_GRACE
:
1112 rpc_delay(task
, FF_LAYOUT_POLL_RETRY_MAX
);
1114 case -NFS4ERR_RETRY_UNCACHED_REP
:
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__
,
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.
1132 pnfs_destroy_layout(NFS_I(inode
));
1133 rpc_wake_up(&tbl
->slot_tbl_waitq
);
1135 /* RPC connection errors */
1143 dprintk("%s DS connection error %d\n", __func__
,
1145 nfs4_mark_deviceid_unavailable(devid
);
1146 rpc_wake_up(&tbl
->slot_tbl_waitq
);
1149 if (ff_layout_avoid_mds_available_ds(lseg
))
1150 return -NFS4ERR_RESET_TO_PNFS
;
1152 dprintk("%s Retry through MDS. Error %d\n", __func__
,
1154 return -NFS4ERR_RESET_TO_MDS
;
1157 task
->tk_status
= 0;
1160 task
->tk_status
= -EIO
;
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
);
1169 /* Retry all errors through either pNFS or MDS except for -EJUKEBOX */
1170 static int ff_layout_async_handle_error_v3(struct rpc_task
*task
,
1171 struct pnfs_layout_segment
*lseg
,
1174 struct nfs4_deviceid_node
*devid
= FF_LAYOUT_DEVID_NODE(lseg
, idx
);
1176 if (task
->tk_status
>= 0)
1179 switch (task
->tk_status
) {
1180 /* File access problems. Don't mark the device as unavailable */
1189 nfs_inc_stats(lseg
->pls_layout
->plh_inode
, NFSIOS_DELAY
);
1192 dprintk("%s DS connection error %d\n", __func__
,
1194 nfs4_mark_deviceid_unavailable(devid
);
1196 /* FIXME: Need to prevent infinite looping here. */
1197 return -NFS4ERR_RESET_TO_PNFS
;
1199 task
->tk_status
= 0;
1200 rpc_restart_call_prepare(task
);
1201 rpc_delay(task
, NFS_JUKEBOX_RETRY_TIME
);
1205 static 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
,
1211 int vers
= clp
->cl_nfs_mod
->rpc_vers
->number
;
1215 return ff_layout_async_handle_error_v3(task
, lseg
, idx
);
1217 return ff_layout_async_handle_error_v4(task
, state
, clp
,
1220 /* should never happen */
1226 static void ff_layout_io_track_ds_error(struct pnfs_layout_segment
*lseg
,
1227 int idx
, u64 offset
, u64 length
,
1228 u32 status
, int opnum
, int error
)
1230 struct nfs4_ff_layout_mirror
*mirror
;
1237 case -EPROTONOSUPPORT
:
1248 status
= NFS4ERR_NXIO
;
1251 status
= NFS4ERR_ACCESS
;
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
,
1270 pnfs_error_mark_layout_for_return(lseg
->pls_layout
->plh_inode
, lseg
);
1271 dprintk("%s: err %d op %d status %u\n", __func__
, err
, opnum
, status
);
1274 /* NFS_PROTO call done callback routines */
1275 static int ff_layout_read_done_cb(struct rpc_task
*task
,
1276 struct nfs_pgio_header
*hdr
)
1280 trace_nfs4_pnfs_read(hdr
, task
->tk_status
);
1281 if (task
->tk_status
< 0)
1282 ff_layout_io_track_ds_error(hdr
->lseg
, hdr
->pgio_mirror_idx
,
1283 hdr
->args
.offset
, hdr
->args
.count
,
1284 hdr
->res
.op_status
, OP_READ
,
1286 err
= ff_layout_async_handle_error(task
, hdr
->args
.context
->state
,
1287 hdr
->ds_clp
, hdr
->lseg
,
1288 hdr
->pgio_mirror_idx
);
1291 case -NFS4ERR_RESET_TO_PNFS
:
1292 if (ff_layout_choose_best_ds_for_read(hdr
->lseg
,
1293 hdr
->pgio_mirror_idx
+ 1,
1294 &hdr
->pgio_mirror_idx
))
1296 pnfs_read_resend_pnfs(hdr
);
1297 return task
->tk_status
;
1298 case -NFS4ERR_RESET_TO_MDS
:
1299 ff_layout_reset_read(hdr
);
1300 return task
->tk_status
;
1307 rpc_restart_call_prepare(task
);
1312 ff_layout_need_layoutcommit(struct pnfs_layout_segment
*lseg
)
1314 return !(FF_LAYOUT_LSEG(lseg
)->flags
& FF_FLAGS_NO_LAYOUTCOMMIT
);
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.
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.
1327 ff_layout_set_layoutcommit(struct inode
*inode
,
1328 struct pnfs_layout_segment
*lseg
,
1331 if (!ff_layout_need_layoutcommit(lseg
))
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
);
1340 ff_layout_device_unavailable(struct pnfs_layout_segment
*lseg
, int idx
)
1342 /* No mirroring for now */
1343 struct nfs4_deviceid_node
*node
= FF_LAYOUT_DEVID_NODE(lseg
, idx
);
1345 return ff_layout_test_devid_unavailable(node
);
1348 static void ff_layout_read_record_layoutstats_start(struct rpc_task
*task
,
1349 struct nfs_pgio_header
*hdr
)
1351 if (test_and_set_bit(NFS_IOHDR_STAT
, &hdr
->flags
))
1353 nfs4_ff_layout_stat_io_start_read(hdr
->inode
,
1354 FF_LAYOUT_COMP(hdr
->lseg
, hdr
->pgio_mirror_idx
),
1359 static void ff_layout_read_record_layoutstats_done(struct rpc_task
*task
,
1360 struct nfs_pgio_header
*hdr
)
1362 if (!test_and_clear_bit(NFS_IOHDR_STAT
, &hdr
->flags
))
1364 nfs4_ff_layout_stat_io_end_read(task
,
1365 FF_LAYOUT_COMP(hdr
->lseg
, hdr
->pgio_mirror_idx
),
1370 static int ff_layout_read_prepare_common(struct rpc_task
*task
,
1371 struct nfs_pgio_header
*hdr
)
1373 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
))) {
1374 rpc_exit(task
, -EIO
);
1377 if (ff_layout_device_unavailable(hdr
->lseg
, hdr
->pgio_mirror_idx
)) {
1378 rpc_exit(task
, -EHOSTDOWN
);
1382 ff_layout_read_record_layoutstats_start(task
, hdr
);
1387 * Call ops for the async read/write cases
1388 * In the case of dense layouts, the offset needs to be reset to its
1391 static void ff_layout_read_prepare_v3(struct rpc_task
*task
, void *data
)
1393 struct nfs_pgio_header
*hdr
= data
;
1395 if (ff_layout_read_prepare_common(task
, hdr
))
1398 rpc_call_start(task
);
1401 static 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
)
1406 if (ds_clp
->cl_session
)
1407 return nfs41_setup_sequence(ds_clp
->cl_session
,
1411 return nfs40_setup_sequence(ds_clp
->cl_slot_tbl
,
1417 static void ff_layout_read_prepare_v4(struct rpc_task
*task
, void *data
)
1419 struct nfs_pgio_header
*hdr
= data
;
1421 if (ff_layout_setup_sequence(hdr
->ds_clp
,
1422 &hdr
->args
.seq_args
,
1427 if (ff_layout_read_prepare_common(task
, hdr
))
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 */
1435 static void ff_layout_read_call_done(struct rpc_task
*task
, void *data
)
1437 struct nfs_pgio_header
*hdr
= data
;
1439 dprintk("--> %s task->tk_status %d\n", __func__
, task
->tk_status
);
1441 if (test_bit(NFS_IOHDR_REDO
, &hdr
->flags
) &&
1442 task
->tk_status
== 0) {
1443 nfs4_sequence_done(task
, &hdr
->res
.seq_res
);
1447 /* Note this may cause RPC to be resent */
1448 hdr
->mds_ops
->rpc_call_done(task
, hdr
);
1451 static void ff_layout_read_count_stats(struct rpc_task
*task
, void *data
)
1453 struct nfs_pgio_header
*hdr
= data
;
1455 ff_layout_read_record_layoutstats_done(task
, hdr
);
1456 rpc_count_iostats_metrics(task
,
1457 &NFS_CLIENT(hdr
->inode
)->cl_metrics
[NFSPROC4_CLNT_READ
]);
1460 static void ff_layout_read_release(void *data
)
1462 struct nfs_pgio_header
*hdr
= data
;
1464 ff_layout_read_record_layoutstats_done(&hdr
->task
, hdr
);
1465 pnfs_generic_rw_release(data
);
1469 static int ff_layout_write_done_cb(struct rpc_task
*task
,
1470 struct nfs_pgio_header
*hdr
)
1472 loff_t end_offs
= 0;
1475 trace_nfs4_pnfs_write(hdr
, task
->tk_status
);
1476 if (task
->tk_status
< 0)
1477 ff_layout_io_track_ds_error(hdr
->lseg
, hdr
->pgio_mirror_idx
,
1478 hdr
->args
.offset
, hdr
->args
.count
,
1479 hdr
->res
.op_status
, OP_WRITE
,
1481 err
= ff_layout_async_handle_error(task
, hdr
->args
.context
->state
,
1482 hdr
->ds_clp
, hdr
->lseg
,
1483 hdr
->pgio_mirror_idx
);
1486 case -NFS4ERR_RESET_TO_PNFS
:
1487 ff_layout_reset_write(hdr
, true);
1488 return task
->tk_status
;
1489 case -NFS4ERR_RESET_TO_MDS
:
1490 ff_layout_reset_write(hdr
, false);
1491 return task
->tk_status
;
1496 if (hdr
->res
.verf
->committed
== NFS_FILE_SYNC
||
1497 hdr
->res
.verf
->committed
== NFS_DATA_SYNC
)
1498 end_offs
= hdr
->mds_offset
+ (loff_t
)hdr
->res
.count
;
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
);
1503 /* zero out fattr since we don't care DS attr at all */
1504 hdr
->fattr
.valid
= 0;
1505 if (task
->tk_status
>= 0)
1506 nfs_writeback_update_inode(hdr
);
1511 static int ff_layout_commit_done_cb(struct rpc_task
*task
,
1512 struct nfs_commit_data
*data
)
1516 trace_nfs4_pnfs_commit_ds(data
, task
->tk_status
);
1517 if (task
->tk_status
< 0)
1518 ff_layout_io_track_ds_error(data
->lseg
, data
->ds_commit_index
,
1519 data
->args
.offset
, data
->args
.count
,
1520 data
->res
.op_status
, OP_COMMIT
,
1522 err
= ff_layout_async_handle_error(task
, NULL
, data
->ds_clp
,
1523 data
->lseg
, data
->ds_commit_index
);
1526 case -NFS4ERR_RESET_TO_PNFS
:
1527 pnfs_generic_prepare_to_resend_writes(data
);
1529 case -NFS4ERR_RESET_TO_MDS
:
1530 pnfs_generic_prepare_to_resend_writes(data
);
1533 rpc_restart_call_prepare(task
);
1537 ff_layout_set_layoutcommit(data
->inode
, data
->lseg
, data
->lwb
);
1542 static void ff_layout_write_record_layoutstats_start(struct rpc_task
*task
,
1543 struct nfs_pgio_header
*hdr
)
1545 if (test_and_set_bit(NFS_IOHDR_STAT
, &hdr
->flags
))
1547 nfs4_ff_layout_stat_io_start_write(hdr
->inode
,
1548 FF_LAYOUT_COMP(hdr
->lseg
, hdr
->pgio_mirror_idx
),
1553 static void ff_layout_write_record_layoutstats_done(struct rpc_task
*task
,
1554 struct nfs_pgio_header
*hdr
)
1556 if (!test_and_clear_bit(NFS_IOHDR_STAT
, &hdr
->flags
))
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
);
1564 static int ff_layout_write_prepare_common(struct rpc_task
*task
,
1565 struct nfs_pgio_header
*hdr
)
1567 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
))) {
1568 rpc_exit(task
, -EIO
);
1572 if (ff_layout_device_unavailable(hdr
->lseg
, hdr
->pgio_mirror_idx
)) {
1573 rpc_exit(task
, -EHOSTDOWN
);
1577 ff_layout_write_record_layoutstats_start(task
, hdr
);
1581 static void ff_layout_write_prepare_v3(struct rpc_task
*task
, void *data
)
1583 struct nfs_pgio_header
*hdr
= data
;
1585 if (ff_layout_write_prepare_common(task
, hdr
))
1588 rpc_call_start(task
);
1591 static void ff_layout_write_prepare_v4(struct rpc_task
*task
, void *data
)
1593 struct nfs_pgio_header
*hdr
= data
;
1595 if (ff_layout_setup_sequence(hdr
->ds_clp
,
1596 &hdr
->args
.seq_args
,
1601 if (ff_layout_write_prepare_common(task
, hdr
))
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 */
1609 static void ff_layout_write_call_done(struct rpc_task
*task
, void *data
)
1611 struct nfs_pgio_header
*hdr
= data
;
1613 if (test_bit(NFS_IOHDR_REDO
, &hdr
->flags
) &&
1614 task
->tk_status
== 0) {
1615 nfs4_sequence_done(task
, &hdr
->res
.seq_res
);
1619 /* Note this may cause RPC to be resent */
1620 hdr
->mds_ops
->rpc_call_done(task
, hdr
);
1623 static void ff_layout_write_count_stats(struct rpc_task
*task
, void *data
)
1625 struct nfs_pgio_header
*hdr
= data
;
1627 ff_layout_write_record_layoutstats_done(task
, hdr
);
1628 rpc_count_iostats_metrics(task
,
1629 &NFS_CLIENT(hdr
->inode
)->cl_metrics
[NFSPROC4_CLNT_WRITE
]);
1632 static void ff_layout_write_release(void *data
)
1634 struct nfs_pgio_header
*hdr
= data
;
1636 ff_layout_write_record_layoutstats_done(&hdr
->task
, hdr
);
1637 pnfs_generic_rw_release(data
);
1640 static void ff_layout_commit_record_layoutstats_start(struct rpc_task
*task
,
1641 struct nfs_commit_data
*cdata
)
1643 if (test_and_set_bit(NFS_IOHDR_STAT
, &cdata
->flags
))
1645 nfs4_ff_layout_stat_io_start_write(cdata
->inode
,
1646 FF_LAYOUT_COMP(cdata
->lseg
, cdata
->ds_commit_index
),
1650 static void ff_layout_commit_record_layoutstats_done(struct rpc_task
*task
,
1651 struct nfs_commit_data
*cdata
)
1653 struct nfs_page
*req
;
1656 if (!test_and_clear_bit(NFS_IOHDR_STAT
, &cdata
->flags
))
1659 if (task
->tk_status
== 0) {
1660 list_for_each_entry(req
, &cdata
->pages
, wb_list
)
1661 count
+= req
->wb_bytes
;
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
);
1668 static void ff_layout_commit_prepare_common(struct rpc_task
*task
,
1669 struct nfs_commit_data
*cdata
)
1671 ff_layout_commit_record_layoutstats_start(task
, cdata
);
1674 static void ff_layout_commit_prepare_v3(struct rpc_task
*task
, void *data
)
1676 ff_layout_commit_prepare_common(task
, data
);
1677 rpc_call_start(task
);
1680 static void ff_layout_commit_prepare_v4(struct rpc_task
*task
, void *data
)
1682 struct nfs_commit_data
*wdata
= data
;
1684 if (ff_layout_setup_sequence(wdata
->ds_clp
,
1685 &wdata
->args
.seq_args
,
1686 &wdata
->res
.seq_res
,
1689 ff_layout_commit_prepare_common(task
, data
);
1692 static void ff_layout_commit_done(struct rpc_task
*task
, void *data
)
1694 pnfs_generic_write_commit_done(task
, data
);
1697 static void ff_layout_commit_count_stats(struct rpc_task
*task
, void *data
)
1699 struct nfs_commit_data
*cdata
= data
;
1701 ff_layout_commit_record_layoutstats_done(task
, cdata
);
1702 rpc_count_iostats_metrics(task
,
1703 &NFS_CLIENT(cdata
->inode
)->cl_metrics
[NFSPROC4_CLNT_COMMIT
]);
1706 static void ff_layout_commit_release(void *data
)
1708 struct nfs_commit_data
*cdata
= data
;
1710 ff_layout_commit_record_layoutstats_done(&cdata
->task
, cdata
);
1711 pnfs_generic_commit_release(data
);
1714 static 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
,
1718 .rpc_release
= ff_layout_read_release
,
1721 static 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
,
1725 .rpc_release
= ff_layout_read_release
,
1728 static 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
,
1732 .rpc_release
= ff_layout_write_release
,
1735 static 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
,
1739 .rpc_release
= ff_layout_write_release
,
1742 static const struct rpc_call_ops ff_layout_commit_call_ops_v3
= {
1743 .rpc_call_prepare
= ff_layout_commit_prepare_v3
,
1744 .rpc_call_done
= ff_layout_commit_done
,
1745 .rpc_count_stats
= ff_layout_commit_count_stats
,
1746 .rpc_release
= ff_layout_commit_release
,
1749 static const struct rpc_call_ops ff_layout_commit_call_ops_v4
= {
1750 .rpc_call_prepare
= ff_layout_commit_prepare_v4
,
1751 .rpc_call_done
= ff_layout_commit_done
,
1752 .rpc_count_stats
= ff_layout_commit_count_stats
,
1753 .rpc_release
= ff_layout_commit_release
,
1756 static enum pnfs_try_status
1757 ff_layout_read_pagelist(struct nfs_pgio_header
*hdr
)
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
;
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
);
1772 ds
= nfs4_ff_layout_prepare_ds(lseg
, idx
, false);
1776 ds_clnt
= nfs4_ff_find_or_create_ds_client(lseg
, idx
, ds
->ds_clp
,
1778 if (IS_ERR(ds_clnt
))
1781 ds_cred
= ff_layout_get_ds_cred(lseg
, idx
, hdr
->cred
);
1785 vers
= nfs4_ff_layout_ds_version(lseg
, idx
);
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
);
1790 hdr
->pgio_done_cb
= ff_layout_read_done_cb
;
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
);
1797 * Note that if we ever decide to split across DSes,
1798 * then we may need to handle dense-like offsets.
1800 hdr
->args
.offset
= offset
;
1801 hdr
->mds_offset
= offset
;
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
);
1808 put_rpccred(ds_cred
);
1809 return PNFS_ATTEMPTED
;
1812 if (ff_layout_avoid_mds_available_ds(lseg
))
1813 return PNFS_TRY_AGAIN
;
1814 return PNFS_NOT_ATTEMPTED
;
1817 /* Perform async writes. */
1818 static enum pnfs_try_status
1819 ff_layout_write_pagelist(struct nfs_pgio_header
*hdr
, int sync
)
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
;
1828 int idx
= hdr
->pgio_mirror_idx
;
1830 ds
= nfs4_ff_layout_prepare_ds(lseg
, idx
, true);
1832 return PNFS_NOT_ATTEMPTED
;
1834 ds_clnt
= nfs4_ff_find_or_create_ds_client(lseg
, idx
, ds
->ds_clp
,
1836 if (IS_ERR(ds_clnt
))
1837 return PNFS_NOT_ATTEMPTED
;
1839 ds_cred
= ff_layout_get_ds_cred(lseg
, idx
, hdr
->cred
);
1841 return PNFS_NOT_ATTEMPTED
;
1843 vers
= nfs4_ff_layout_ds_version(lseg
, idx
);
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
),
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
);
1859 * Note that if we ever decide to split across DSes,
1860 * then we may need to handle dense-like offsets.
1862 hdr
->args
.offset
= offset
;
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
);
1869 put_rpccred(ds_cred
);
1870 return PNFS_ATTEMPTED
;
1873 static u32
calc_ds_index_from_commit(struct pnfs_layout_segment
*lseg
, u32 i
)
1878 static struct nfs_fh
*
1879 select_ds_fh_from_commit(struct pnfs_layout_segment
*lseg
, u32 i
)
1881 struct nfs4_ff_layout_segment
*flseg
= FF_LAYOUT_LSEG(lseg
);
1883 /* FIXME: Assume that there is only one NFS version available
1886 return &flseg
->mirror_array
[i
]->fh_versions
[0];
1889 static int ff_layout_initiate_commit(struct nfs_commit_data
*data
, int how
)
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
;
1899 idx
= calc_ds_index_from_commit(lseg
, data
->ds_commit_index
);
1900 ds
= nfs4_ff_layout_prepare_ds(lseg
, idx
, true);
1904 ds_clnt
= nfs4_ff_find_or_create_ds_client(lseg
, idx
, ds
->ds_clp
,
1906 if (IS_ERR(ds_clnt
))
1909 ds_cred
= ff_layout_get_ds_cred(lseg
, idx
, data
->cred
);
1913 vers
= nfs4_ff_layout_ds_version(lseg
, idx
);
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
),
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
);
1926 ret
= nfs_initiate_commit(ds_clnt
, data
, ds
->ds_clp
->rpc_ops
,
1927 vers
== 3 ? &ff_layout_commit_call_ops_v3
:
1928 &ff_layout_commit_call_ops_v4
,
1929 how
, RPC_TASK_SOFTCONN
);
1930 put_rpccred(ds_cred
);
1933 pnfs_generic_prepare_to_resend_writes(data
);
1934 pnfs_generic_commit_release(data
);
1939 ff_layout_commit_pagelist(struct inode
*inode
, struct list_head
*mds_pages
,
1940 int how
, struct nfs_commit_info
*cinfo
)
1942 return pnfs_generic_commit_pagelist(inode
, mds_pages
, how
, cinfo
,
1943 ff_layout_initiate_commit
);
1946 static struct pnfs_ds_commit_info
*
1947 ff_layout_get_ds_info(struct inode
*inode
)
1949 struct pnfs_layout_hdr
*layout
= NFS_I(inode
)->layout
;
1954 return &FF_LAYOUT_FROM_HDR(layout
)->commit_info
;
1958 ff_layout_free_deviceid_node(struct nfs4_deviceid_node
*d
)
1960 nfs4_ff_layout_free_deviceid(container_of(d
, struct nfs4_ff_layout_ds
,
1964 static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout
*flo
,
1965 struct xdr_stream
*xdr
,
1966 const struct nfs4_layoutreturn_args
*args
)
1968 struct pnfs_layout_hdr
*hdr
= &flo
->generic_hdr
;
1970 int count
= 0, ret
= 0;
1972 start
= xdr_reserve_space(xdr
, 4);
1973 if (unlikely(!start
))
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
);
1981 *start
= cpu_to_be32(count
);
1986 /* report nothing for now */
1987 static void ff_layout_encode_iostats(struct nfs4_flexfile_layout
*flo
,
1988 struct xdr_stream
*xdr
,
1989 const struct nfs4_layoutreturn_args
*args
)
1993 p
= xdr_reserve_space(xdr
, 4);
1995 *p
= cpu_to_be32(0);
1998 static struct nfs4_deviceid_node
*
1999 ff_layout_alloc_deviceid_node(struct nfs_server
*server
,
2000 struct pnfs_device
*pdev
, gfp_t gfp_flags
)
2002 struct nfs4_ff_layout_ds
*dsaddr
;
2004 dsaddr
= nfs4_ff_alloc_deviceid_node(server
, pdev
, gfp_flags
);
2007 return &dsaddr
->id_node
;
2011 ff_layout_encode_layoutreturn(struct pnfs_layout_hdr
*lo
,
2012 struct xdr_stream
*xdr
,
2013 const struct nfs4_layoutreturn_args
*args
)
2015 struct nfs4_flexfile_layout
*flo
= FF_LAYOUT_FROM_HDR(lo
);
2018 dprintk("%s: Begin\n", __func__
);
2019 start
= xdr_reserve_space(xdr
, 4);
2022 ff_layout_encode_ioerr(flo
, xdr
, args
);
2023 ff_layout_encode_iostats(flo
, xdr
, args
);
2025 *start
= cpu_to_be32((xdr
->p
- start
- 1) * 4);
2026 dprintk("%s: Return\n", __func__
);
2030 ff_layout_ntop4(const struct sockaddr
*sap
, char *buf
, const size_t buflen
)
2032 const struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
2034 return snprintf(buf
, buflen
, "%pI4", &sin
->sin_addr
);
2038 ff_layout_ntop6_noscopeid(const struct sockaddr
*sap
, char *buf
,
2041 const struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sap
;
2042 const struct in6_addr
*addr
= &sin6
->sin6_addr
;
2045 * RFC 4291, Section 2.2.2
2047 * Shorthanded ANY address
2049 if (ipv6_addr_any(addr
))
2050 return snprintf(buf
, buflen
, "::");
2053 * RFC 4291, Section 2.2.2
2055 * Shorthanded loopback address
2057 if (ipv6_addr_loopback(addr
))
2058 return snprintf(buf
, buflen
, "::1");
2061 * RFC 4291, Section 2.2.3
2063 * Special presentation address format for mapped v4
2066 if (ipv6_addr_v4mapped(addr
))
2067 return snprintf(buf
, buflen
, "::ffff:%pI4",
2068 &addr
->s6_addr32
[3]);
2071 * RFC 4291, Section 2.2.1
2073 return snprintf(buf
, buflen
, "%pI6c", addr
);
2076 /* Derived from rpc_sockaddr2uaddr */
2078 ff_layout_encode_netaddr(struct xdr_stream
*xdr
, struct nfs4_pnfs_ds_addr
*da
)
2080 struct sockaddr
*sap
= (struct sockaddr
*)&da
->da_addr
;
2081 char portbuf
[RPCBIND_MAXUADDRPLEN
];
2082 char addrbuf
[RPCBIND_MAXUADDRLEN
];
2084 unsigned short port
;
2088 switch (sap
->sa_family
) {
2090 if (ff_layout_ntop4(sap
, addrbuf
, sizeof(addrbuf
)) == 0)
2092 port
= ntohs(((struct sockaddr_in
*)sap
)->sin_port
);
2097 if (ff_layout_ntop6_noscopeid(sap
, addrbuf
, sizeof(addrbuf
)) == 0)
2099 port
= ntohs(((struct sockaddr_in6
*)sap
)->sin6_port
);
2104 /* we only support tcp and tcp6 */
2109 snprintf(portbuf
, sizeof(portbuf
), ".%u.%u", port
>> 8, port
& 0xff);
2110 len
= strlcat(addrbuf
, portbuf
, sizeof(addrbuf
));
2112 p
= xdr_reserve_space(xdr
, 4 + netid_len
);
2113 xdr_encode_opaque(p
, netid
, netid_len
);
2115 p
= xdr_reserve_space(xdr
, 4 + len
);
2116 xdr_encode_opaque(p
, addrbuf
, len
);
2120 ff_layout_encode_nfstime(struct xdr_stream
*xdr
,
2123 struct timespec64 ts
;
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
);
2133 ff_layout_encode_io_latency(struct xdr_stream
*xdr
,
2134 struct nfs4_ff_io_stat
*stat
)
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
);
2149 ff_layout_encode_layoutstats(struct xdr_stream
*xdr
,
2150 struct nfs42_layoutstat_args
*args
,
2151 struct nfs42_layoutstat_devinfo
*devinfo
)
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];
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);
2165 ff_layout_encode_netaddr(xdr
, da
);
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
);
2176 ff_layout_encode_nfstime(xdr
, ktime_sub(ktime_get(), mirror
->start_time
));
2178 p
= xdr_reserve_space(xdr
, 4);
2179 *p
= cpu_to_be32(false);
2181 *start
= cpu_to_be32((xdr
->p
- start
- 1) * 4);
2185 ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args
*args
,
2186 struct pnfs_layout_hdr
*lo
,
2189 struct nfs4_flexfile_layout
*ff_layout
= FF_LAYOUT_FROM_HDR(lo
);
2190 struct nfs4_ff_layout_mirror
*mirror
;
2191 struct nfs4_deviceid_node
*dev
;
2192 struct nfs42_layoutstat_devinfo
*devinfo
;
2195 list_for_each_entry(mirror
, &ff_layout
->mirrors
, mirrors
) {
2198 if (!mirror
->mirror_ds
)
2200 /* mirror refcount put in cleanup_layoutstats */
2201 if (!atomic_inc_not_zero(&mirror
->ref
))
2203 dev
= &mirror
->mirror_ds
->id_node
;
2204 devinfo
= &args
->devinfo
[i
];
2205 memcpy(&devinfo
->dev_id
, &dev
->deviceid
, NFS4_DEVICEID4_SIZE
);
2206 devinfo
->offset
= 0;
2207 devinfo
->length
= NFS4_MAX_UINT64
;
2208 devinfo
->read_count
= mirror
->read_stat
.io_stat
.ops_completed
;
2209 devinfo
->read_bytes
= mirror
->read_stat
.io_stat
.bytes_completed
;
2210 devinfo
->write_count
= mirror
->write_stat
.io_stat
.ops_completed
;
2211 devinfo
->write_bytes
= mirror
->write_stat
.io_stat
.bytes_completed
;
2212 devinfo
->layout_type
= LAYOUT_FLEX_FILES
;
2213 devinfo
->layoutstats_encode
= ff_layout_encode_layoutstats
;
2214 devinfo
->layout_private
= mirror
;
2222 ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args
*args
)
2224 struct nfs4_flexfile_layout
*ff_layout
;
2225 struct nfs4_ff_layout_mirror
*mirror
;
2228 spin_lock(&args
->inode
->i_lock
);
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)
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
;
2241 args
->devinfo
= kmalloc_array(dev_count
, sizeof(*args
->devinfo
), GFP_NOIO
);
2245 spin_lock(&args
->inode
->i_lock
);
2246 args
->num_dev
= ff_layout_mirror_prepare_stats(args
,
2247 &ff_layout
->generic_hdr
, dev_count
);
2248 spin_unlock(&args
->inode
->i_lock
);
2254 ff_layout_cleanup_layoutstats(struct nfs42_layoutstat_data
*data
)
2256 struct nfs4_ff_layout_mirror
*mirror
;
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
;
2262 ff_layout_put_mirror(mirror
);
2266 static 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
,
2274 .add_lseg
= ff_layout_add_lseg
,
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
,
2278 .free_deviceid_node
= ff_layout_free_deviceid_node
,
2279 .mark_request_commit
= pnfs_layout_mark_request_commit
,
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
,
2288 .sync
= pnfs_nfs_generic_sync
,
2289 .prepare_layoutstats
= ff_layout_prepare_layoutstats
,
2290 .cleanup_layoutstats
= ff_layout_cleanup_layoutstats
,
2293 static int __init
nfs4flexfilelayout_init(void)
2295 printk(KERN_INFO
"%s: NFSv4 Flexfile Layout Driver Registering...\n",
2297 if (!ff_zero_group
) {
2298 ff_zero_group
= groups_alloc(0);
2302 return pnfs_register_layoutdriver(&flexfilelayout_type
);
2305 static void __exit
nfs4flexfilelayout_exit(void)
2307 printk(KERN_INFO
"%s: NFSv4 Flexfile Layout Driver Unregistering...\n",
2309 pnfs_unregister_layoutdriver(&flexfilelayout_type
);
2310 if (ff_zero_group
) {
2311 put_group_info(ff_zero_group
);
2312 ff_zero_group
= NULL
;
2316 MODULE_ALIAS("nfs-layouttype4-4");
2318 MODULE_LICENSE("GPL");
2319 MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");
2321 module_init(nfs4flexfilelayout_init
);
2322 module_exit(nfs4flexfilelayout_exit
);