xref: /openbmc/linux/fs/nfsd/netns.h (revision b38269ec)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * per net namespace data structures for nfsd
4  *
5  * Copyright (C) 2012, Jeff Layton <jlayton@redhat.com>
6  */
7 
8 #ifndef __NFSD_NETNS_H__
9 #define __NFSD_NETNS_H__
10 
11 #include <net/net_namespace.h>
12 #include <net/netns/generic.h>
13 #include <linux/percpu_counter.h>
14 
15 /* Hash tables for nfs4_clientid state */
16 #define CLIENT_HASH_BITS                 4
17 #define CLIENT_HASH_SIZE                (1 << CLIENT_HASH_BITS)
18 #define CLIENT_HASH_MASK                (CLIENT_HASH_SIZE - 1)
19 
20 #define SESSION_HASH_SIZE	512
21 
22 struct cld_net;
23 struct nfsd4_client_tracking_ops;
24 
25 enum {
26 	/* cache misses due only to checksum comparison failures */
27 	NFSD_NET_PAYLOAD_MISSES,
28 	/* amount of memory (in bytes) currently consumed by the DRC */
29 	NFSD_NET_DRC_MEM_USAGE,
30 	NFSD_NET_COUNTERS_NUM
31 };
32 
33 /*
34  * Represents a nfsd "container". With respect to nfsv4 state tracking, the
35  * fields of interest are the *_id_hashtbls and the *_name_tree. These track
36  * the nfs4_client objects by either short or long form clientid.
37  *
38  * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
39  * up expired clients and delegations within the container.
40  */
41 struct nfsd_net {
42 	struct cld_net *cld_net;
43 
44 	struct cache_detail *svc_expkey_cache;
45 	struct cache_detail *svc_export_cache;
46 
47 	struct cache_detail *idtoname_cache;
48 	struct cache_detail *nametoid_cache;
49 
50 	struct lock_manager nfsd4_manager;
51 	bool grace_ended;
52 	time64_t boot_time;
53 
54 	struct dentry *nfsd_client_dir;
55 
56 	/*
57 	 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
58 	 * used in reboot/reset lease grace period processing
59 	 *
60 	 * conf_id_hashtbl[], and conf_name_tree hold confirmed
61 	 * setclientid_confirmed info.
62 	 *
63 	 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
64 	 * setclientid info.
65 	 */
66 	struct list_head *reclaim_str_hashtbl;
67 	int reclaim_str_hashtbl_size;
68 	struct list_head *conf_id_hashtbl;
69 	struct rb_root conf_name_tree;
70 	struct list_head *unconf_id_hashtbl;
71 	struct rb_root unconf_name_tree;
72 	struct list_head *sessionid_hashtbl;
73 	/*
74 	 * client_lru holds client queue ordered by nfs4_client.cl_time
75 	 * for lease renewal.
76 	 *
77 	 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
78 	 * for last close replay.
79 	 *
80 	 * All of the above fields are protected by the client_mutex.
81 	 */
82 	struct list_head client_lru;
83 	struct list_head close_lru;
84 	struct list_head del_recall_lru;
85 
86 	/* protected by blocked_locks_lock */
87 	struct list_head blocked_locks_lru;
88 
89 	struct delayed_work laundromat_work;
90 
91 	/* client_lock protects the client lru list and session hash table */
92 	spinlock_t client_lock;
93 
94 	/* protects blocked_locks_lru */
95 	spinlock_t blocked_locks_lock;
96 
97 	struct file *rec_file;
98 	bool in_grace;
99 	const struct nfsd4_client_tracking_ops *client_tracking_ops;
100 
101 	time64_t nfsd4_lease;
102 	time64_t nfsd4_grace;
103 	bool somebody_reclaimed;
104 
105 	bool track_reclaim_completes;
106 	atomic_t nr_reclaim_complete;
107 
108 	bool nfsd_net_up;
109 	bool lockd_up;
110 
111 	/* Time of server startup */
112 	struct timespec64 nfssvc_boot;
113 	seqlock_t boot_lock;
114 
115 	/*
116 	 * Max number of connections this nfsd container will allow. Defaults
117 	 * to '0' which is means that it bases this on the number of threads.
118 	 */
119 	unsigned int max_connections;
120 
121 	u32 clientid_base;
122 	u32 clientid_counter;
123 	u32 clverifier_counter;
124 
125 	struct svc_serv *nfsd_serv;
126 
127 	wait_queue_head_t ntf_wq;
128 	atomic_t ntf_refcnt;
129 
130 	/* Allow umount to wait for nfsd state cleanup */
131 	struct completion nfsd_shutdown_complete;
132 
133 	/*
134 	 * clientid and stateid data for construction of net unique COPY
135 	 * stateids.
136 	 */
137 	u32		s2s_cp_cl_id;
138 	struct idr	s2s_cp_stateids;
139 	spinlock_t	s2s_cp_lock;
140 
141 	/*
142 	 * Version information
143 	 */
144 	bool *nfsd_versions;
145 	bool *nfsd4_minorversions;
146 
147 	/*
148 	 * Duplicate reply cache
149 	 */
150 	struct nfsd_drc_bucket   *drc_hashtbl;
151 
152 	/* max number of entries allowed in the cache */
153 	unsigned int             max_drc_entries;
154 
155 	/* number of significant bits in the hash value */
156 	unsigned int             maskbits;
157 	unsigned int             drc_hashsize;
158 
159 	/*
160 	 * Stats and other tracking of on the duplicate reply cache.
161 	 * The longest_chain* fields are modified with only the per-bucket
162 	 * cache lock, which isn't really safe and should be fixed if we want
163 	 * these statistics to be completely accurate.
164 	 */
165 
166 	/* total number of entries */
167 	atomic_t                 num_drc_entries;
168 
169 	/* Per-netns stats counters */
170 	struct percpu_counter    counter[NFSD_NET_COUNTERS_NUM];
171 
172 	/* longest hash chain seen */
173 	unsigned int             longest_chain;
174 
175 	/* size of cache when we saw the longest hash chain */
176 	unsigned int             longest_chain_cachesize;
177 
178 	struct shrinker		nfsd_reply_cache_shrinker;
179 
180 	/* tracking server-to-server copy mounts */
181 	spinlock_t              nfsd_ssc_lock;
182 	struct list_head        nfsd_ssc_mount_list;
183 	wait_queue_head_t       nfsd_ssc_waitq;
184 
185 	/* utsname taken from the process that starts the server */
186 	char			nfsd_name[UNX_MAXNODENAME+1];
187 };
188 
189 /* Simple check to find out if a given net was properly initialized */
190 #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
191 
192 extern void nfsd_netns_free_versions(struct nfsd_net *nn);
193 
194 extern unsigned int nfsd_net_id;
195 
196 void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn);
197 void nfsd_reset_boot_verifier(struct nfsd_net *nn);
198 #endif /* __NFSD_NETNS_H__ */
199