• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * NFSv4 flexfile layout driver data structures.
4  *
5  * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
6  *
7  * Tao Peng <bergwolf@primarydata.com>
8  */
9 
10 #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H
11 #define FS_NFS_NFS4FLEXFILELAYOUT_H
12 
13 #define FF_FLAGS_NO_LAYOUTCOMMIT 1
14 #define FF_FLAGS_NO_IO_THRU_MDS  2
15 #define FF_FLAGS_NO_READ_IO      4
16 
17 #include "../pnfs.h"
18 
19 /* XXX: Let's filter out insanely large mirror count for now to avoid oom
20  * due to network error etc. */
21 #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096
22 
23 /* LAYOUTSTATS report interval in ms */
24 #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
25 #define FF_LAYOUTSTATS_MAXDEV 4
26 
27 struct nfs4_ff_ds_version {
28 	u32				version;
29 	u32				minor_version;
30 	u32				rsize;
31 	u32				wsize;
32 	bool				tightly_coupled;
33 };
34 
35 /* chained in global deviceid hlist */
36 struct nfs4_ff_layout_ds {
37 	struct nfs4_deviceid_node	id_node;
38 	u32				ds_versions_cnt;
39 	struct nfs4_ff_ds_version	*ds_versions;
40 	struct nfs4_pnfs_ds		*ds;
41 };
42 
43 struct nfs4_ff_layout_ds_err {
44 	struct list_head		list; /* linked in mirror error_list */
45 	u64				offset;
46 	u64				length;
47 	int				status;
48 	enum nfs_opnum4			opnum;
49 	nfs4_stateid			stateid;
50 	struct nfs4_deviceid		deviceid;
51 };
52 
53 struct nfs4_ff_io_stat {
54 	__u64				ops_requested;
55 	__u64				bytes_requested;
56 	__u64				ops_completed;
57 	__u64				bytes_completed;
58 	__u64				bytes_not_delivered;
59 	ktime_t				total_busy_time;
60 	ktime_t				aggregate_completion_time;
61 };
62 
63 struct nfs4_ff_busy_timer {
64 	ktime_t start_time;
65 	atomic_t n_ops;
66 };
67 
68 struct nfs4_ff_layoutstat {
69 	struct nfs4_ff_io_stat io_stat;
70 	struct nfs4_ff_busy_timer busy_timer;
71 };
72 
73 struct nfs4_ff_layout_mirror {
74 	struct pnfs_layout_hdr		*layout;
75 	struct list_head		mirrors;
76 	u32				ds_count;
77 	u32				efficiency;
78 	struct nfs4_deviceid		devid;
79 	struct nfs4_ff_layout_ds	*mirror_ds;
80 	u32				fh_versions_cnt;
81 	struct nfs_fh			*fh_versions;
82 	nfs4_stateid			stateid;
83 	struct rpc_cred	__rcu		*ro_cred;
84 	struct rpc_cred	__rcu		*rw_cred;
85 	atomic_t			ref;
86 	spinlock_t			lock;
87 	unsigned long			flags;
88 	struct nfs4_ff_layoutstat	read_stat;
89 	struct nfs4_ff_layoutstat	write_stat;
90 	ktime_t				start_time;
91 	u32				report_interval;
92 };
93 
94 #define NFS4_FF_MIRROR_STAT_AVAIL	(0)
95 
96 struct nfs4_ff_layout_segment {
97 	struct pnfs_layout_segment	generic_hdr;
98 	u64				stripe_unit;
99 	u32				flags;
100 	u32				mirror_array_cnt;
101 	struct nfs4_ff_layout_mirror	**mirror_array;
102 };
103 
104 struct nfs4_flexfile_layout {
105 	struct pnfs_layout_hdr generic_hdr;
106 	struct pnfs_ds_commit_info commit_info;
107 	struct list_head	mirrors;
108 	struct list_head	error_list; /* nfs4_ff_layout_ds_err */
109 	ktime_t			last_report_time; /* Layoutstat report times */
110 };
111 
112 struct nfs4_flexfile_layoutreturn_args {
113 	struct list_head errors;
114 	struct nfs42_layoutstat_devinfo devinfo[FF_LAYOUTSTATS_MAXDEV];
115 	unsigned int num_errors;
116 	unsigned int num_dev;
117 	struct page *pages[1];
118 };
119 
120 static inline struct nfs4_flexfile_layout *
FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr * lo)121 FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo)
122 {
123 	return container_of(lo, struct nfs4_flexfile_layout, generic_hdr);
124 }
125 
126 static inline struct nfs4_ff_layout_segment *
FF_LAYOUT_LSEG(struct pnfs_layout_segment * lseg)127 FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg)
128 {
129 	return container_of(lseg,
130 			    struct nfs4_ff_layout_segment,
131 			    generic_hdr);
132 }
133 
134 static inline struct nfs4_ff_layout_ds *
FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node * node)135 FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node)
136 {
137 	return container_of(node, struct nfs4_ff_layout_ds, id_node);
138 }
139 
140 static inline struct nfs4_ff_layout_mirror *
FF_LAYOUT_COMP(struct pnfs_layout_segment * lseg,u32 idx)141 FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx)
142 {
143 	struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
144 
145 	if (idx < fls->mirror_array_cnt)
146 		return fls->mirror_array[idx];
147 	return NULL;
148 }
149 
150 static inline struct nfs4_deviceid_node *
FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment * lseg,u32 idx)151 FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx)
152 {
153 	struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, idx);
154 
155 	if (mirror != NULL) {
156 		struct nfs4_ff_layout_ds *mirror_ds = mirror->mirror_ds;
157 
158 		if (!IS_ERR_OR_NULL(mirror_ds))
159 			return &mirror_ds->id_node;
160 	}
161 	return NULL;
162 }
163 
164 static inline u32
FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment * lseg)165 FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg)
166 {
167 	return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt;
168 }
169 
170 static inline bool
ff_layout_no_fallback_to_mds(struct pnfs_layout_segment * lseg)171 ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg)
172 {
173 	return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS;
174 }
175 
176 static inline bool
ff_layout_no_read_on_rw(struct pnfs_layout_segment * lseg)177 ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg)
178 {
179 	return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_READ_IO;
180 }
181 
182 static inline bool
ff_layout_test_devid_unavailable(struct nfs4_deviceid_node * node)183 ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node)
184 {
185 	/*
186 	 * Flexfiles should never mark a DS unavailable, but if it does
187 	 * print a (ratelimited) warning as this can affect performance.
188 	 */
189 	if (nfs4_test_deviceid_unavailable(node)) {
190 		u32 *p = (u32 *)node->deviceid.data;
191 
192 		pr_warn_ratelimited("NFS: flexfiles layout referencing an "
193 				"unavailable device [%x%x%x%x]\n",
194 				p[0], p[1], p[2], p[3]);
195 		return true;
196 	}
197 	return false;
198 }
199 
200 static inline int
nfs4_ff_layout_ds_version(struct pnfs_layout_segment * lseg,u32 ds_idx)201 nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx)
202 {
203 	return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version;
204 }
205 
206 struct nfs4_ff_layout_ds *
207 nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
208 			    gfp_t gfp_flags);
209 void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
210 void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
211 int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
212 			     struct nfs4_ff_layout_mirror *mirror, u64 offset,
213 			     u64 length, int status, enum nfs_opnum4 opnum,
214 			     gfp_t gfp_flags);
215 int ff_layout_encode_ds_ioerr(struct xdr_stream *xdr, const struct list_head *head);
216 void ff_layout_free_ds_ioerr(struct list_head *head);
217 unsigned int ff_layout_fetch_ds_ioerr(struct pnfs_layout_hdr *lo,
218 		const struct pnfs_layout_range *range,
219 		struct list_head *head,
220 		unsigned int maxnum);
221 struct nfs_fh *
222 nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx);
223 int
224 nfs4_ff_layout_select_ds_stateid(struct pnfs_layout_segment *lseg,
225 				u32 mirror_idx,
226 				nfs4_stateid *stateid);
227 
228 struct nfs4_pnfs_ds *
229 nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
230 			  bool fail_return);
231 
232 struct rpc_clnt *
233 nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
234 				 u32 ds_idx,
235 				 struct nfs_client *ds_clp,
236 				 struct inode *inode);
237 struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
238 				       u32 ds_idx, struct rpc_cred *mdscred);
239 bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg);
240 bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg);
241 
242 #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */
243