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
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
20 /* LAYOUTSTATS report interval in ms */
21 #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
23 struct nfs4_ff_ds_version
{
31 /* chained in global deviceid hlist */
32 struct nfs4_ff_layout_ds
{
33 struct nfs4_deviceid_node id_node
;
35 struct nfs4_ff_ds_version
*ds_versions
;
36 struct nfs4_pnfs_ds
*ds
;
39 struct nfs4_ff_layout_ds_err
{
40 struct list_head list
; /* linked in mirror error_list */
44 enum nfs_opnum4 opnum
;
46 struct nfs4_deviceid deviceid
;
49 struct nfs4_ff_io_stat
{
51 __u64 bytes_requested
;
53 __u64 bytes_completed
;
54 __u64 bytes_not_delivered
;
55 ktime_t total_busy_time
;
56 ktime_t aggregate_completion_time
;
59 struct nfs4_ff_busy_timer
{
64 struct nfs4_ff_layoutstat
{
65 struct nfs4_ff_io_stat io_stat
;
66 struct nfs4_ff_busy_timer busy_timer
;
69 struct nfs4_ff_layout_mirror
{
70 struct pnfs_layout_segment
*lseg
; /* back pointer */
73 struct nfs4_ff_layout_ds
*mirror_ds
;
75 struct nfs_fh
*fh_versions
;
79 struct rpc_cred
*cred
;
81 struct nfs4_ff_layoutstat read_stat
;
82 struct nfs4_ff_layoutstat write_stat
;
84 ktime_t last_report_time
;
87 struct nfs4_ff_layout_segment
{
88 struct pnfs_layout_segment generic_hdr
;
92 struct nfs4_ff_layout_mirror
**mirror_array
;
95 struct nfs4_flexfile_layout
{
96 struct pnfs_layout_hdr generic_hdr
;
97 struct pnfs_ds_commit_info commit_info
;
98 struct list_head error_list
; /* nfs4_ff_layout_ds_err */
101 static inline struct nfs4_flexfile_layout
*
102 FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr
*lo
)
104 return container_of(lo
, struct nfs4_flexfile_layout
, generic_hdr
);
107 static inline struct nfs4_ff_layout_segment
*
108 FF_LAYOUT_LSEG(struct pnfs_layout_segment
*lseg
)
110 return container_of(lseg
,
111 struct nfs4_ff_layout_segment
,
115 static inline struct nfs4_deviceid_node
*
116 FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment
*lseg
, u32 idx
)
118 if (idx
>= FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
||
119 FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
] == NULL
||
120 FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
]->mirror_ds
== NULL
)
122 return &FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
]->mirror_ds
->id_node
;
125 static inline struct nfs4_ff_layout_ds
*
126 FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node
*node
)
128 return container_of(node
, struct nfs4_ff_layout_ds
, id_node
);
131 static inline struct nfs4_ff_layout_mirror
*
132 FF_LAYOUT_COMP(struct pnfs_layout_segment
*lseg
, u32 idx
)
134 if (idx
>= FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
)
136 return FF_LAYOUT_LSEG(lseg
)->mirror_array
[idx
];
140 FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment
*lseg
)
142 return FF_LAYOUT_LSEG(lseg
)->mirror_array_cnt
;
146 ff_layout_test_devid_unavailable(struct nfs4_deviceid_node
*node
)
148 return nfs4_test_deviceid_unavailable(node
);
152 nfs4_ff_layout_ds_version(struct pnfs_layout_segment
*lseg
, u32 ds_idx
)
154 return FF_LAYOUT_COMP(lseg
, ds_idx
)->mirror_ds
->ds_versions
[0].version
;
157 struct nfs4_ff_layout_ds
*
158 nfs4_ff_alloc_deviceid_node(struct nfs_server
*server
, struct pnfs_device
*pdev
,
160 void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
161 void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds
*mirror_ds
);
162 int ff_layout_track_ds_error(struct nfs4_flexfile_layout
*flo
,
163 struct nfs4_ff_layout_mirror
*mirror
, u64 offset
,
164 u64 length
, int status
, enum nfs_opnum4 opnum
,
166 int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout
*flo
,
167 struct xdr_stream
*xdr
, int *count
,
168 const struct pnfs_layout_range
*range
);
170 nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment
*lseg
, u32 mirror_idx
);
172 struct nfs4_pnfs_ds
*
173 nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment
*lseg
, u32 ds_idx
,
177 nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment
*lseg
,
179 struct nfs_client
*ds_clp
,
180 struct inode
*inode
);
181 struct rpc_cred
*ff_layout_get_ds_cred(struct pnfs_layout_segment
*lseg
,
182 u32 ds_idx
, struct rpc_cred
*mdscred
);
183 bool ff_layout_has_available_ds(struct pnfs_layout_segment
*lseg
);
184 #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */