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