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/filelock.h> 14 #include <linux/nfs4.h> 15 #include <linux/percpu_counter.h> 16 #include <linux/percpu-refcount.h> 17 #include <linux/siphash.h> 18 #include <linux/sunrpc/stats.h> 19 20 /* Hash tables for nfs4_clientid state */ 21 #define CLIENT_HASH_BITS 4 22 #define CLIENT_HASH_SIZE (1 << CLIENT_HASH_BITS) 23 #define CLIENT_HASH_MASK (CLIENT_HASH_SIZE - 1) 24 25 #define SESSION_HASH_SIZE 512 26 27 struct cld_net; 28 struct nfsd_net_cb; 29 struct nfsd4_client_tracking_ops; 30 31 enum nfsd_net_flag { 32 NFSD_NET_GRACE_ENDED, 33 NFSD_NET_GRACE_END_FORCED, 34 NFSD_NET_IN_GRACE, 35 NFSD_NET_SOMEBODY_RECLAIMED, 36 NFSD_NET_TRACK_RECLAIM_COMPLETES, 37 NFSD_NET_UP, 38 NFSD_NET_LOCKD_UP, 39 }; 40 41 enum { 42 /* cache misses due only to checksum comparison failures */ 43 NFSD_STATS_PAYLOAD_MISSES, 44 /* amount of memory (in bytes) currently consumed by the DRC */ 45 NFSD_STATS_DRC_MEM_USAGE, 46 NFSD_STATS_RC_HITS, /* repcache hits */ 47 NFSD_STATS_RC_MISSES, /* repcache misses */ 48 NFSD_STATS_RC_NOCACHE, /* uncached reqs */ 49 NFSD_STATS_FH_STALE, /* FH stale error */ 50 NFSD_STATS_IO_READ, /* bytes returned to read requests */ 51 NFSD_STATS_IO_WRITE, /* bytes passed in write requests */ 52 #ifdef CONFIG_NFSD_V4 53 NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */ 54 NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP, 55 #define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op)) 56 #endif 57 NFSD_STATS_COUNTERS_NUM 58 }; 59 60 /* 61 * Per-netns NFSv4 callback (backchannel) per-operation counters, indexed 62 * directly by RFC 8881 callback opcode (OP_CB_GETATTR..OP_CB_OFFLOAD). 63 */ 64 #define NFSD_STATS_CB_OPS_NUM (OP_CB_OFFLOAD + 1) 65 66 /* 67 * Represents a nfsd "container". With respect to nfsv4 state tracking, the 68 * fields of interest are the *_id_hashtbls and the *_name_tree. These track 69 * the nfs4_client objects by either short or long form clientid. 70 * 71 * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean 72 * up expired clients and delegations within the container. 73 */ 74 struct nfsd_net { 75 struct cld_net *cld_net; 76 77 struct cache_detail *svc_expkey_cache; 78 struct cache_detail *svc_export_cache; 79 80 struct cache_detail *idtoname_cache; 81 struct cache_detail *nametoid_cache; 82 83 struct lock_manager nfsd4_manager; 84 unsigned long flags; 85 time64_t boot_time; 86 time64_t boot_time_bt; /* same instant in CLOCK_BOOTTIME */ 87 88 struct dentry *nfsd_client_dir; 89 90 /* 91 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot 92 * used in reboot/reset lease grace period processing 93 * 94 * conf_id_hashtbl[], and conf_name_tree hold confirmed 95 * setclientid_confirmed info. 96 * 97 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed 98 * setclientid info. 99 */ 100 struct list_head *reclaim_str_hashtbl; 101 int reclaim_str_hashtbl_size; 102 struct rw_semaphore reclaim_str_hashtbl_lock; 103 struct list_head *conf_id_hashtbl; 104 struct rb_root conf_name_tree; 105 struct list_head *unconf_id_hashtbl; 106 struct rb_root unconf_name_tree; 107 struct list_head *sessionid_hashtbl; 108 /* 109 * client_lru holds client queue ordered by nfs4_client.cl_time 110 * for lease renewal. 111 * 112 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time 113 * for last close replay. 114 * 115 * reclaim_str_hashtbl[], reclaim_str_hashtbl_size are protected by 116 * reclaim_str_hashtbl_lock. 117 * 118 * All of the remaining fields are protected by the client_lock. 119 */ 120 struct list_head client_lru; 121 struct list_head close_lru; 122 123 /* protects del_recall_lru and delegation hash/unhash; 124 * nests outside client_lock */ 125 spinlock_t deleg_lock ____cacheline_aligned; 126 struct list_head del_recall_lru; 127 128 /* protected by blocked_locks_lock */ 129 struct list_head blocked_locks_lru; 130 131 struct delayed_work laundromat_work; 132 133 /* client_lock protects the client lru list and session hash 134 * table; nests inside deleg_lock */ 135 spinlock_t client_lock; 136 137 /* protects blocked_locks_lru */ 138 spinlock_t blocked_locks_lock; 139 140 struct file *rec_file; 141 const struct nfsd4_client_tracking_ops *client_tracking_ops; 142 143 time64_t nfsd4_lease; 144 time64_t nfsd4_grace; 145 146 atomic_t nr_reclaim_complete; 147 148 seqlock_t writeverf_lock; 149 unsigned char writeverf[8]; 150 151 /* 152 * Minimum number of threads to run per pool. If 0 then the 153 * min == max requested number of threads. 154 */ 155 unsigned int min_threads; 156 157 u32 clientid_base; 158 u32 clientid_counter; 159 u32 clverifier_counter; 160 161 struct svc_info nfsd_info; 162 #define nfsd_serv nfsd_info.serv 163 164 struct percpu_ref nfsd_net_ref; 165 struct completion nfsd_net_confirm_done; 166 struct completion nfsd_net_free_done; 167 168 /* 169 * clientid and stateid data for construction of net unique COPY 170 * stateids. 171 */ 172 u32 s2s_cp_cl_id; 173 struct idr s2s_cp_stateids; 174 spinlock_t s2s_cp_lock; 175 atomic_t pending_async_copies; 176 177 /* 178 * Version information 179 */ 180 bool nfsd_versions[NFSD_MAXVERS + 1]; 181 bool nfsd4_minorversions[NFSD_SUPPORTED_MINOR_VERSION + 1]; 182 183 /* 184 * Duplicate reply cache 185 */ 186 struct nfsd_drc_bucket *drc_hashtbl; 187 188 /* max number of entries allowed in the cache */ 189 unsigned int max_drc_entries; 190 191 /* number of significant bits in the hash value */ 192 unsigned int maskbits; 193 unsigned int drc_hashsize; 194 195 /* 196 * Stats and other tracking of on the duplicate reply cache. 197 * The longest_chain* fields are modified with only the per-bucket 198 * cache lock, which isn't really safe and should be fixed if we want 199 * these statistics to be completely accurate. 200 */ 201 202 /* total number of entries */ 203 atomic_t num_drc_entries; 204 205 /* Per-netns stats counters */ 206 struct percpu_counter counter[NFSD_STATS_COUNTERS_NUM]; 207 208 #ifdef CONFIG_NFSD_V4 209 /* Per-netns NFSv4 callback (backchannel) per-operation counters */ 210 struct percpu_counter cb_counter[NFSD_STATS_CB_OPS_NUM]; 211 #endif 212 213 /* sunrpc svc stats */ 214 struct svc_stat nfsd_svcstats; 215 216 /* longest hash chain seen */ 217 unsigned int longest_chain; 218 219 /* size of cache when we saw the longest hash chain */ 220 unsigned int longest_chain_cachesize; 221 222 struct shrinker *nfsd_reply_cache_shrinker; 223 224 /* tracking server-to-server copy mounts */ 225 spinlock_t nfsd_ssc_lock; 226 struct list_head nfsd_ssc_mount_list; 227 wait_queue_head_t nfsd_ssc_waitq; 228 229 /* utsname taken from the process that starts the server */ 230 char nfsd_name[UNX_MAXNODENAME+1]; 231 232 spinlock_t fcache_dispose_lock; 233 struct list_head fcache_dispose_list; 234 235 siphash_key_t siphash_key; 236 237 atomic_t nfs4_client_count; 238 int nfs4_max_clients; 239 240 atomic_t nfsd_courtesy_clients; 241 struct shrinker *nfsd_client_shrinker; 242 struct work_struct nfsd_shrinker_work; 243 244 /* last time an admin-revoke happened for NFSv4.0 */ 245 time64_t nfs40_last_revoke; 246 247 #if IS_ENABLED(CONFIG_NFS_LOCALIO) 248 /* Local clients to be invalidated when net is shut down */ 249 spinlock_t local_clients_lock; 250 struct list_head local_clients; 251 #endif 252 siphash_key_t *fh_key; 253 254 struct nfsd_net_cb *nfsd_cb; 255 }; 256 257 /* Simple check to find out if a given net was properly initialized */ 258 #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl) 259 260 extern bool nfsd_support_version(int vers); 261 extern unsigned int nfsd_net_id; 262 263 bool nfsd_net_try_get(struct net *net); 264 void nfsd_net_put(struct net *net); 265 266 void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn); 267 void nfsd_reset_write_verifier(struct nfsd_net *nn); 268 #endif /* __NFSD_NETNS_H__ */ 269