1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2d430e8d5SChristoph Hellwig /*
3d430e8d5SChristoph Hellwig * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
4d430e8d5SChristoph Hellwig */
5d430e8d5SChristoph Hellwig #ifndef NFSD_EXPORT_H
6d430e8d5SChristoph Hellwig #define NFSD_EXPORT_H
7d430e8d5SChristoph Hellwig
8d430e8d5SChristoph Hellwig #include <linux/sunrpc/cache.h>
920ad856eSAmir Goldstein #include <linux/percpu_counter.h>
10d430e8d5SChristoph Hellwig #include <uapi/linux/nfsd/export.h>
114bc66037SJeff Layton #include <linux/nfs4.h>
12d430e8d5SChristoph Hellwig
13d430e8d5SChristoph Hellwig struct knfsd_fh;
14d430e8d5SChristoph Hellwig struct svc_fh;
15d430e8d5SChristoph Hellwig struct svc_rqst;
16d430e8d5SChristoph Hellwig
17d430e8d5SChristoph Hellwig /*
18d430e8d5SChristoph Hellwig * FS Locations
19d430e8d5SChristoph Hellwig */
20d430e8d5SChristoph Hellwig
21d430e8d5SChristoph Hellwig #define MAX_FS_LOCATIONS 128
22d430e8d5SChristoph Hellwig
23d430e8d5SChristoph Hellwig struct nfsd4_fs_location {
24d430e8d5SChristoph Hellwig char *hosts; /* colon separated list of hosts */
25d430e8d5SChristoph Hellwig char *path; /* slash separated list of path components */
26d430e8d5SChristoph Hellwig };
27d430e8d5SChristoph Hellwig
28d430e8d5SChristoph Hellwig struct nfsd4_fs_locations {
29d430e8d5SChristoph Hellwig uint32_t locations_count;
30d430e8d5SChristoph Hellwig struct nfsd4_fs_location *locations;
31d430e8d5SChristoph Hellwig /* If we're not actually serving this data ourselves (only providing a
32d430e8d5SChristoph Hellwig * list of replicas that do serve it) then we set "migrated": */
33d430e8d5SChristoph Hellwig int migrated;
34d430e8d5SChristoph Hellwig };
35d430e8d5SChristoph Hellwig
36d430e8d5SChristoph Hellwig /*
37d430e8d5SChristoph Hellwig * We keep an array of pseudoflavors with the export, in order from most
38d430e8d5SChristoph Hellwig * to least preferred. For the foreseeable future, we don't expect more
39d430e8d5SChristoph Hellwig * than the eight pseudoflavors null, unix, krb5, krb5i, krb5p, skpm3,
40d430e8d5SChristoph Hellwig * spkm3i, and spkm3p (and using all 8 at once should be rare).
41d430e8d5SChristoph Hellwig */
42d430e8d5SChristoph Hellwig #define MAX_SECINFO_LIST 8
4394eb3689SKinglong Mee #define EX_UUID_LEN 16
44d430e8d5SChristoph Hellwig
45d430e8d5SChristoph Hellwig struct exp_flavor_info {
46d430e8d5SChristoph Hellwig u32 pseudoflavor;
47d430e8d5SChristoph Hellwig u32 flags;
48d430e8d5SChristoph Hellwig };
49d430e8d5SChristoph Hellwig
5020ad856eSAmir Goldstein /* Per-export stats */
5120ad856eSAmir Goldstein enum {
5220ad856eSAmir Goldstein EXP_STATS_FH_STALE,
5320ad856eSAmir Goldstein EXP_STATS_IO_READ,
5420ad856eSAmir Goldstein EXP_STATS_IO_WRITE,
5520ad856eSAmir Goldstein EXP_STATS_COUNTERS_NUM
5620ad856eSAmir Goldstein };
5720ad856eSAmir Goldstein
5820ad856eSAmir Goldstein struct export_stats {
5920ad856eSAmir Goldstein time64_t start_time;
6020ad856eSAmir Goldstein struct percpu_counter counter[EXP_STATS_COUNTERS_NUM];
6120ad856eSAmir Goldstein };
6220ad856eSAmir Goldstein
63d430e8d5SChristoph Hellwig struct svc_export {
64d430e8d5SChristoph Hellwig struct cache_head h;
65d430e8d5SChristoph Hellwig struct auth_domain * ex_client;
66d430e8d5SChristoph Hellwig int ex_flags;
679b31d561SChuck Lever int ex_fsid;
68d430e8d5SChristoph Hellwig struct path ex_path;
69d430e8d5SChristoph Hellwig kuid_t ex_anon_uid;
70d430e8d5SChristoph Hellwig kgid_t ex_anon_gid;
71d430e8d5SChristoph Hellwig unsigned char * ex_uuid; /* 16 byte fsid */
72d430e8d5SChristoph Hellwig struct nfsd4_fs_locations ex_fslocs;
731f53146dSKinglong Mee uint32_t ex_nflavors;
74d430e8d5SChristoph Hellwig struct exp_flavor_info ex_flavors[MAX_SECINFO_LIST];
758a4c3926SJeff Layton u32 ex_layout_types;
769cf514ccSChristoph Hellwig struct nfsd4_deviceid_map *ex_devid_map;
77d430e8d5SChristoph Hellwig struct cache_detail *cd;
78*48830406SYang Erkun struct rcu_head ex_rcu;
799280c577SChuck Lever unsigned long ex_xprtsec_modes;
809b31d561SChuck Lever struct export_stats *ex_stats;
81d430e8d5SChristoph Hellwig };
82d430e8d5SChristoph Hellwig
83d430e8d5SChristoph Hellwig /* an "export key" (expkey) maps a filehandlefragement to an
84d430e8d5SChristoph Hellwig * svc_export for a given client. There can be several per export,
85d430e8d5SChristoph Hellwig * for the different fsid types.
86d430e8d5SChristoph Hellwig */
87d430e8d5SChristoph Hellwig struct svc_expkey {
88d430e8d5SChristoph Hellwig struct cache_head h;
89d430e8d5SChristoph Hellwig
90d430e8d5SChristoph Hellwig struct auth_domain * ek_client;
91d430e8d5SChristoph Hellwig int ek_fsidtype;
92d430e8d5SChristoph Hellwig u32 ek_fsid[6];
93d430e8d5SChristoph Hellwig
94d430e8d5SChristoph Hellwig struct path ek_path;
95*48830406SYang Erkun struct rcu_head ek_rcu;
96d430e8d5SChristoph Hellwig };
97d430e8d5SChristoph Hellwig
98d430e8d5SChristoph Hellwig #define EX_ISSYNC(exp) (!((exp)->ex_flags & NFSEXP_ASYNC))
99d430e8d5SChristoph Hellwig #define EX_NOHIDE(exp) ((exp)->ex_flags & NFSEXP_NOHIDE)
100d430e8d5SChristoph Hellwig #define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
101d430e8d5SChristoph Hellwig
102d430e8d5SChristoph Hellwig int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
103d430e8d5SChristoph Hellwig __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
104d430e8d5SChristoph Hellwig
105d430e8d5SChristoph Hellwig /*
106d430e8d5SChristoph Hellwig * Function declarations
107d430e8d5SChristoph Hellwig */
108d430e8d5SChristoph Hellwig int nfsd_export_init(struct net *);
109d430e8d5SChristoph Hellwig void nfsd_export_shutdown(struct net *);
110d430e8d5SChristoph Hellwig void nfsd_export_flush(struct net *);
111d430e8d5SChristoph Hellwig struct svc_export * rqst_exp_get_by_name(struct svc_rqst *,
112d430e8d5SChristoph Hellwig struct path *);
113d430e8d5SChristoph Hellwig struct svc_export * rqst_exp_parent(struct svc_rqst *,
114d430e8d5SChristoph Hellwig struct path *);
115d430e8d5SChristoph Hellwig struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *);
116d430e8d5SChristoph Hellwig int exp_rootfh(struct net *, struct auth_domain *,
117d430e8d5SChristoph Hellwig char *path, struct knfsd_fh *, int maxsize);
118d430e8d5SChristoph Hellwig __be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *);
119d430e8d5SChristoph Hellwig
exp_put(struct svc_export * exp)120d430e8d5SChristoph Hellwig static inline void exp_put(struct svc_export *exp)
121d430e8d5SChristoph Hellwig {
122d430e8d5SChristoph Hellwig cache_put(&exp->h, exp->cd);
123d430e8d5SChristoph Hellwig }
124d430e8d5SChristoph Hellwig
exp_get(struct svc_export * exp)125bf18f163SKinglong Mee static inline struct svc_export *exp_get(struct svc_export *exp)
126d430e8d5SChristoph Hellwig {
127d430e8d5SChristoph Hellwig cache_get(&exp->h);
128bf18f163SKinglong Mee return exp;
129d430e8d5SChristoph Hellwig }
130d430e8d5SChristoph Hellwig struct svc_export * rqst_exp_find(struct svc_rqst *, int, u32 *);
131d430e8d5SChristoph Hellwig
132d430e8d5SChristoph Hellwig #endif /* NFSD_EXPORT_H */
133