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 /* internal mount of the "nfsd" pseudofilesystem: */ 55 struct vfsmount *nfsd_mnt; 56 57 struct dentry *nfsd_client_dir; 58 59 /* 60 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot 61 * used in reboot/reset lease grace period processing 62 * 63 * conf_id_hashtbl[], and conf_name_tree hold confirmed 64 * setclientid_confirmed info. 65 * 66 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed 67 * setclientid info. 68 */ 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; 76 /* 77 * client_lru holds client queue ordered by nfs4_client.cl_time 78 * for lease renewal. 79 * 80 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time 81 * for last close replay. 82 * 83 * All of the above fields are protected by the client_mutex. 84 */ 85 struct list_head client_lru; 86 struct list_head close_lru; 87 struct list_head del_recall_lru; 88 89 /* protected by blocked_locks_lock */ 90 struct list_head blocked_locks_lru; 91 92 struct delayed_work laundromat_work; 93 94 /* client_lock protects the client lru list and session hash table */ 95 spinlock_t client_lock; 96 97 /* protects blocked_locks_lru */ 98 spinlock_t blocked_locks_lock; 99 100 struct file *rec_file; 101 bool in_grace; 102 const struct nfsd4_client_tracking_ops *client_tracking_ops; 103 104 time64_t nfsd4_lease; 105 time64_t nfsd4_grace; 106 bool somebody_reclaimed; 107 108 bool track_reclaim_completes; 109 atomic_t nr_reclaim_complete; 110 111 bool nfsd_net_up; 112 bool lockd_up; 113 114 /* Time of server startup */ 115 struct timespec64 nfssvc_boot; 116 seqlock_t boot_lock; 117 118 /* 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. 121 */ 122 unsigned int max_connections; 123 124 u32 clientid_base; 125 u32 clientid_counter; 126 u32 clverifier_counter; 127 128 struct svc_serv *nfsd_serv; 129 130 wait_queue_head_t ntf_wq; 131 atomic_t ntf_refcnt; 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 /* utsname taken from the process that starts the server */ 180 char nfsd_name[UNX_MAXNODENAME+1]; 181 }; 182 183 /* Simple check to find out if a given net was properly initialized */ 184 #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl) 185 186 extern void nfsd_netns_free_versions(struct nfsd_net *nn); 187 188 extern unsigned int nfsd_net_id; 189 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__ */ 193