nfs4session.h 4.4 KB

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