Leaked source code of windows server 2003
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.

183 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. notify.c
  5. Abstract:
  6. Interface for reporting resource notifications to cluster
  7. manager.
  8. Author:
  9. John Vert (jvert) 12-Jan-1996
  10. Revision History:
  11. --*/
  12. #include "resmonp.h"
  13. #define RESMON_MODULE RESMON_MODULE_NOTIFY
  14. //
  15. // Define queue to post notifications to
  16. //
  17. CL_QUEUE RmpNotifyQueue;
  18. //
  19. // Define notification block structure
  20. //
  21. typedef struct _NOTIFY {
  22. LIST_ENTRY ListEntry;
  23. RM_NOTIFY_KEY Key;
  24. NOTIFY_REASON Reason;
  25. CLUSTER_RESOURCE_STATE State;
  26. } NOTIFY, *PNOTIFY;
  27. BOOL
  28. s_RmNotifyChanges(
  29. IN handle_t IDL_handle,
  30. OUT RM_NOTIFY_KEY *lpNotifyKey,
  31. OUT DWORD *lpNotifyEvent,
  32. OUT DWORD *lpCurrentState
  33. )
  34. /*++
  35. Routine Description:
  36. This is a blocking RPC call which is used to implement notification.
  37. The client calls this API and blocks until a notification event
  38. occurs. Any notification events wake up the blocked thread and
  39. it returns to the client with the notification information.
  40. Arguments:
  41. IDL_handle - Supplies binding handle, currently unused
  42. lpNotifyKey - Returns the notification key of the resource
  43. lpCurrentState - Returns the current state of the resource
  44. Return Value:
  45. TRUE - A notification event was successfully delivered
  46. FALSE - No notification events were delivered, the process is
  47. shutting down.
  48. --*/
  49. {
  50. PLIST_ENTRY ListEntry;
  51. PNOTIFY Notify;
  52. DWORD Status;
  53. BOOL Continue;
  54. //
  55. // Wait for something to be posted to the queue, pull it off, and
  56. // return it.
  57. //
  58. ListEntry = ClRtlRemoveHeadQueue(&RmpNotifyQueue);
  59. if ( ListEntry == NULL ) {
  60. // If we got nothing - assume we are shutting down!
  61. return(FALSE);
  62. }
  63. Notify = CONTAINING_RECORD(ListEntry,
  64. NOTIFY,
  65. ListEntry);
  66. if (Notify->Reason == NotifyShutdown) {
  67. //
  68. // System is shutting down.
  69. //
  70. RmpFree(Notify);
  71. ClRtlLogPrint( LOG_NOISE, "[RM] NotifyChanges shutting down.\n");
  72. return(FALSE);
  73. }
  74. //
  75. // Return to the client with the notification data
  76. //
  77. *lpNotifyKey = Notify->Key;
  78. *lpNotifyEvent = Notify->Reason;
  79. *lpCurrentState = Notify->State;
  80. RmpFree(Notify);
  81. return(TRUE);
  82. } // RmNotifyChanges
  83. VOID
  84. RmpPostNotify(
  85. IN PRESOURCE Resource,
  86. IN NOTIFY_REASON Reason
  87. )
  88. /*++
  89. Routine Description:
  90. Posts a notification block to the notify queue.
  91. Arguments:
  92. Resource - Supplies the resource to post the notification for
  93. Reason - Supplies the reason for the notification.
  94. Return Value:
  95. None.
  96. --*/
  97. {
  98. PNOTIFY Notify;
  99. Notify = RmpAlloc(sizeof(NOTIFY));
  100. if (Notify != NULL) {
  101. Notify->Reason = Reason;
  102. switch ( Reason ) {
  103. case NotifyResourceStateChange:
  104. Notify->Key = Resource->NotifyKey;
  105. Notify->State = Resource->State;
  106. break;
  107. case NotifyResourceResuscitate:
  108. Notify->Key = Resource->NotifyKey;
  109. Notify->State = 0;
  110. break;
  111. case NotifyShutdown:
  112. Notify->Key = 0;
  113. Notify->State = 0;
  114. break;
  115. default:
  116. Notify->Key = 0;
  117. Notify->State = 0;
  118. }
  119. ClRtlInsertTailQueue(&RmpNotifyQueue, &Notify->ListEntry);
  120. } else {
  121. //
  122. // The notification will get dropped on the floor, but there's
  123. // not too much we can do about it anyway.
  124. //
  125. ClRtlLogPrint( LOG_ERROR, "[RM] RmpPostNotify dropped notification for %1!ws!, reason %2!u!\n",
  126. Resource->ResourceName,
  127. Reason);
  128. CL_UNEXPECTED_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  129. }
  130. } // RmpPostNotify