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 | |
| 44 | struct nfs4_ff_layout_mirror { |
| 45 | u32 ds_count; |
| 46 | u32 efficiency; |
| 47 | struct nfs4_ff_layout_ds *mirror_ds; |
| 48 | u32 fh_versions_cnt; |
| 49 | struct nfs_fh *fh_versions; |
| 50 | nfs4_stateid stateid; |
| 51 | struct nfs4_string user_name; |
| 52 | struct nfs4_string group_name; |
| 53 | u32 uid; |
| 54 | u32 gid; |
| 55 | struct rpc_cred *cred; |
| 56 | spinlock_t lock; |
| 57 | }; |
| 58 | |
| 59 | struct nfs4_ff_layout_segment { |
| 60 | struct pnfs_layout_segment generic_hdr; |
| 61 | u64 stripe_unit; |
| 62 | u32 mirror_array_cnt; |
| 63 | struct nfs4_ff_layout_mirror **mirror_array; |
| 64 | }; |
| 65 | |
| 66 | struct nfs4_flexfile_layout { |
| 67 | struct pnfs_layout_hdr generic_hdr; |
| 68 | struct pnfs_ds_commit_info commit_info; |
| 69 | struct list_head error_list; /* nfs4_ff_layout_ds_err */ |
| 70 | }; |
| 71 | |
| 72 | static inline struct nfs4_flexfile_layout * |
| 73 | FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) |
| 74 | { |
| 75 | return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); |
| 76 | } |
| 77 | |
| 78 | static inline struct nfs4_ff_layout_segment * |
| 79 | FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) |
| 80 | { |
| 81 | return container_of(lseg, |
| 82 | struct nfs4_ff_layout_segment, |
| 83 | generic_hdr); |
| 84 | } |
| 85 | |
| 86 | static inline struct nfs4_deviceid_node * |
| 87 | FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx) |
| 88 | { |
| 89 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt || |
| 90 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx] == NULL || |
| 91 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds == NULL) |
| 92 | return NULL; |
| 93 | return &FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds->id_node; |
| 94 | } |
| 95 | |
| 96 | static inline struct nfs4_ff_layout_ds * |
| 97 | FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) |
| 98 | { |
| 99 | return container_of(node, struct nfs4_ff_layout_ds, id_node); |
| 100 | } |
| 101 | |
| 102 | static inline struct nfs4_ff_layout_mirror * |
| 103 | FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx) |
| 104 | { |
| 105 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt) |
| 106 | return NULL; |
| 107 | return FF_LAYOUT_LSEG(lseg)->mirror_array[idx]; |
| 108 | } |
| 109 | |
| 110 | static inline u32 |
| 111 | FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) |
| 112 | { |
| 113 | return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; |
| 114 | } |
| 115 | |
| 116 | static inline bool |
| 117 | ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node) |
| 118 | { |
| 119 | return nfs4_test_deviceid_unavailable(node); |
| 120 | } |
| 121 | |
| 122 | static inline int |
| 123 | nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 124 | { |
| 125 | return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version; |
| 126 | } |
| 127 | |
| 128 | struct nfs4_ff_layout_ds * |
| 129 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 130 | gfp_t gfp_flags); |
| 131 | void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 132 | void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds); |
| 133 | int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo, |
| 134 | struct nfs4_ff_layout_mirror *mirror, u64 offset, |
| 135 | u64 length, int status, enum nfs_opnum4 opnum, |
| 136 | gfp_t gfp_flags); |
| 137 | int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo, |
| 138 | struct xdr_stream *xdr, int *count, |
| 139 | const struct pnfs_layout_range *range); |
| 140 | struct nfs_fh * |
| 141 | nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx); |
| 142 | |
| 143 | struct nfs4_pnfs_ds * |
| 144 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, |
| 145 | bool fail_return); |
| 146 | |
| 147 | struct rpc_clnt * |
| 148 | nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg, |
| 149 | u32 ds_idx, |
| 150 | struct nfs_client *ds_clp, |
| 151 | struct inode *inode); |
| 152 | struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, |
| 153 | u32 ds_idx, struct rpc_cred *mdscred); |
| 154 | bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg); |
| 155 | #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ |