netns.h 5.7 KB

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