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.

328 lines
11 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2001 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** ml.cpp
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program to exercise backup and multilayer snapshots
  15. **
  16. ** Author:
  17. **
  18. ** Adi Oltean [aoltean] 02/22/2001
  19. **
  20. **
  21. ** Revision History:
  22. **
  23. **--
  24. */
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // Includes
  27. #include "ml.h"
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // Processing functions
  30. // Adding a diff area association
  31. void CVssMultilayerTest::AddDiffArea()
  32. {
  33. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::AddDiffArea");
  34. wprintf (L"\n---------- Adding a diff area ----------------------------\n");
  35. // Create a Coordinator interface
  36. CComPtr<IVssSnapshotMgmt> pMgmt;
  37. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  38. wprintf (L"Management object created.\n");
  39. // Get the management object
  40. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  41. CHECK_SUCCESS( pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ) );
  42. CHECK_SUCCESS( pSnapMgmt->AddDiffArea( m_pwszVolume, m_pwszDiffAreaVolume, m_llMaxDiffArea ));
  43. }
  44. // Removing a diff area association
  45. void CVssMultilayerTest::RemoveDiffArea()
  46. {
  47. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::RemoveDiffArea");
  48. wprintf (L"\n---------- Removing a diff area ----------------------------\n");
  49. // Create a Coordinator interface
  50. CComPtr<IVssSnapshotMgmt> pMgmt;
  51. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  52. wprintf (L"Management object created.\n");
  53. // Get the management object
  54. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  55. CHECK_SUCCESS( pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  56. // Remove the diff area
  57. CHECK_SUCCESS( pSnapMgmt->ChangeDiffAreaMaximumSize( m_pwszVolume, m_pwszDiffAreaVolume, VSS_ASSOC_REMOVE ));
  58. }
  59. // Changing the diff area max size
  60. void CVssMultilayerTest::ChangeDiffAreaMaximumSize()
  61. {
  62. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::ChangeDiffAreaMaximumSize");
  63. wprintf (L"\n---------- Changing diff area max size ----------------------\n");
  64. // Create a Coordinator interface
  65. CComPtr<IVssSnapshotMgmt> pMgmt;
  66. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  67. wprintf (L"Management object created.\n");
  68. // Get the management object
  69. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  70. CHECK_SUCCESS(pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  71. CHECK_SUCCESS(pSnapMgmt->ChangeDiffAreaMaximumSize( m_pwszVolume, m_pwszDiffAreaVolume, m_llMaxDiffArea ));
  72. }
  73. // Querying volumes for diff area
  74. void CVssMultilayerTest::QueryVolumesSupportedForDiffAreas()
  75. {
  76. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::QueryVolumesSupportedForDiffAreas");
  77. wprintf (L"\n---------- Querying volumes supported for diff area ----------------\n");
  78. // Create a Coordinator interface
  79. CComPtr<IVssSnapshotMgmt> pMgmt;
  80. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  81. wprintf (L"Management object created.\n");
  82. // Get the management object
  83. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  84. CHECK_SUCCESS(pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  85. // Get list all supported volumes for diff area
  86. CComPtr<IVssEnumMgmtObject> pIEnum;
  87. CHECK_NOFAIL(pSnapMgmt->QueryVolumesSupportedForDiffAreas( m_pwszVolume, &pIEnum ));
  88. if (ft.hr == S_FALSE) {
  89. wprintf(L"Query: Empty result...\n");
  90. return;
  91. }
  92. wprintf(L"\n%-50s %-15s %-10s %-10s\n", L"Volume Name", L"Display name", L"Free space", L"Total space");
  93. wprintf(L"------------------------------------------------------------------------------------------\n");
  94. // For all volumes do...
  95. VSS_MGMT_OBJECT_PROP Prop;
  96. VSS_DIFF_VOLUME_PROP& DiffVol = Prop.Obj.DiffVol;
  97. for(;;) {
  98. // Get next element
  99. ULONG ulFetched;
  100. CHECK_NOFAIL(pIEnum->Next( 1, &Prop, &ulFetched ));
  101. // Test if the cycle is finished
  102. if (ft.hr == S_FALSE) {
  103. BS_ASSERT( ulFetched == 0);
  104. break;
  105. }
  106. wprintf(L"%-50s %-15s %I64d %I64d\n",
  107. DiffVol.m_pwszVolumeName,
  108. DiffVol.m_pwszVolumeDisplayName,
  109. DiffVol.m_llVolumeFreeSpace,
  110. DiffVol.m_llVolumeTotalSpace
  111. );
  112. ::CoTaskMemFree(DiffVol.m_pwszVolumeName);
  113. ::CoTaskMemFree(DiffVol.m_pwszVolumeDisplayName);
  114. }
  115. wprintf(L"------------------------------------------------------------------------------------------\n");
  116. }
  117. // Querying diff areas for volume
  118. void CVssMultilayerTest::QueryDiffAreasForVolume()
  119. {
  120. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::QueryDiffAreasForVolume");
  121. wprintf (L"\n---------- Querying diff areas for volume ----------------\n");
  122. // Create a Coordinator interface
  123. CComPtr<IVssSnapshotMgmt> pMgmt;
  124. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  125. wprintf (L"Management object created.\n");
  126. // Get the management object
  127. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  128. CHECK_SUCCESS(pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  129. // Get list all supported volumes for diff area
  130. CComPtr<IVssEnumMgmtObject> pIEnum;
  131. CHECK_NOFAIL(pSnapMgmt->QueryDiffAreasForVolume( m_pwszVolume, &pIEnum ));
  132. if (ft.hr == S_FALSE) {
  133. wprintf(L"Query: Empty result...\n");
  134. return;
  135. }
  136. wprintf(L"\n%- 50s %- 50s %-10s %-10s %-10s\n", L"Volume", L"Diff area", L"Used", L"Allocated", L"Maximum");
  137. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  138. // For all volumes do...
  139. VSS_MGMT_OBJECT_PROP Prop;
  140. VSS_DIFF_AREA_PROP& DiffArea = Prop.Obj.DiffArea;
  141. for(;;) {
  142. // Get next element
  143. ULONG ulFetched;
  144. CHECK_NOFAIL(pIEnum->Next( 1, &Prop, &ulFetched ));
  145. // Test if the cycle is finished
  146. if (ft.hr == S_FALSE) {
  147. BS_ASSERT( ulFetched == 0);
  148. break;
  149. }
  150. wprintf(L"%- 50s %- 50s %-10I64d %-10I64d %-10I64d\n",
  151. DiffArea.m_pwszVolumeName,
  152. DiffArea.m_pwszDiffAreaVolumeName,
  153. DiffArea.m_llUsedDiffSpace,
  154. DiffArea.m_llAllocatedDiffSpace,
  155. DiffArea.m_llMaximumDiffSpace
  156. );
  157. ::CoTaskMemFree(DiffArea.m_pwszVolumeName);
  158. ::CoTaskMemFree(DiffArea.m_pwszDiffAreaVolumeName);
  159. }
  160. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  161. }
  162. // Querying diff areas on volume
  163. void CVssMultilayerTest::QueryDiffAreasOnVolume()
  164. {
  165. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::QueryDiffAreasOnVolume");
  166. wprintf (L"\n---------- Querying diff areas On volume ----------------\n");
  167. // Create a Coordinator interface
  168. CComPtr<IVssSnapshotMgmt> pMgmt;
  169. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  170. wprintf (L"Management object created.\n");
  171. // Get the management object
  172. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  173. CHECK_SUCCESS(pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  174. // Get list all supported volumes for diff area
  175. CComPtr<IVssEnumMgmtObject> pIEnum;
  176. CHECK_NOFAIL(pSnapMgmt->QueryDiffAreasOnVolume( m_pwszDiffAreaVolume, &pIEnum ));
  177. if (ft.hr == S_FALSE) {
  178. wprintf(L"Query: Empty result...\n");
  179. return;
  180. }
  181. wprintf(L"\n%- 50s %- 50s %-10s %-10s %-10s\n", L"Volume", L"Diff area", L"Used", L"Allocated", L"Maximum");
  182. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  183. // For all volumes do...
  184. VSS_MGMT_OBJECT_PROP Prop;
  185. VSS_DIFF_AREA_PROP& DiffArea = Prop.Obj.DiffArea;
  186. for(;;) {
  187. // Get next element
  188. ULONG ulFetched;
  189. CHECK_NOFAIL(pIEnum->Next( 1, &Prop, &ulFetched ));
  190. // Test if the cycle is finished
  191. if (ft.hr == S_FALSE) {
  192. BS_ASSERT( ulFetched == 0);
  193. break;
  194. }
  195. wprintf(L"%- 50s %- 50s %-10I64d %-10I64d %-10I64d\n",
  196. DiffArea.m_pwszVolumeName,
  197. DiffArea.m_pwszDiffAreaVolumeName,
  198. DiffArea.m_llUsedDiffSpace,
  199. DiffArea.m_llAllocatedDiffSpace,
  200. DiffArea.m_llMaximumDiffSpace
  201. );
  202. ::CoTaskMemFree(DiffArea.m_pwszVolumeName);
  203. ::CoTaskMemFree(DiffArea.m_pwszDiffAreaVolumeName);
  204. }
  205. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  206. }
  207. // Querying diff areas for snapshot
  208. void CVssMultilayerTest::QueryDiffAreasForSnapshot()
  209. {
  210. CVssFunctionTracer ft(VSSDBG_VSSTEST, L"CVssMultilayerTest::QueryDiffAreasForSnapshot");
  211. wprintf (L"\n---------- Querying diff areas for snapshot ----------------\n");
  212. // Create a Coordinator interface
  213. CComPtr<IVssSnapshotMgmt> pMgmt;
  214. CHECK_NOFAIL(pMgmt.CoCreateInstance( CLSID_VssSnapshotMgmt ));
  215. wprintf (L"Management object created.\n");
  216. // Get the management object
  217. CComPtr<IVssDifferentialSoftwareSnapshotMgmt> pSnapMgmt;
  218. CHECK_SUCCESS(pMgmt->GetProviderMgmtInterface( m_ProviderId, IID_IVssDifferentialSoftwareSnapshotMgmt, (IUnknown**)&pSnapMgmt ));
  219. // Get list all supported volumes for diff area
  220. CComPtr<IVssEnumMgmtObject> pIEnum;
  221. CHECK_NOFAIL(pSnapMgmt->QueryDiffAreasForSnapshot( m_SnapshotId, &pIEnum ));
  222. if (ft.hr == S_FALSE) {
  223. wprintf(L"Query: Empty result...\n");
  224. return;
  225. }
  226. wprintf(L"\n%- 50s %- 50s %-10s %-10s %-10s\n", L"Volume", L"Diff area", L"Used", L"Allocated", L"Maximum");
  227. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  228. // For all volumes do...
  229. VSS_MGMT_OBJECT_PROP Prop;
  230. VSS_DIFF_AREA_PROP& DiffArea = Prop.Obj.DiffArea;
  231. for(;;) {
  232. // Get next element
  233. ULONG ulFetched;
  234. CHECK_NOFAIL(pIEnum->Next( 1, &Prop, &ulFetched ));
  235. // Test if the cycle is finished
  236. if (ft.hr == S_FALSE) {
  237. BS_ASSERT( ulFetched == 0);
  238. break;
  239. }
  240. wprintf(L"%- 50s %- 50s %-10I64d %-10I64d %-10I64d\n",
  241. DiffArea.m_pwszVolumeName,
  242. DiffArea.m_pwszDiffAreaVolumeName,
  243. DiffArea.m_llUsedDiffSpace,
  244. DiffArea.m_llAllocatedDiffSpace,
  245. DiffArea.m_llMaximumDiffSpace
  246. );
  247. ::CoTaskMemFree(DiffArea.m_pwszVolumeName);
  248. ::CoTaskMemFree(DiffArea.m_pwszDiffAreaVolumeName);
  249. }
  250. wprintf(L"-------------------------------------------------------------------------------------------------------------------------------\n");
  251. }