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.

161 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. backpack.c
  5. Abstract:
  6. This module contains the package for pseudo polling. When a caller
  7. requests the same operation and gets the same error return the rdr
  8. must prevent flooding the network by backing off requests. Examples
  9. of when this is desirable are receiving 0 bytes on consequtive reads
  10. and consequtive fails on a file lock.
  11. If the caller is flooding the network, the rdr will return the 0 bytes
  12. for a pipe read or lock fail to the user until NextTime is reached.
  13. When NextTime is reached BackOff will indicate that the network should
  14. be used.
  15. Author:
  16. Colin Watson (colinw) 02-Jan-1991
  17. Notes:
  18. Typical usage would be demonstrated by fsctrl.c on the peek request.
  19. 1) Each time peek is called it calls RxShouldRequestBeThrottled.
  20. When the result is true, the wrapper returns to the caller a response
  21. indicating there is no data at the other end of the pipe.
  22. When the result is false, a request is made to the network.
  23. 2) If the reply from the server to the peek in step 1 indicates that
  24. there is no data in the pipe then the wrapper calls RxInitiateOrContinueThrottling.
  25. 3) Whenever there is data in the pipe or when this workstation may
  26. unblock the pipe (eg. the workstation writing to the pipe)
  27. RxTerminateThrottling is called.
  28. Revision History:
  29. ColinWatson [ColinW] 24-Dec-1990 Created
  30. Joe Linn [JoeLinn] 10-Oct-1996 Lifted from rdr1 and massaged for rdr2
  31. --*/
  32. #include "precomp.h"
  33. #pragma hdrstop
  34. #ifdef ALLOC_PRAGMA
  35. //#pragma alloc_text(PAGE3FILE, RxBackOff) spinlock
  36. //#pragma alloc_text(PAGE3FILE, RxBackPackFailure) spinlock
  37. #endif
  38. BOOLEAN
  39. RxShouldRequestBeThrottled (
  40. IN PTHROTTLING_STATE pBP
  41. )
  42. /*++
  43. Routine Description:
  44. This routine is called each time a request is made to find out if a the
  45. request should be sent to the network or a standard reply should be
  46. returned to the caller.
  47. Arguments:
  48. pBP - supplies back pack data for this request.
  49. Return Value:
  50. TRUE when caller should not access the network.
  51. --*/
  52. {
  53. LARGE_INTEGER CurrentTime,SavedThrottlingTime;
  54. BOOLEAN result;
  55. // If the previous request worked then we should access the network.
  56. if (( pBP->CurrentIncrement == 0 ) ||
  57. ( pBP->MaximumDelay == 0 )) {
  58. return FALSE;
  59. }
  60. // If the delay has expired then access the network.
  61. KeQuerySystemTime(&CurrentTime);
  62. InterlockedIncrement(&pBP->NumberOfQueries);
  63. SavedThrottlingTime.QuadPart = 0;
  64. RxAcquireSerializationMutex();
  65. SavedThrottlingTime.QuadPart = pBP->NextTime.QuadPart;
  66. RxReleaseSerializationMutex();
  67. result = (CurrentTime.QuadPart < SavedThrottlingTime.QuadPart);
  68. RxLog(("shouldthrttle=%x (%x)\n",result,pBP));
  69. return(result);
  70. }
  71. VOID
  72. RxInitiateOrContinueThrottling (
  73. IN PTHROTTLING_STATE pBP
  74. )
  75. /*++
  76. Routine Description:
  77. This routine is called each time a request fails.
  78. Arguments:
  79. pBP - supplies back pack data for this request.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. LARGE_INTEGER CurrentTime,NextTime;
  85. KeQuerySystemTime(&CurrentTime);
  86. if (pBP->CurrentIncrement < pBP->MaximumDelay ) {
  87. //
  88. // We have reached NextTime but not our maximum delay limit.
  89. //
  90. InterlockedIncrement(&pBP->CurrentIncrement);
  91. }
  92. // NextTime = CurrentTime + (Interval * CurrentIncrement )
  93. NextTime.QuadPart = CurrentTime.QuadPart +
  94. (pBP->Increment.QuadPart * pBP->CurrentIncrement);
  95. RxAcquireSerializationMutex();
  96. pBP->NextTime.QuadPart = NextTime.QuadPart;
  97. RxReleaseSerializationMutex();
  98. }
  99.