2 * NFSv4 flexfile layout driver data structures.
4 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
6 * Tao Peng <bergwolf@primarydata.com>
9 #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H
10 #define FS_NFS_NFS4FLEXFILELAYOUT_H
12 #define FF_FLAGS_NO_LAYOUTCOMMIT 1
13 #define FF_FLAGS_NO_IO_THRU_MDS 2
14 #define FF_FLAGS_NO_READ_IO 4
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
22 /* LAYOUTSTATS report interval in ms */
23 #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
25 struct nfs4_ff_ds_version
{
33 /* chained in global deviceid hlist */
34 struct nfs4_ff_layout_ds
{
35 struct nfs4_deviceid_node id_node
;
37 struct nfs4_ff_ds_version
*ds_versions
;
38 struct nfs4_pnfs_ds
*ds
;
41 struct nfs4_ff_layout_ds_err
{
42 struct list_head list
; /* linked in mirror error_list */
46 enum nfs_opnum4 opnum
;
48 struct nfs4_deviceid deviceid
;
51 struct nfs4_ff_io_stat
{
53 __u64 bytes_requested
;
55 __u64 bytes_completed
;
56 __u64 bytes_not_delivered
;
57 ktime_t total_busy_time
;
58 ktime_t aggregate_completion_time
;
61 struct nfs4_ff_busy_timer
{
66 struct nfs4_ff_layoutstat
{
67 struct nfs4_ff_io_stat io_stat
;
68 struct nfs4_ff_busy_timer busy_timer
;
71 struct nfs4_ff_layout_mirror
{
72 struct pnfs_layout_hdr
*layout
;
73 struct list_head mirrors
;
76 struct nfs4_ff_layout_ds
*mirror_ds
;
78 struct nfs_fh
*fh_versions
;
80 struct rpc_cred __rcu
*ro_cred
;
81 struct rpc_cred __rcu
*rw_cred
;
85 struct nfs4_ff_layoutstat read_stat
;
86 struct nfs4_ff_layoutstat write_stat
;
91 #define NFS4_FF_MIRROR_STAT_AVAIL (0)
93 struct nfs4_ff_layout_segment
{
94 struct pnfs_layout_segment generic_hdr
;
98 struct nfs4_ff_layout_mirror
**mirror_array
;
101 struct nfs4_flexfile_layout
{
102 struct pnfs_layout_hdr generic_hdr
;
103 struct pnfs_ds_commit_info commit_info
;
104 struct list_head mirrors
;
105 struct list_head error_list
; /* nfs4_ff_layout_ds_err */
106 ktime_t last_report_time
; /* Layoutstat report times */
109 static inline struct nfs4_flexfile_layout
*
110 FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr
*lo
)
112 return container_of(lo
, struct nfs4_flexfile_layout
, generic_hdr
);
115 static inline struct nfs4_ff_layout_segment
*
116 FF_LAYOUT_LSEG(struct pnfs_layout_segment
*lseg
)
118 return container_of(lseg
,
119 struct nfs4_ff_layout_segment
,
123 static inline struct nfs4_deviceid_node
*
124 FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment
*lseg
, u32 idx
)
126 if (idx
>= FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
||
127 FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
] == NULL
||
128 FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
]->mirror_ds
== NULL
)
130 return &FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
]->mirror_ds
->id_node
;
133 static inline struct nfs4_ff_layout_ds
*
134 FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node
*node
)
136 return container_of(node
, struct nfs4_ff_layout_ds
, id_node
);
139 static inline struct nfs4_ff_layout_mirror
*
140 FF_LAYOUT_COMP(struct pnfs_layout_segment
*lseg
, u32 idx
)
142 if (idx
>= FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
)
144 return FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
];
148 FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment
*lseg
)
150 return FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
;
154 ff_layout_no_fallback_to_mds(struct pnfs_layout_segment
*lseg
)
156 return FF_LAYOUT_LSEG(lseg
)->flags
& FF_FLAGS_NO_IO_THRU_MDS
;
160 ff_layout_no_read_on_rw(struct pnfs_layout_segment
*lseg
)
162 return FF_LAYOUT_LSEG(lseg
)->flags
& FF_FLAGS_NO_READ_IO
;
166 ff_layout_test_devid_unavailable(struct nfs4_deviceid_node
*node
)
168 return nfs4_test_deviceid_unavailable(node
);
172 nfs4_ff_layout_ds_version(struct pnfs_layout_segment
*lseg
, u32 ds_idx
)
174 return FF_LAYOUT_COMP(lseg
, ds_idx
)->mirror_ds
->ds_versions
[0].version
;
177 struct nfs4_ff_layout_ds
*
178 nfs4_ff_alloc_deviceid_node(struct nfs_server
*server
, struct pnfs_device
*pdev
,
180 void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
181 void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
182 int ff_layout_track_ds_error(struct nfs4_flexfile_layout
*flo
,
183 struct nfs4_ff_layout_mirror
*mirror
, u64 offset
,
184 u64 length
, int status
, enum nfs_opnum4 opnum
,
186 int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout
*flo
,
187 struct xdr_stream
*xdr
, int *count
,
188 const struct pnfs_layout_range
*range
);
190 nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment
*lseg
, u32 mirror_idx
);
192 struct nfs4_pnfs_ds
*
193 nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment
*lseg
, u32 ds_idx
,
197 nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment
*lseg
,
199 struct nfs_client
*ds_clp
,
200 struct inode
*inode
);
201 struct rpc_cred
*ff_layout_get_ds_cred(struct pnfs_layout_segment
*lseg
,
202 u32 ds_idx
, struct rpc_cred
*mdscred
);
203 bool ff_layout_has_available_ds(struct pnfs_layout_segment
*lseg
);
204 bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment
*lseg
);
205 bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment
*lseg
);
207 #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */