1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NFSv4 flexfile layout driver data structures.
5 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
7 * Tao Peng <bergwolf@primarydata.com>
10 #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H
11 #define FS_NFS_NFS4FLEXFILELAYOUT_H
13 #define FF_FLAGS_NO_LAYOUTCOMMIT 1
14 #define FF_FLAGS_NO_IO_THRU_MDS 2
15 #define FF_FLAGS_NO_READ_IO 4
17 #include <linux/refcount.h>
20 /* XXX: Let's filter out insanely large mirror count for now to avoid oom
21 * due to network error etc. */
22 #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096
24 /* LAYOUTSTATS report interval in ms */
25 #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
26 #define FF_LAYOUTSTATS_MAXDEV 4
28 struct nfs4_ff_ds_version
{
36 /* chained in global deviceid hlist */
37 struct nfs4_ff_layout_ds
{
38 struct nfs4_deviceid_node id_node
;
40 struct nfs4_ff_ds_version
*ds_versions
;
41 struct nfs4_pnfs_ds
*ds
;
44 struct nfs4_ff_layout_ds_err
{
45 struct list_head list
; /* linked in mirror error_list */
49 enum nfs_opnum4 opnum
;
51 struct nfs4_deviceid deviceid
;
54 struct nfs4_ff_io_stat
{
56 __u64 bytes_requested
;
58 __u64 bytes_completed
;
59 __u64 bytes_not_delivered
;
60 ktime_t total_busy_time
;
61 ktime_t aggregate_completion_time
;
64 struct nfs4_ff_busy_timer
{
69 struct nfs4_ff_layoutstat
{
70 struct nfs4_ff_io_stat io_stat
;
71 struct nfs4_ff_busy_timer busy_timer
;
74 struct nfs4_ff_layout_mirror
{
75 struct pnfs_layout_hdr
*layout
;
76 struct list_head mirrors
;
79 struct nfs4_deviceid devid
;
80 struct nfs4_ff_layout_ds
*mirror_ds
;
82 struct nfs_fh
*fh_versions
;
84 const struct cred __rcu
*ro_cred
;
85 const struct cred __rcu
*rw_cred
;
89 struct nfs4_ff_layoutstat read_stat
;
90 struct nfs4_ff_layoutstat write_stat
;
95 #define NFS4_FF_MIRROR_STAT_AVAIL (0)
97 struct nfs4_ff_layout_segment
{
98 struct pnfs_layout_segment generic_hdr
;
101 u32 mirror_array_cnt
;
102 struct nfs4_ff_layout_mirror
*mirror_array
[];
105 struct nfs4_flexfile_layout
{
106 struct pnfs_layout_hdr generic_hdr
;
107 struct pnfs_ds_commit_info commit_info
;
108 struct list_head mirrors
;
109 struct list_head error_list
; /* nfs4_ff_layout_ds_err */
110 ktime_t last_report_time
; /* Layoutstat report times */
113 struct nfs4_flexfile_layoutreturn_args
{
114 struct list_head errors
;
115 struct nfs42_layoutstat_devinfo devinfo
[FF_LAYOUTSTATS_MAXDEV
];
116 unsigned int num_errors
;
117 unsigned int num_dev
;
118 struct page
*pages
[1];
121 static inline struct nfs4_flexfile_layout
*
122 FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr
*lo
)
124 return container_of(lo
, struct nfs4_flexfile_layout
, generic_hdr
);
127 static inline struct nfs4_ff_layout_segment
*
128 FF_LAYOUT_LSEG(struct pnfs_layout_segment
*lseg
)
130 return container_of(lseg
,
131 struct nfs4_ff_layout_segment
,
135 static inline struct nfs4_ff_layout_ds
*
136 FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node
*node
)
138 return container_of(node
, struct nfs4_ff_layout_ds
, id_node
);
141 static inline struct nfs4_ff_layout_mirror
*
142 FF_LAYOUT_COMP(struct pnfs_layout_segment
*lseg
, u32 idx
)
144 struct nfs4_ff_layout_segment
*fls
= FF_LAYOUT_LSEG(lseg
);
146 if (idx
< fls
->mirror_array_cnt
)
147 return fls
->mirror_array
[idx
];
151 static inline struct nfs4_deviceid_node
*
152 FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment
*lseg
, u32 idx
)
154 struct nfs4_ff_layout_mirror
*mirror
= FF_LAYOUT_COMP(lseg
, idx
);
156 if (mirror
!= NULL
) {
157 struct nfs4_ff_layout_ds
*mirror_ds
= mirror
->mirror_ds
;
159 if (!IS_ERR_OR_NULL(mirror_ds
))
160 return &mirror_ds
->id_node
;
166 FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment
*lseg
)
168 return FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
;
172 ff_layout_no_fallback_to_mds(struct pnfs_layout_segment
*lseg
)
174 return FF_LAYOUT_LSEG(lseg
)->flags
& FF_FLAGS_NO_IO_THRU_MDS
;
178 ff_layout_no_read_on_rw(struct pnfs_layout_segment
*lseg
)
180 return FF_LAYOUT_LSEG(lseg
)->flags
& FF_FLAGS_NO_READ_IO
;
184 nfs4_ff_layout_ds_version(const struct nfs4_ff_layout_mirror
*mirror
)
186 return mirror
->mirror_ds
->ds_versions
[0].version
;
189 struct nfs4_ff_layout_ds
*
190 nfs4_ff_alloc_deviceid_node(struct nfs_server
*server
, struct pnfs_device
*pdev
,
192 void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
193 void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
194 int ff_layout_track_ds_error(struct nfs4_flexfile_layout
*flo
,
195 struct nfs4_ff_layout_mirror
*mirror
, u64 offset
,
196 u64 length
, int status
, enum nfs_opnum4 opnum
,
198 void ff_layout_send_layouterror(struct pnfs_layout_segment
*lseg
);
199 int ff_layout_encode_ds_ioerr(struct xdr_stream
*xdr
, const struct list_head
*head
);
200 void ff_layout_free_ds_ioerr(struct list_head
*head
);
201 unsigned int ff_layout_fetch_ds_ioerr(struct pnfs_layout_hdr
*lo
,
202 const struct pnfs_layout_range
*range
,
203 struct list_head
*head
,
204 unsigned int maxnum
);
206 nfs4_ff_layout_select_ds_fh(struct nfs4_ff_layout_mirror
*mirror
);
208 nfs4_ff_layout_select_ds_stateid(const struct nfs4_ff_layout_mirror
*mirror
,
209 nfs4_stateid
*stateid
);
211 struct nfs4_pnfs_ds
*
212 nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment
*lseg
,
213 struct nfs4_ff_layout_mirror
*mirror
,
217 nfs4_ff_find_or_create_ds_client(struct nfs4_ff_layout_mirror
*mirror
,
218 struct nfs_client
*ds_clp
,
219 struct inode
*inode
);
220 const struct cred
*ff_layout_get_ds_cred(struct nfs4_ff_layout_mirror
*mirror
,
221 const struct pnfs_layout_range
*range
,
222 const struct cred
*mdscred
);
223 bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment
*lseg
);
224 bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment
*lseg
);
226 #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */