xref: /OK3568_Linux_fs/kernel/fs/nfs/filelayout/filelayout.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  NFSv4 file layout driver data structures.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  Copyright (c) 2002
5*4882a593Smuzhiyun  *  The Regents of the University of Michigan
6*4882a593Smuzhiyun  *  All Rights Reserved
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *  Dean Hildebrand <dhildebz@umich.edu>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *  Permission is granted to use, copy, create derivative works, and
11*4882a593Smuzhiyun  *  redistribute this software and such derivative works for any purpose,
12*4882a593Smuzhiyun  *  so long as the name of the University of Michigan is not used in
13*4882a593Smuzhiyun  *  any advertising or publicity pertaining to the use or distribution
14*4882a593Smuzhiyun  *  of this software without specific, written prior authorization. If
15*4882a593Smuzhiyun  *  the above copyright notice or any other identification of the
16*4882a593Smuzhiyun  *  University of Michigan is included in any copy of any portion of
17*4882a593Smuzhiyun  *  this software, then the disclaimer below must also be included.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  *  This software is provided as is, without representation or warranty
20*4882a593Smuzhiyun  *  of any kind either express or implied, including without limitation
21*4882a593Smuzhiyun  *  the implied warranties of merchantability, fitness for a particular
22*4882a593Smuzhiyun  *  purpose, or noninfringement.  The Regents of the University of
23*4882a593Smuzhiyun  *  Michigan shall not be liable for any damages, including special,
24*4882a593Smuzhiyun  *  indirect, incidental, or consequential damages, with respect to any
25*4882a593Smuzhiyun  *  claim arising out of or in connection with the use of the software,
26*4882a593Smuzhiyun  *  even if it has been or is hereafter advised of the possibility of
27*4882a593Smuzhiyun  *  such damages.
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #ifndef FS_NFS_NFS4FILELAYOUT_H
31*4882a593Smuzhiyun #define FS_NFS_NFS4FILELAYOUT_H
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #include "../pnfs.h"
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun  * Field testing shows we need to support up to 4096 stripe indices.
37*4882a593Smuzhiyun  * We store each index as a u8 (u32 on the wire) to keep the memory footprint
38*4882a593Smuzhiyun  * reasonable. This in turn means we support a maximum of 256
39*4882a593Smuzhiyun  * RFC 5661 multipath_list4 structures.
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun #define NFS4_PNFS_MAX_STRIPE_CNT 4096
42*4882a593Smuzhiyun #define NFS4_PNFS_MAX_MULTI_CNT  256 /* 256 fit into a u8 stripe_index */
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun enum stripetype4 {
45*4882a593Smuzhiyun 	STRIPE_SPARSE = 1,
46*4882a593Smuzhiyun 	STRIPE_DENSE = 2
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun struct nfs4_file_layout_dsaddr {
50*4882a593Smuzhiyun 	struct nfs4_deviceid_node	id_node;
51*4882a593Smuzhiyun 	u32				stripe_count;
52*4882a593Smuzhiyun 	u8				*stripe_indices;
53*4882a593Smuzhiyun 	u32				ds_num;
54*4882a593Smuzhiyun 	struct nfs4_pnfs_ds		*ds_list[1];
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun struct nfs4_filelayout_segment {
58*4882a593Smuzhiyun 	struct pnfs_layout_segment	generic_hdr;
59*4882a593Smuzhiyun 	u32				stripe_type;
60*4882a593Smuzhiyun 	u32				commit_through_mds;
61*4882a593Smuzhiyun 	u32				stripe_unit;
62*4882a593Smuzhiyun 	u32				first_stripe_index;
63*4882a593Smuzhiyun 	u64				pattern_offset;
64*4882a593Smuzhiyun 	struct nfs4_deviceid		deviceid;
65*4882a593Smuzhiyun 	struct nfs4_file_layout_dsaddr	*dsaddr; /* Point to GETDEVINFO data */
66*4882a593Smuzhiyun 	unsigned int			num_fh;
67*4882a593Smuzhiyun 	struct nfs_fh			**fh_array;
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun struct nfs4_filelayout {
71*4882a593Smuzhiyun 	struct pnfs_layout_hdr generic_hdr;
72*4882a593Smuzhiyun 	struct pnfs_ds_commit_info commit_info;
73*4882a593Smuzhiyun };
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun static inline struct nfs4_filelayout *
FILELAYOUT_FROM_HDR(struct pnfs_layout_hdr * lo)76*4882a593Smuzhiyun FILELAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun 	return container_of(lo, struct nfs4_filelayout, generic_hdr);
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun static inline struct nfs4_filelayout_segment *
FILELAYOUT_LSEG(struct pnfs_layout_segment * lseg)82*4882a593Smuzhiyun FILELAYOUT_LSEG(struct pnfs_layout_segment *lseg)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	return container_of(lseg,
85*4882a593Smuzhiyun 			    struct nfs4_filelayout_segment,
86*4882a593Smuzhiyun 			    generic_hdr);
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun static inline struct nfs4_deviceid_node *
FILELAYOUT_DEVID_NODE(struct pnfs_layout_segment * lseg)90*4882a593Smuzhiyun FILELAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	return &FILELAYOUT_LSEG(lseg)->dsaddr->id_node;
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun static inline bool
filelayout_test_devid_invalid(struct nfs4_deviceid_node * node)96*4882a593Smuzhiyun filelayout_test_devid_invalid(struct nfs4_deviceid_node *node)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	return test_bit(NFS_DEVICEID_INVALID, &node->flags);
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun extern bool
102*4882a593Smuzhiyun filelayout_test_devid_unavailable(struct nfs4_deviceid_node *node);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun extern struct nfs_fh *
105*4882a593Smuzhiyun nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun u32 nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset);
108*4882a593Smuzhiyun u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j);
109*4882a593Smuzhiyun struct nfs4_pnfs_ds *nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg,
110*4882a593Smuzhiyun 					u32 ds_idx);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun extern struct nfs4_file_layout_dsaddr *
113*4882a593Smuzhiyun nfs4_fl_alloc_deviceid_node(struct nfs_server *server,
114*4882a593Smuzhiyun 	struct pnfs_device *pdev, gfp_t gfp_flags);
115*4882a593Smuzhiyun extern void nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
116*4882a593Smuzhiyun extern void nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #endif /* FS_NFS_NFS4FILELAYOUT_H */
119