nfs4session.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 (16U)
  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. unsigned long renewal_time;
  20. u32 slot_nr;
  21. u32 seq_nr;
  22. };
  23. /* Sessions */
  24. #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, 8*sizeof(long))
  25. struct nfs4_slot_table {
  26. struct nfs4_session *session; /* Parent session */
  27. struct nfs4_slot *slots; /* seqid per slot */
  28. unsigned long used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */
  29. spinlock_t slot_tbl_lock;
  30. struct rpc_wait_queue slot_tbl_waitq; /* allocators may wait here */
  31. u32 max_slots; /* # slots in table */
  32. u32 max_slotid; /* Max allowed slotid value */
  33. u32 highest_used_slotid; /* sent to server on each SEQ.
  34. * op for dynamic resizing */
  35. u32 target_highest_slotid; /* Server max_slot target */
  36. u32 server_highest_slotid; /* Server highest slotid */
  37. unsigned long generation; /* Generation counter for
  38. target_highest_slotid */
  39. struct completion complete;
  40. };
  41. /*
  42. * Session related parameters
  43. */
  44. struct nfs4_session {
  45. struct nfs4_sessionid sess_id;
  46. u32 flags;
  47. unsigned long session_state;
  48. u32 hash_alg;
  49. u32 ssv_len;
  50. /* The fore and back channel */
  51. struct nfs4_channel_attrs fc_attrs;
  52. struct nfs4_slot_table fc_slot_table;
  53. struct nfs4_channel_attrs bc_attrs;
  54. struct nfs4_slot_table bc_slot_table;
  55. struct nfs_client *clp;
  56. /* Create session arguments */
  57. unsigned int fc_target_max_rqst_sz;
  58. unsigned int fc_target_max_resp_sz;
  59. };
  60. enum nfs4_session_state {
  61. NFS4_SESSION_INITING,
  62. NFS4_SESSION_DRAINING,
  63. };
  64. #if defined(CONFIG_NFS_V4_1)
  65. extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
  66. extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
  67. extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
  68. u32 target_highest_slotid);
  69. extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
  70. struct nfs4_slot *slot,
  71. struct nfs4_sequence_res *res);
  72. extern int nfs4_setup_session_slot_tables(struct nfs4_session *ses);
  73. extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
  74. extern void nfs4_destroy_session(struct nfs4_session *session);
  75. extern int nfs4_init_session(struct nfs_server *server);
  76. extern int nfs4_init_ds_session(struct nfs_client *, unsigned long);
  77. extern void nfs4_session_drain_complete(struct nfs4_session *session,
  78. struct nfs4_slot_table *tbl);
  79. static inline bool nfs4_session_draining(struct nfs4_session *session)
  80. {
  81. return !!test_bit(NFS4_SESSION_DRAINING, &session->session_state);
  82. }
  83. /*
  84. * Determine if sessions are in use.
  85. */
  86. static inline int nfs4_has_session(const struct nfs_client *clp)
  87. {
  88. if (clp->cl_session)
  89. return 1;
  90. return 0;
  91. }
  92. static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
  93. {
  94. if (nfs4_has_session(clp))
  95. return (clp->cl_session->flags & SESSION4_PERSIST);
  96. return 0;
  97. }
  98. #else /* defined(CONFIG_NFS_V4_1) */
  99. static inline int nfs4_init_session(struct nfs_server *server)
  100. {
  101. return 0;
  102. }
  103. /*
  104. * Determine if sessions are in use.
  105. */
  106. static inline int nfs4_has_session(const struct nfs_client *clp)
  107. {
  108. return 0;
  109. }
  110. static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
  111. {
  112. return 0;
  113. }
  114. #endif /* defined(CONFIG_NFS_V4_1) */
  115. #endif /* IS_ENABLED(CONFIG_NFS_V4) */
  116. #endif /* __LINUX_FS_NFS_NFS4SESSION_H */