blob: 1b1a962a18041c53021b26d8331fbf196679fcc6 [file] [log] [blame]
Thomas Gleixner16216332019-05-19 15:51:31 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Jeff Layton7ea34ac2012-03-21 09:52:05 -04002/*
3 * per net namespace data structures for nfsd
4 *
5 * Copyright (C) 2012, Jeff Layton <jlayton@redhat.com>
Jeff Layton7ea34ac2012-03-21 09:52:05 -04006 */
7
8#ifndef __NFSD_NETNS_H__
9#define __NFSD_NETNS_H__
10
11#include <net/net_namespace.h>
12#include <net/netns/generic.h>
Amir Goldsteine567b982021-01-06 09:52:35 +020013#include <linux/percpu_counter.h>
Chuck Lever91d2e9b2021-12-29 14:43:16 -050014#include <linux/siphash.h>
Jeff Layton7ea34ac2012-03-21 09:52:05 -040015
Stanislav Kinsbursky52e19c02012-11-14 18:21:16 +030016/* Hash tables for nfs4_clientid state */
17#define CLIENT_HASH_BITS 4
18#define CLIENT_HASH_SIZE (1 << CLIENT_HASH_BITS)
19#define CLIENT_HASH_MASK (CLIENT_HASH_SIZE - 1)
20
Stanislav Kinsbursky1872de02012-11-14 18:21:51 +030021#define SESSION_HASH_SIZE 512
22
Jeff Layton7ea34ac2012-03-21 09:52:05 -040023struct cld_net;
Stanislav Kinsbursky9a9c6472012-12-04 14:29:27 +030024struct nfsd4_client_tracking_ops;
Jeff Layton7ea34ac2012-03-21 09:52:05 -040025
Amir Goldsteine567b982021-01-06 09:52:35 +020026enum {
27 /* cache misses due only to checksum comparison failures */
28 NFSD_NET_PAYLOAD_MISSES,
29 /* amount of memory (in bytes) currently consumed by the DRC */
30 NFSD_NET_DRC_MEM_USAGE,
31 NFSD_NET_COUNTERS_NUM
32};
33
Jeff Layton14a571a2014-08-05 15:13:30 -040034/*
35 * Represents a nfsd "container". With respect to nfsv4 state tracking, the
36 * fields of interest are the *_id_hashtbls and the *_name_tree. These track
37 * the nfs4_client objects by either short or long form clientid.
38 *
39 * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
40 * up expired clients and delegations within the container.
41 */
Jeff Layton7ea34ac2012-03-21 09:52:05 -040042struct nfsd_net {
43 struct cld_net *cld_net;
Stanislav Kinsburskyb3853e02012-04-11 15:13:21 +040044
Stanislav Kinsburskye5f06f72012-04-11 15:13:28 +040045 struct cache_detail *svc_expkey_cache;
Stanislav Kinsburskyb3853e02012-04-11 15:13:21 +040046 struct cache_detail *svc_export_cache;
Stanislav Kinsburskyc2e76ef2012-04-11 17:32:51 +040047
48 struct cache_detail *idtoname_cache;
Stanislav Kinsbursky9e75a4d2012-04-11 17:32:58 +040049 struct cache_detail *nametoid_cache;
Stanislav Kinsbursky5e1533c2012-07-25 16:56:58 +040050
51 struct lock_manager nfsd4_manager;
Stanislav Kinsburskya51c84e2012-07-25 16:57:37 +040052 bool grace_ended;
Arnd Bergmann9cc76802019-10-31 15:53:13 +010053 time64_t boot_time;
Stanislav Kinsbursky52e19c02012-11-14 18:21:16 +030054
J. Bruce Fieldse8a79fb2019-03-22 11:11:06 -040055 struct dentry *nfsd_client_dir;
56
Stanislav Kinsbursky52e19c02012-11-14 18:21:16 +030057 /*
58 * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
59 * used in reboot/reset lease grace period processing
Stanislav Kinsbursky382a62e2012-11-14 18:21:26 +030060 *
61 * conf_id_hashtbl[], and conf_name_tree hold confirmed
62 * setclientid_confirmed info.
Stanislav Kinsburskya99454a2012-11-14 18:21:36 +030063 *
64 * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
65 * setclientid info.
Stanislav Kinsbursky52e19c02012-11-14 18:21:16 +030066 */
67 struct list_head *reclaim_str_hashtbl;
68 int reclaim_str_hashtbl_size;
Stanislav Kinsbursky8daae4d2012-11-14 18:21:21 +030069 struct list_head *conf_id_hashtbl;
Stanislav Kinsbursky382a62e2012-11-14 18:21:26 +030070 struct rb_root conf_name_tree;
Stanislav Kinsbursky0a7ec372012-11-14 18:21:31 +030071 struct list_head *unconf_id_hashtbl;
Stanislav Kinsburskya99454a2012-11-14 18:21:36 +030072 struct rb_root unconf_name_tree;
Stanislav Kinsbursky1872de02012-11-14 18:21:51 +030073 struct list_head *sessionid_hashtbl;
Stanislav Kinsbursky5ed58bb2012-11-14 18:21:56 +030074 /*
75 * client_lru holds client queue ordered by nfs4_client.cl_time
76 * for lease renewal.
Stanislav Kinsbursky73758fed2012-11-14 18:22:01 +030077 *
78 * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
79 * for last close replay.
80 *
81 * All of the above fields are protected by the client_mutex.
Stanislav Kinsbursky5ed58bb2012-11-14 18:21:56 +030082 */
83 struct list_head client_lru;
Stanislav Kinsbursky73758fed2012-11-14 18:22:01 +030084 struct list_head close_lru;
J. Bruce Fieldse8c69d12013-03-21 15:19:33 -040085 struct list_head del_recall_lru;
Jeff Layton0cc11a62016-10-20 09:34:31 -040086
87 /* protected by blocked_locks_lock */
Jeff Layton7919d0a2016-09-16 16:28:25 -040088 struct list_head blocked_locks_lru;
Stanislav Kinsbursky09121282012-11-14 18:22:17 +030089
90 struct delayed_work laundromat_work;
Stanislav Kinsburskyc9a49622012-11-26 15:21:58 +030091
92 /* client_lock protects the client lru list and session hash table */
93 spinlock_t client_lock;
Stanislav Kinsbursky3a073362012-11-26 16:16:25 +030094
Jeff Layton0cc11a62016-10-20 09:34:31 -040095 /* protects blocked_locks_lru */
96 spinlock_t blocked_locks_lock;
97
Stanislav Kinsbursky3a073362012-11-26 16:16:25 +030098 struct file *rec_file;
Stanislav Kinsburskyf141f792012-11-26 16:16:30 +030099 bool in_grace;
Julia Lawall7c582e42015-11-22 08:22:10 +0100100 const struct nfsd4_client_tracking_ops *client_tracking_ops;
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +0300101
Arnd Bergmann20b7d862019-11-04 16:31:52 +0100102 time64_t nfsd4_lease;
103 time64_t nfsd4_grace;
J. Bruce Fields03f318c2018-06-08 12:28:47 -0400104 bool somebody_reclaimed;
Stanislav Kinsbursky2c2fe292012-12-06 14:23:14 +0300105
Scott Mayhew362063a2019-03-26 18:06:28 -0400106 bool track_reclaim_completes;
107 atomic_t nr_reclaim_complete;
108
Stanislav Kinsbursky2c2fe292012-12-06 14:23:14 +0300109 bool nfsd_net_up;
Kinglong Mee8ef66712013-12-31 13:17:30 +0800110 bool lockd_up;
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300111
Chuck Lever91d2e9b2021-12-29 14:43:16 -0500112 seqlock_t writeverf_lock;
113 unsigned char writeverf[8];
Stanislav Kinsbursky9dd98452012-12-06 14:23:24 +0300114
Jeff Layton5b8db002014-07-02 16:11:22 -0400115 /*
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
J. Bruce Fieldsbf5ed3e2019-03-14 16:20:19 -0400121 u32 clientid_base;
Jeff Layton294ac322014-07-30 08:27:15 -0400122 u32 clientid_counter;
Kinglong Mee19311aa82015-07-18 07:33:31 +0800123 u32 clverifier_counter;
Jeff Layton294ac322014-07-30 08:27:15 -0400124
Stanislav Kinsbursky9dd98452012-12-06 14:23:24 +0300125 struct svc_serv *nfsd_serv;
NeilBrownec523612021-11-29 15:51:25 +1100126 /* When a listening socket is added to nfsd, keep_active is set
127 * and this justifies a reference on nfsd_serv. This stops
128 * nfsd_serv from being freed. When the number of threads is
129 * set, keep_active is cleared and the reference is dropped. So
130 * when the last thread exits, the service will be destroyed.
131 */
132 int keep_active;
Vasily Averin2317dc52017-11-10 10:19:35 +0300133
Olga Kornievskaiae0639dc2018-07-20 18:19:20 -0400134 /*
135 * clientid and stateid data for construction of net unique COPY
136 * stateids.
137 */
138 u32 s2s_cp_cl_id;
139 struct idr s2s_cp_stateids;
140 spinlock_t s2s_cp_lock;
Trond Myklebuste333f3b2019-04-09 11:46:19 -0400141
142 /*
143 * Version information
144 */
145 bool *nfsd_versions;
146 bool *nfsd4_minorversions;
J. Bruce Fields3ba75832019-05-17 09:03:38 -0400147
148 /*
149 * Duplicate reply cache
150 */
151 struct nfsd_drc_bucket *drc_hashtbl;
J. Bruce Fields3ba75832019-05-17 09:03:38 -0400152
153 /* max number of entries allowed in the cache */
154 unsigned int max_drc_entries;
155
156 /* number of significant bits in the hash value */
157 unsigned int maskbits;
158 unsigned int drc_hashsize;
159
160 /*
J. Bruce Fields22a46eb42019-05-17 16:22:18 -0400161 * Stats and other tracking of on the duplicate reply cache.
Amir Goldsteine567b982021-01-06 09:52:35 +0200162 * The longest_chain* fields are modified with only the per-bucket
163 * cache lock, which isn't really safe and should be fixed if we want
164 * these statistics to be completely accurate.
J. Bruce Fields3ba75832019-05-17 09:03:38 -0400165 */
166
167 /* total number of entries */
168 atomic_t num_drc_entries;
169
Amir Goldsteine567b982021-01-06 09:52:35 +0200170 /* Per-netns stats counters */
171 struct percpu_counter counter[NFSD_NET_COUNTERS_NUM];
J. Bruce Fields3ba75832019-05-17 09:03:38 -0400172
173 /* longest hash chain seen */
174 unsigned int longest_chain;
175
176 /* size of cache when we saw the longest hash chain */
177 unsigned int longest_chain_cachesize;
178
179 struct shrinker nfsd_reply_cache_shrinker;
Dai Ngof4e44b32021-05-21 15:09:37 -0400180
181 /* tracking server-to-server copy mounts */
182 spinlock_t nfsd_ssc_lock;
183 struct list_head nfsd_ssc_mount_list;
184 wait_queue_head_t nfsd_ssc_waitq;
185
Randy Dunlap94a4bea2020-07-19 17:14:03 -0700186 /* utsname taken from the process that starts the server */
Scott Mayhew7627d7d2020-02-19 15:52:15 -0500187 char nfsd_name[UNX_MAXNODENAME+1];
NeilBrown1463b382021-12-01 10:58:14 +1100188
189 struct nfsd_fcache_disposal *fcache_disposal;
Chuck Lever91d2e9b2021-12-29 14:43:16 -0500190
191 siphash_key_t siphash_key;
Jeff Layton7ea34ac2012-03-21 09:52:05 -0400192};
193
Bryan Schumaker44e34da602012-11-29 11:40:39 -0500194/* Simple check to find out if a given net was properly initialized */
195#define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
196
Trond Myklebuste333f3b2019-04-09 11:46:19 -0400197extern void nfsd_netns_free_versions(struct nfsd_net *nn);
198
Alexey Dobriyanc7d03a02016-11-17 04:58:21 +0300199extern unsigned int nfsd_net_id;
Trond Myklebust27c438f2019-09-02 13:02:56 -0400200
Chuck Lever3988a572021-12-30 10:22:05 -0500201void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn);
202void nfsd_reset_write_verifier(struct nfsd_net *nn);
Jeff Layton7ea34ac2012-03-21 09:52:05 -0400203#endif /* __NFSD_NETNS_H__ */