nfs4session.h 5.1 KB

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