Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1 | /* |
| 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 Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 12 | #define FF_FLAGS_NO_LAYOUTCOMMIT 1 |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 13 | #define FF_FLAGS_NO_IO_THRU_MDS 2 |
| 14 | #define FF_FLAGS_NO_READ_IO 4 |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 15 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 16 | #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 Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 22 | /* LAYOUTSTATS report interval in ms */ |
| 23 | #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L) |
| 24 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 25 | struct 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 */ |
| 34 | struct 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 | |
| 41 | struct 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 Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 51 | struct 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 | |
| 61 | struct nfs4_ff_busy_timer { |
| 62 | ktime_t start_time; |
| 63 | atomic_t n_ops; |
| 64 | }; |
| 65 | |
| 66 | struct nfs4_ff_layoutstat { |
| 67 | struct nfs4_ff_io_stat io_stat; |
| 68 | struct nfs4_ff_busy_timer busy_timer; |
| 69 | }; |
| 70 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 71 | struct nfs4_ff_layout_mirror { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame] | 72 | struct pnfs_layout_hdr *layout; |
| 73 | struct list_head mirrors; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 74 | 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 Layton | 3064b68 | 2016-04-21 20:52:00 -0400 | [diff] [blame] | 80 | struct rpc_cred __rcu *ro_cred; |
| 81 | struct rpc_cred __rcu *rw_cred; |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 82 | atomic_t ref; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 83 | spinlock_t lock; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 84 | struct nfs4_ff_layoutstat read_stat; |
| 85 | struct nfs4_ff_layoutstat write_stat; |
Peng Tao | d983803 | 2015-06-23 19:52:00 +0800 | [diff] [blame] | 86 | ktime_t start_time; |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 87 | ktime_t last_report_time; |
Trond Myklebust | d0379a5 | 2015-11-16 11:26:07 -0500 | [diff] [blame] | 88 | u32 report_interval; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct nfs4_ff_layout_segment { |
| 92 | struct pnfs_layout_segment generic_hdr; |
| 93 | u64 stripe_unit; |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 94 | u32 flags; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 95 | u32 mirror_array_cnt; |
| 96 | struct nfs4_ff_layout_mirror **mirror_array; |
| 97 | }; |
| 98 | |
| 99 | struct nfs4_flexfile_layout { |
| 100 | struct pnfs_layout_hdr generic_hdr; |
| 101 | struct pnfs_ds_commit_info commit_info; |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame] | 102 | struct list_head mirrors; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 103 | struct list_head error_list; /* nfs4_ff_layout_ds_err */ |
| 104 | }; |
| 105 | |
| 106 | static inline struct nfs4_flexfile_layout * |
| 107 | FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) |
| 108 | { |
| 109 | return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); |
| 110 | } |
| 111 | |
| 112 | static inline struct nfs4_ff_layout_segment * |
| 113 | FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) |
| 114 | { |
| 115 | return container_of(lseg, |
| 116 | struct nfs4_ff_layout_segment, |
| 117 | generic_hdr); |
| 118 | } |
| 119 | |
| 120 | static inline struct nfs4_deviceid_node * |
| 121 | FF_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 | |
| 130 | static inline struct nfs4_ff_layout_ds * |
| 131 | FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) |
| 132 | { |
| 133 | return container_of(node, struct nfs4_ff_layout_ds, id_node); |
| 134 | } |
| 135 | |
| 136 | static inline struct nfs4_ff_layout_mirror * |
| 137 | FF_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 | |
| 144 | static inline u32 |
| 145 | FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) |
| 146 | { |
| 147 | return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; |
| 148 | } |
| 149 | |
| 150 | static inline bool |
Trond Myklebust | 260074c | 2015-11-02 09:59:00 -0500 | [diff] [blame] | 151 | ff_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 | |
| 156 | static inline bool |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 157 | ff_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 | |
| 162 | static inline bool |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 163 | ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node) |
| 164 | { |
| 165 | return nfs4_test_deviceid_unavailable(node); |
| 166 | } |
| 167 | |
| 168 | static inline int |
| 169 | nfs4_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 | |
| 174 | struct nfs4_ff_layout_ds * |
| 175 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 176 | gfp_t gfp_flags); |
| 177 | void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 178 | void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 179 | int 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); |
| 183 | int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo, |
| 184 | struct xdr_stream *xdr, int *count, |
| 185 | const struct pnfs_layout_range *range); |
| 186 | struct nfs_fh * |
| 187 | nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx); |
| 188 | |
| 189 | struct nfs4_pnfs_ds * |
| 190 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, |
| 191 | bool fail_return); |
| 192 | |
| 193 | struct rpc_clnt * |
| 194 | nfs4_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); |
| 198 | struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, |
| 199 | u32 ds_idx, struct rpc_cred *mdscred); |
| 200 | bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg); |
Tom Haynes | 3b13b4b | 2016-05-17 12:28:37 -0400 | [diff] [blame] | 201 | bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg); |
Tom Haynes | fb1084e | 2016-05-25 07:31:12 -0700 | [diff] [blame] | 202 | bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg); |
| 203 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 204 | #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ |