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.

200 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. Initialization and shutdown routines for the GUM component
  7. of the NT Cluster Service
  8. Author:
  9. John Vert (jvert) 17-Apr-1996
  10. Revision History:
  11. --*/
  12. #include "gump.h"
  13. //
  14. // Global information (used to be per-update)
  15. //
  16. DWORD GumpSequence;
  17. CRITICAL_SECTION GumpUpdateLock;
  18. CRITICAL_SECTION GumpSendUpdateLock;
  19. CRITICAL_SECTION GumpRpcLock;
  20. PVOID GumpLastBuffer;
  21. DWORD GumpLastContext;
  22. DWORD GumpLastBufferLength;
  23. DWORD GumpLastUpdateType;
  24. LIST_ENTRY GumpLockQueue;
  25. DWORD GumpLockingNode;
  26. DWORD GumpLockerNode;
  27. BOOL GumpLastBufferValid;
  28. //
  29. // Table of per-update information
  30. //
  31. GUM_INFO GumTable[GumUpdateMaximum];
  32. CRITICAL_SECTION GumpLock;
  33. //
  34. // Per-node information
  35. //
  36. GUM_NODE_WAIT GumNodeWait[ClusterMinNodeId + ClusterDefaultMaxNodes];
  37. RPC_BINDING_HANDLE GumpRpcBindings[ClusterMinNodeId + ClusterDefaultMaxNodes];
  38. RPC_BINDING_HANDLE GumpReplayRpcBindings[
  39. ClusterMinNodeId + ClusterDefaultMaxNodes
  40. ];
  41. DWORD
  42. GumInitialize(
  43. VOID
  44. )
  45. /*++
  46. Routine Description:
  47. Initializes the Global Update Manager.
  48. Arguments:
  49. None.
  50. Return Value:
  51. ERROR_SUCCESS if successful
  52. Win32 error code otherwise
  53. --*/
  54. {
  55. DWORD i;
  56. DWORD Status;
  57. //
  58. // Initialize global data
  59. //
  60. InitializeCriticalSection(&GumpLock);
  61. InitializeCriticalSection(&GumpUpdateLock);
  62. InitializeCriticalSection(&GumpSendUpdateLock);
  63. InitializeCriticalSection(&GumpRpcLock);
  64. GumpSequence = 0;
  65. InitializeListHead(&GumpLockQueue);
  66. GumpLockingNode = (DWORD)-1;
  67. GumpLastBuffer = NULL;
  68. GumpLastBufferValid = FALSE;
  69. GumpLastContext = 0;
  70. GumpLastBufferLength = 0;
  71. //set it to illegal value;
  72. GumpLastUpdateType = GumUpdateMaximum;
  73. //
  74. // Assume we are the locker node.
  75. //
  76. GumpLockerNode = NmGetNodeId(NmLocalNode);
  77. //
  78. // Initialize GumTable
  79. //
  80. for (i=0; i < GumUpdateMaximum; i++) {
  81. GumTable[i].Receivers = NULL;
  82. GumTable[i].Joined = FALSE;
  83. ZeroMemory(&GumTable[i].ActiveNode,
  84. sizeof(GumTable[i].ActiveNode));
  85. GumTable[i].ActiveNode[NmGetNodeId(NmLocalNode)] = TRUE;
  86. }
  87. //
  88. // Initialize per-node information
  89. //
  90. for (i=ClusterMinNodeId; i <= NmMaxNodeId; i++) {
  91. GumpRpcBindings[i] = NULL;
  92. GumpReplayRpcBindings[i] = NULL;
  93. GumNodeWait[i].WaiterCount = 0;
  94. GumNodeWait[i].hSemaphore = CreateSemaphore(NULL,0,100,NULL);
  95. if (GumNodeWait[i].hSemaphore == NULL) {
  96. CL_UNEXPECTED_ERROR( GetLastError() );
  97. }
  98. }
  99. Status = EpRegisterEventHandler(CLUSTER_EVENT_NODE_DOWN_EX,
  100. GumpEventHandler);
  101. if (Status == ERROR_SUCCESS) {
  102. Status = EpRegisterSyncEventHandler(CLUSTER_EVENT_NODE_DOWN_EX,
  103. GumpSyncEventHandler);
  104. }
  105. return(Status);
  106. }
  107. VOID
  108. GumShutdown(
  109. VOID
  110. )
  111. /*++
  112. Routine Description:
  113. Shuts down the Global Update Manager.
  114. Arguments:
  115. None.
  116. Return Value:
  117. None.
  118. --*/
  119. {
  120. DWORD i;
  121. PGUM_RECEIVER Receiver;
  122. PGUM_RECEIVER Next;
  123. //
  124. // Tear down GumTable
  125. //
  126. for (i=0; i < GumUpdateMaximum; i++) {
  127. Receiver = GumTable[i].Receivers;
  128. while (Receiver != NULL) {
  129. Next = Receiver->Next;
  130. LocalFree(Receiver);
  131. Receiver = Next;
  132. }
  133. }
  134. //
  135. // Free per-node information
  136. //
  137. for (i=ClusterMinNodeId; i <= NmMaxNodeId; i++) {
  138. if (GumpRpcBindings[i] != NULL) {
  139. ClMsgDeleteRpcBinding(GumpRpcBindings[i]);
  140. }
  141. if (GumpReplayRpcBindings[i] != NULL) {
  142. ClMsgDeleteRpcBinding(GumpReplayRpcBindings[i]);
  143. }
  144. if (GumNodeWait[i].hSemaphore != NULL) {
  145. CloseHandle(GumNodeWait[i].hSemaphore);
  146. }
  147. }
  148. DeleteCriticalSection(&GumpLock);
  149. DeleteCriticalSection(&GumpUpdateLock);
  150. DeleteCriticalSection(&GumpSendUpdateLock);
  151. }
  152.