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 | |
| 12 | #include "../pnfs.h" |
| 13 | |
| 14 | /* XXX: Let's filter out insanely large mirror count for now to avoid oom |
| 15 | * due to network error etc. */ |
| 16 | #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096 |
| 17 | |
| 18 | struct nfs4_ff_ds_version { |
| 19 | u32 version; |
| 20 | u32 minor_version; |
| 21 | u32 rsize; |
| 22 | u32 wsize; |
| 23 | bool tightly_coupled; |
| 24 | }; |
| 25 | |
| 26 | /* chained in global deviceid hlist */ |
| 27 | struct nfs4_ff_layout_ds { |
| 28 | struct nfs4_deviceid_node id_node; |
| 29 | u32 ds_versions_cnt; |
| 30 | struct nfs4_ff_ds_version *ds_versions; |
| 31 | struct nfs4_pnfs_ds *ds; |
| 32 | }; |
| 33 | |
| 34 | struct nfs4_ff_layout_ds_err { |
| 35 | struct list_head list; /* linked in mirror error_list */ |
| 36 | u64 offset; |
| 37 | u64 length; |
| 38 | int status; |
| 39 | enum nfs_opnum4 opnum; |
| 40 | nfs4_stateid stateid; |
| 41 | struct nfs4_deviceid deviceid; |
| 42 | }; |
| 43 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 44 | struct nfs4_ff_io_stat { |
| 45 | __u64 ops_requested; |
| 46 | __u64 bytes_requested; |
| 47 | __u64 ops_completed; |
| 48 | __u64 bytes_completed; |
| 49 | __u64 bytes_not_delivered; |
| 50 | ktime_t total_busy_time; |
| 51 | ktime_t aggregate_completion_time; |
| 52 | }; |
| 53 | |
| 54 | struct nfs4_ff_busy_timer { |
| 55 | ktime_t start_time; |
| 56 | atomic_t n_ops; |
| 57 | }; |
| 58 | |
| 59 | struct nfs4_ff_layoutstat { |
| 60 | struct nfs4_ff_io_stat io_stat; |
| 61 | struct nfs4_ff_busy_timer busy_timer; |
| 62 | }; |
| 63 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 64 | struct nfs4_ff_layout_mirror { |
| 65 | u32 ds_count; |
| 66 | u32 efficiency; |
| 67 | struct nfs4_ff_layout_ds *mirror_ds; |
| 68 | u32 fh_versions_cnt; |
| 69 | struct nfs_fh *fh_versions; |
| 70 | nfs4_stateid stateid; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 71 | u32 uid; |
| 72 | u32 gid; |
| 73 | struct rpc_cred *cred; |
| 74 | spinlock_t lock; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 75 | struct nfs4_ff_layoutstat read_stat; |
| 76 | struct nfs4_ff_layoutstat write_stat; |
Peng Tao | d983803 | 2015-06-23 19:52:00 +0800 | [diff] [blame] | 77 | ktime_t start_time; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct nfs4_ff_layout_segment { |
| 81 | struct pnfs_layout_segment generic_hdr; |
| 82 | u64 stripe_unit; |
| 83 | u32 mirror_array_cnt; |
| 84 | struct nfs4_ff_layout_mirror **mirror_array; |
| 85 | }; |
| 86 | |
| 87 | struct nfs4_flexfile_layout { |
| 88 | struct pnfs_layout_hdr generic_hdr; |
| 89 | struct pnfs_ds_commit_info commit_info; |
| 90 | struct list_head error_list; /* nfs4_ff_layout_ds_err */ |
| 91 | }; |
| 92 | |
| 93 | static inline struct nfs4_flexfile_layout * |
| 94 | FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) |
| 95 | { |
| 96 | return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); |
| 97 | } |
| 98 | |
| 99 | static inline struct nfs4_ff_layout_segment * |
| 100 | FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) |
| 101 | { |
| 102 | return container_of(lseg, |
| 103 | struct nfs4_ff_layout_segment, |
| 104 | generic_hdr); |
| 105 | } |
| 106 | |
| 107 | static inline struct nfs4_deviceid_node * |
| 108 | FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx) |
| 109 | { |
| 110 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt || |
| 111 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx] == NULL || |
| 112 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds == NULL) |
| 113 | return NULL; |
| 114 | return &FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds->id_node; |
| 115 | } |
| 116 | |
| 117 | static inline struct nfs4_ff_layout_ds * |
| 118 | FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) |
| 119 | { |
| 120 | return container_of(node, struct nfs4_ff_layout_ds, id_node); |
| 121 | } |
| 122 | |
| 123 | static inline struct nfs4_ff_layout_mirror * |
| 124 | FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx) |
| 125 | { |
| 126 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt) |
| 127 | return NULL; |
| 128 | return FF_LAYOUT_LSEG(lseg)->mirror_array[idx]; |
| 129 | } |
| 130 | |
| 131 | static inline u32 |
| 132 | FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) |
| 133 | { |
| 134 | return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; |
| 135 | } |
| 136 | |
| 137 | static inline bool |
| 138 | ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node) |
| 139 | { |
| 140 | return nfs4_test_deviceid_unavailable(node); |
| 141 | } |
| 142 | |
| 143 | static inline int |
| 144 | nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 145 | { |
| 146 | return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version; |
| 147 | } |
| 148 | |
| 149 | struct nfs4_ff_layout_ds * |
| 150 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 151 | gfp_t gfp_flags); |
| 152 | void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 153 | void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 154 | int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo, |
| 155 | struct nfs4_ff_layout_mirror *mirror, u64 offset, |
| 156 | u64 length, int status, enum nfs_opnum4 opnum, |
| 157 | gfp_t gfp_flags); |
| 158 | int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo, |
| 159 | struct xdr_stream *xdr, int *count, |
| 160 | const struct pnfs_layout_range *range); |
| 161 | struct nfs_fh * |
| 162 | nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx); |
| 163 | |
| 164 | struct nfs4_pnfs_ds * |
| 165 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, |
| 166 | bool fail_return); |
| 167 | |
| 168 | struct rpc_clnt * |
| 169 | nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg, |
| 170 | u32 ds_idx, |
| 171 | struct nfs_client *ds_clp, |
| 172 | struct inode *inode); |
| 173 | struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, |
| 174 | u32 ds_idx, struct rpc_cred *mdscred); |
| 175 | bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg); |
| 176 | #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ |