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.

245 lines
6.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: scanmgr.hxx
  7. //
  8. // Contents: Scan manager
  9. //
  10. // Classes: CCiScanInfo
  11. // CCiScanMgr
  12. //
  13. // History: 14-Jul-97 SitaramR Created from dlnotify.hxx
  14. // 25-Feb-98 KitmanH Added private member _fIsReadOnly
  15. // and the IsReadOnly method
  16. // 03-Mar-98 KitmanH Added SetReadOnly method
  17. //
  18. //----------------------------------------------------------------------------
  19. #pragma once
  20. #include <refcount.hxx>
  21. #include <regevent.hxx>
  22. #include <fatnot.hxx>
  23. #include <rcstrmhd.hxx>
  24. #include <cimbmgr.hxx>
  25. #include "scaninfo.hxx"
  26. #include "acinotfy.hxx"
  27. #include "usnlist.hxx"
  28. #include "usnmgr.hxx"
  29. class CiCat;
  30. class CCiNotifyMgr;
  31. class CClientDocStore;
  32. //+---------------------------------------------------------------------------
  33. //
  34. // Class: CCiScanMgr
  35. //
  36. // Purpose: Class that manages the scan thread that does background
  37. // scanning of scopes to enumerate files in that scope. The
  38. // same thread is used for deletion of scopes also.
  39. //
  40. // History: 1-19-96 srikants Created
  41. //
  42. // Notes:
  43. //
  44. //----------------------------------------------------------------------------
  45. class CCiScanMgr
  46. {
  47. enum { MAX_RETRIES = 5 };
  48. enum { AUTOSCAN_WAIT = 30 * 60 * 1000, // 30 minutes
  49. PREINIT_WAIT = 1 * 60 * 1000 // 1 minute
  50. };
  51. enum EState { eStart,
  52. eDoRecovery,
  53. eRecovered,
  54. eStartScans,
  55. eNormal };
  56. friend class XEndScan;
  57. public:
  58. CCiScanMgr( CiCat & cicat );
  59. ~CCiScanMgr();
  60. void Resume() { _thrScan.Resume(); }
  61. void ScanScope( WCHAR const * pwcsScope, PARTITIONID partId,
  62. ULONG updFlag,
  63. BOOL fDoDeletions,
  64. BOOL fDelayed,
  65. BOOL fNewScope = FALSE );
  66. void ScanScope( XPtr<CCiScanInfo> & xScope, BOOL fDelayed, BOOL fRefiled );
  67. void DirAddNotification( WCHAR const *pwcsDirName );
  68. void DirRenameNotification( WCHAR const * pwcsDirOldName, WCHAR const *pwcsDirNewName );
  69. void ScheduleSerializeChanges();
  70. void StartRecovery();
  71. void StartScansAndNotifies();
  72. void InitiateShutdown();
  73. void WaitForShutdown();
  74. // thread management routines
  75. void WakeUp();
  76. // batch processing enabling and disabling
  77. void SetBatch();
  78. void ClearBatch();
  79. void RemoveScope( WCHAR const * pwcsScope );
  80. void SetStatus( CCiScanInfo * pScanInfo, NTSTATUS status )
  81. {
  82. CLock lock(_mutex);
  83. if ( pScanInfo->IsRetryableError(status) )
  84. {
  85. pScanInfo->LokSetRetry();
  86. }
  87. else
  88. {
  89. pScanInfo->LokSetDone();
  90. }
  91. }
  92. void SetDone( CCiScanInfo *pScanInfo )
  93. {
  94. CLock lock(_mutex);
  95. pScanInfo->LokSetDone();
  96. }
  97. void SetScanSuccess( CCiScanInfo * pScanInfo );
  98. BOOL IsScopeDeleted( CCiScanInfo * pScanInfo )
  99. {
  100. CLock lock(_mutex);
  101. return pScanInfo->LokIsDelScope();
  102. }
  103. BOOL IsRenameDir( CCiScanInfo *pScanInfo )
  104. {
  105. CLock lock( _mutex );
  106. return pScanInfo->LokIsRenameDir();
  107. }
  108. void DisableScan();
  109. void EnableScan();
  110. BOOL IsScanDisabled() const { return _fScanDisabled; }
  111. void Count( ULONG & ulInProgress, ULONG & ulPending )
  112. {
  113. CLock lock( _mutex );
  114. ulInProgress = _scansInProgress.Count();
  115. ulPending = _scansToDo.Count();
  116. }
  117. BOOL AnyInitialScans();
  118. BOOL IsReadOnly () { return _fIsReadOnly; }
  119. void SetReadOnly () { _fIsReadOnly = TRUE; }
  120. private:
  121. static DWORD WINAPI ScanThread( void * self );
  122. void _DoScans();
  123. void _Scan();
  124. void _LokEmptyInProgressScans();
  125. BOOL _LokIsScanScheduled( const XPtr<CCiScanInfo> & xScanInfo );
  126. BOOL _IsRetryableError( NTSTATUS status )
  127. {
  128. return STATUS_INSUFFICIENT_RESOURCES == status ||
  129. STATUS_DISK_FULL == status ||
  130. ERROR_DISK_FULL == status ||
  131. HRESULT_FROM_WIN32(ERROR_DISK_FULL) == status ||
  132. FILTER_S_DISK_FULL == status ||
  133. CI_E_CONFIG_DISK_FULL == status;
  134. }
  135. BOOL _LokIsOkToScan() const { return eNormal == _state; }
  136. BOOL _LokIsDoRecovery() const { return eDoRecovery == _state; }
  137. BOOL _LokIsStartScans() const { return eStartScans == _state; }
  138. void _SetRecoveryDone();
  139. void _LokScheduleRemove( WCHAR const * pwcsPath );
  140. CCiScanInfo * _QueryScanInfo( WCHAR const * pwcsScope,
  141. PARTITIONID partId,
  142. ULONG updFlag,
  143. BOOL fDoDeletions,
  144. BOOL fNewScope = FALSE );
  145. CiCat & _cicat;
  146. CMutexSem _mutex;
  147. CEventSem _evtScan; // Event used to signal the scan thread.
  148. BOOL _fAbort; // Aborts and kills the thread.
  149. BOOL _fSerializeChanges; // TRUE if scan time, usn info needs
  150. // to be serialized
  151. EState _state;
  152. // Set to TRUE if long initialization has been
  153. // completed.
  154. CScanInfoList _scansToDo; // Paths that must be scanned.
  155. CThread _thrScan;
  156. BOOL _fBatch; // set to TRUE if batch scope processing is
  157. // being done.
  158. BOOL _fScanDisabled;
  159. // set to TRUE when scans are disabled
  160. // running scans
  161. BOOL _fAbortScan; // Just aborts the current scan.
  162. CScanInfoList _scansInProgress;
  163. // Stack of in-progress scans.
  164. BOOL _fIsReadOnly;
  165. DWORD _dwLastShareSynch;
  166. };
  167. //+---------------------------------------------------------------------------
  168. //
  169. // Class: XBatchScan
  170. //
  171. // Purpose: A unwindable class to enable and disable batch processing of
  172. // scope scanning.
  173. //
  174. // History: 1-23-96 srikants Created
  175. //
  176. // Notes:
  177. //
  178. //----------------------------------------------------------------------------
  179. class XBatchScan
  180. {
  181. public:
  182. XBatchScan( CCiScanMgr & scanMgr ) : _scanMgr(scanMgr)
  183. {
  184. _scanMgr.SetBatch();
  185. }
  186. ~XBatchScan()
  187. {
  188. _scanMgr.ClearBatch();
  189. }
  190. private:
  191. CCiScanMgr & _scanMgr;
  192. };