blob: 1bcdb15d0c41a74d139ce7db378c3e19844052a0 [file] [log] [blame]
Tom Haynesd67ae822014-12-11 17:02:04 -05001/*
2 * NFSv4 flexfile layout driver data structures.
3 *
4 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
5 *
6 * Tao Peng <bergwolf@primarydata.com>
7 */
8
9#ifndef FS_NFS_NFS4FLEXFILELAYOUT_H
10#define FS_NFS_NFS4FLEXFILELAYOUT_H
11
Trond Myklebustc0f5f502015-06-26 14:51:32 -040012#define FF_FLAGS_NO_LAYOUTCOMMIT 1
Tom Haynesfb1084e2016-05-25 07:31:12 -070013#define FF_FLAGS_NO_IO_THRU_MDS 2
14#define FF_FLAGS_NO_READ_IO 4
Trond Myklebustc0f5f502015-06-26 14:51:32 -040015
Tom Haynesd67ae822014-12-11 17:02:04 -050016#include "../pnfs.h"
17
18/* XXX: Let's filter out insanely large mirror count for now to avoid oom
19 * due to network error etc. */
20#define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096
21
Peng Tao97ba3752015-06-23 19:52:04 +080022/* LAYOUTSTATS report interval in ms */
23#define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
24
Tom Haynesd67ae822014-12-11 17:02:04 -050025struct nfs4_ff_ds_version {
26 u32 version;
27 u32 minor_version;
28 u32 rsize;
29 u32 wsize;
30 bool tightly_coupled;
31};
32
33/* chained in global deviceid hlist */
34struct nfs4_ff_layout_ds {
35 struct nfs4_deviceid_node id_node;
36 u32 ds_versions_cnt;
37 struct nfs4_ff_ds_version *ds_versions;
38 struct nfs4_pnfs_ds *ds;
39};
40
41struct nfs4_ff_layout_ds_err {
42 struct list_head list; /* linked in mirror error_list */
43 u64 offset;
44 u64 length;
45 int status;
46 enum nfs_opnum4 opnum;
47 nfs4_stateid stateid;
48 struct nfs4_deviceid deviceid;
49};
50
Trond Myklebustabcb7bf2015-06-23 19:51:59 +080051struct nfs4_ff_io_stat {
52 __u64 ops_requested;
53 __u64 bytes_requested;
54 __u64 ops_completed;
55 __u64 bytes_completed;
56 __u64 bytes_not_delivered;
57 ktime_t total_busy_time;
58 ktime_t aggregate_completion_time;
59};
60
61struct nfs4_ff_busy_timer {
62 ktime_t start_time;
63 atomic_t n_ops;
64};
65
66struct nfs4_ff_layoutstat {
67 struct nfs4_ff_io_stat io_stat;
68 struct nfs4_ff_busy_timer busy_timer;
69};
70
Tom Haynesd67ae822014-12-11 17:02:04 -050071struct nfs4_ff_layout_mirror {
Trond Myklebust266d12d2015-08-24 20:03:17 -040072 struct pnfs_layout_hdr *layout;
73 struct list_head mirrors;
Tom Haynesd67ae822014-12-11 17:02:04 -050074 u32 ds_count;
75 u32 efficiency;
76 struct nfs4_ff_layout_ds *mirror_ds;
77 u32 fh_versions_cnt;
78 struct nfs_fh *fh_versions;
79 nfs4_stateid stateid;
Jeff Layton3064b682016-04-21 20:52:00 -040080 struct rpc_cred __rcu *ro_cred;
81 struct rpc_cred __rcu *rw_cred;
Trond Myklebust28a0d722015-08-24 18:08:30 -040082 atomic_t ref;
Tom Haynesd67ae822014-12-11 17:02:04 -050083 spinlock_t lock;
Trond Myklebustabcb7bf2015-06-23 19:51:59 +080084 struct nfs4_ff_layoutstat read_stat;
85 struct nfs4_ff_layoutstat write_stat;
Peng Taod9838032015-06-23 19:52:00 +080086 ktime_t start_time;
Peng Tao97ba3752015-06-23 19:52:04 +080087 ktime_t last_report_time;
Trond Myklebustd0379a52015-11-16 11:26:07 -050088 u32 report_interval;
Tom Haynesd67ae822014-12-11 17:02:04 -050089};
90
91struct nfs4_ff_layout_segment {
92 struct pnfs_layout_segment generic_hdr;
93 u64 stripe_unit;
Trond Myklebustc0f5f502015-06-26 14:51:32 -040094 u32 flags;
Tom Haynesd67ae822014-12-11 17:02:04 -050095 u32 mirror_array_cnt;
96 struct nfs4_ff_layout_mirror **mirror_array;
97};
98
99struct nfs4_flexfile_layout {
100 struct pnfs_layout_hdr generic_hdr;
101 struct pnfs_ds_commit_info commit_info;
Trond Myklebust266d12d2015-08-24 20:03:17 -0400102 struct list_head mirrors;
Tom Haynesd67ae822014-12-11 17:02:04 -0500103 struct list_head error_list; /* nfs4_ff_layout_ds_err */
104};
105
106static inline struct nfs4_flexfile_layout *
107FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo)
108{
109 return container_of(lo, struct nfs4_flexfile_layout, generic_hdr);
110}
111
112static inline struct nfs4_ff_layout_segment *
113FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg)
114{
115 return container_of(lseg,
116 struct nfs4_ff_layout_segment,
117 generic_hdr);
118}
119
120static inline struct nfs4_deviceid_node *
121FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx)
122{
123 if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt ||
124 FF_LAYOUT_LSEG(lseg)->mirror_array[idx] == NULL ||
125 FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds == NULL)
126 return NULL;
127 return &FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds->id_node;
128}
129
130static inline struct nfs4_ff_layout_ds *
131FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node)
132{
133 return container_of(node, struct nfs4_ff_layout_ds, id_node);
134}
135
136static inline struct nfs4_ff_layout_mirror *
137FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx)
138{
139 if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt)
140 return NULL;
141 return FF_LAYOUT_LSEG(lseg)->mirror_array[idx];
142}
143
144static inline u32
145FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg)
146{
147 return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt;
148}
149
150static inline bool
Trond Myklebust260074c2015-11-02 09:59:00 -0500151ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg)
152{
153 return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS;
154}
155
156static inline bool
Tom Haynesfb1084e2016-05-25 07:31:12 -0700157ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg)
158{
159 return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_READ_IO;
160}
161
162static inline bool
Tom Haynesd67ae822014-12-11 17:02:04 -0500163ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node)
164{
165 return nfs4_test_deviceid_unavailable(node);
166}
167
168static inline int
169nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx)
170{
171 return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version;
172}
173
174struct nfs4_ff_layout_ds *
175nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
176 gfp_t gfp_flags);
177void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
178void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
179int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
180 struct nfs4_ff_layout_mirror *mirror, u64 offset,
181 u64 length, int status, enum nfs_opnum4 opnum,
182 gfp_t gfp_flags);
183int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo,
184 struct xdr_stream *xdr, int *count,
185 const struct pnfs_layout_range *range);
186struct nfs_fh *
187nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx);
188
189struct nfs4_pnfs_ds *
190nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
191 bool fail_return);
192
193struct rpc_clnt *
194nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
195 u32 ds_idx,
196 struct nfs_client *ds_clp,
197 struct inode *inode);
198struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
199 u32 ds_idx, struct rpc_cred *mdscred);
200bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg);
Tom Haynes3b13b4b2016-05-17 12:28:37 -0400201bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg);
Tom Haynesfb1084e2016-05-25 07:31:12 -0700202bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg);
203
Tom Haynesd67ae822014-12-11 17:02:04 -0500204#endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */