xref: /openbmc/linux/fs/nfsd/netns.h (revision f6d73b12ca9fd3b1c29a6a725cd751b972c740cf)
116216333SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
27ea34ac1SJeff Layton /*
37ea34ac1SJeff Layton  * per net namespace data structures for nfsd
47ea34ac1SJeff Layton  *
57ea34ac1SJeff Layton  * Copyright (C) 2012, Jeff Layton <jlayton@redhat.com>
67ea34ac1SJeff Layton  */
77ea34ac1SJeff Layton 
87ea34ac1SJeff Layton #ifndef __NFSD_NETNS_H__
97ea34ac1SJeff Layton #define __NFSD_NETNS_H__
107ea34ac1SJeff Layton 
117ea34ac1SJeff Layton #include <net/net_namespace.h>
127ea34ac1SJeff Layton #include <net/netns/generic.h>
135970e15dSJeff Layton #include <linux/filelock.h>
14b670a598SJosef Bacik #include <linux/nfs4.h>
15e567b98cSAmir Goldstein #include <linux/percpu_counter.h>
1691d2e9b5SChuck Lever #include <linux/siphash.h>
179eae1900SJosef Bacik #include <linux/sunrpc/stats.h>
187ea34ac1SJeff Layton 
1952e19c09SStanislav Kinsbursky /* Hash tables for nfs4_clientid state */
2052e19c09SStanislav Kinsbursky #define CLIENT_HASH_BITS                 4
2152e19c09SStanislav Kinsbursky #define CLIENT_HASH_SIZE                (1 << CLIENT_HASH_BITS)
2252e19c09SStanislav Kinsbursky #define CLIENT_HASH_MASK                (CLIENT_HASH_SIZE - 1)
2352e19c09SStanislav Kinsbursky 
241872de0eSStanislav Kinsbursky #define SESSION_HASH_SIZE	512
251872de0eSStanislav Kinsbursky 
267ea34ac1SJeff Layton struct cld_net;
279a9c6478SStanislav Kinsbursky struct nfsd4_client_tracking_ops;
287ea34ac1SJeff Layton 
29e567b98cSAmir Goldstein enum {
30e567b98cSAmir Goldstein 	/* cache misses due only to checksum comparison failures */
315b3a1ecfSJosef Bacik 	NFSD_STATS_PAYLOAD_MISSES,
32e567b98cSAmir Goldstein 	/* amount of memory (in bytes) currently consumed by the DRC */
335b3a1ecfSJosef Bacik 	NFSD_STATS_DRC_MEM_USAGE,
34b670a598SJosef Bacik 	NFSD_STATS_RC_HITS,		/* repcache hits */
35b670a598SJosef Bacik 	NFSD_STATS_RC_MISSES,		/* repcache misses */
36b670a598SJosef Bacik 	NFSD_STATS_RC_NOCACHE,		/* uncached reqs */
37b670a598SJosef Bacik 	NFSD_STATS_FH_STALE,		/* FH stale error */
38b670a598SJosef Bacik 	NFSD_STATS_IO_READ,		/* bytes returned to read requests */
39b670a598SJosef Bacik 	NFSD_STATS_IO_WRITE,		/* bytes passed in write requests */
40b670a598SJosef Bacik #ifdef CONFIG_NFSD_V4
41b670a598SJosef Bacik 	NFSD_STATS_FIRST_NFS4_OP,	/* count of individual nfsv4 operations */
42b670a598SJosef Bacik 	NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP,
43b670a598SJosef Bacik #define NFSD_STATS_NFS4_OP(op)	(NFSD_STATS_FIRST_NFS4_OP + (op))
44b670a598SJosef Bacik 	NFSD_STATS_WDELEG_GETATTR,	/* count of getattr conflict with wdeleg */
45b670a598SJosef Bacik #endif
46b670a598SJosef Bacik 	NFSD_STATS_COUNTERS_NUM
47e567b98cSAmir Goldstein };
48e567b98cSAmir Goldstein 
4914a571a8SJeff Layton /*
5014a571a8SJeff Layton  * Represents a nfsd "container". With respect to nfsv4 state tracking, the
5114a571a8SJeff Layton  * fields of interest are the *_id_hashtbls and the *_name_tree. These track
5214a571a8SJeff Layton  * the nfs4_client objects by either short or long form clientid.
5314a571a8SJeff Layton  *
5414a571a8SJeff Layton  * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
5514a571a8SJeff Layton  * up expired clients and delegations within the container.
5614a571a8SJeff Layton  */
577ea34ac1SJeff Layton struct nfsd_net {
587ea34ac1SJeff Layton 	struct cld_net *cld_net;
59b3853e0eSStanislav Kinsbursky 
60e5f06f72SStanislav Kinsbursky 	struct cache_detail *svc_expkey_cache;
61b3853e0eSStanislav Kinsbursky 	struct cache_detail *svc_export_cache;
62c2e76ef5SStanislav Kinsbursky 
63c2e76ef5SStanislav Kinsbursky 	struct cache_detail *idtoname_cache;
649e75a4deSStanislav Kinsbursky 	struct cache_detail *nametoid_cache;
655e1533c7SStanislav Kinsbursky 
665e1533c7SStanislav Kinsbursky 	struct lock_manager nfsd4_manager;
67a51c84edSStanislav Kinsbursky 	bool grace_ended;
689cc76801SArnd Bergmann 	time64_t boot_time;
6952e19c09SStanislav Kinsbursky 
70e8a79fb1SJ. Bruce Fields 	struct dentry *nfsd_client_dir;
71e8a79fb1SJ. Bruce Fields 
7252e19c09SStanislav Kinsbursky 	/*
7352e19c09SStanislav Kinsbursky 	 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
7452e19c09SStanislav Kinsbursky 	 * used in reboot/reset lease grace period processing
75382a62e7SStanislav Kinsbursky 	 *
76382a62e7SStanislav Kinsbursky 	 * conf_id_hashtbl[], and conf_name_tree hold confirmed
77382a62e7SStanislav Kinsbursky 	 * setclientid_confirmed info.
78a99454aaSStanislav Kinsbursky 	 *
79a99454aaSStanislav Kinsbursky 	 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
80a99454aaSStanislav Kinsbursky 	 * setclientid info.
8152e19c09SStanislav Kinsbursky 	 */
8252e19c09SStanislav Kinsbursky 	struct list_head *reclaim_str_hashtbl;
8352e19c09SStanislav Kinsbursky 	int reclaim_str_hashtbl_size;
848daae4dcSStanislav Kinsbursky 	struct list_head *conf_id_hashtbl;
85382a62e7SStanislav Kinsbursky 	struct rb_root conf_name_tree;
860a7ec377SStanislav Kinsbursky 	struct list_head *unconf_id_hashtbl;
87a99454aaSStanislav Kinsbursky 	struct rb_root unconf_name_tree;
881872de0eSStanislav Kinsbursky 	struct list_head *sessionid_hashtbl;
895ed58bb2SStanislav Kinsbursky 	/*
905ed58bb2SStanislav Kinsbursky 	 * client_lru holds client queue ordered by nfs4_client.cl_time
915ed58bb2SStanislav Kinsbursky 	 * for lease renewal.
9273758fedSStanislav Kinsbursky 	 *
9373758fedSStanislav Kinsbursky 	 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
9473758fedSStanislav Kinsbursky 	 * for last close replay.
9573758fedSStanislav Kinsbursky 	 *
9673758fedSStanislav Kinsbursky 	 * All of the above fields are protected by the client_mutex.
975ed58bb2SStanislav Kinsbursky 	 */
985ed58bb2SStanislav Kinsbursky 	struct list_head client_lru;
9973758fedSStanislav Kinsbursky 	struct list_head close_lru;
100e8c69d17SJ. Bruce Fields 	struct list_head del_recall_lru;
1010cc11a61SJeff Layton 
1020cc11a61SJeff Layton 	/* protected by blocked_locks_lock */
1037919d0a2SJeff Layton 	struct list_head blocked_locks_lru;
10409121281SStanislav Kinsbursky 
10509121281SStanislav Kinsbursky 	struct delayed_work laundromat_work;
106c9a49628SStanislav Kinsbursky 
107c9a49628SStanislav Kinsbursky 	/* client_lock protects the client lru list and session hash table */
108c9a49628SStanislav Kinsbursky 	spinlock_t client_lock;
1093a073369SStanislav Kinsbursky 
1100cc11a61SJeff Layton 	/* protects blocked_locks_lru */
1110cc11a61SJeff Layton 	spinlock_t blocked_locks_lock;
1120cc11a61SJeff Layton 
1133a073369SStanislav Kinsbursky 	struct file *rec_file;
114f141f79dSStanislav Kinsbursky 	bool in_grace;
1157c582e4fSJulia Lawall 	const struct nfsd4_client_tracking_ops *client_tracking_ops;
1163d733711SStanislav Kinsbursky 
11720b7d86fSArnd Bergmann 	time64_t nfsd4_lease;
11820b7d86fSArnd Bergmann 	time64_t nfsd4_grace;
11903f318caSJ. Bruce Fields 	bool somebody_reclaimed;
1202c2fe290SStanislav Kinsbursky 
121362063a5SScott Mayhew 	bool track_reclaim_completes;
122362063a5SScott Mayhew 	atomic_t nr_reclaim_complete;
123362063a5SScott Mayhew 
1242c2fe290SStanislav Kinsbursky 	bool nfsd_net_up;
1258ef66714SKinglong Mee 	bool lockd_up;
126b9c0ef85SStanislav Kinsbursky 
12791d2e9b5SChuck Lever 	seqlock_t writeverf_lock;
12891d2e9b5SChuck Lever 	unsigned char writeverf[8];
1299dd9845fSStanislav Kinsbursky 
1305b8db00bSJeff Layton 	/*
1315b8db00bSJeff Layton 	 * Max number of connections this nfsd container will allow. Defaults
1325b8db00bSJeff Layton 	 * to '0' which is means that it bases this on the number of threads.
1335b8db00bSJeff Layton 	 */
1345b8db00bSJeff Layton 	unsigned int max_connections;
1355b8db00bSJeff Layton 
136bf5ed3e3SJ. Bruce Fields 	u32 clientid_base;
137294ac32eSJeff Layton 	u32 clientid_counter;
13819311aa8SKinglong Mee 	u32 clverifier_counter;
139294ac32eSJeff Layton 
1409dd9845fSStanislav Kinsbursky 	struct svc_serv *nfsd_serv;
141ec52361dSNeilBrown 	/* When a listening socket is added to nfsd, keep_active is set
142ec52361dSNeilBrown 	 * and this justifies a reference on nfsd_serv.  This stops
143ec52361dSNeilBrown 	 * nfsd_serv from being freed.  When the number of threads is
144ec52361dSNeilBrown 	 * set, keep_active is cleared and the reference is dropped.  So
145ec52361dSNeilBrown 	 * when the last thread exits, the service will be destroyed.
146ec52361dSNeilBrown 	 */
147ec52361dSNeilBrown 	int keep_active;
1482317dc55SVasily Averin 
149e0639dc5SOlga Kornievskaia 	/*
150e0639dc5SOlga Kornievskaia 	 * clientid and stateid data for construction of net unique COPY
151e0639dc5SOlga Kornievskaia 	 * stateids.
152e0639dc5SOlga Kornievskaia 	 */
153e0639dc5SOlga Kornievskaia 	u32		s2s_cp_cl_id;
154e0639dc5SOlga Kornievskaia 	struct idr	s2s_cp_stateids;
155e0639dc5SOlga Kornievskaia 	spinlock_t	s2s_cp_lock;
156*ae267989SChuck Lever 	atomic_t	pending_async_copies;
157e333f3bbSTrond Myklebust 
158e333f3bbSTrond Myklebust 	/*
159e333f3bbSTrond Myklebust 	 * Version information
160e333f3bbSTrond Myklebust 	 */
161e333f3bbSTrond Myklebust 	bool *nfsd_versions;
162e333f3bbSTrond Myklebust 	bool *nfsd4_minorversions;
1633ba75830SJ. Bruce Fields 
1643ba75830SJ. Bruce Fields 	/*
1653ba75830SJ. Bruce Fields 	 * Duplicate reply cache
1663ba75830SJ. Bruce Fields 	 */
1673ba75830SJ. Bruce Fields 	struct nfsd_drc_bucket   *drc_hashtbl;
1683ba75830SJ. Bruce Fields 
1693ba75830SJ. Bruce Fields 	/* max number of entries allowed in the cache */
1703ba75830SJ. Bruce Fields 	unsigned int             max_drc_entries;
1713ba75830SJ. Bruce Fields 
1723ba75830SJ. Bruce Fields 	/* number of significant bits in the hash value */
1733ba75830SJ. Bruce Fields 	unsigned int             maskbits;
1743ba75830SJ. Bruce Fields 	unsigned int             drc_hashsize;
1753ba75830SJ. Bruce Fields 
1763ba75830SJ. Bruce Fields 	/*
17722a46eb4SJ. Bruce Fields 	 * Stats and other tracking of on the duplicate reply cache.
178e567b98cSAmir Goldstein 	 * The longest_chain* fields are modified with only the per-bucket
179e567b98cSAmir Goldstein 	 * cache lock, which isn't really safe and should be fixed if we want
180e567b98cSAmir Goldstein 	 * these statistics to be completely accurate.
1813ba75830SJ. Bruce Fields 	 */
1823ba75830SJ. Bruce Fields 
1833ba75830SJ. Bruce Fields 	/* total number of entries */
1843ba75830SJ. Bruce Fields 	atomic_t                 num_drc_entries;
1853ba75830SJ. Bruce Fields 
186e567b98cSAmir Goldstein 	/* Per-netns stats counters */
187b670a598SJosef Bacik 	struct percpu_counter    counter[NFSD_STATS_COUNTERS_NUM];
1883ba75830SJ. Bruce Fields 
1899eae1900SJosef Bacik 	/* sunrpc svc stats */
1909eae1900SJosef Bacik 	struct svc_stat          nfsd_svcstats;
1919eae1900SJosef Bacik 
1923ba75830SJ. Bruce Fields 	/* longest hash chain seen */
1933ba75830SJ. Bruce Fields 	unsigned int             longest_chain;
1943ba75830SJ. Bruce Fields 
1953ba75830SJ. Bruce Fields 	/* size of cache when we saw the longest hash chain */
1963ba75830SJ. Bruce Fields 	unsigned int             longest_chain_cachesize;
1973ba75830SJ. Bruce Fields 
1983ba75830SJ. Bruce Fields 	struct shrinker		nfsd_reply_cache_shrinker;
199f4e44b39SDai Ngo 
200f4e44b39SDai Ngo 	/* tracking server-to-server copy mounts */
201f4e44b39SDai Ngo 	spinlock_t              nfsd_ssc_lock;
202f4e44b39SDai Ngo 	struct list_head        nfsd_ssc_mount_list;
203f4e44b39SDai Ngo 	wait_queue_head_t       nfsd_ssc_waitq;
204f4e44b39SDai Ngo 
20594a4beaaSRandy Dunlap 	/* utsname taken from the process that starts the server */
2067627d7dcSScott Mayhew 	char			nfsd_name[UNX_MAXNODENAME+1];
2071463b38eSNeilBrown 
2081463b38eSNeilBrown 	struct nfsd_fcache_disposal *fcache_disposal;
20991d2e9b5SChuck Lever 
21091d2e9b5SChuck Lever 	siphash_key_t		siphash_key;
2110926c395SDai Ngo 
2120926c395SDai Ngo 	atomic_t		nfs4_client_count;
2134271c2c0SDai Ngo 	int			nfs4_max_clients;
2143a4ea23dSDai Ngo 
2153a4ea23dSDai Ngo 	atomic_t		nfsd_courtesy_clients;
2167746b32fSDai Ngo 	struct shrinker		nfsd_client_shrinker;
2177c24fa22SDai Ngo 	struct work_struct	nfsd_shrinker_work;
2187ea34ac1SJeff Layton };
2197ea34ac1SJeff Layton 
22044e34da6SBryan Schumaker /* Simple check to find out if a given net was properly initialized */
22144e34da6SBryan Schumaker #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
22244e34da6SBryan Schumaker 
223e333f3bbSTrond Myklebust extern void nfsd_netns_free_versions(struct nfsd_net *nn);
224e333f3bbSTrond Myklebust 
225c7d03a00SAlexey Dobriyan extern unsigned int nfsd_net_id;
22627c438f5STrond Myklebust 
2273988a578SChuck Lever void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn);
2283988a578SChuck Lever void nfsd_reset_write_verifier(struct nfsd_net *nn);
2297ea34ac1SJeff Layton #endif /* __NFSD_NETNS_H__ */
230