blob: ee0e3aba4a6e51df4c4e21cc9946665b1564b336 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
4 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#ifndef NFSD_EXPORT_H
6#define NFSD_EXPORT_H
7
Christoph Hellwig9c69de42014-05-06 19:37:13 +02008#include <linux/sunrpc/cache.h>
Amir Goldstein20ad8562021-01-06 09:52:36 +02009#include <linux/percpu_counter.h>
David Howells616d1ca2012-10-09 09:49:02 +010010#include <uapi/linux/nfsd/export.h>
Jeff Layton4bc66032015-07-30 09:52:13 -040011#include <linux/nfs4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Christoph Hellwig9c69de42014-05-06 19:37:13 +020013struct knfsd_fh;
14struct svc_fh;
15struct svc_rqst;
16
Manoj Naik933469192006-10-04 02:16:18 -070017/*
18 * FS Locations
19 */
20
21#define MAX_FS_LOCATIONS 128
22
23struct nfsd4_fs_location {
24 char *hosts; /* colon separated list of hosts */
25 char *path; /* slash separated list of path components */
26};
27
28struct nfsd4_fs_locations {
29 uint32_t locations_count;
30 struct nfsd4_fs_location *locations;
31/* If we're not actually serving this data ourselves (only providing a
32 * list of replicas that do serve it) then we set "migrated": */
33 int migrated;
34};
35
Andy Adamsone677bfe2007-07-17 04:04:42 -070036/*
37 * We keep an array of pseudoflavors with the export, in order from most
Lucas De Marchi25985ed2011-03-30 22:57:33 -030038 * to least preferred. For the foreseeable future, we don't expect more
Andy Adamsone677bfe2007-07-17 04:04:42 -070039 * than the eight pseudoflavors null, unix, krb5, krb5i, krb5p, skpm3,
40 * spkm3i, and spkm3p (and using all 8 at once should be rare).
41 */
42#define MAX_SECINFO_LIST 8
Kinglong Mee94eb3682014-05-23 20:00:19 +080043#define EX_UUID_LEN 16
Andy Adamsone677bfe2007-07-17 04:04:42 -070044
45struct exp_flavor_info {
46 u32 pseudoflavor;
47 u32 flags;
48};
49
Amir Goldstein20ad8562021-01-06 09:52:36 +020050/* Per-export stats */
51enum {
52 EXP_STATS_FH_STALE,
53 EXP_STATS_IO_READ,
54 EXP_STATS_IO_WRITE,
55 EXP_STATS_COUNTERS_NUM
56};
57
58struct export_stats {
59 time64_t start_time;
60 struct percpu_counter counter[EXP_STATS_COUNTERS_NUM];
61};
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063struct svc_export {
64 struct cache_head h;
65 struct auth_domain * ex_client;
66 int ex_flags;
Jan Blunck54775492008-02-14 19:38:39 -080067 struct path ex_path;
Eric W. Biederman4c1e1b32013-02-02 06:42:53 -080068 kuid_t ex_anon_uid;
69 kgid_t ex_anon_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 int ex_fsid;
NeilBrownaf6a4e22007-02-14 00:33:12 -080071 unsigned char * ex_uuid; /* 16 byte fsid */
Manoj Naik933469192006-10-04 02:16:18 -070072 struct nfsd4_fs_locations ex_fslocs;
Kinglong Mee1f531462014-05-24 11:26:49 +080073 uint32_t ex_nflavors;
Andy Adamsone677bfe2007-07-17 04:04:42 -070074 struct exp_flavor_info ex_flavors[MAX_SECINFO_LIST];
Jeff Layton8a4c3922016-07-10 15:55:58 -040075 u32 ex_layout_types;
Christoph Hellwig9cf514c2014-05-05 13:11:59 +020076 struct nfsd4_deviceid_map *ex_devid_map;
Stanislav Kinsburskydb3a3532012-03-28 19:09:08 +040077 struct cache_detail *cd;
Trond Myklebust9ceddd92018-10-01 10:41:47 -040078 struct rcu_head ex_rcu;
Amir Goldstein20ad8562021-01-06 09:52:36 +020079 struct export_stats ex_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
82/* an "export key" (expkey) maps a filehandlefragement to an
NeilBrownaf6a4e22007-02-14 00:33:12 -080083 * svc_export for a given client. There can be several per export,
84 * for the different fsid types.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86struct svc_expkey {
87 struct cache_head h;
88
89 struct auth_domain * ek_client;
90 int ek_fsidtype;
NeilBrownaf6a4e22007-02-14 00:33:12 -080091 u32 ek_fsid[6];
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Jan Bluncke83aece2008-02-14 19:38:41 -080093 struct path ek_path;
Trond Myklebust9ceddd92018-10-01 10:41:47 -040094 struct rcu_head ek_rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095};
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#define EX_ISSYNC(exp) (!((exp)->ex_flags & NFSEXP_ASYNC))
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define EX_NOHIDE(exp) ((exp)->ex_flags & NFSEXP_NOHIDE)
99#define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
100
J. Bruce Fieldsc7d51402007-07-19 01:49:20 -0700101int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
Andy Adamson32c1eb02007-07-17 04:04:48 -0700102__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104/*
105 * Function declarations
106 */
Stanislav Kinsburskyb89109b2012-04-11 15:13:14 +0400107int nfsd_export_init(struct net *);
108void nfsd_export_shutdown(struct net *);
Stanislav Kinsburskyb3853e02012-04-11 15:13:21 +0400109void nfsd_export_flush(struct net *);
J. Bruce Fields0989a782007-07-17 04:04:44 -0700110struct svc_export * rqst_exp_get_by_name(struct svc_rqst *,
Al Viro91c9fa82009-04-18 02:42:05 -0400111 struct path *);
J. Bruce Fields0989a782007-07-17 04:04:44 -0700112struct svc_export * rqst_exp_parent(struct svc_rqst *,
Al Viroe64c3902009-04-18 03:00:46 -0400113 struct path *);
Trond Myklebusted748aa2011-09-12 19:37:06 -0400114struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *);
Stanislav Kinsburskyb3853e02012-04-11 15:13:21 +0400115int exp_rootfh(struct net *, struct auth_domain *,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 char *path, struct knfsd_fh *, int maxsize);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700117__be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *);
Al Viro63f103112006-10-19 23:28:54 -0700118__be32 nfserrno(int errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120static inline void exp_put(struct svc_export *exp)
121{
Stanislav Kinsbursky71234972012-03-28 19:09:15 +0400122 cache_put(&exp->h, exp->cd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Kinglong Meebf18f162014-06-10 22:06:44 +0800125static inline struct svc_export *exp_get(struct svc_export *exp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 cache_get(&exp->h);
Kinglong Meebf18f162014-06-10 22:06:44 +0800128 return exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
J. Bruce Fields0989a782007-07-17 04:04:44 -0700130struct svc_export * rqst_exp_find(struct svc_rqst *, int, u32 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif /* NFSD_EXPORT_H */