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.

282 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. perfrdr.c
  5. Abstract:
  6. This file implements a Performance Object that presents
  7. Redirector Performance object data
  8. Created:
  9. Bob Watson 22-Oct-1996
  10. Revision History
  11. --*/
  12. //
  13. // Include Files
  14. //
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <ntddnfs.h>
  19. #include <ntioapi.h>
  20. #include <windows.h>
  21. #include <assert.h>
  22. #include <srvfsctl.h>
  23. #include <winperf.h>
  24. #include <ntprfctr.h>
  25. #include <perfutil.h>
  26. #include "perfnet.h"
  27. #include "netsvcmc.h"
  28. #include "datardr.h"
  29. static HANDLE hRdr = NULL;
  30. DWORD APIENTRY
  31. OpenRedirObject (
  32. IN LPWSTR lpValueName
  33. )
  34. {
  35. UNICODE_STRING DeviceNameU;
  36. OBJECT_ATTRIBUTES ObjectAttributes;
  37. IO_STATUS_BLOCK IoStatusBlock;
  38. NTSTATUS status;
  39. RTL_RELATIVE_NAME RelativeName;
  40. UNREFERENCED_PARAMETER (lpValueName);
  41. // open the handle to the server for data collection
  42. //
  43. // Now get access to the Redirector for its data
  44. //
  45. RtlInitUnicodeString(&DeviceNameU, (LPCWSTR)DD_NFS_DEVICE_NAME_U);
  46. RelativeName.ContainingDirectory = NULL;
  47. InitializeObjectAttributes(&ObjectAttributes,
  48. &DeviceNameU,
  49. OBJ_CASE_INSENSITIVE,
  50. RelativeName.ContainingDirectory,
  51. NULL
  52. );
  53. status = NtCreateFile(&hRdr,
  54. SYNCHRONIZE,
  55. &ObjectAttributes,
  56. &IoStatusBlock,
  57. NULL,
  58. FILE_ATTRIBUTE_NORMAL,
  59. FILE_SHARE_READ | FILE_SHARE_WRITE,
  60. FILE_OPEN_IF,
  61. FILE_SYNCHRONOUS_IO_NONALERT,
  62. NULL,
  63. 0
  64. );
  65. if (!NT_SUCCESS(status)) {
  66. ReportEvent (hEventLog,
  67. EVENTLOG_ERROR_TYPE,
  68. 0,
  69. PERFNET_UNABLE_OPEN_REDIR,
  70. NULL,
  71. 0,
  72. sizeof(DWORD),
  73. NULL,
  74. (LPVOID)&status);
  75. }
  76. return (DWORD)RtlNtStatusToDosError(status);
  77. }
  78. DWORD APIENTRY
  79. CollectRedirObjectData(
  80. IN OUT LPVOID *lppData,
  81. IN OUT LPDWORD lpcbTotalBytes,
  82. IN OUT LPDWORD lpNumObjectTypes
  83. )
  84. /*++
  85. Routine Description:
  86. This routine will return the data for the Physical Disk object
  87. Arguments:
  88. IN OUT LPVOID *lppData
  89. IN: pointer to the address of the buffer to receive the completed
  90. PerfDataBlock and subordinate structures. This routine will
  91. append its data to the buffer starting at the point referenced
  92. by *lppData.
  93. OUT: points to the first byte after the data structure added by this
  94. routine. This routine updated the value at lppdata after appending
  95. its data.
  96. IN OUT LPDWORD lpcbTotalBytes
  97. IN: the address of the DWORD that tells the size in bytes of the
  98. buffer referenced by the lppData argument
  99. OUT: the number of bytes added by this routine is writted to the
  100. DWORD pointed to by this argument
  101. IN OUT LPDWORD NumObjectTypes
  102. IN: the address of the DWORD to receive the number of objects added
  103. by this routine
  104. OUT: the number of objects added by this routine is writted to the
  105. DWORD pointed to by this argument
  106. Returns:
  107. 0 if successful, else Win 32 error code of failure
  108. --*/
  109. {
  110. DWORD TotalLen; // Length of the total return block
  111. NTSTATUS Status = ERROR_SUCCESS;
  112. IO_STATUS_BLOCK IoStatusBlock;
  113. RDR_DATA_DEFINITION *pRdrDataDefinition;
  114. RDR_COUNTER_DATA *pRCD;
  115. REDIR_STATISTICS RdrStatistics;
  116. if ( hRdr == NULL ) {
  117. // redir didn't get opened and it has already been logged
  118. *lpcbTotalBytes = (DWORD) 0;
  119. *lpNumObjectTypes = (DWORD) 0;
  120. return ERROR_SUCCESS;
  121. }
  122. //
  123. // Check for sufficient space for redirector data
  124. //
  125. TotalLen = sizeof(RDR_DATA_DEFINITION) +
  126. sizeof(RDR_COUNTER_DATA);
  127. if ( *lpcbTotalBytes < TotalLen ) {
  128. *lpcbTotalBytes = (DWORD) 0;
  129. *lpNumObjectTypes = (DWORD) 0;
  130. return ERROR_MORE_DATA;
  131. }
  132. //
  133. // Define objects data block
  134. //
  135. pRdrDataDefinition = (RDR_DATA_DEFINITION *) *lppData;
  136. memcpy (pRdrDataDefinition,
  137. &RdrDataDefinition,
  138. sizeof(RDR_DATA_DEFINITION));
  139. //
  140. // Format and collect redirector data
  141. //
  142. pRCD = (PRDR_COUNTER_DATA)&pRdrDataDefinition[1];
  143. // test for quadword alignment of the structure
  144. assert (((DWORD)(pRCD) & 0x00000007) == 0);
  145. pRCD->CounterBlock.ByteLength = sizeof (RDR_COUNTER_DATA);
  146. Status = NtFsControlFile(hRdr,
  147. NULL,
  148. NULL,
  149. NULL,
  150. &IoStatusBlock,
  151. FSCTL_LMR_GET_STATISTICS,
  152. NULL,
  153. 0,
  154. &RdrStatistics,
  155. sizeof(RdrStatistics)
  156. );
  157. if (NT_SUCCESS(Status)) {
  158. // transfer Redir data
  159. pRCD->Bytes = RdrStatistics.BytesReceived.QuadPart +
  160. RdrStatistics.BytesTransmitted.QuadPart;
  161. pRCD->IoOperations = RdrStatistics.ReadOperations +
  162. RdrStatistics.WriteOperations;
  163. pRCD->Smbs = RdrStatistics.SmbsReceived.QuadPart +
  164. RdrStatistics.SmbsTransmitted.QuadPart;
  165. pRCD->BytesReceived = RdrStatistics.BytesReceived.QuadPart;
  166. pRCD->SmbsReceived = RdrStatistics.SmbsReceived.QuadPart;
  167. pRCD->PagingReadBytesRequested = RdrStatistics.PagingReadBytesRequested.QuadPart;
  168. pRCD->NonPagingReadBytesRequested = RdrStatistics.NonPagingReadBytesRequested.QuadPart;
  169. pRCD->CacheReadBytesRequested = RdrStatistics.CacheReadBytesRequested.QuadPart;
  170. pRCD->NetworkReadBytesRequested = RdrStatistics.NetworkReadBytesRequested.QuadPart;
  171. pRCD->BytesTransmitted = RdrStatistics.BytesTransmitted.QuadPart;
  172. pRCD->SmbsTransmitted = RdrStatistics.SmbsTransmitted.QuadPart;
  173. pRCD->PagingWriteBytesRequested = RdrStatistics.PagingWriteBytesRequested.QuadPart;
  174. pRCD->NonPagingWriteBytesRequested = RdrStatistics.NonPagingWriteBytesRequested.QuadPart;
  175. pRCD->CacheWriteBytesRequested = RdrStatistics.CacheWriteBytesRequested.QuadPart;
  176. pRCD->NetworkWriteBytesRequested = RdrStatistics.NetworkWriteBytesRequested.QuadPart;
  177. pRCD->ReadOperations = RdrStatistics.ReadOperations;
  178. pRCD->RandomReadOperations = RdrStatistics.RandomReadOperations;
  179. pRCD->ReadSmbs = RdrStatistics.ReadSmbs;
  180. pRCD->LargeReadSmbs = RdrStatistics.LargeReadSmbs;
  181. pRCD->SmallReadSmbs = RdrStatistics.SmallReadSmbs;
  182. pRCD->WriteOperations = RdrStatistics.WriteOperations;
  183. pRCD->RandomWriteOperations = RdrStatistics.RandomWriteOperations;
  184. pRCD->WriteSmbs = RdrStatistics.WriteSmbs;
  185. pRCD->LargeWriteSmbs = RdrStatistics.LargeWriteSmbs;
  186. pRCD->SmallWriteSmbs = RdrStatistics.SmallWriteSmbs;
  187. pRCD->RawReadsDenied = RdrStatistics.RawReadsDenied;
  188. pRCD->RawWritesDenied = RdrStatistics.RawWritesDenied;
  189. pRCD->NetworkErrors = RdrStatistics.NetworkErrors;
  190. pRCD->Sessions = RdrStatistics.Sessions;
  191. pRCD->Reconnects = RdrStatistics.Reconnects;
  192. pRCD->CoreConnects = RdrStatistics.CoreConnects;
  193. pRCD->Lanman20Connects = RdrStatistics.Lanman20Connects;
  194. pRCD->Lanman21Connects = RdrStatistics.Lanman21Connects;
  195. pRCD->LanmanNtConnects = RdrStatistics.LanmanNtConnects;
  196. pRCD->ServerDisconnects = RdrStatistics.ServerDisconnects;
  197. pRCD->HungSessions = RdrStatistics.HungSessions;
  198. pRCD->CurrentCommands = RdrStatistics.CurrentCommands;
  199. } else {
  200. //
  201. // Failure to access Redirector: clear counters to 0
  202. //
  203. ReportEvent (hEventLog,
  204. EVENTLOG_ERROR_TYPE,
  205. 0,
  206. PERFNET_UNABLE_READ_REDIR,
  207. NULL,
  208. 0,
  209. sizeof(DWORD),
  210. NULL,
  211. (LPVOID)&Status);
  212. memset(pRCD, 0, sizeof(RDR_COUNTER_DATA));
  213. pRCD->CounterBlock.ByteLength = sizeof (RDR_COUNTER_DATA);
  214. }
  215. *lppData = (LPVOID)&pRCD[1];
  216. *lpcbTotalBytes = (DWORD)((LPBYTE)&pRCD[1] - (LPBYTE)pRdrDataDefinition);
  217. *lpNumObjectTypes = 1;
  218. return ERROR_SUCCESS;
  219. }
  220. DWORD APIENTRY
  221. CloseRedirObject ()
  222. {
  223. if (hRdr != NULL) {
  224. NtClose(hRdr);
  225. hRdr = NULL;
  226. }
  227. return ERROR_SUCCESS;
  228. }