| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* NFSv4 flexfile layout driver data structures. |
| 4 |
* |
| 5 |
* Copyright (c) 2014, Primary Data, Inc. All rights reserved. |
| 6 |
* |
| 7 |
* Tao Peng <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef FS_NFS_NFS4FLEXFILELAYOUT_H |
| 11 |
#define FS_NFS_NFS4FLEXFILELAYOUT_H |
| 12 |
|
| 13 |
#define FF_FLAGS_NO_LAYOUTCOMMIT 1 |
| 14 |
#define FF_FLAGS_NO_IO_THRU_MDS 2 |
| 15 |
#define FF_FLAGS_NO_READ_IO 4 |
| 16 |
|
| 17 |
#include <linux/refcount.h> |
| 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 |
|
| 24 |
#define NFS4_FLEXFILE_LAYOUT_MAX_STRIPE_CNT 4096 |
| 25 |
|
| 26 |
/* LAYOUTSTATS report interval in ms */ |
| 27 |
#define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L) |
| 28 |
#define FF_LAYOUTSTATS_MAXDEV 4 |
| 29 |
|
| 30 |
struct nfs4_ff_ds_version { |
| 31 |
u32 version; |
| 32 |
u32 minor_version; |
| 33 |
u32 rsize; |
| 34 |
u32 wsize; |
| 35 |
bool tightly_coupled; |
| 36 |
}; |
| 37 |
|
| 38 |
/* chained in global deviceid hlist */ |
| 39 |
struct nfs4_ff_layout_ds { |
| 40 |
struct nfs4_deviceid_node id_node; |
| 41 |
u32 ds_versions_cnt; |
| 42 |
struct nfs4_ff_ds_version *ds_versions; |
| 43 |
struct nfs4_pnfs_ds *ds; |
| 44 |
}; |
| 45 |
|
| 46 |
struct nfs4_ff_layout_ds_err { |
| 47 |
struct list_head list; /* linked in mirror error_list */ |
| 48 |
u64 offset; |
| 49 |
u64 length; |
| 50 |
int status; |
| 51 |
enum nfs_opnum4 opnum; |
| 52 |
nfs4_stateid stateid; |
| 53 |
struct nfs4_deviceid deviceid; |
| 54 |
}; |
| 55 |
|
| 56 |
struct nfs4_ff_io_stat { |
| 57 |
__u64 ops_requested; |
| 58 |
__u64 bytes_requested; |
| 59 |
__u64 ops_completed; |
| 60 |
__u64 bytes_completed; |
| 61 |
__u64 bytes_not_delivered; |
| 62 |
ktime_t total_busy_time; |
| 63 |
ktime_t aggregate_completion_time; |
| 64 |
}; |
| 65 |
|
| 66 |
struct nfs4_ff_busy_timer { |
| 67 |
ktime_t start_time; |
| 68 |
atomic_t n_ops; |
| 69 |
}; |
| 70 |
|
| 71 |
struct nfs4_ff_layoutstat { |
| 72 |
struct nfs4_ff_io_stat io_stat; |
| 73 |
struct nfs4_ff_busy_timer busy_timer; |
| 74 |
}; |
| 75 |
|
| 76 |
struct nfs4_ff_layout_mirror; |
| 77 |
|
| 78 |
struct nfs4_ff_layout_ds_stripe { |
| 79 |
struct nfs4_ff_layout_mirror *mirror; |
| 80 |
struct nfs4_deviceid devid; |
| 81 |
u32 efficiency; |
| 82 |
struct nfs4_ff_layout_ds *mirror_ds; |
| 83 |
u32 fh_versions_cnt; |
| 84 |
struct nfs_fh *fh_versions; |
| 85 |
nfs4_stateid stateid; |
| 86 |
const struct cred __rcu *ro_cred; |
| 87 |
const struct cred __rcu *rw_cred; |
| 88 |
struct nfs_file_localio nfl; |
| 89 |
struct nfs4_ff_layoutstat read_stat; |
| 90 |
struct nfs4_ff_layoutstat write_stat; |
| 91 |
ktime_t start_time; |
| 92 |
}; |
| 93 |
|
| 94 |
struct nfs4_ff_layout_mirror { |
| 95 |
struct pnfs_layout_hdr *layout; |
| 96 |
struct list_head mirrors; |
| 97 |
u32 dss_count; |
| 98 |
struct nfs4_ff_layout_ds_stripe *dss; |
| 99 |
refcount_t ref; |
| 100 |
spinlock_t lock; |
| 101 |
unsigned long flags; |
| 102 |
u32 report_interval; |
| 103 |
}; |
| 104 |
|
| 105 |
#define NFS4_FF_MIRROR_STAT_AVAIL (0) |
| 106 |
|
| 107 |
struct nfs4_ff_layout_segment { |
| 108 |
struct pnfs_layout_segment generic_hdr; |
| 109 |
u64 stripe_unit; |
| 110 |
u32 flags; |
| 111 |
u32 mirror_array_cnt; |
| 112 |
struct nfs4_ff_layout_mirror *mirror_array[] __counted_by(mirror_array_cnt); |
| 113 |
}; |
| 114 |
|
| 115 |
struct nfs4_flexfile_layout { |
| 116 |
struct pnfs_layout_hdr generic_hdr; |
| 117 |
struct pnfs_ds_commit_info commit_info; |
| 118 |
struct list_head mirrors; |
| 119 |
struct list_head error_list; /* nfs4_ff_layout_ds_err */ |
| 120 |
ktime_t last_report_time; /* Layoutstat report times */ |
| 121 |
}; |
| 122 |
|
| 123 |
struct nfs4_flexfile_layoutreturn_args { |
| 124 |
struct list_head errors; |
| 125 |
struct nfs42_layoutstat_devinfo devinfo[FF_LAYOUTSTATS_MAXDEV]; |
| 126 |
unsigned int num_errors; |
| 127 |
unsigned int num_dev; |
| 128 |
struct page *pages[1]; |
| 129 |
}; |
| 130 |
|
| 131 |
static inline struct nfs4_flexfile_layout * |
| 132 |
FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) |
| 133 |
{ |
| 134 |
return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); |
| 135 |
} |
| 136 |
|
| 137 |
static inline struct nfs4_ff_layout_segment * |
| 138 |
FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) |
| 139 |
{ |
| 140 |
return container_of(lseg, |
| 141 |
struct nfs4_ff_layout_segment, |
| 142 |
generic_hdr); |
| 143 |
} |
| 144 |
|
| 145 |
static inline struct nfs4_ff_layout_ds * |
| 146 |
FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) |
| 147 |
{ |
| 148 |
return container_of(node, struct nfs4_ff_layout_ds, id_node); |
| 149 |
} |
| 150 |
|
| 151 |
static inline struct nfs4_ff_layout_mirror * |
| 152 |
FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx) |
| 153 |
{ |
| 154 |
struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); |
| 155 |
|
| 156 |
if (idx < fls->mirror_array_cnt) |
| 157 |
return fls->mirror_array[idx]; |
| 158 |
return NULL; |
| 159 |
} |
| 160 |
|
| 161 |
static inline struct nfs4_deviceid_node * |
| 162 |
FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx, u32 dss_id) |
| 163 |
{ |
| 164 |
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, idx); |
| 165 |
|
| 166 |
if (mirror != NULL) { |
| 167 |
struct nfs4_ff_layout_ds *mirror_ds = mirror->dss[dss_id].mirror_ds; |
| 168 |
|
| 169 |
if (!IS_ERR_OR_NULL(mirror_ds)) |
| 170 |
return &mirror_ds->id_node; |
| 171 |
} |
| 172 |
return NULL; |
| 173 |
} |
| 174 |
|
| 175 |
static inline u32 |
| 176 |
FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) |
| 177 |
{ |
| 178 |
return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; |
| 179 |
} |
| 180 |
|
| 181 |
static inline bool |
| 182 |
ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg) |
| 183 |
{ |
| 184 |
return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS; |
| 185 |
} |
| 186 |
|
| 187 |
static inline bool |
| 188 |
ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg) |
| 189 |
{ |
| 190 |
return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_READ_IO; |
| 191 |
} |
| 192 |
|
| 193 |
static inline int |
| 194 |
nfs4_ff_layout_ds_version(const struct nfs4_ff_layout_mirror *mirror, u32 dss_id) |
| 195 |
{ |
| 196 |
return mirror->dss[dss_id].mirror_ds->ds_versions[0].version; |
| 197 |
} |
| 198 |
|
| 199 |
static inline u32 |
| 200 |
nfs4_ff_layout_calc_dss_id(const u64 stripe_unit, const u32 dss_count, const loff_t offset) |
| 201 |
{ |
| 202 |
u64 tmp = offset; |
| 203 |
|
| 204 |
if (dss_count == 1 || stripe_unit == 0) |
| 205 |
return 0; |
| 206 |
|
| 207 |
do_div(tmp, stripe_unit); |
| 208 |
|
| 209 |
return do_div(tmp, dss_count); |
| 210 |
} |
| 211 |
|
| 212 |
struct nfs4_ff_layout_ds * |
| 213 |
nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 214 |
gfp_t gfp_flags); |
| 215 |
void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 216 |
void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 217 |
int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo, |
| 218 |
struct nfs4_ff_layout_mirror *mirror, |
| 219 |
u32 dss_id, u64 offset, u64 length, int status, |
| 220 |
enum nfs_opnum4 opnum, gfp_t gfp_flags); |
| 221 |
void ff_layout_send_layouterror(struct pnfs_layout_segment *lseg); |
| 222 |
int ff_layout_encode_ds_ioerr(struct xdr_stream *xdr, const struct list_head *head); |
| 223 |
void ff_layout_free_ds_ioerr(struct list_head *head); |
| 224 |
unsigned int ff_layout_fetch_ds_ioerr(struct pnfs_layout_hdr *lo, |
| 225 |
const struct pnfs_layout_range *range, |
| 226 |
struct list_head *head, |
| 227 |
unsigned int maxnum); |
| 228 |
struct nfs_fh * |
| 229 |
nfs4_ff_layout_select_ds_fh(struct nfs4_ff_layout_mirror *mirror, u32 dss_id); |
| 230 |
void |
| 231 |
nfs4_ff_layout_select_ds_stateid(const struct nfs4_ff_layout_mirror *mirror, |
| 232 |
u32 dss_id, |
| 233 |
nfs4_stateid *stateid); |
| 234 |
|
| 235 |
struct nfs4_pnfs_ds * |
| 236 |
nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, |
| 237 |
struct nfs4_ff_layout_mirror *mirror, |
| 238 |
u32 dss_id, |
| 239 |
bool fail_return); |
| 240 |
|
| 241 |
struct rpc_clnt * |
| 242 |
nfs4_ff_find_or_create_ds_client(struct nfs4_ff_layout_mirror *mirror, |
| 243 |
struct nfs_client *ds_clp, |
| 244 |
struct inode *inode, |
| 245 |
u32 dss_id); |
| 246 |
const struct cred *ff_layout_get_ds_cred(struct nfs4_ff_layout_mirror *mirror, |
| 247 |
const struct pnfs_layout_range *range, |
| 248 |
const struct cred *mdscred, |
| 249 |
u32 dss_id); |
| 250 |
bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg); |
| 251 |
bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg); |
| 252 |
|
| 253 |
#endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ |