1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * per net namespace data structures for nfsd
8 #ifndef __NFSD_NETNS_H__
9 #define __NFSD_NETNS_H__
11 #include <net/net_namespace.h>
12 #include <net/netns/generic.h>
13 #include <linux/percpu_counter.h>
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)
20 #define SESSION_HASH_SIZE 512
23 struct nfsd4_client_tracking_ops;
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,
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.
38 * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
39 * up expired clients and delegations within the container.
42 struct cld_net *cld_net;
44 struct cache_detail *svc_expkey_cache;
45 struct cache_detail *svc_export_cache;
47 struct cache_detail *idtoname_cache;
48 struct cache_detail *nametoid_cache;
50 struct lock_manager nfsd4_manager;
54 /* internal mount of the "nfsd" pseudofilesystem: */
55 struct vfsmount *nfsd_mnt;
57 struct dentry *nfsd_client_dir;
60 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
61 * used in reboot/reset lease grace period processing
63 * conf_id_hashtbl[], and conf_name_tree hold confirmed
64 * setclientid_confirmed info.
66 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
69 struct list_head *reclaim_str_hashtbl;
70 int reclaim_str_hashtbl_size;
71 struct list_head *conf_id_hashtbl;
72 struct rb_root conf_name_tree;
73 struct list_head *unconf_id_hashtbl;
74 struct rb_root unconf_name_tree;
75 struct list_head *sessionid_hashtbl;
77 * client_lru holds client queue ordered by nfs4_client.cl_time
80 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
81 * for last close replay.
83 * All of the above fields are protected by the client_mutex.
85 struct list_head client_lru;
86 struct list_head close_lru;
87 struct list_head del_recall_lru;
89 /* protected by blocked_locks_lock */
90 struct list_head blocked_locks_lru;
92 struct delayed_work laundromat_work;
94 /* client_lock protects the client lru list and session hash table */
95 spinlock_t client_lock;
97 /* protects blocked_locks_lru */
98 spinlock_t blocked_locks_lock;
100 struct file *rec_file;
102 const struct nfsd4_client_tracking_ops *client_tracking_ops;
104 time64_t nfsd4_lease;
105 time64_t nfsd4_grace;
106 bool somebody_reclaimed;
108 bool track_reclaim_completes;
109 atomic_t nr_reclaim_complete;
114 /* Time of server startup */
115 struct timespec64 nfssvc_boot;
119 * Max number of connections this nfsd container will allow. Defaults
120 * to '0' which is means that it bases this on the number of threads.
122 unsigned int max_connections;
125 u32 clientid_counter;
126 u32 clverifier_counter;
128 struct svc_serv *nfsd_serv;
130 wait_queue_head_t ntf_wq;
134 * clientid and stateid data for construction of net unique COPY
138 struct idr s2s_cp_stateids;
139 spinlock_t s2s_cp_lock;
142 * Version information
145 bool *nfsd4_minorversions;
148 * Duplicate reply cache
150 struct nfsd_drc_bucket *drc_hashtbl;
152 /* max number of entries allowed in the cache */
153 unsigned int max_drc_entries;
155 /* number of significant bits in the hash value */
156 unsigned int maskbits;
157 unsigned int drc_hashsize;
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.
166 /* total number of entries */
167 atomic_t num_drc_entries;
169 /* Per-netns stats counters */
170 struct percpu_counter counter[NFSD_NET_COUNTERS_NUM];
172 /* longest hash chain seen */
173 unsigned int longest_chain;
175 /* size of cache when we saw the longest hash chain */
176 unsigned int longest_chain_cachesize;
178 struct shrinker nfsd_reply_cache_shrinker;
179 /* utsname taken from the process that starts the server */
180 char nfsd_name[UNX_MAXNODENAME+1];
183 /* Simple check to find out if a given net was properly initialized */
184 #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
186 extern void nfsd_netns_free_versions(struct nfsd_net *nn);
188 extern unsigned int nfsd_net_id;
190 void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn);
191 void nfsd_reset_boot_verifier(struct nfsd_net *nn);
192 #endif /* __NFSD_NETNS_H__ */