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.

213 lines
5.4 KiB

  1. /*
  2. * ARBITER.C
  3. *
  4. *
  5. * DRIVEARB.DLL - Shared Drive Aribiter for shared disks and libraries
  6. * - inter-machine sharing client
  7. * - inter-app sharing service
  8. *
  9. * Author: ErvinP
  10. *
  11. * (c) 2000 Microsoft Corporation
  12. *
  13. */
  14. #include <stdlib.h>
  15. #include <wtypes.h>
  16. #include <dlmhdr.h> // BUGBUG - get a common DLM header from Cluster team
  17. #include <drivearb.h>
  18. #include "internal.h"
  19. //
  20. // Temporary inter-node arbiters
  21. //
  22. #define DRIVEARB_ARBITER_DLM 1
  23. #define DRIVEARB_ARBITER_HACK 2
  24. #define DRIVEARB_ARBITER DRIVEARB_ARBITER_DLM
  25. BOOL InitializeArbitrationService(driveContext *drive)
  26. {
  27. // nothing to do at service level
  28. return TRUE;
  29. }
  30. VOID ShutDownArbitrationService(driveContext *drive)
  31. {
  32. // nothing to do at service level
  33. }
  34. /*
  35. * InitializeClientArbitration
  36. *
  37. * Must be called with globalMutex held.
  38. *
  39. */
  40. BOOL InitializeClientArbitration(clientSessionContext *session)
  41. {
  42. BOOL result = FALSE;
  43. #if DRIVEARB_ARBITER == DRIVEARB_ARBITER_DLM
  44. {
  45. int dlmStat;
  46. dlmStat = InitializeDistributedLockManager(&session->sessionDlmHandle);
  47. if (dlmStat == DLM_ERROR_SUCCESS){
  48. dlmStat = InitializeDistributedLock(
  49. &session->sessionDlmLockHandle,
  50. NULL,
  51. session->driveViewPtr->driveName,
  52. strlen(session->driveViewPtr->driveName));
  53. if (dlmStat == DLM_ERROR_SUCCESS){
  54. result = TRUE;
  55. }
  56. else {
  57. DBGMSG("InitializeClientArbitration: InitializeDistributedLock failed", session->driveIndex);
  58. }
  59. }
  60. else {
  61. DBGMSG("InitializeClientArbitration: InitializeDistributedLockManager failed", session->driveIndex);
  62. }
  63. }
  64. #elif DRIVEARB_ARBITER = DRIVEARB_ARBITER_HACK
  65. // nothing to do
  66. #endif
  67. return result;
  68. }
  69. /*
  70. * ShutDownClientArbitration
  71. *
  72. * Must be called with globalMutex held.
  73. *
  74. */
  75. VOID ShutDownClientArbitration(clientSessionContext *session)
  76. {
  77. #if DRIVEARB_ARBITER == DRIVEARB_ARBITER_DLM
  78. if (session->sessionDlmLockHandle){
  79. CloseHandle(session->sessionDlmLockHandle); // BUGBUG - how to close this handle ?
  80. session->sessionDlmLockHandle = NULL;
  81. // CloseHandle(session->sessionDlmHandle); // BUGBUG - how to close this handle ?
  82. }
  83. #elif DRIVEARB_ARBITER = DRIVEARB_ARBITER_HACK
  84. // nothing to do
  85. #endif
  86. }
  87. /*
  88. * AcquireNodeLevelOwnership
  89. *
  90. * Must be called with drive mutex held.
  91. *
  92. */
  93. BOOL AcquireNodeLevelOwnership(clientSessionContext *session)
  94. {
  95. BOOL result = FALSE;
  96. // DBGMSG("> AcquireNodeLevelOwnership", 0);
  97. #if DRIVEARB_ARBITER == DRIVEARB_ARBITER_DLM
  98. {
  99. int dlmStat;
  100. dlmStat = ConvertDistributedLock( session->sessionDlmLockHandle,
  101. DLM_MODE_EX);
  102. if (dlmStat == DLM_ERROR_SUCCESS){
  103. /*
  104. * We do not alert others that we have the lock.
  105. */
  106. #if 0
  107. DWORD bmode = 0;
  108. while (bmode == 0){
  109. dlmStat = QueueDistributedLockEvent(
  110. drive->dlmLockHandle,
  111. NULL,
  112. 0,
  113. 0,
  114. &ioStat);
  115. if (dlmStat == DLM_ERROR_QUEUED){
  116. WaitForSingleObject(drive->dlmLockHandle, INFINITE);
  117. bmode = ioStat.Information;
  118. DBGMSG("QueueDistributedLockEvent returned DLM_ERROR_QUEUED", bmode);
  119. }
  120. else if (dlmStat == DLM_ERROR_SUCCESS){
  121. bmode = ioStat.Information;
  122. // DBGMSG("QueueDistributedLockEvent returned bmode==", bmode);
  123. }
  124. else {
  125. DBGMSG("QueueDistributedLockEvent failed", dlmStat);
  126. break;
  127. }
  128. }
  129. if (bmode != 0){
  130. result = TRUE;
  131. }
  132. else {
  133. DBGMSG("QueueDistributedLockEvent returned bmode==zero", 0);
  134. }
  135. #else
  136. result = TRUE;
  137. #endif
  138. }
  139. else {
  140. DBGMSG("ConvertDistributedLockEx failed", dlmStat);
  141. DBGMSG("drive->dlmLockHandle == ", (ULONG_PTR)session->sessionDlmLockHandle);
  142. }
  143. }
  144. #elif DRIVEARB_ARBITER = DRIVEARB_ARBITER_HACK
  145. BUGBUG FINISH
  146. #endif
  147. // DBGMSG("< AcquireNodeLevelOwnership", result);
  148. return result;
  149. }
  150. /*
  151. * ReleaseNodeLevelOwnership
  152. *
  153. * Must be called with drive mutex held.
  154. *
  155. */
  156. VOID ReleaseNodeLevelOwnership(clientSessionContext *session)
  157. {
  158. // DBGMSG("> ReleaseNodeLevelOwnership", 0);
  159. #if DRIVEARB_ARBITER == DRIVEARB_ARBITER_DLM
  160. {
  161. int dlmStat;
  162. dlmStat = ConvertDistributedLock( session->sessionDlmLockHandle,
  163. DLM_MODE_NL);
  164. ASSERT(dlmStat == DLM_ERROR_SUCCESS);
  165. }
  166. #elif DRIVEARB_ARBITER = DRIVEARB_ARBITER_HACK
  167. BUGBUG FINISH
  168. #endif
  169. // DBGMSG("< ReleaseNodeLevelOwnership", 0);
  170. }