Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 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 | |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 13 | #define FF_FLAGS_NO_LAYOUTCOMMIT 1 |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 14 | #define FF_FLAGS_NO_IO_THRU_MDS 2 |
| 15 | #define FF_FLAGS_NO_READ_IO 4 |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 16 | |
Elena Reshetova | 81a090b | 2017-10-20 12:53:34 +0300 | [diff] [blame] | 17 | #include <linux/refcount.h> |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 18 | #include "../pnfs.h" |
| 19 | |
| 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 |
| 23 | |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 24 | /* LAYOUTSTATS report interval in ms */ |
| 25 | #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L) |
Trond Myklebust | 230bc96 | 2016-10-19 15:59:28 -0400 | [diff] [blame] | 26 | #define FF_LAYOUTSTATS_MAXDEV 4 |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 27 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 28 | struct nfs4_ff_ds_version { |
| 29 | u32 version; |
| 30 | u32 minor_version; |
| 31 | u32 rsize; |
| 32 | u32 wsize; |
| 33 | bool tightly_coupled; |
| 34 | }; |
| 35 | |
| 36 | /* chained in global deviceid hlist */ |
| 37 | struct nfs4_ff_layout_ds { |
| 38 | struct nfs4_deviceid_node id_node; |
| 39 | u32 ds_versions_cnt; |
| 40 | struct nfs4_ff_ds_version *ds_versions; |
| 41 | struct nfs4_pnfs_ds *ds; |
| 42 | }; |
| 43 | |
| 44 | struct nfs4_ff_layout_ds_err { |
| 45 | struct list_head list; /* linked in mirror error_list */ |
| 46 | u64 offset; |
| 47 | u64 length; |
| 48 | int status; |
| 49 | enum nfs_opnum4 opnum; |
| 50 | nfs4_stateid stateid; |
| 51 | struct nfs4_deviceid deviceid; |
| 52 | }; |
| 53 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 54 | struct nfs4_ff_io_stat { |
| 55 | __u64 ops_requested; |
| 56 | __u64 bytes_requested; |
| 57 | __u64 ops_completed; |
| 58 | __u64 bytes_completed; |
| 59 | __u64 bytes_not_delivered; |
| 60 | ktime_t total_busy_time; |
| 61 | ktime_t aggregate_completion_time; |
| 62 | }; |
| 63 | |
| 64 | struct nfs4_ff_busy_timer { |
| 65 | ktime_t start_time; |
| 66 | atomic_t n_ops; |
| 67 | }; |
| 68 | |
| 69 | struct nfs4_ff_layoutstat { |
| 70 | struct nfs4_ff_io_stat io_stat; |
| 71 | struct nfs4_ff_busy_timer busy_timer; |
| 72 | }; |
| 73 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 74 | struct nfs4_ff_layout_mirror { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame] | 75 | struct pnfs_layout_hdr *layout; |
| 76 | struct list_head mirrors; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 77 | u32 ds_count; |
| 78 | u32 efficiency; |
Fred Isaman | 65990d1 | 2016-09-30 14:37:41 -0400 | [diff] [blame] | 79 | struct nfs4_deviceid devid; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 80 | struct nfs4_ff_layout_ds *mirror_ds; |
| 81 | u32 fh_versions_cnt; |
| 82 | struct nfs_fh *fh_versions; |
| 83 | nfs4_stateid stateid; |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 84 | const struct cred __rcu *ro_cred; |
| 85 | const struct cred __rcu *rw_cred; |
Elena Reshetova | 81a090b | 2017-10-20 12:53:34 +0300 | [diff] [blame] | 86 | refcount_t ref; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 87 | spinlock_t lock; |
Trond Myklebust | 06946c6 | 2016-11-25 13:17:15 -0500 | [diff] [blame] | 88 | unsigned long flags; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 89 | struct nfs4_ff_layoutstat read_stat; |
| 90 | struct nfs4_ff_layoutstat write_stat; |
Peng Tao | d983803 | 2015-06-23 19:52:00 +0800 | [diff] [blame] | 91 | ktime_t start_time; |
Trond Myklebust | d0379a5 | 2015-11-16 11:26:07 -0500 | [diff] [blame] | 92 | u32 report_interval; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
Trond Myklebust | 06946c6 | 2016-11-25 13:17:15 -0500 | [diff] [blame] | 95 | #define NFS4_FF_MIRROR_STAT_AVAIL (0) |
| 96 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 97 | struct nfs4_ff_layout_segment { |
| 98 | struct pnfs_layout_segment generic_hdr; |
| 99 | u64 stripe_unit; |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 100 | u32 flags; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 101 | u32 mirror_array_cnt; |
Kees Cook | 1c67401 | 2023-09-15 13:14:39 -0700 | [diff] [blame] | 102 | struct nfs4_ff_layout_mirror *mirror_array[] __counted_by(mirror_array_cnt); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | struct nfs4_flexfile_layout { |
| 106 | struct pnfs_layout_hdr generic_hdr; |
| 107 | struct pnfs_ds_commit_info commit_info; |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame] | 108 | struct list_head mirrors; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 109 | struct list_head error_list; /* nfs4_ff_layout_ds_err */ |
Trond Myklebust | 1c8d477 | 2016-08-14 12:47:49 -0400 | [diff] [blame] | 110 | ktime_t last_report_time; /* Layoutstat report times */ |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 111 | }; |
| 112 | |
Trond Myklebust | 5b9b3c8 | 2016-12-02 16:15:05 -0500 | [diff] [blame] | 113 | struct nfs4_flexfile_layoutreturn_args { |
| 114 | struct list_head errors; |
Trond Myklebust | 230bc96 | 2016-10-19 15:59:28 -0400 | [diff] [blame] | 115 | struct nfs42_layoutstat_devinfo devinfo[FF_LAYOUTSTATS_MAXDEV]; |
Trond Myklebust | 5b9b3c8 | 2016-12-02 16:15:05 -0500 | [diff] [blame] | 116 | unsigned int num_errors; |
Trond Myklebust | 230bc96 | 2016-10-19 15:59:28 -0400 | [diff] [blame] | 117 | unsigned int num_dev; |
Trond Myklebust | d915211 | 2016-12-09 18:07:51 -0500 | [diff] [blame] | 118 | struct page *pages[1]; |
Trond Myklebust | 5b9b3c8 | 2016-12-02 16:15:05 -0500 | [diff] [blame] | 119 | }; |
| 120 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 121 | static inline struct nfs4_flexfile_layout * |
| 122 | FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) |
| 123 | { |
| 124 | return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); |
| 125 | } |
| 126 | |
| 127 | static inline struct nfs4_ff_layout_segment * |
| 128 | FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) |
| 129 | { |
| 130 | return container_of(lseg, |
| 131 | struct nfs4_ff_layout_segment, |
| 132 | generic_hdr); |
| 133 | } |
| 134 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 135 | static inline struct nfs4_ff_layout_ds * |
| 136 | FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) |
| 137 | { |
| 138 | return container_of(node, struct nfs4_ff_layout_ds, id_node); |
| 139 | } |
| 140 | |
| 141 | static inline struct nfs4_ff_layout_mirror * |
| 142 | FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx) |
| 143 | { |
Trond Myklebust | 108bb4a | 2019-02-26 11:19:46 -0500 | [diff] [blame] | 144 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); |
| 145 | |
| 146 | if (idx < fls->mirror_array_cnt) |
| 147 | return fls->mirror_array[idx]; |
| 148 | return NULL; |
| 149 | } |
| 150 | |
| 151 | static inline struct nfs4_deviceid_node * |
| 152 | FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx) |
| 153 | { |
| 154 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, idx); |
| 155 | |
| 156 | if (mirror != NULL) { |
| 157 | struct nfs4_ff_layout_ds *mirror_ds = mirror->mirror_ds; |
| 158 | |
| 159 | if (!IS_ERR_OR_NULL(mirror_ds)) |
| 160 | return &mirror_ds->id_node; |
| 161 | } |
| 162 | return NULL; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static inline u32 |
| 166 | FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) |
| 167 | { |
| 168 | return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; |
| 169 | } |
| 170 | |
| 171 | static inline bool |
Trond Myklebust | 260074c | 2015-11-02 09:59:00 -0500 | [diff] [blame] | 172 | ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg) |
| 173 | { |
| 174 | return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS; |
| 175 | } |
| 176 | |
| 177 | static inline bool |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 178 | ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg) |
| 179 | { |
| 180 | return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_READ_IO; |
| 181 | } |
| 182 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 183 | static inline int |
Trond Myklebust | 626d48b | 2019-02-28 10:44:15 -0500 | [diff] [blame] | 184 | nfs4_ff_layout_ds_version(const struct nfs4_ff_layout_mirror *mirror) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 185 | { |
Trond Myklebust | 626d48b | 2019-02-28 10:44:15 -0500 | [diff] [blame] | 186 | return mirror->mirror_ds->ds_versions[0].version; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | struct nfs4_ff_layout_ds * |
| 190 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 191 | gfp_t gfp_flags); |
| 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, |
| 197 | gfp_t gfp_flags); |
Trond Myklebust | f0922a6 | 2019-02-10 22:38:43 -0500 | [diff] [blame] | 198 | void ff_layout_send_layouterror(struct pnfs_layout_segment *lseg); |
Trond Myklebust | 5b9b3c8 | 2016-12-02 16:15:05 -0500 | [diff] [blame] | 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); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 205 | struct nfs_fh * |
Trond Myklebust | 749da52 | 2019-02-28 10:34:13 -0500 | [diff] [blame] | 206 | nfs4_ff_layout_select_ds_fh(struct nfs4_ff_layout_mirror *mirror); |
Trond Myklebust | 4cbc8a5 | 2019-02-28 10:49:11 -0500 | [diff] [blame] | 207 | void |
| 208 | nfs4_ff_layout_select_ds_stateid(const struct nfs4_ff_layout_mirror *mirror, |
| 209 | nfs4_stateid *stateid); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 210 | |
| 211 | struct nfs4_pnfs_ds * |
Trond Myklebust | 2444ff2 | 2019-02-14 13:45:45 -0500 | [diff] [blame] | 212 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, |
| 213 | struct nfs4_ff_layout_mirror *mirror, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 214 | bool fail_return); |
| 215 | |
| 216 | struct rpc_clnt * |
Trond Myklebust | 561d6f8 | 2019-02-28 10:38:41 -0500 | [diff] [blame] | 217 | nfs4_ff_find_or_create_ds_client(struct nfs4_ff_layout_mirror *mirror, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 218 | struct nfs_client *ds_clp, |
| 219 | struct inode *inode); |
Trond Myklebust | 312cd4c | 2019-02-28 10:41:57 -0500 | [diff] [blame] | 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); |
Tom Haynes | 3b13b4b | 2016-05-17 12:28:37 -0400 | [diff] [blame] | 223 | bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg); |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 224 | bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg); |
| 225 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 226 | #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ |