xref: /OK3568_Linux_fs/kernel/fs/nfsd/export.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun #ifndef NFSD_EXPORT_H
6*4882a593Smuzhiyun #define NFSD_EXPORT_H
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/sunrpc/cache.h>
9*4882a593Smuzhiyun #include <uapi/linux/nfsd/export.h>
10*4882a593Smuzhiyun #include <linux/nfs4.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun struct knfsd_fh;
13*4882a593Smuzhiyun struct svc_fh;
14*4882a593Smuzhiyun struct svc_rqst;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun  * FS Locations
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define MAX_FS_LOCATIONS	128
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun struct nfsd4_fs_location {
23*4882a593Smuzhiyun 	char *hosts; /* colon separated list of hosts */
24*4882a593Smuzhiyun 	char *path;  /* slash separated list of path components */
25*4882a593Smuzhiyun };
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun struct nfsd4_fs_locations {
28*4882a593Smuzhiyun 	uint32_t locations_count;
29*4882a593Smuzhiyun 	struct nfsd4_fs_location *locations;
30*4882a593Smuzhiyun /* If we're not actually serving this data ourselves (only providing a
31*4882a593Smuzhiyun  * list of replicas that do serve it) then we set "migrated": */
32*4882a593Smuzhiyun 	int migrated;
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun  * We keep an array of pseudoflavors with the export, in order from most
37*4882a593Smuzhiyun  * to least preferred.  For the foreseeable future, we don't expect more
38*4882a593Smuzhiyun  * than the eight pseudoflavors null, unix, krb5, krb5i, krb5p, skpm3,
39*4882a593Smuzhiyun  * spkm3i, and spkm3p (and using all 8 at once should be rare).
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun #define MAX_SECINFO_LIST	8
42*4882a593Smuzhiyun #define EX_UUID_LEN		16
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun struct exp_flavor_info {
45*4882a593Smuzhiyun 	u32	pseudoflavor;
46*4882a593Smuzhiyun 	u32	flags;
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun struct svc_export {
50*4882a593Smuzhiyun 	struct cache_head	h;
51*4882a593Smuzhiyun 	struct auth_domain *	ex_client;
52*4882a593Smuzhiyun 	int			ex_flags;
53*4882a593Smuzhiyun 	struct path		ex_path;
54*4882a593Smuzhiyun 	kuid_t			ex_anon_uid;
55*4882a593Smuzhiyun 	kgid_t			ex_anon_gid;
56*4882a593Smuzhiyun 	int			ex_fsid;
57*4882a593Smuzhiyun 	unsigned char *		ex_uuid; /* 16 byte fsid */
58*4882a593Smuzhiyun 	struct nfsd4_fs_locations ex_fslocs;
59*4882a593Smuzhiyun 	uint32_t		ex_nflavors;
60*4882a593Smuzhiyun 	struct exp_flavor_info	ex_flavors[MAX_SECINFO_LIST];
61*4882a593Smuzhiyun 	u32			ex_layout_types;
62*4882a593Smuzhiyun 	struct nfsd4_deviceid_map *ex_devid_map;
63*4882a593Smuzhiyun 	struct cache_detail	*cd;
64*4882a593Smuzhiyun 	struct rcu_head		ex_rcu;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /* an "export key" (expkey) maps a filehandlefragement to an
68*4882a593Smuzhiyun  * svc_export for a given client.  There can be several per export,
69*4882a593Smuzhiyun  * for the different fsid types.
70*4882a593Smuzhiyun  */
71*4882a593Smuzhiyun struct svc_expkey {
72*4882a593Smuzhiyun 	struct cache_head	h;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	struct auth_domain *	ek_client;
75*4882a593Smuzhiyun 	int			ek_fsidtype;
76*4882a593Smuzhiyun 	u32			ek_fsid[6];
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	struct path		ek_path;
79*4882a593Smuzhiyun 	struct rcu_head		ek_rcu;
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #define EX_ISSYNC(exp)		(!((exp)->ex_flags & NFSEXP_ASYNC))
83*4882a593Smuzhiyun #define EX_NOHIDE(exp)		((exp)->ex_flags & NFSEXP_NOHIDE)
84*4882a593Smuzhiyun #define EX_WGATHER(exp)		((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
87*4882a593Smuzhiyun __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /*
90*4882a593Smuzhiyun  * Function declarations
91*4882a593Smuzhiyun  */
92*4882a593Smuzhiyun int			nfsd_export_init(struct net *);
93*4882a593Smuzhiyun void			nfsd_export_shutdown(struct net *);
94*4882a593Smuzhiyun void			nfsd_export_flush(struct net *);
95*4882a593Smuzhiyun struct svc_export *	rqst_exp_get_by_name(struct svc_rqst *,
96*4882a593Smuzhiyun 					     struct path *);
97*4882a593Smuzhiyun struct svc_export *	rqst_exp_parent(struct svc_rqst *,
98*4882a593Smuzhiyun 					struct path *);
99*4882a593Smuzhiyun struct svc_export *	rqst_find_fsidzero_export(struct svc_rqst *);
100*4882a593Smuzhiyun int			exp_rootfh(struct net *, struct auth_domain *,
101*4882a593Smuzhiyun 					char *path, struct knfsd_fh *, int maxsize);
102*4882a593Smuzhiyun __be32			exp_pseudoroot(struct svc_rqst *, struct svc_fh *);
103*4882a593Smuzhiyun __be32			nfserrno(int errno);
104*4882a593Smuzhiyun 
exp_put(struct svc_export * exp)105*4882a593Smuzhiyun static inline void exp_put(struct svc_export *exp)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	cache_put(&exp->h, exp->cd);
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
exp_get(struct svc_export * exp)110*4882a593Smuzhiyun static inline struct svc_export *exp_get(struct svc_export *exp)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	cache_get(&exp->h);
113*4882a593Smuzhiyun 	return exp;
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun struct svc_export * rqst_exp_find(struct svc_rqst *, int, u32 *);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #endif /* NFSD_EXPORT_H */
118