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.

627 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // TaskGatherClusterInfo.cpp
  7. //
  8. // Description:
  9. // TaskGatherClusterInfo implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 07-APR-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "TaskGatherClusterInfo.h"
  17. DEFINE_THISCLASS("CTaskGatherClusterInfo")
  18. // ************************************************************************
  19. //
  20. // Constructor / Destructor
  21. //
  22. // ************************************************************************
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // HRESULT
  26. // CTaskGatherClusterInfo::S_HrCreateInstance(
  27. // IUnknown ** ppunkOut
  28. // )
  29. //
  30. //////////////////////////////////////////////////////////////////////////////
  31. HRESULT
  32. CTaskGatherClusterInfo::S_HrCreateInstance(
  33. IUnknown ** ppunkOut
  34. )
  35. {
  36. TraceFunc( "" );
  37. HRESULT hr = S_OK;
  38. CTaskGatherClusterInfo * ptgci = NULL;
  39. Assert( ppunkOut != NULL );
  40. if ( ppunkOut == NULL )
  41. {
  42. hr = THR( E_POINTER );
  43. goto Cleanup;
  44. }
  45. ptgci = new CTaskGatherClusterInfo;
  46. if ( ptgci == NULL )
  47. {
  48. hr = THR( E_OUTOFMEMORY );
  49. goto Cleanup;
  50. }
  51. hr = THR( ptgci->HrInit() );
  52. if ( FAILED( hr ) )
  53. {
  54. goto Cleanup;
  55. }
  56. hr = THR( ptgci->TypeSafeQI( IUnknown, ppunkOut ) );
  57. if ( FAILED( hr ) )
  58. {
  59. goto Cleanup;
  60. }
  61. Cleanup:
  62. if ( ptgci != NULL )
  63. {
  64. ptgci->Release();
  65. }
  66. HRETURN( hr );
  67. } //*** CTaskGatherClusterInfo::S_HrCreateInstance
  68. //////////////////////////////////////////////////////////////////////////////
  69. //
  70. // CTaskGatherClusterInfo::CTaskGatherClusterInfo
  71. //
  72. //////////////////////////////////////////////////////////////////////////////
  73. CTaskGatherClusterInfo::CTaskGatherClusterInfo( void )
  74. : m_cRef( 1 )
  75. {
  76. TraceFunc( "" );
  77. InterlockedIncrement( &g_cObjects );
  78. TraceFuncExit();
  79. } //*** CTaskGatherClusterInfo::CTaskGatherClusterInfo
  80. //////////////////////////////////////////////////////////////////////////////
  81. //
  82. // STDMETHODIMP
  83. // CTaskGatherClusterInfo::HrInit
  84. //
  85. //////////////////////////////////////////////////////////////////////////////
  86. STDMETHODIMP
  87. CTaskGatherClusterInfo::HrInit( void )
  88. {
  89. TraceFunc( "" );
  90. HRESULT hr = S_OK;
  91. // IUnknown stuff
  92. Assert( m_cRef == 1 );
  93. // IDoTask / ITaskGatherClusterInfo
  94. Assert( m_cookie == NULL );
  95. Assert( m_fStop == FALSE );
  96. HRETURN( hr );
  97. } //*** CTaskGatherClusterInfo::HrInit
  98. //////////////////////////////////////////////////////////////////////////////
  99. //
  100. // CTaskGatherClusterInfo::~CTaskGatherClusterInfo
  101. //
  102. //////////////////////////////////////////////////////////////////////////////
  103. CTaskGatherClusterInfo::~CTaskGatherClusterInfo( void )
  104. {
  105. TraceFunc( "" );
  106. //
  107. // This keeps the per thread memory tracking from screaming.
  108. //
  109. TraceMoveFromMemoryList( this, g_GlobalMemoryList );
  110. InterlockedDecrement( &g_cObjects );
  111. TraceFuncExit();
  112. } //*** CTaskGatherClusterInfo::~CTaskGatherClusterInfo
  113. // ************************************************************************
  114. //
  115. // IUnknown
  116. //
  117. // ************************************************************************
  118. //////////////////////////////////////////////////////////////////////////////
  119. //++
  120. //
  121. // CTaskGatherClusterInfo::QueryInterface
  122. //
  123. // Description:
  124. // Query this object for the passed in interface.
  125. //
  126. // Arguments:
  127. // riidIn
  128. // Id of interface requested.
  129. //
  130. // ppvOut
  131. // Pointer to the requested interface.
  132. //
  133. // Return Value:
  134. // S_OK
  135. // If the interface is available on this object.
  136. //
  137. // E_NOINTERFACE
  138. // If the interface is not available.
  139. //
  140. // E_POINTER
  141. // ppvOut was NULL.
  142. //
  143. // Remarks:
  144. // None.
  145. //
  146. //--
  147. //////////////////////////////////////////////////////////////////////////////
  148. STDMETHODIMP
  149. CTaskGatherClusterInfo::QueryInterface(
  150. REFIID riidIn
  151. , LPVOID * ppvOut
  152. )
  153. {
  154. TraceQIFunc( riidIn, ppvOut );
  155. HRESULT hr = S_OK;
  156. //
  157. // Validate arguments.
  158. //
  159. Assert( ppvOut != NULL );
  160. if ( ppvOut == NULL )
  161. {
  162. hr = THR( E_POINTER );
  163. goto Cleanup;
  164. }
  165. //
  166. // Handle known interfaces.
  167. //
  168. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  169. {
  170. *ppvOut = static_cast< ITaskGatherClusterInfo * >( this );
  171. } // if: IUnknown
  172. else if ( IsEqualIID( riidIn, IID_IDoTask ) )
  173. {
  174. *ppvOut = TraceInterface( __THISCLASS__, IDoTask, this, 0 );
  175. } // else if: IDoTask
  176. else if ( IsEqualIID( riidIn, IID_ITaskGatherClusterInfo ) )
  177. {
  178. *ppvOut = TraceInterface( __THISCLASS__, ITaskGatherClusterInfo, this, 0 );
  179. } // else if: IClusCfgManagedResourceInfo
  180. else
  181. {
  182. *ppvOut = NULL;
  183. hr = E_NOINTERFACE;
  184. }
  185. //
  186. // Add a reference to the interface if successful.
  187. //
  188. if ( SUCCEEDED( hr ) )
  189. {
  190. ((IUnknown *) *ppvOut)->AddRef();
  191. } // if: success
  192. Cleanup:
  193. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  194. } //*** CTaskGatherClusterInfo::QueryInterface
  195. //////////////////////////////////////////////////////////////////////////////
  196. //
  197. // STDMETHODIMP_(ULONG)
  198. // CTaskGatherClusterInfo::AddRef
  199. //
  200. //////////////////////////////////////////////////////////////////////////////
  201. STDMETHODIMP_( ULONG )
  202. CTaskGatherClusterInfo::AddRef( void )
  203. {
  204. TraceFunc( "[IUnknown]" );
  205. InterlockedIncrement( &m_cRef );
  206. CRETURN( m_cRef );
  207. } //*** CTaskGatherClusterInfo::AddRef
  208. //////////////////////////////////////////////////////////////////////////////
  209. //
  210. // STDMETHODIMP_(ULONG)
  211. // CTaskGatherClusterInfo::Release
  212. //
  213. //////////////////////////////////////////////////////////////////////////////
  214. STDMETHODIMP_( ULONG )
  215. CTaskGatherClusterInfo::Release( void )
  216. {
  217. TraceFunc( "[IUnknown]" );
  218. LONG cRef;
  219. cRef = InterlockedDecrement( &m_cRef );
  220. if ( cRef == 0 )
  221. {
  222. TraceDo( delete this );
  223. }
  224. CRETURN( cRef );
  225. } //*** CTaskGatherClusterInfo::Release
  226. // ************************************************************************
  227. //
  228. // IDoTask / ITaskGatherClusterInfo
  229. //
  230. // ************************************************************************
  231. //////////////////////////////////////////////////////////////////////////////
  232. //
  233. // STDMETHODIMP
  234. // CTaskGatherClusterInfo::BeginTask( void );
  235. //
  236. //////////////////////////////////////////////////////////////////////////////
  237. STDMETHODIMP
  238. CTaskGatherClusterInfo::BeginTask( void )
  239. {
  240. TraceFunc( "[IDoTask]" );
  241. HRESULT hr;
  242. IServiceProvider * psp = NULL;
  243. IUnknown * punk = NULL;
  244. IObjectManager * pom = NULL;
  245. IConnectionManager * pcm = NULL;
  246. IConnectionPointContainer * pcpc = NULL;
  247. IConnectionPoint * pcp = NULL;
  248. INotifyUI * pnui = NULL;
  249. IClusCfgNodeInfo * pccni = NULL;
  250. IClusCfgServer * pccs = NULL;
  251. IGatherData * pgd = NULL;
  252. IClusCfgClusterInfo * pccci = NULL;
  253. TraceInitializeThread( L"TaskGatherClusterInfo" );
  254. //
  255. // Collect the manager we need to complete this task.
  256. //
  257. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  258. NULL,
  259. CLSCTX_INPROC_SERVER,
  260. TypeSafeParams( IServiceProvider, &psp )
  261. ) );
  262. if ( FAILED( hr ) )
  263. goto Cleanup;
  264. hr = THR( psp->TypeSafeQS( CLSID_ObjectManager, IObjectManager, &pom ) );
  265. if ( FAILED( hr ) )
  266. goto Cleanup;
  267. hr = THR( psp->TypeSafeQS( CLSID_ClusterConnectionManager, IConnectionManager, &pcm ) );
  268. if ( FAILED( hr ) )
  269. goto Cleanup;
  270. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager, IConnectionPointContainer, &pcpc ) );
  271. if ( FAILED( hr ) )
  272. goto Cleanup;
  273. hr = THR( pcpc->FindConnectionPoint( IID_INotifyUI, &pcp ) );
  274. if ( FAILED( hr ) )
  275. goto Cleanup;
  276. pcp = TraceInterface( L"CTaskGatherClusterInfo!IConnectionPoint", IConnectionPoint, pcp, 1 );
  277. hr = THR( pcp->TypeSafeQI( INotifyUI, &pnui ) );
  278. if ( FAILED( hr ) )
  279. goto Cleanup;
  280. //pnui = TraceInterface( L"CTaskGatherClusterInfo!INotifyUI", INotifyUI, pnui, 1 );
  281. psp->Release();
  282. psp = NULL;
  283. if ( m_fStop == TRUE )
  284. {
  285. goto Cleanup;
  286. } // if:
  287. //
  288. // Ask the Connection Manager for a connection to the object.
  289. //
  290. // don't wrap - this can fail.
  291. hr = pcm->GetConnectionToObject( m_cookie, &punk );
  292. //
  293. // This means the cluster has not been created yet.
  294. //
  295. if ( hr == HR_S_RPC_S_SERVER_UNAVAILABLE )
  296. {
  297. goto ReportStatus;
  298. }
  299. // HR_S_RPC_S_CLUSTER_NODE_DOWN
  300. else if ( FAILED( hr ) )
  301. {
  302. THR( hr );
  303. goto ReportStatus;
  304. }
  305. hr = THR( punk->TypeSafeQI( IClusCfgServer, &pccs ) );
  306. if ( FAILED( hr ) )
  307. goto Cleanup;
  308. punk->Release();
  309. punk = NULL;
  310. if ( m_fStop == TRUE )
  311. {
  312. goto Cleanup;
  313. } // if:
  314. //
  315. // Get the Node information.
  316. //
  317. hr = THR( pccs->GetClusterNodeInfo( &pccni ) );
  318. if ( FAILED( hr ) )
  319. goto ReportStatus;
  320. //
  321. // See if the node is a member of a cluster.
  322. //
  323. hr = STHR( pccni->IsMemberOfCluster() );
  324. if ( FAILED( hr ) )
  325. goto ReportStatus;
  326. //
  327. // If it is not a cluster, then there is nothing to do the "default"
  328. // configuration will do.
  329. //
  330. if ( hr == S_FALSE )
  331. {
  332. hr = S_OK;
  333. goto ReportStatus;
  334. }
  335. if ( m_fStop == TRUE )
  336. {
  337. goto Cleanup;
  338. } // if:
  339. //
  340. // Ask the Node for the Cluster Information.
  341. //
  342. hr = THR( pccni->GetClusterConfigInfo( &pccci ) );
  343. if ( FAILED( hr ) )
  344. goto ReportStatus;
  345. //
  346. // Ask the Object Manager to retrieve the data format to store the information.
  347. //
  348. Assert( punk == NULL );
  349. hr = THR( pom->GetObject( DFGUID_ClusterConfigurationInfo, m_cookie, &punk ) );
  350. if ( FAILED( hr ) )
  351. goto ReportStatus;
  352. hr = THR( punk->TypeSafeQI( IGatherData, &pgd ) );
  353. if ( FAILED( hr ) )
  354. goto ReportStatus;
  355. //
  356. // Start sucking.
  357. //
  358. hr = THR( pgd->Gather( NULL, pccci ) );
  359. //
  360. // Update the status. Ignore the error (if any).
  361. //
  362. ReportStatus:
  363. if ( pom != NULL )
  364. {
  365. HRESULT hr2;
  366. IUnknown * punkTemp = NULL;
  367. hr2 = THR( pom->GetObject( DFGUID_StandardInfo,
  368. m_cookie,
  369. &punkTemp
  370. ) );
  371. if ( SUCCEEDED( hr2 ) )
  372. {
  373. IStandardInfo * psi;
  374. hr2 = THR( punkTemp->TypeSafeQI( IStandardInfo, &psi ) );
  375. punkTemp->Release();
  376. punkTemp = NULL;
  377. if ( SUCCEEDED( hr2 ) )
  378. {
  379. hr2 = THR( psi->SetStatus( hr ) );
  380. psi->Release();
  381. }
  382. }
  383. } // if: ( pom != NULL )
  384. if ( pnui != NULL )
  385. {
  386. THR( pnui->ObjectChanged( m_cookie ) );
  387. }
  388. Cleanup:
  389. if ( psp != NULL )
  390. {
  391. psp->Release();
  392. }
  393. if ( pcm != NULL )
  394. {
  395. pcm->Release();
  396. }
  397. if ( pccs != NULL )
  398. {
  399. pccs->Release();
  400. }
  401. if ( pccni != NULL )
  402. {
  403. pccni->Release();
  404. }
  405. if ( punk != NULL )
  406. {
  407. punk->Release();
  408. }
  409. if ( pom != NULL )
  410. {
  411. HRESULT hr2;
  412. IUnknown * punkTemp = NULL;
  413. hr2 = THR( pom->GetObject( DFGUID_StandardInfo,
  414. m_cookieCompletion,
  415. &punkTemp
  416. ) );
  417. if ( SUCCEEDED( hr2 ) )
  418. {
  419. IStandardInfo * psi;
  420. hr2 = THR( punkTemp->TypeSafeQI( IStandardInfo, &psi ) );
  421. punkTemp->Release();
  422. punkTemp = NULL;
  423. if ( SUCCEEDED( hr2 ) )
  424. {
  425. hr2 = THR( psi->SetStatus( hr ) );
  426. psi->Release();
  427. }
  428. }
  429. pom->Release();
  430. } // if: ( pom != NULL )
  431. if ( pgd != NULL )
  432. {
  433. pgd->Release();
  434. }
  435. if ( pccci != NULL )
  436. {
  437. pccci->Release();
  438. }
  439. if ( pcp != NULL )
  440. {
  441. pcp->Release();
  442. }
  443. if ( pcpc != NULL )
  444. {
  445. pcpc->Release();
  446. }
  447. if ( pnui !=NULL )
  448. {
  449. if ( m_cookieCompletion != 0 )
  450. {
  451. hr = THR( pnui->ObjectChanged( m_cookieCompletion ) );
  452. } // if:
  453. pnui->Release();
  454. } // if:
  455. LogMsg( L"[MT] [CTaskGatherClusterInfo] exiting task. The task was%ws cancelled.", m_fStop == FALSE ? L" not" : L"" );
  456. HRETURN( hr );
  457. } //*** CTaskGatherClusterInfo::BeginTask
  458. //////////////////////////////////////////////////////////////////////////////
  459. //
  460. // STDMETHODIMP
  461. // CTaskGatherClusterInfo::StopTask( void )
  462. //
  463. //////////////////////////////////////////////////////////////////////////////
  464. STDMETHODIMP
  465. CTaskGatherClusterInfo::StopTask( void )
  466. {
  467. TraceFunc( "[IDoTask]" );
  468. HRESULT hr = S_OK;
  469. m_fStop = TRUE;
  470. LogMsg( L"[MT] [CTaskGatherClusterInfo] is being stopped." );
  471. HRETURN( hr );
  472. } //*** StopTask
  473. //////////////////////////////////////////////////////////////////////////////
  474. //
  475. // STDMETHODIMP
  476. // CTaskGatherClusterInfo::SetCookie(
  477. // OBJECTCOOKIE cookieIn
  478. // )
  479. //
  480. //////////////////////////////////////////////////////////////////////////////
  481. STDMETHODIMP
  482. CTaskGatherClusterInfo::SetCookie(
  483. OBJECTCOOKIE cookieIn
  484. )
  485. {
  486. TraceFunc( "[ITaskGatherClusterInfo]" );
  487. HRESULT hr = S_OK;
  488. m_cookie = cookieIn;
  489. HRETURN( hr );
  490. } //*** SetCookie
  491. //////////////////////////////////////////////////////////////////////////////
  492. //
  493. // STDMETHODIMP
  494. // CTaskGatherClusterInfo::SetCompletionCookie(
  495. // OBJECTCOOKIE cookieIn
  496. // )
  497. //
  498. //////////////////////////////////////////////////////////////////////////////
  499. STDMETHODIMP
  500. CTaskGatherClusterInfo::SetCompletionCookie(
  501. OBJECTCOOKIE cookieIn
  502. )
  503. {
  504. TraceFunc( "" );
  505. HRESULT hr = S_OK;
  506. m_cookieCompletion = cookieIn;
  507. HRETURN( hr );
  508. } //*** CTaskGatherClusterInfo::SetGatherPunk