netns.h 4.9 KB

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