netns.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #ifndef __NFSD_NETNS_H__
  8. #define __NFSD_NETNS_H__
  9. #include <net/net_namespace.h>
  10. #include <net/netns/generic.h>
  11. #include <linux/filelock.h>
  12. #include <linux/nfs4.h>
  13. #include <linux/percpu_counter.h>
  14. #include <linux/percpu-refcount.h>
  15. #include <linux/siphash.h>
  16. #include <linux/sunrpc/stats.h>
  17. /* Hash tables for nfs4_clientid state */
  18. #define CLIENT_HASH_BITS 4
  19. #define CLIENT_HASH_SIZE (1 << CLIENT_HASH_BITS)
  20. #define CLIENT_HASH_MASK (CLIENT_HASH_SIZE - 1)
  21. #define SESSION_HASH_SIZE 512
  22. struct cld_net;
  23. struct nfsd4_client_tracking_ops;
  24. enum {
  25. /* cache misses due only to checksum comparison failures */
  26. NFSD_STATS_PAYLOAD_MISSES,
  27. /* amount of memory (in bytes) currently consumed by the DRC */
  28. NFSD_STATS_DRC_MEM_USAGE,
  29. NFSD_STATS_RC_HITS, /* repcache hits */
  30. NFSD_STATS_RC_MISSES, /* repcache misses */
  31. NFSD_STATS_RC_NOCACHE, /* uncached reqs */
  32. NFSD_STATS_FH_STALE, /* FH stale error */
  33. NFSD_STATS_IO_READ, /* bytes returned to read requests */
  34. NFSD_STATS_IO_WRITE, /* bytes passed in write requests */
  35. #ifdef CONFIG_NFSD_V4
  36. NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */
  37. NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP,
  38. #define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op))
  39. NFSD_STATS_WDELEG_GETATTR, /* count of getattr conflict with wdeleg */
  40. #endif
  41. NFSD_STATS_COUNTERS_NUM
  42. };
  43. /*
  44. * Represents a nfsd "container". With respect to nfsv4 state tracking, the
  45. * fields of interest are the *_id_hashtbls and the *_name_tree. These track
  46. * the nfs4_client objects by either short or long form clientid.
  47. *
  48. * Each nfsd_net runs a nfs4_laundromat workqueue job when necessary to clean
  49. * up expired clients and delegations within the container.
  50. */
  51. struct nfsd_net {
  52. struct cld_net *cld_net;
  53. struct cache_detail *svc_expkey_cache;
  54. struct cache_detail *svc_export_cache;
  55. struct cache_detail *idtoname_cache;
  56. struct cache_detail *nametoid_cache;
  57. struct lock_manager nfsd4_manager;
  58. bool grace_ended;
  59. time64_t boot_time;
  60. struct dentry *nfsd_client_dir;
  61. /*
  62. * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
  63. * used in reboot/reset lease grace period processing
  64. *
  65. * conf_id_hashtbl[], and conf_name_tree hold confirmed
  66. * setclientid_confirmed info.
  67. *
  68. * unconf_str_hastbl[] and unconf_name_tree hold unconfirmed
  69. * setclientid info.
  70. */
  71. struct list_head *reclaim_str_hashtbl;
  72. int reclaim_str_hashtbl_size;
  73. struct list_head *conf_id_hashtbl;
  74. struct rb_root conf_name_tree;
  75. struct list_head *unconf_id_hashtbl;
  76. struct rb_root unconf_name_tree;
  77. struct list_head *sessionid_hashtbl;
  78. /*
  79. * client_lru holds client queue ordered by nfs4_client.cl_time
  80. * for lease renewal.
  81. *
  82. * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
  83. * for last close replay.
  84. *
  85. * All of the above fields are protected by the client_mutex.
  86. */
  87. struct list_head client_lru;
  88. struct list_head close_lru;
  89. struct list_head del_recall_lru;
  90. /* protected by blocked_locks_lock */
  91. struct list_head blocked_locks_lru;
  92. struct delayed_work laundromat_work;
  93. /* client_lock protects the client lru list and session hash table */
  94. spinlock_t client_lock;
  95. /* protects blocked_locks_lru */
  96. spinlock_t blocked_locks_lock;
  97. struct file *rec_file;
  98. bool in_grace;
  99. const struct nfsd4_client_tracking_ops *client_tracking_ops;
  100. time64_t nfsd4_lease;
  101. time64_t nfsd4_grace;
  102. bool somebody_reclaimed;
  103. bool track_reclaim_completes;
  104. atomic_t nr_reclaim_complete;
  105. bool nfsd_net_up;
  106. bool lockd_up;
  107. seqlock_t writeverf_lock;
  108. unsigned char writeverf[8];
  109. /*
  110. * Max number of non-validated connections this nfsd container
  111. * will allow. Defaults to '0' gets mapped to 64.
  112. */
  113. unsigned int max_connections;
  114. u32 clientid_base;
  115. u32 clientid_counter;
  116. u32 clverifier_counter;
  117. struct svc_info nfsd_info;
  118. #define nfsd_serv nfsd_info.serv
  119. struct percpu_ref nfsd_serv_ref;
  120. struct completion nfsd_serv_confirm_done;
  121. struct completion nfsd_serv_free_done;
  122. /*
  123. * clientid and stateid data for construction of net unique COPY
  124. * stateids.
  125. */
  126. u32 s2s_cp_cl_id;
  127. struct idr s2s_cp_stateids;
  128. spinlock_t s2s_cp_lock;
  129. atomic_t pending_async_copies;
  130. /*
  131. * Version information
  132. */
  133. bool nfsd_versions[NFSD_MAXVERS + 1];
  134. bool nfsd4_minorversions[NFSD_SUPPORTED_MINOR_VERSION + 1];
  135. /*
  136. * Duplicate reply cache
  137. */
  138. struct nfsd_drc_bucket *drc_hashtbl;
  139. /* max number of entries allowed in the cache */
  140. unsigned int max_drc_entries;
  141. /* number of significant bits in the hash value */
  142. unsigned int maskbits;
  143. unsigned int drc_hashsize;
  144. /*
  145. * Stats and other tracking of on the duplicate reply cache.
  146. * The longest_chain* fields are modified with only the per-bucket
  147. * cache lock, which isn't really safe and should be fixed if we want
  148. * these statistics to be completely accurate.
  149. */
  150. /* total number of entries */
  151. atomic_t num_drc_entries;
  152. /* Per-netns stats counters */
  153. struct percpu_counter counter[NFSD_STATS_COUNTERS_NUM];
  154. /* sunrpc svc stats */
  155. struct svc_stat nfsd_svcstats;
  156. /* longest hash chain seen */
  157. unsigned int longest_chain;
  158. /* size of cache when we saw the longest hash chain */
  159. unsigned int longest_chain_cachesize;
  160. struct shrinker *nfsd_reply_cache_shrinker;
  161. /* tracking server-to-server copy mounts */
  162. spinlock_t nfsd_ssc_lock;
  163. struct list_head nfsd_ssc_mount_list;
  164. wait_queue_head_t nfsd_ssc_waitq;
  165. /* utsname taken from the process that starts the server */
  166. char nfsd_name[UNX_MAXNODENAME+1];
  167. struct nfsd_fcache_disposal *fcache_disposal;
  168. siphash_key_t siphash_key;
  169. atomic_t nfs4_client_count;
  170. int nfs4_max_clients;
  171. atomic_t nfsd_courtesy_clients;
  172. struct shrinker *nfsd_client_shrinker;
  173. struct work_struct nfsd_shrinker_work;
  174. /* last time an admin-revoke happened for NFSv4.0 */
  175. time64_t nfs40_last_revoke;
  176. #if IS_ENABLED(CONFIG_NFS_LOCALIO)
  177. /* Local clients to be invalidated when net is shut down */
  178. struct list_head local_clients;
  179. #endif
  180. };
  181. /* Simple check to find out if a given net was properly initialized */
  182. #define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
  183. extern bool nfsd_support_version(int vers);
  184. extern unsigned int nfsd_net_id;
  185. bool nfsd_serv_try_get(struct net *net);
  186. void nfsd_serv_put(struct net *net);
  187. void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn);
  188. void nfsd_reset_write_verifier(struct nfsd_net *nn);
  189. #endif /* __NFSD_NETNS_H__ */