Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> |
| 4 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #ifndef NFSD_EXPORT_H |
| 6 | #define NFSD_EXPORT_H |
| 7 | |
Christoph Hellwig | 9c69de4 | 2014-05-06 19:37:13 +0200 | [diff] [blame] | 8 | #include <linux/sunrpc/cache.h> |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 9 | #include <linux/percpu_counter.h> |
David Howells | 616d1ca | 2012-10-09 09:49:02 +0100 | [diff] [blame] | 10 | #include <uapi/linux/nfsd/export.h> |
Jeff Layton | 4bc6603 | 2015-07-30 09:52:13 -0400 | [diff] [blame] | 11 | #include <linux/nfs4.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Christoph Hellwig | 9c69de4 | 2014-05-06 19:37:13 +0200 | [diff] [blame] | 13 | struct knfsd_fh; |
| 14 | struct svc_fh; |
| 15 | struct svc_rqst; |
| 16 | |
Manoj Naik | 93346919 | 2006-10-04 02:16:18 -0700 | [diff] [blame] | 17 | /* |
| 18 | * FS Locations |
| 19 | */ |
| 20 | |
| 21 | #define MAX_FS_LOCATIONS 128 |
| 22 | |
| 23 | struct nfsd4_fs_location { |
| 24 | char *hosts; /* colon separated list of hosts */ |
| 25 | char *path; /* slash separated list of path components */ |
| 26 | }; |
| 27 | |
| 28 | struct 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 Adamson | e677bfe | 2007-07-17 04:04:42 -0700 | [diff] [blame] | 36 | /* |
| 37 | * We keep an array of pseudoflavors with the export, in order from most |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 38 | * to least preferred. For the foreseeable future, we don't expect more |
Andy Adamson | e677bfe | 2007-07-17 04:04:42 -0700 | [diff] [blame] | 39 | * 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 Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 43 | #define EX_UUID_LEN 16 |
Andy Adamson | e677bfe | 2007-07-17 04:04:42 -0700 | [diff] [blame] | 44 | |
| 45 | struct exp_flavor_info { |
| 46 | u32 pseudoflavor; |
| 47 | u32 flags; |
| 48 | }; |
| 49 | |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 50 | /* Per-export stats */ |
| 51 | enum { |
| 52 | EXP_STATS_FH_STALE, |
| 53 | EXP_STATS_IO_READ, |
| 54 | EXP_STATS_IO_WRITE, |
| 55 | EXP_STATS_COUNTERS_NUM |
| 56 | }; |
| 57 | |
| 58 | struct export_stats { |
| 59 | time64_t start_time; |
| 60 | struct percpu_counter counter[EXP_STATS_COUNTERS_NUM]; |
| 61 | }; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | struct svc_export { |
| 64 | struct cache_head h; |
| 65 | struct auth_domain * ex_client; |
| 66 | int ex_flags; |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 67 | struct path ex_path; |
Eric W. Biederman | 4c1e1b3 | 2013-02-02 06:42:53 -0800 | [diff] [blame] | 68 | kuid_t ex_anon_uid; |
| 69 | kgid_t ex_anon_gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | int ex_fsid; |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 71 | unsigned char * ex_uuid; /* 16 byte fsid */ |
Manoj Naik | 93346919 | 2006-10-04 02:16:18 -0700 | [diff] [blame] | 72 | struct nfsd4_fs_locations ex_fslocs; |
Kinglong Mee | 1f53146 | 2014-05-24 11:26:49 +0800 | [diff] [blame] | 73 | uint32_t ex_nflavors; |
Andy Adamson | e677bfe | 2007-07-17 04:04:42 -0700 | [diff] [blame] | 74 | struct exp_flavor_info ex_flavors[MAX_SECINFO_LIST]; |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 75 | u32 ex_layout_types; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 76 | struct nfsd4_deviceid_map *ex_devid_map; |
Stanislav Kinsbursky | db3a353 | 2012-03-28 19:09:08 +0400 | [diff] [blame] | 77 | struct cache_detail *cd; |
Trond Myklebust | 9ceddd9 | 2018-10-01 10:41:47 -0400 | [diff] [blame] | 78 | struct rcu_head ex_rcu; |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 79 | struct export_stats ex_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /* an "export key" (expkey) maps a filehandlefragement to an |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 83 | * svc_export for a given client. There can be several per export, |
| 84 | * for the different fsid types. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | */ |
| 86 | struct svc_expkey { |
| 87 | struct cache_head h; |
| 88 | |
| 89 | struct auth_domain * ek_client; |
| 90 | int ek_fsidtype; |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 91 | u32 ek_fsid[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Jan Blunck | e83aece | 2008-02-14 19:38:41 -0800 | [diff] [blame] | 93 | struct path ek_path; |
Trond Myklebust | 9ceddd9 | 2018-10-01 10:41:47 -0400 | [diff] [blame] | 94 | struct rcu_head ek_rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #define EX_ISSYNC(exp) (!((exp)->ex_flags & NFSEXP_ASYNC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #define EX_NOHIDE(exp) ((exp)->ex_flags & NFSEXP_NOHIDE) |
| 99 | #define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES) |
| 100 | |
J. Bruce Fields | c7d5140 | 2007-07-19 01:49:20 -0700 | [diff] [blame] | 101 | int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp); |
Andy Adamson | 32c1eb0 | 2007-07-17 04:04:48 -0700 | [diff] [blame] | 102 | __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Function declarations |
| 106 | */ |
Stanislav Kinsbursky | b89109b | 2012-04-11 15:13:14 +0400 | [diff] [blame] | 107 | int nfsd_export_init(struct net *); |
| 108 | void nfsd_export_shutdown(struct net *); |
Stanislav Kinsbursky | b3853e0 | 2012-04-11 15:13:21 +0400 | [diff] [blame] | 109 | void nfsd_export_flush(struct net *); |
J. Bruce Fields | 0989a78 | 2007-07-17 04:04:44 -0700 | [diff] [blame] | 110 | struct svc_export * rqst_exp_get_by_name(struct svc_rqst *, |
Al Viro | 91c9fa8 | 2009-04-18 02:42:05 -0400 | [diff] [blame] | 111 | struct path *); |
J. Bruce Fields | 0989a78 | 2007-07-17 04:04:44 -0700 | [diff] [blame] | 112 | struct svc_export * rqst_exp_parent(struct svc_rqst *, |
Al Viro | e64c390 | 2009-04-18 03:00:46 -0400 | [diff] [blame] | 113 | struct path *); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 114 | struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *); |
Stanislav Kinsbursky | b3853e0 | 2012-04-11 15:13:21 +0400 | [diff] [blame] | 115 | int exp_rootfh(struct net *, struct auth_domain *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | char *path, struct knfsd_fh *, int maxsize); |
J. Bruce Fields | df547ef | 2007-07-17 04:04:43 -0700 | [diff] [blame] | 117 | __be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *); |
Al Viro | 63f10311 | 2006-10-19 23:28:54 -0700 | [diff] [blame] | 118 | __be32 nfserrno(int errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | static inline void exp_put(struct svc_export *exp) |
| 121 | { |
Stanislav Kinsbursky | 7123497 | 2012-03-28 19:09:15 +0400 | [diff] [blame] | 122 | cache_put(&exp->h, exp->cd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Kinglong Mee | bf18f16 | 2014-06-10 22:06:44 +0800 | [diff] [blame] | 125 | static inline struct svc_export *exp_get(struct svc_export *exp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | cache_get(&exp->h); |
Kinglong Mee | bf18f16 | 2014-06-10 22:06:44 +0800 | [diff] [blame] | 128 | return exp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
J. Bruce Fields | 0989a78 | 2007-07-17 04:04:44 -0700 | [diff] [blame] | 130 | struct svc_export * rqst_exp_find(struct svc_rqst *, int, u32 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #endif /* NFSD_EXPORT_H */ |