Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. gsp.h
  5. Abstract:
  6. Private gs definitions
  7. Author:
  8. Ahmed Mohamed (ahmedm) 12, 01, 2000
  9. Revision History:
  10. --*/
  11. #ifndef _GS_P_H
  12. #define _GS_P_H
  13. #include "type.h"
  14. #include "msg.h"
  15. #include <Mmsystem.h>
  16. #define GS_DEFAULT_WINDOW_SZ 8
  17. #define GS_DEFAULT_MAX_MSG_SZ GS_MAX_MSG_SZ
  18. extern int GS_MAX_MSG_SZ;
  19. #define GsGroupTableSize 16
  20. #define GS_FLAGS_CLOSE 0x01
  21. #define GS_FLAGS_CONTINUED 0x02
  22. #define GS_FLAGS_DELIVERED 0x04
  23. #define GS_FLAGS_QUEUED 0x08 // in receive queue
  24. #define GS_FLAGS_LAST 0x10
  25. #define GS_FLAGS_REPLAY 0x20
  26. #define GS_FLAGS_REPLY 0x40
  27. #define GS_FLAGS_PTP 0x80
  28. #define GS_FLAGS_MASK 0x07
  29. #define GS_GROUP_STATE_FREE 0x0
  30. #define GS_GROUP_STATE_NEW 0x01
  31. #define GS_GROUP_STATE_FORM 0x02
  32. #define GS_GROUP_STATE_JOIN 0x04
  33. #define GS_GROUP_STATE_EVICT 0x08
  34. #define GS_GROUP_FLAGS_RECOVERY 0x10
  35. #define GS_GROUP_FLAGS_NEWMASTER 0x20
  36. #define GS_CONTEXT_INVALID_ID ((gs_cookie_t) -1)
  37. typedef struct gs_member {
  38. gs_memberid_t m_id;
  39. gs_sequence_t m_expected_seq; // next expected 1-to-1 sequence
  40. gs_msg_t *m_queue; // list of queued 1-to-1 msgs
  41. // gs_addr_t m_uaddr; // ip addr
  42. UINT16 m_wsz; // max. window sz
  43. UINT16 m_msz; // max. msg sz
  44. }gs_member_t;
  45. typedef struct gs_ctx {
  46. gs_gid_t ctx_gid;
  47. gs_cookie_t ctx_id;
  48. PVOID ctx_buf;
  49. gs_sequence_t ctx_mseq;
  50. gs_sequence_t ctx_bnum;
  51. UINT16 ctx_flags;
  52. gs_msg_t *ctx_msg;
  53. PVOID *ctx_rbuf;
  54. IO_STATUS_BLOCK *ctx_ios;
  55. ULONG ctx_mask;
  56. gs_event_t ctx_syncevent;
  57. gs_event_t ctx_event;
  58. MMRESULT ctx_timer;
  59. }gs_context_t;
  60. typedef struct {
  61. gs_semaphore_t s_sema; // how many concurrent sends are allowed
  62. gs_context_t *s_ctxpool; // send contexts pool
  63. UINT16 s_wsz; // max. window sz
  64. gs_msg_t *s_waitqueue; // list of msgs waiting for global sequence
  65. gs_sequence_t s_lseq; // last completed mseq
  66. gs_sequence_t s_mseq; // last allocated global sequence
  67. gs_sequence_t s_bnum; // next 1-to-1 sequence for a given mseq
  68. }gs_send_state_t;
  69. typedef struct {
  70. gs_sequence_t r_mseq; // next expected global sequence
  71. gs_sequence_t r_bnum; // next expected batch sequence
  72. gs_msg_t **r_next; // next message to deliver to app
  73. gs_msg_t *r_head; // head of receive queue
  74. }gs_recv_state_t;
  75. typedef struct gs_rblk {
  76. struct gs_rblk *next;
  77. gs_sequence_t mseq;
  78. ULONG have;
  79. }gs_rblk_t;
  80. typedef struct {
  81. gs_event_t rs_event;
  82. ULONG rs_dset; // down member set
  83. ULONG rs_mset; // member set to hear from
  84. UINT16 rs_epoch;
  85. UINT16 rs_sz;
  86. gs_rblk_t *rs_list;
  87. }gs_recovery_state_t;
  88. typedef struct gs_group {
  89. gs_lock_t g_lock;
  90. gs_gid_t g_id; // cluster wide group id
  91. gs_nid_t g_nid; // local cluster node id
  92. // int g_port; // group port number
  93. // gs_addr_t g_maddr; // multicast ip addr
  94. UINT8 g_state;
  95. UINT8 g_pending;
  96. UINT16 g_curview; // increment on every member down/up
  97. UINT16 g_startview; // set to curview on member down
  98. // member information
  99. UINT16 g_sz;
  100. gs_member_t *g_mlist;
  101. gs_memberid_t g_mid; // master id
  102. gs_mset_t g_mset; // current member set
  103. // master/send/receive states
  104. gs_sequence_t g_global_seq; // next global sequence number
  105. gs_send_state_t g_send;
  106. gs_recv_state_t g_recv;
  107. // event handler
  108. gs_callback_t g_callback;
  109. // recovery state
  110. gs_recovery_state_t *g_rs;
  111. int g_namelen;
  112. char *g_name;
  113. }gs_group_t;
  114. #define GspLookupContext(gd, cid) &gd->g_send.s_ctxpool[cid]
  115. gs_group_t *
  116. GspLookupGroup(gs_gid_t gid);
  117. void
  118. GspProcessReply(gs_group_t *gd, gs_context_t *ctx,
  119. int sid, char *buf, int rlen,
  120. NTSTATUS status);
  121. void
  122. GspDispatch(gs_group_t *gd);
  123. void
  124. GspOpenContext(gs_group_t *gd, gs_context_t **context);
  125. void
  126. GspCloseContext(gs_group_t *gd, gs_context_t *ctx);
  127. void
  128. GspOrderInsert(gs_group_t *gd, gs_msg_t *head, gs_msg_t *tail,
  129. gs_sequence_t mseq, gs_sequence_t bnum);
  130. void
  131. GspUOrderInsert(gs_group_t *gd, gs_msg_t *head, gs_msg_t *tail,
  132. gs_sequence_t mseq, gs_sequence_t lseq);
  133. void
  134. GspDeliverMsg(gs_group_t *gd, gs_msg_t *msg);
  135. void
  136. GspSendAck(gs_group_t *gd, gs_msg_t *msg, NTSTATUS status);
  137. void
  138. GspRemoveMsg(gs_group_t *gd, gs_msg_t *msg);
  139. NTSTATUS
  140. GspSendDirectedRequest(gs_group_t *gd, gs_context_t *ctx, gs_event_t ev,
  141. int memberid, gs_tag_t tag,
  142. PVOID buf, UINT32 len,
  143. PVOID rbuf, UINT32 rlen,
  144. IO_STATUS_BLOCK *status,
  145. UINT32 flags, UINT32 type);
  146. // Response of name server during phase 1 of join
  147. typedef struct {
  148. union {
  149. USHORT id;
  150. USHORT wsz;
  151. };
  152. USHORT owner;
  153. char name[GS_MAX_NAME_SZ];
  154. }gs_ns_info_t;
  155. // Response of current master to a join request
  156. typedef struct {
  157. UINT16 sz;
  158. UINT16 viewnum;
  159. gs_sequence_t mseq;
  160. gs_mset_t mset; // current member set
  161. }gs_join_info_t;
  162. // Response of current master to a sequence allocation request
  163. typedef struct {
  164. gs_sequence_t mseq;
  165. UINT16 viewnum;
  166. }gs_seq_info_t;
  167. typedef struct {
  168. gs_sequence_t cur_mseq, last_mseq;
  169. UINT16 have_sz;
  170. gs_sequence_t have_set[];
  171. }gs_recovery_info_t;
  172. typedef struct {
  173. gs_sequence_t down_mseq;
  174. UINT16 view;
  175. UINT16 sz;
  176. struct {
  177. gs_sequence_t mseq;
  178. }skip_set[];
  179. }gs_sync_info_t;
  180. #ifndef min
  181. #define min(a, b) ((a) < (b) ? (a) : (b))
  182. #endif
  183. #define GspValidateView(gd, vn) ((vn) >= (gd)->g_startview && (vn) <= (gd)->g_curview)
  184. NTSTATUS
  185. GspSendRequest(gs_group_t *gd, gs_context_t *ctx, gs_event_t ev,
  186. int type, gs_sequence_t mid, gs_tag_t tag,
  187. PVOID buf, UINT32 len,
  188. PVOID rbuf[], UINT32 rlen,
  189. IO_STATUS_BLOCK status[],
  190. UINT32 flags, gs_join_info_t *);
  191. void
  192. GspProcessWaitQueue(gs_group_t *gd, gs_seq_info_t *);
  193. void
  194. GspAllocateSequence(gs_group_t *gd);
  195. void
  196. GspCleanQueue(gs_group_t *gd, gs_sequence_t mseq);
  197. void
  198. GspAddMember(gs_group_t *, gs_memberid_t, int);
  199. void
  200. GspPhase1NodeDown(ULONG mask);
  201. void
  202. GspPhase2NodeDown(ULONG mask);
  203. #endif