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.

385 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. tsinit.cxx
  5. Abstract:
  6. This module contains the tsunami initialization code.
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 16-Jan-1995
  9. --*/
  10. #include "TsunamiP.Hxx"
  11. #include <dbgutil.h>
  12. #include <inetsvcs.h>
  13. #pragma hdrstop
  14. #include <iistypes.hxx>
  15. #include <iisver.h>
  16. #include <iiscnfg.h>
  17. #include <imd.h>
  18. #include <mb.hxx>
  19. HANDLE g_hQuit = NULL;
  20. HANDLE g_hNewItem = NULL;
  21. BOOL g_fW3OnlyNoAuth = FALSE;
  22. extern LONG g_nTsunamiThreads;
  23. //
  24. // Disables Tsunami Caching
  25. //
  26. BOOL DisableTsunamiCaching = FALSE;
  27. //
  28. // DisableSPUD
  29. //
  30. BOOL DisableSPUD = FALSE;
  31. //
  32. // Allows us to mask the invalid flags
  33. //
  34. DWORD TsValidCreateFileOptions = TS_IIS_VALID_FLAGS;
  35. //
  36. // flags to set on CreateFile
  37. //
  38. DWORD TsCreateFileShareMode = (FILE_SHARE_READ |
  39. FILE_SHARE_WRITE |
  40. FILE_SHARE_DELETE);
  41. BOOL TsNoDirOpenSupport = FALSE;
  42. DWORD TsCreateFileFlags = (FILE_FLAG_SEQUENTIAL_SCAN |
  43. FILE_FLAG_OVERLAPPED |
  44. FILE_FLAG_BACKUP_SEMANTICS );
  45. BOOL
  46. Tsunami_Initialize(
  47. VOID
  48. )
  49. /*++
  50. Description:
  51. Initializes the tsunami package
  52. Note: This routine assumes the caller is handling multiple initializers
  53. and will only call this routine once in a thread safe manner
  54. --*/
  55. {
  56. HKEY hKey;
  57. DWORD dwType;
  58. DWORD nBytes;
  59. DWORD dwValue;
  60. DWORD dwMaxFile;
  61. DWORD err;
  62. #if TSUNAMI_REF_DEBUG
  63. RefTraceLog = CreateRefTraceLog(
  64. 256, // LogSize
  65. 0 // ExtraBytesInHeader
  66. );
  67. #endif // TSUNAMI_REF_DEBUG
  68. //
  69. // Initialize global events
  70. //
  71. g_hQuit = IIS_CREATE_EVENT(
  72. "g_hQuit",
  73. &g_hQuit,
  74. TRUE,
  75. FALSE
  76. );
  77. g_hNewItem = IIS_CREATE_EVENT(
  78. "g_hNewItem",
  79. &g_hNewItem,
  80. FALSE,
  81. FALSE
  82. );
  83. if ( (g_hQuit == NULL) || (g_hNewItem == NULL) ) {
  84. goto Failure;
  85. }
  86. //
  87. // Set defaults
  88. //
  89. MEMORYSTATUS ms;
  90. ms.dwLength = sizeof(MEMORYSTATUS);
  91. GlobalMemoryStatus( &ms );
  92. //
  93. // default is 1K files per 32MB of physical memory after the 1st 8MB,
  94. // minimum INETA_MIN_DEF_FILE_HANDLE
  95. //
  96. if ( ms.dwTotalPhys > 8 * 1024 * 1024 )
  97. {
  98. dwMaxFile = (ms.dwTotalPhys - 8 * 1024 * 1024) / ( 32 * 1024 );
  99. if ( dwMaxFile < INETA_MIN_DEF_FILE_HANDLE )
  100. {
  101. dwMaxFile = INETA_MIN_DEF_FILE_HANDLE;
  102. }
  103. }
  104. else
  105. {
  106. dwMaxFile = INETA_MIN_DEF_FILE_HANDLE;
  107. }
  108. //
  109. // If this is not a NTS, disable tsunami caching by default
  110. //
  111. DisableSPUD = !AtqSpudInitialized();
  112. if ( !TsIsNtServer() ) {
  113. DisableTsunamiCaching = TRUE;
  114. DisableSPUD = TRUE;
  115. }
  116. DisableSPUD = TRUE;
  117. if ( DisableSPUD ) {
  118. DbgPrint("DisableCacheOplocks set to TRUE by default.\n");
  119. } else {
  120. DbgPrint("DisableCacheOplocks set to FALSE by default.\n");
  121. }
  122. //
  123. // no overlapped i/o in win95.
  124. //
  125. if ( TsIsWindows95() ) {
  126. TsCreateFileFlags = FILE_FLAG_SEQUENTIAL_SCAN;
  127. TsCreateFileShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
  128. TsNoDirOpenSupport = TRUE;
  129. // |FILE_FLAG_BACKUP_SEMANTICS;
  130. }
  131. //
  132. // Read the registry key to see whether tsunami caching is enabled
  133. //
  134. err = RegOpenKeyEx(
  135. HKEY_LOCAL_MACHINE,
  136. INETA_PARAMETERS_KEY,
  137. 0,
  138. KEY_READ,
  139. &hKey
  140. );
  141. if ( err == ERROR_SUCCESS ) {
  142. //
  143. // This cannot be overridded in win95
  144. //
  145. if ( !TsIsWindows95() ) {
  146. nBytes = sizeof(dwValue);
  147. err = RegQueryValueEx(
  148. hKey,
  149. INETA_DISABLE_TSUNAMI_CACHING,
  150. NULL,
  151. &dwType,
  152. (LPBYTE)&dwValue,
  153. &nBytes
  154. );
  155. if ( (err == ERROR_SUCCESS) && (dwType == REG_DWORD) ) {
  156. DisableTsunamiCaching = (BOOL)dwValue;
  157. }
  158. nBytes = sizeof(dwValue);
  159. err = RegQueryValueEx(
  160. hKey,
  161. INETA_DISABLE_TSUNAMI_SPUD,
  162. NULL,
  163. &dwType,
  164. (LPBYTE)&dwValue,
  165. &nBytes
  166. );
  167. if ( (err == ERROR_SUCCESS) && (dwType == REG_DWORD) ) {
  168. DisableSPUD = (BOOL)dwValue;
  169. if ( DisableSPUD ) {
  170. DbgPrint("DisableCacheOplocks set to TRUE in Registry.\n");
  171. } else {
  172. DbgPrint("DisableCacheOplocks set to FALSE in Registry.\n");
  173. }
  174. DbgPrint("The Registry Setting will override the default.\n");
  175. }
  176. }
  177. if ( g_fW3OnlyNoAuth )
  178. {
  179. //
  180. // TODO: investigate is security descriptor caching
  181. // can be used in the non-SYSTEM account case.
  182. //
  183. g_fCacheSecDesc = FALSE;
  184. }
  185. else
  186. {
  187. //
  188. // read the enable cache sec desc flag
  189. //
  190. nBytes = sizeof(dwValue);
  191. err = RegQueryValueEx(
  192. hKey,
  193. INETA_CACHE_USE_ACCESS_CHECK,
  194. NULL,
  195. &dwType,
  196. (LPBYTE)&dwValue,
  197. &nBytes
  198. );
  199. if ( (err == ERROR_SUCCESS) && (dwType == REG_DWORD) ) {
  200. g_fCacheSecDesc = !!dwValue;
  201. }
  202. else {
  203. g_fCacheSecDesc = INETA_DEF_CACHE_USE_ACCESS_CHECK;
  204. }
  205. }
  206. //
  207. // Read the maximum # of files in cache
  208. //
  209. nBytes = sizeof(dwValue);
  210. if ( RegQueryValueEx(
  211. hKey,
  212. INETA_MAX_OPEN_FILE,
  213. NULL,
  214. &dwType,
  215. (LPBYTE) &dwValue,
  216. &nBytes
  217. ) == ERROR_SUCCESS && dwType == REG_DWORD )
  218. {
  219. dwMaxFile = dwValue;
  220. }
  221. RegCloseKey( hKey );
  222. }
  223. //
  224. // if tsunami caching is disabled, set the flags accordingly
  225. //
  226. if ( DisableTsunamiCaching ) {
  227. g_fDisableCaching = TRUE;
  228. TsValidCreateFileOptions = TS_PWS_VALID_FLAGS;
  229. g_fCacheSecDesc = FALSE;
  230. }
  231. //
  232. // Initialize the directory change manager
  233. //
  234. if ( !DcmInitialize( ) ) {
  235. goto Failure;
  236. }
  237. //
  238. // Initialize the tsunami cache manager
  239. //
  240. if ( !Cache_Initialize( dwMaxFile )) {
  241. goto Failure;
  242. }
  243. if ( !MetaCache_Initialize() ) {
  244. goto Failure;
  245. }
  246. return( TRUE );
  247. Failure:
  248. IIS_PRINTF( ( buff, "Tsunami_Initialize() Failed. Error = %d\n",
  249. GetLastError()));
  250. if ( g_hQuit )
  251. {
  252. CloseHandle( g_hQuit );
  253. g_hQuit = NULL;
  254. }
  255. if ( g_hNewItem )
  256. {
  257. CloseHandle( g_hNewItem );
  258. g_hNewItem = NULL;
  259. }
  260. return FALSE;
  261. } // Tsunami_Initialize
  262. VOID
  263. Tsunami_Terminate(
  264. VOID
  265. )
  266. /*++
  267. Description:
  268. Cleans up the Tsunami package
  269. --*/
  270. {
  271. DWORD dwResult;
  272. if ( !SetEvent( g_hQuit ) ) {
  273. IIS_PRINTF((buff,
  274. "No Quit event posted for Tsunami. No Cleanup\n"));
  275. return;
  276. }
  277. //
  278. // Flush all items from the cache
  279. //
  280. TsCacheFlush( 0 );
  281. //
  282. // Synchronize with our thread so we don't leave here before the
  283. // thread has finished cleaning up
  284. //
  285. if ( g_hChangeWaitThread != NULL ) {
  286. DBG_REQUIRE( WaitForSingleObject( g_hChangeWaitThread, 20000 ) == WAIT_OBJECT_0 );
  287. CloseHandle( g_hChangeWaitThread);
  288. }
  289. CloseHandle( g_hQuit );
  290. CloseHandle( g_hNewItem );
  291. DeleteCriticalSection( &csVirtualRoots );
  292. MetaCache_Terminate();
  293. #if TSUNAMI_REF_DEBUG
  294. if( RefTraceLog != NULL ) {
  295. DestroyRefTraceLog( RefTraceLog );
  296. RefTraceLog = NULL;
  297. }
  298. #endif // TSUNAMI_REF_DEBUG
  299. } // Tsunami_Terminate