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