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.

303 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ophandle.h
  5. Abstract:
  6. Routines to manipulate the global DsRole operation handle
  7. Author:
  8. Colin Brace (ColinBr) April 5, 1999
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #ifndef __OPHANDLE_H__
  14. #define __OPHANDLE_H__
  15. //
  16. // First, a type definition of the finite difference states a role operation
  17. // can be in
  18. //
  19. //
  20. // Operation State diagram of a role change
  21. //
  22. //
  23. // /-----------------------\
  24. // | (operation failed |
  25. // | or cancelled) |
  26. // v ^
  27. // Idle <--> Running --> Finished ---------------> Need Reboot
  28. // | | ^ (operation
  29. // | | | succeeded)
  30. // | | |
  31. // | | |
  32. // | v |
  33. // | Cancelling -->|
  34. // | ^ ^
  35. // | | |
  36. // | | |
  37. // | | |
  38. // v ^ |
  39. // Running |
  40. // Non Critical ---------/
  41. //
  42. //
  43. // N.B. Running to Idle to a rare error case, where the worker thread could
  44. // not be created.
  45. //
  46. //
  47. typedef enum _DSROLEP_OPERATION_STATE {
  48. DSROLEP_IDLE = 0,
  49. DSROLEP_RUNNING,
  50. DSROLEP_RUNNING_NON_CRITICAL,
  51. DSROLEP_CANCELING,
  52. DSROLEP_FINISHED,
  53. DSROLEP_NEED_REBOOT
  54. } DSROLEP_OPERATION_STATE;
  55. #define DSROLEP_OPERATION_ACTIVE( Op ) \
  56. ( (Op == DSROLEP_IDLE) || (Op == DSROLEP_NEED_REBOOT) ? FALSE : TRUE )
  57. //
  58. // Now, the definition of the global operation handle that controls a role
  59. // change
  60. //
  61. // Whenever reading or writing a value to the operation handle, you must
  62. // lock the structure first.
  63. //
  64. // Use LockOpHandle() and UnLockOpHandle().
  65. //
  66. //
  67. typedef struct _DSROLEP_OPERATION_HANDLE {
  68. RTL_RESOURCE CurrentOpLock;
  69. DSROLEP_OPERATION_STATE OperationState;
  70. HANDLE CompletionEvent;
  71. HANDLE OperationThread;
  72. HANDLE MsgModuleHandle;
  73. HANDLE CancelEvent;
  74. HANDLE ClientToken;
  75. ULONG OperationStatus;
  76. ULONG MsgIndex;
  77. ULONG DisplayStringCount;
  78. PVOID Parameter1;
  79. PVOID Parameter2;
  80. PVOID Parameter3;
  81. PVOID Parameter4;
  82. PWSTR UpdateStringDisplayable;
  83. PWSTR FinalResultStringDisplayable;
  84. PWSTR InstalledSiteName;
  85. DWORD OperationResultFlags;
  86. } DSROLEP_OPERATION_HANDLE, *PDSROLEP_OPERATION_HANDLE;
  87. extern DSROLEP_OPERATION_HANDLE DsRolepCurrentOperationHandle;
  88. //
  89. // Type definition for the server handle
  90. //
  91. typedef DSROLE_SERVEROP_HANDLE *PDSROLE_SERVEROP_HANDLE;
  92. //
  93. // Macros for locking the the operation handle
  94. //
  95. #define LockOpHandle() RtlAcquireResourceExclusive( &DsRolepCurrentOperationHandle.CurrentOpLock, TRUE );
  96. #define UnlockOpHandle() RtlReleaseResource( &DsRolepCurrentOperationHandle.CurrentOpLock );
  97. //
  98. // Function for knowing is current thread owns the lock
  99. //
  100. BOOLEAN
  101. DsRolepCurrentThreadOwnsLock(
  102. VOID
  103. );
  104. //
  105. // Macros for setting the current operation state
  106. //
  107. #define DSROLEP_CURRENT_OP0( msg ) \
  108. DsRolepSetCurrentOperationStatus( msg, NULL, NULL, NULL, NULL );
  109. #define DSROLEP_CURRENT_OP1( msg, p1 ) \
  110. DsRolepSetCurrentOperationStatus( msg, ( PVOID )p1, NULL, NULL, NULL );
  111. #define DSROLEP_CURRENT_OP2( msg, p1, p2 ) \
  112. DsRolepSetCurrentOperationStatus( msg, ( PVOID )p1, ( PVOID )p2, \
  113. NULL, NULL );
  114. #define DSROLEP_CURRENT_OP3( msg, p1, p2, p3 ) \
  115. DsRolepSetCurrentOperationStatus( msg, ( PVOID )p1, ( PVOID )p2, \
  116. NULL, NULL );
  117. #define DSROLEP_CURRENT_OP4( msg, p1, p2, p3, p4 ) \
  118. DsRolepSetCurrentOperationStatus( msg, ( PVOID )p1, ( PVOID )p2, \
  119. ( PVOID )p3, ( PVOID )p4 );
  120. #define DSROLEP_FAIL0( err, msg ) \
  121. if(err != ERROR_SUCCESS) DsRolepSetFailureMessage( err, msg, NULL, NULL, NULL, NULL );
  122. #define DSROLEP_FAIL1( err, msg, p1 ) \
  123. if(err != ERROR_SUCCESS) DsRolepSetFailureMessage( err, msg, ( PVOID )( p1 ), NULL, NULL, NULL );
  124. #define DSROLEP_FAIL2( err, msg, p1, p2 ) \
  125. if(err != ERROR_SUCCESS) DsRolepSetFailureMessage( err, msg, ( PVOID )( p1 ), ( PVOID )( p2 ), NULL, NULL );
  126. #define DSROLEP_FAIL3( err, msg, p1, p2, p3 ) \
  127. if(err != ERROR_SUCCESS) DsRolepSetFailureMessage( err, msg, ( PVOID )( p1 ), ( PVOID )( p2 ), \
  128. ( PVOID )( p3 ), NULL );
  129. #define DSROLEP_FAIL4( err, msg, p1, p2, p3, p4 ) \
  130. if(err != ERROR_SUCCESS) DsRolepSetFailureMessage( err, msg, ( PVOID )( p1 ), ( PVOID )( p2 ), \
  131. ( PVOID )( p3 ), ( PVOID )( p4 ) );
  132. #define DSROLEP_SET_NON_FATAL_ERROR( Err ) DsRolepCurrentOperationHandle.OperationResultFlags |= DSROLE_NON_FATAL_ERROR_OCCURRED;
  133. #define DSROLEP_SET_NON_CRIT_REPL_ERROR( ) DsRolepCurrentOperationHandle.OperationResultFlags |= DSROLE_NON_CRITICAL_REPL_NOT_FINISHED;
  134. #define DSROLEP_SET_IFM_RESTORED_DATABASE_FILES_MOVED( ) DsRolepCurrentOperationHandle.OperationResultFlags |= DSROLE_IFM_RESTORED_DATABASE_FILES_MOVED;
  135. //
  136. // Macro to determine whether to cancel an operation or not
  137. //
  138. #define DSROLEP_CHECK_FOR_CANCEL( WErr ) \
  139. { \
  140. LockOpHandle(); \
  141. if( DsRolepCurrentOperationHandle.OperationState == DSROLEP_CANCELING \
  142. && (WErr == ERROR_SUCCESS)) { \
  143. \
  144. WErr = ERROR_CANCELLED; \
  145. } \
  146. UnlockOpHandle(); \
  147. }
  148. #define DSROLEP_CHECK_FOR_CANCEL_EX( WErr, Label ) \
  149. { \
  150. LockOpHandle(); \
  151. if( DsRolepCurrentOperationHandle.OperationState == DSROLEP_CANCELING \
  152. && (WErr == ERROR_SUCCESS)) { \
  153. \
  154. WErr = ERROR_CANCELLED; \
  155. UnlockOpHandle(); \
  156. goto Label; \
  157. } \
  158. UnlockOpHandle(); \
  159. }
  160. //
  161. // Prototypes for worker functions
  162. //
  163. DWORD
  164. DsRolepGetDcOperationProgress(
  165. IN PDSROLE_SERVEROP_HANDLE DsOperationHandle,
  166. IN OUT PDSROLER_SERVEROP_STATUS *ServerOperationStatus
  167. );
  168. DWORD
  169. DsRolepGetDcOperationResults(
  170. IN PDSROLE_SERVEROP_HANDLE DsOperationHandle,
  171. OUT PDSROLER_SERVEROP_RESULTS *ServerOperationResults
  172. );
  173. DWORD
  174. DsRolepSetOperationHandleSiteName(
  175. IN LPWSTR SiteName
  176. );
  177. VOID
  178. DsRolepSetCriticalOperationsDone(
  179. VOID
  180. );
  181. DWORD
  182. DsRolepInitializeOperationHandle(
  183. VOID
  184. );
  185. typedef enum _DSROLEP_OPERATION_TYPE {
  186. DSROLEP_OPERATION_DC = 0,
  187. DSROLEP_OPERATION_REPLICA,
  188. DSROLEP_OPERATION_DEMOTE
  189. } DSROLEP_OPERATION_TYPE, *PDSROLEP_OPERATION_TYPE;
  190. DWORD
  191. DsRolepResetOperationHandle(
  192. DSROLEP_OPERATION_STATE OpState
  193. );
  194. VOID
  195. DsRolepResetOperationHandleLockHeld(
  196. VOID
  197. );
  198. DWORD
  199. DsRolepSetCurrentOperationStatus(
  200. IN ULONG MsgIndex,
  201. IN PVOID Parameter1,
  202. IN PVOID Parameter2,
  203. IN PVOID Parameter3,
  204. IN PVOID Parameter4
  205. );
  206. DWORD
  207. DsRolepSetFailureMessage(
  208. IN DWORD FailureStatus,
  209. IN ULONG MsgIndex,
  210. IN PVOID Parameter1,
  211. IN PVOID Parameter2,
  212. IN PVOID Parameter3,
  213. IN PVOID Parameter4
  214. );
  215. VOID
  216. DsRolepClearErrors(
  217. VOID
  218. );
  219. #define DSROLEP_OP_PROMOTION 0x00000001
  220. #define DSROLEP_OP_DEMOTION 0x00000002
  221. DWORD
  222. DsRolepSetOperationDone(
  223. IN DWORD Flags,
  224. IN DWORD OperationStatus
  225. );
  226. DWORD
  227. DsRolepFormatOperationString(
  228. IN ULONG MsgId,
  229. OUT LPWSTR *FormattedString,
  230. ...
  231. );
  232. DWORD
  233. DsRolepStringUpdateCallback(
  234. IN PWSTR StringUpdate
  235. );
  236. DWORD
  237. DsRolepStringErrorUpdateCallback(
  238. IN PWSTR String,
  239. IN DWORD ErrorCode
  240. );
  241. DWORD
  242. DsRolepOperationResultFlagsCallBack(
  243. IN DWORD Flags
  244. );
  245. #endif // __OPHANDLE_H__