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.

370 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1995-1997 Microsoft Corporation
  3. Module Name:
  4. resmonp.h
  5. Abstract:
  6. Private header file for the Resource Monitor component
  7. Author:
  8. John Vert (jvert) 30-Nov-1995
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "cluster.h"
  13. #include "rm_rpc.h"
  14. #include "monmsg.h"
  15. #define LOG_CURRENT_MODULE 0x0800
  16. #define RESMON_MODULE_EVNTLIST 1
  17. #define RESMON_MODULE_NOTIFY 2
  18. #define RESMON_MODULE_POLLER 3
  19. #define RESMON_MODULE_PROPERTY 4
  20. #define RESMON_MODULE_RESLIST 5
  21. #define RESMON_MODULE_RESMON 6
  22. #define RESMON_MODULE_RMAPI 7
  23. //
  24. // Private type definitions and structures
  25. //
  26. #define RmDbgPrint ClRtlLogPrint
  27. //
  28. // Define the maximum number of resources handled per thread.
  29. // (This value must be smaller than MAXIMUM_WAIT_OBJECTS-1!)
  30. //
  31. #define MAX_RESOURCES_PER_THREAD 16
  32. #define MAX_HANDLES_PER_THREAD (MAX_RESOURCES_PER_THREAD+1)
  33. //
  34. // Define the maximum number of threads.
  35. // (This value can be up to MAXIMUM_WAIT_OBJECTS, however the first two
  36. // entries are taken by events, so in fact we have 2 less threads available).
  37. //
  38. #define MAX_THREADS (MAXIMUM_WAIT_OBJECTS)
  39. //
  40. // Define structure and flags used for each resource entry
  41. //
  42. #define RESOURCE_SIGNATURE 'crsR'
  43. typedef struct *_PPOLL_EVENT_LIST;
  44. //
  45. // Flags
  46. //
  47. #define RESOURCE_INSERTED 1
  48. typedef struct _RESOURCE {
  49. ULONG Signature; // 'Rsrc'
  50. ULONG Flags;
  51. LIST_ENTRY ListEntry; // for linking onto monitoring list
  52. LPWSTR DllName;
  53. LPWSTR ResourceType;
  54. LPWSTR ResourceId;
  55. LPWSTR ResourceName;
  56. DWORD LooksAlivePollInterval;
  57. DWORD IsAlivePollInterval;
  58. HINSTANCE Dll; // handle to resource's DLL
  59. RESID Id;
  60. HANDLE EventHandle; // async error notification handle
  61. POPEN_ROUTINE Open;
  62. PCLOSE_ROUTINE Close;
  63. PONLINE_ROUTINE Online;
  64. POFFLINE_ROUTINE Offline;
  65. PTERMINATE_ROUTINE Terminate;
  66. PIS_ALIVE_ROUTINE IsAlive;
  67. PLOOKS_ALIVE_ROUTINE LooksAlive;
  68. PARBITRATE_ROUTINE Arbitrate;
  69. PRELEASE_ROUTINE Release;
  70. PRESOURCE_CONTROL_ROUTINE ResourceControl;
  71. PRESOURCE_TYPE_CONTROL_ROUTINE ResourceTypeControl;
  72. CLUSTER_RESOURCE_STATE State;
  73. ULONG IsAliveCount;
  74. ULONG IsAliveRollover;
  75. DWORD NotifyKey;
  76. _PPOLL_EVENT_LIST EventList;
  77. HANDLE TimerEvent; // Timer event for offline completion.
  78. DWORD PendingTimeout;
  79. } RESOURCE, *PRESOURCE;
  80. typedef struct _MONITOR_BUCKET {
  81. LIST_ENTRY BucketList; // For chaining buckets together.
  82. LIST_ENTRY ResourceList; // List of resources in this bucket
  83. DWORDLONG DueTime; // Next time that these resources should be polled
  84. DWORDLONG Period; // Periodic interval of this bucket.
  85. } MONITOR_BUCKET, *PMONITOR_BUCKET;
  86. //
  87. // The Poll Event List structure.
  88. //
  89. typedef struct _POLL_EVENT_LIST {
  90. LIST_ENTRY Next; // Next event list
  91. LIST_ENTRY BucketListHead; // Bucket Listhead for this list/thread
  92. DWORD NumberOfBuckets; // Number of entries on this bucket list
  93. DWORD NumberOfResources; // Number of resources on this event list
  94. CRITICAL_SECTION ListLock; // Critical section to add/remove events
  95. DWORD PPrevPrevListLock;
  96. DWORD PrevPrevListLock;
  97. DWORD PrevListLock;
  98. DWORD LastListLock;
  99. DWORD LastListUnlock;
  100. DWORD PrevListUnlock;
  101. DWORD PrevPrevListUnlock;
  102. DWORD PPrevPrevListUnlock;
  103. HANDLE ListNotify; // List change notification
  104. HANDLE ThreadHandle; // Handle of thread processing this list
  105. DWORD EventCount; // Number of events/resources in lists
  106. HANDLE Handle[MAX_HANDLES_PER_THREAD]; // Array of handles to wait for
  107. PRESOURCE Resource[MAX_HANDLES_PER_THREAD]; // Resources that match handles
  108. } POLL_EVENT_LIST, *PPOLL_EVENT_LIST;
  109. #define POLL_GRANULARITY (10) // 10ms
  110. #define PENDING_TIMEOUT (3*1000*60) // 3 minutes for pending requests to finish
  111. //
  112. // Private helper macros
  113. //
  114. #define RmpAlloc(size) LocalAlloc(LMEM_FIXED, (size))
  115. #define RmpFree(size) LocalFree((size))
  116. #define RmpSetMonitorState(state, resource) \
  117. EnterCriticalSection(&RmpMonitorStateLock); \
  118. GetSystemTimeAsFileTime((PFILETIME)&RmpSharedState->LastUpdate); \
  119. RmpSharedState->State = (state); \
  120. RmpSharedState->ActiveResource = (HANDLE)(resource); \
  121. LeaveCriticalSection(&RmpMonitorStateLock);
  122. #define AcquireListLock() \
  123. EnterCriticalSection( &RmpListLock ); \
  124. RmpListPPrevPrevLock = RmpListPrevPrevLock; \
  125. RmpListPrevPrevLock = RmpListPrevLock; \
  126. RmpListPrevLock = RmpListLastLock; \
  127. RmpListLastLock = ((RESMON_MODULE << 24) | __LINE__)
  128. #define ReleaseListLock() \
  129. RmpListPPrevPrevUnlock = RmpListPrevPrevUnlock; \
  130. RmpListPrevPrevUnlock = RmpListPrevUnlock; \
  131. RmpListPrevUnlock = RmpListLastUnlock; \
  132. RmpListLastUnlock = ((RESMON_MODULE << 24) | __LINE__); \
  133. LeaveCriticalSection( &RmpListLock )
  134. #define AcquireEventListLock( EventList ) \
  135. EnterCriticalSection( &(EventList)->ListLock ); \
  136. (EventList)->PPrevPrevListLock = (EventList)->PrevPrevListLock; \
  137. (EventList)->PrevPrevListLock = (EventList)->PrevListLock; \
  138. (EventList)->PrevListLock = (EventList)->LastListLock; \
  139. (EventList)->LastListLock = ((RESMON_MODULE << 24) | __LINE__)
  140. #define ReleaseEventListLock( EventList ) \
  141. (EventList)->PPrevPrevListUnlock = (EventList)->PrevPrevListUnlock; \
  142. (EventList)->PrevPrevListUnlock = (EventList)->PrevListUnlock; \
  143. (EventList)->PrevListUnlock = (EventList)->LastListUnlock; \
  144. (EventList)->LastListUnlock = ((RESMON_MODULE << 24) | __LINE__); \
  145. LeaveCriticalSection( &(EventList)->ListLock )
  146. //
  147. // Data global to Resource Monitor
  148. //
  149. extern CRITICAL_SECTION RmpListLock;
  150. extern DWORD RmpListPPrevPrevLock;
  151. extern DWORD RmpListPrevPrevLock;
  152. extern DWORD RmpListPrevLock;
  153. extern DWORD RmpListLastLock;
  154. extern DWORD RmpListLastUnlock;
  155. extern DWORD RmpListPrevUnlock;
  156. extern DWORD RmpListPrevPrevUnlock;
  157. extern DWORD RmpListPPrevPrevUnlock;
  158. extern CRITICAL_SECTION RmpMonitorStateLock;
  159. extern PMONITOR_STATE RmpSharedState;
  160. extern CL_QUEUE RmpNotifyQueue;
  161. extern HKEY RmpResourcesKey;
  162. extern HKEY RmpResTypesKey;
  163. extern HCLUSTER RmpHCluster;
  164. extern BOOL RmpShutdown;
  165. extern LIST_ENTRY RmpEventListHead;
  166. extern HANDLE RmpWaitArray[];
  167. extern HANDLE RmpRewaitEvent;
  168. extern HANDLE RmpClusterProcess;
  169. extern DWORD RmpNumberOfThreads;
  170. //
  171. // Interfaces for manipulating the resource lists
  172. //
  173. VOID
  174. RmpRundownResources(
  175. VOID
  176. );
  177. VOID
  178. RmpInsertResourceList(
  179. IN PRESOURCE Resource
  180. );
  181. VOID
  182. RmpRemoveResourceList(
  183. IN PRESOURCE Resource
  184. );
  185. DWORD
  186. RmpOfflineResource(
  187. IN RESID ResourceId,
  188. IN BOOL Shutdown,
  189. OUT DWORD *pdwState
  190. );
  191. VOID
  192. RmpSetResourceStatus(
  193. IN RESOURCE_HANDLE ResourceHandle,
  194. IN PRESOURCE_STATUS ResourceStatus
  195. );
  196. VOID
  197. RmpLogEvent(
  198. IN RESOURCE_HANDLE ResourceHandle,
  199. IN LOG_LEVEL LogLevel,
  200. IN LPCWSTR FormatString,
  201. ...
  202. );
  203. VOID
  204. RmpLostQuorumResource(
  205. IN RESOURCE_HANDLE ResourceHandle
  206. );
  207. //
  208. // Interfaces for interfacing with the poller thread
  209. //
  210. DWORD
  211. RmpPollerThread(
  212. IN LPVOID lpParameter
  213. );
  214. VOID
  215. RmpSignalPoller(
  216. IN PPOLL_EVENT_LIST EventList
  217. );
  218. PVOID
  219. RmpCreateEventList(
  220. VOID
  221. );
  222. DWORD
  223. RmpAddPollEvent(
  224. IN PPOLL_EVENT_LIST EventList,
  225. IN HANDLE EventHandle,
  226. IN PRESOURCE Resource
  227. );
  228. DWORD
  229. RmpRemovePollEvent(
  230. IN HANDLE EventHandle
  231. );
  232. DWORD
  233. RmpResourceEventSignaled(
  234. IN PPOLL_EVENT_LIST EventList,
  235. IN DWORD EventIndex
  236. );
  237. //
  238. // Notification interfaces
  239. //
  240. typedef enum _NOTIFY_REASON {
  241. NotifyResourceStateChange,
  242. NotifyResourceResuscitate,
  243. NotifyShutdown
  244. } NOTIFY_REASON;
  245. VOID
  246. RmpPostNotify(
  247. IN PRESOURCE Resource,
  248. IN NOTIFY_REASON Reason
  249. );
  250. DWORD
  251. RmpTimerThread(
  252. IN LPVOID Context
  253. );
  254. DWORD
  255. RmpResourceGetCommonProperties(
  256. IN PRESOURCE Resource,
  257. OUT PVOID OutBuffer,
  258. IN DWORD OutBufferSize,
  259. OUT LPDWORD BytesReturned,
  260. OUT LPDWORD Required
  261. );
  262. DWORD
  263. RmpResourceSetCommonProperties(
  264. IN PRESOURCE Resource,
  265. IN PVOID InBuffer,
  266. IN DWORD InBufferSize
  267. );
  268. DWORD
  269. RmpResourceGetPrivateProperties(
  270. IN PRESOURCE Resource,
  271. OUT PVOID OutBuffer,
  272. IN DWORD OutBufferSize,
  273. OUT LPDWORD BytesReturned,
  274. OUT LPDWORD Required
  275. );
  276. DWORD
  277. RmpResourceSetPrivateProperties(
  278. IN PRESOURCE Resource,
  279. IN PVOID InBuffer,
  280. IN DWORD InBufferSize
  281. );
  282. DWORD
  283. RmpResourceTypeGetCommonProperties(
  284. IN LPCWSTR ResourceTypeName,
  285. OUT PVOID OutBuffer,
  286. IN DWORD OutBufferSize,
  287. OUT LPDWORD BytesReturned,
  288. OUT LPDWORD Required
  289. );
  290. DWORD
  291. RmpResourceTypeSetCommonProperties(
  292. IN LPCWSTR ResourceTypeName,
  293. IN PVOID InBuffer,
  294. IN DWORD InBufferSize
  295. );
  296. DWORD
  297. RmpResourceTypeGetPrivateProperties(
  298. IN LPCWSTR ResourceTypeName,
  299. OUT PVOID OutBuffer,
  300. IN DWORD OutBufferSize,
  301. OUT LPDWORD BytesReturned,
  302. OUT LPDWORD Required
  303. );
  304. DWORD
  305. RmpResourceTypeSetPrivateProperties(
  306. IN LPCWSTR ResourceTypeName,
  307. IN PVOID InBuffer,
  308. IN DWORD InBufferSize
  309. );