nfs4session.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * fs/nfs/nfs4session.h
  4. *
  5. * Copyright (c) 2012 Trond Myklebust <[email protected]>
  6. *
  7. */
  8. #ifndef __LINUX_FS_NFS_NFS4SESSION_H
  9. #define __LINUX_FS_NFS_NFS4SESSION_H
  10. /* maximum number of slots to use */
  11. #define NFS4_DEF_SLOT_TABLE_SIZE (64U)
  12. #define NFS4_DEF_CB_SLOT_TABLE_SIZE (16U)
  13. #define NFS4_MAX_SLOT_TABLE (1024U)
  14. #define NFS4_MAX_SLOTID (NFS4_MAX_SLOT_TABLE - 1U)
  15. #define NFS4_NO_SLOT ((u32)-1)
  16. #if IS_ENABLED(CONFIG_NFS_V4)
  17. /* Sessions slot seqid */
  18. struct nfs4_slot {
  19. struct nfs4_slot_table *table;
  20. struct nfs4_slot *next;
  21. unsigned long generation;
  22. u32 slot_nr;
  23. u32 seq_nr;
  24. u32 seq_nr_last_acked;
  25. u32 seq_nr_highest_sent;
  26. unsigned int privileged : 1,
  27. seq_done : 1;
  28. };
  29. /* Sessions */
  30. enum nfs4_slot_tbl_state {
  31. NFS4_SLOT_TBL_DRAINING,
  32. };
  33. #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, BITS_PER_LONG)
  34. struct nfs4_slot_table {
  35. struct nfs4_session *session; /* Parent session */
  36. struct nfs4_slot *slots; /* seqid per slot */
  37. unsigned long used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */
  38. spinlock_t slot_tbl_lock;
  39. struct rpc_wait_queue slot_tbl_waitq; /* allocators may wait here */
  40. wait_queue_head_t slot_waitq; /* Completion wait on slot */
  41. u32 max_slots; /* # slots in table */
  42. u32 max_slotid; /* Max allowed slotid value */
  43. u32 highest_used_slotid; /* sent to server on each SEQ.
  44. * op for dynamic resizing */
  45. u32 target_highest_slotid; /* Server max_slot target */
  46. u32 server_highest_slotid; /* Server highest slotid */
  47. s32 d_target_highest_slotid; /* Derivative */
  48. s32 d2_target_highest_slotid; /* 2nd derivative */
  49. unsigned long generation; /* Generation counter for
  50. target_highest_slotid */
  51. struct completion complete;
  52. unsigned long slot_tbl_state;
  53. };
  54. /*
  55. * Session related parameters
  56. */
  57. struct nfs4_session {
  58. struct nfs4_sessionid sess_id;
  59. u32 flags;
  60. unsigned long session_state;
  61. u32 hash_alg;
  62. u32 ssv_len;
  63. /* The fore and back channel */
  64. struct nfs4_channel_attrs fc_attrs;
  65. struct nfs4_slot_table fc_slot_table;
  66. struct nfs4_channel_attrs bc_attrs;
  67. struct nfs4_slot_table bc_slot_table;
  68. struct nfs_client *clp;
  69. };
  70. enum nfs4_session_state {
  71. NFS4_SESSION_INITING,
  72. NFS4_SESSION_ESTABLISHED,
  73. };
  74. extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl,
  75. unsigned int max_reqs, const char *queue);
  76. extern void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl);
  77. extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
  78. extern struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid);
  79. extern int nfs4_slot_wait_on_seqid(struct nfs4_slot_table *tbl,
  80. u32 slotid, u32 seq_nr,
  81. unsigned long timeout);
  82. extern bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
  83. extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
  84. extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl);
  85. bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
  86. struct nfs4_slot *slot);
  87. void nfs41_wake_slot_table(struct nfs4_slot_table *tbl);
  88. static inline bool nfs4_slot_tbl_draining(struct nfs4_slot_table *tbl)
  89. {
  90. return !!test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state);
  91. }
  92. static inline bool nfs4_test_locked_slot(const struct nfs4_slot_table *tbl,
  93. u32 slotid)
  94. {
  95. return !!test_bit(slotid, tbl->used_slots);
  96. }
  97. static inline struct nfs4_session *nfs4_get_session(const struct nfs_client *clp)
  98. {
  99. return clp->cl_session;
  100. }
  101. #if defined(CONFIG_NFS_V4_1)
  102. extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
  103. u32 target_highest_slotid);
  104. extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
  105. struct nfs4_slot *slot,
  106. struct nfs4_sequence_res *res);
  107. extern int nfs4_setup_session_slot_tables(struct nfs4_session *ses);
  108. extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
  109. extern void nfs4_destroy_session(struct nfs4_session *session);
  110. extern int nfs4_init_session(struct nfs_client *clp);
  111. extern int nfs4_init_ds_session(struct nfs_client *, unsigned long);
  112. /*
  113. * Determine if sessions are in use.
  114. */
  115. static inline int nfs4_has_session(const struct nfs_client *clp)
  116. {
  117. if (clp->cl_session)
  118. return 1;
  119. return 0;
  120. }
  121. static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
  122. {
  123. if (nfs4_has_session(clp))
  124. return (clp->cl_session->flags & SESSION4_PERSIST);
  125. return 0;
  126. }
  127. static inline void nfs4_copy_sessionid(struct nfs4_sessionid *dst,
  128. const struct nfs4_sessionid *src)
  129. {
  130. memcpy(dst->data, src->data, NFS4_MAX_SESSIONID_LEN);
  131. }
  132. #ifdef CONFIG_CRC32
  133. /*
  134. * nfs_session_id_hash - calculate the crc32 hash for the session id
  135. * @session - pointer to session
  136. */
  137. #define nfs_session_id_hash(sess_id) \
  138. (~crc32_le(0xFFFFFFFF, &(sess_id)->data[0], sizeof((sess_id)->data)))
  139. #else
  140. #define nfs_session_id_hash(session) (0)
  141. #endif
  142. #else /* defined(CONFIG_NFS_V4_1) */
  143. static inline int nfs4_init_session(struct nfs_client *clp)
  144. {
  145. return 0;
  146. }
  147. /*
  148. * Determine if sessions are in use.
  149. */
  150. static inline int nfs4_has_session(const struct nfs_client *clp)
  151. {
  152. return 0;
  153. }
  154. static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
  155. {
  156. return 0;
  157. }
  158. #define nfs_session_id_hash(session) (0)
  159. #endif /* defined(CONFIG_NFS_V4_1) */
  160. #endif /* IS_ENABLED(CONFIG_NFS_V4) */
  161. #endif /* __LINUX_FS_NFS_NFS4SESSION_H */