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.

1917 lines
48 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumClusCfgManagedResources.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumClusCfgManagedResources
  10. // class.
  11. //
  12. // The class CEnumClusCfgManagedResources is the enumeration of cluster
  13. // managed devices. It implements the IEnumClusCfgManagedResources
  14. // interface.
  15. //
  16. // Maintained By:
  17. // Galen Barbee (GalenB) 23-FEB-2000
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Include Files
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "Pch.h"
  24. #include "CEnumClusCfgManagedResources.h"
  25. #include "CEnumUnknownQuorum.h"
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Constant Definitions
  28. //////////////////////////////////////////////////////////////////////////////
  29. DEFINE_THISCLASS( "CEnumClusCfgManagedResources" );
  30. //*************************************************************************//
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CEnumClusCfgManagedResources class
  33. /////////////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////////
  35. //++
  36. //
  37. // CEnumClusCfgManagedResources::S_HrCreateInstance
  38. //
  39. // Description:
  40. // Create a CEnumClusCfgManagedResources instance.
  41. //
  42. // Arguments:
  43. // None.
  44. //
  45. // Return Values:
  46. // Pointer to CEnumClusCfgManagedResources instance.
  47. //
  48. //--
  49. //////////////////////////////////////////////////////////////////////////////
  50. HRESULT
  51. CEnumClusCfgManagedResources::S_HrCreateInstance( IUnknown ** ppunkOut )
  52. {
  53. TraceFunc( "" );
  54. HRESULT hr = S_OK;
  55. CEnumClusCfgManagedResources * peccmr = NULL;
  56. if ( ppunkOut == NULL )
  57. {
  58. hr = THR( E_POINTER );
  59. goto Cleanup;
  60. } // if:
  61. peccmr = new CEnumClusCfgManagedResources();
  62. if ( peccmr == NULL )
  63. {
  64. hr = THR( E_OUTOFMEMORY );
  65. goto Cleanup;
  66. } // if: error allocating object
  67. hr = THR( peccmr->HrInit() );
  68. if ( FAILED( hr ) )
  69. {
  70. goto Cleanup;
  71. } // if: HrInit() failed
  72. hr = THR( peccmr->TypeSafeQI( IUnknown, ppunkOut ) );
  73. if ( FAILED( hr ) )
  74. {
  75. goto Cleanup;
  76. } // if: QI failed
  77. Cleanup:
  78. if ( FAILED( hr ) )
  79. {
  80. LogMsg( L"[SRV] CEnumClusCfgManagedResources::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  81. } // if:
  82. if ( peccmr != NULL )
  83. {
  84. peccmr->Release();
  85. } // if:
  86. HRETURN( hr );
  87. } //*** CEnumClusCfgManagedResources::S_HrCreateInstance
  88. //////////////////////////////////////////////////////////////////////////////
  89. //++
  90. //
  91. // CEnumClusCfgManagedResources::CEnumClusCfgManagedResources
  92. //
  93. // Description:
  94. // Constructor of the CEnumClusCfgManagedResources class. This initializes
  95. // the m_cRef variable to 1 instead of 0 to account of possible
  96. // QueryInterface failure in DllGetClassObject.
  97. //
  98. // Arguments:
  99. // None.
  100. //
  101. // Return Value:
  102. // None.
  103. //
  104. // Remarks:
  105. // None.
  106. //
  107. //--
  108. //////////////////////////////////////////////////////////////////////////////
  109. CEnumClusCfgManagedResources::CEnumClusCfgManagedResources( void )
  110. : m_cRef( 1 )
  111. , m_lcid( LOCALE_NEUTRAL )
  112. {
  113. TraceFunc( "" );
  114. Assert( m_idxNextEnum == 0 );
  115. Assert( m_idxCurrentEnum == 0 );
  116. Assert( m_picccCallback == NULL );
  117. Assert( m_pIWbemServices == NULL );
  118. Assert( m_prgEnums == NULL );
  119. Assert( m_cTotalResources == 0);
  120. Assert( !m_fLoadedDevices );
  121. Assert( m_bstrNodeName == NULL );
  122. // Increment the count of components in memory so the DLL hosting this
  123. // object cannot be unloaded.
  124. InterlockedIncrement( &g_cObjects );
  125. TraceFuncExit();
  126. } //*** CEnumClusCfgManagedResources::CEnumClusCfgManagedResources
  127. //////////////////////////////////////////////////////////////////////////////
  128. //++
  129. //
  130. // CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources
  131. //
  132. // Description:
  133. // Desstructor of the CEnumClusCfgManagedResources class.
  134. //
  135. // Arguments:
  136. // None.
  137. //
  138. // Return Value:
  139. // None.
  140. //
  141. // Remarks:
  142. // None.
  143. //
  144. //--
  145. //////////////////////////////////////////////////////////////////////////////
  146. CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources( void )
  147. {
  148. TraceFunc( "" );
  149. ULONG idx;
  150. if ( m_pIWbemServices != NULL )
  151. {
  152. m_pIWbemServices->Release();
  153. } // if:
  154. if ( m_picccCallback != NULL )
  155. {
  156. m_picccCallback->Release();
  157. } // if:
  158. for ( idx = 0; idx < m_idxNextEnum; idx++ )
  159. {
  160. Assert( (m_prgEnums[ idx ]).punk != NULL );
  161. (m_prgEnums[ idx ]).punk->Release();
  162. TraceSysFreeString( (m_prgEnums[ idx ]).bstrComponentName );
  163. } // for: each enum in the array...
  164. TraceFree( m_prgEnums );
  165. TraceSysFreeString( m_bstrNodeName );
  166. // There's going to be one less component in memory. Decrement component count.
  167. InterlockedDecrement( &g_cObjects );
  168. TraceFuncExit();
  169. } //*** CEnumClusCfgManagedResources::~CEnumClusCfgManagedResources
  170. //*************************************************************************//
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CEnumClusCfgManagedResources -- IUknkown interface.
  173. /////////////////////////////////////////////////////////////////////////////
  174. //////////////////////////////////////////////////////////////////////////////
  175. //++
  176. //
  177. // CEnumClusCfgManagedResources::AddRef
  178. //
  179. // Description:
  180. // Increment the reference count of this object by one.
  181. //
  182. // Arguments:
  183. // None.
  184. //
  185. // Return Value:
  186. // The new reference count.
  187. //
  188. // Remarks:
  189. // None.
  190. //
  191. //--
  192. //////////////////////////////////////////////////////////////////////////////
  193. STDMETHODIMP_( ULONG )
  194. CEnumClusCfgManagedResources::AddRef( void )
  195. {
  196. TraceFunc( "[IUnknown]" );
  197. InterlockedIncrement( &m_cRef );
  198. CRETURN( m_cRef );
  199. } //*** CEnumClusCfgManagedResources::AddRef
  200. //////////////////////////////////////////////////////////////////////////////
  201. //++
  202. //
  203. // CEnumClusCfgManagedResources::Release
  204. //
  205. // Description:
  206. // Decrement the reference count of this object by one.
  207. //
  208. // Arguments:
  209. // None.
  210. //
  211. // Return Value:
  212. // The new reference count.
  213. //
  214. // Remarks:
  215. // None.
  216. //
  217. //--
  218. //////////////////////////////////////////////////////////////////////////////
  219. STDMETHODIMP_( ULONG )
  220. CEnumClusCfgManagedResources::Release( void )
  221. {
  222. TraceFunc( "[IUnknown]" );
  223. LONG cRef;
  224. cRef = InterlockedDecrement( &m_cRef );
  225. if ( cRef == 0 )
  226. {
  227. TraceDo( delete this );
  228. } // if: reference count equal to zero
  229. CRETURN( cRef );
  230. } //*** CEnumClusCfgManagedResources::Release
  231. //////////////////////////////////////////////////////////////////////////////
  232. //++
  233. //
  234. // CEnumClusCfgManagedResources::QueryInterface
  235. //
  236. // Description:
  237. // Query this object for the passed in interface.
  238. //
  239. // Arguments:
  240. // riidIn
  241. // Id of interface requested.
  242. //
  243. // ppvOut
  244. // Pointer to the requested interface.
  245. //
  246. // Return Value:
  247. // S_OK
  248. // If the interface is available on this object.
  249. //
  250. // E_NOINTERFACE
  251. // If the interface is not available.
  252. //
  253. // E_POINTER
  254. // ppvOut was NULL.
  255. //
  256. // Remarks:
  257. // None.
  258. //
  259. //--
  260. //////////////////////////////////////////////////////////////////////////////
  261. STDMETHODIMP
  262. CEnumClusCfgManagedResources::QueryInterface(
  263. REFIID riidIn
  264. , void ** ppvOut
  265. )
  266. {
  267. TraceQIFunc( riidIn, ppvOut );
  268. HRESULT hr = S_OK;
  269. //
  270. // Validate arguments.
  271. //
  272. Assert( ppvOut != NULL );
  273. if ( ppvOut == NULL )
  274. {
  275. hr = THR( E_POINTER );
  276. goto Cleanup;
  277. }
  278. //
  279. // Handle known interfaces.
  280. //
  281. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  282. {
  283. *ppvOut = static_cast< IEnumClusCfgManagedResources * >( this );
  284. } // if: IUnknown
  285. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgManagedResources ) )
  286. {
  287. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgManagedResources, this, 0 );
  288. } // else if: IEnumClusCfgManagedResources
  289. else if ( IsEqualIID( riidIn, IID_IClusCfgWbemServices ) )
  290. {
  291. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  292. } // else if: IClusCfgWbemServices
  293. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  294. {
  295. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  296. } // else if: IClusCfgInitialize
  297. else
  298. {
  299. *ppvOut = NULL;
  300. hr = E_NOINTERFACE;
  301. }
  302. //
  303. // Add a reference to the interface if successful.
  304. //
  305. if ( SUCCEEDED( hr ) )
  306. {
  307. ((IUnknown *) *ppvOut)->AddRef();
  308. } // if: success
  309. Cleanup:
  310. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  311. } //*** CEnumClusCfgManagedResources::QueryInterface
  312. //*************************************************************************//
  313. /////////////////////////////////////////////////////////////////////////////
  314. // CEnumClusCfgManagedResources -- IClusCfgWbemServices interface.
  315. /////////////////////////////////////////////////////////////////////////////
  316. //////////////////////////////////////////////////////////////////////////////
  317. //++
  318. //
  319. // CEnumClusCfgManagedResources::SetWbemServices
  320. //
  321. // Description:
  322. // Set the WBEM services provider.
  323. //
  324. // Arguments:
  325. // IN IWbemServices pIWbemServicesIn
  326. //
  327. // Return Value:
  328. // S_OK
  329. // Success
  330. //
  331. // E_POINTER
  332. // The pIWbemServicesIn param is NULL.
  333. //
  334. // Remarks:
  335. // None.
  336. //
  337. //--
  338. //////////////////////////////////////////////////////////////////////////////
  339. STDMETHODIMP
  340. CEnumClusCfgManagedResources::SetWbemServices( IWbemServices * pIWbemServicesIn )
  341. {
  342. TraceFunc( "[IClusCfgWbemServices]" );
  343. HRESULT hr = S_OK;
  344. if ( pIWbemServicesIn == NULL )
  345. {
  346. hr = THR( E_POINTER );
  347. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Enum_Resources, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  348. goto Cleanup;
  349. } // if:
  350. m_pIWbemServices = pIWbemServicesIn;
  351. m_pIWbemServices->AddRef();
  352. Cleanup:
  353. HRETURN( hr );
  354. } //*** CEnumClusCfgManagedResources::SetWbemServices
  355. //*************************************************************************//
  356. /////////////////////////////////////////////////////////////////////////////
  357. // CEnumClusCfgManagedResources -- IClusCfgInitialize interface.
  358. /////////////////////////////////////////////////////////////////////////////
  359. //////////////////////////////////////////////////////////////////////////////
  360. //++
  361. //
  362. // CEnumClusCfgManagedResources::Initialize
  363. //
  364. // Description:
  365. // Initialize this component.
  366. //
  367. // Arguments:
  368. // IN IUknown * punkCallbackIn
  369. //
  370. // IN LCID lcidIn
  371. //
  372. // Return Value:
  373. // S_OK
  374. // Success
  375. //
  376. // Remarks:
  377. // None.
  378. //
  379. //--
  380. //////////////////////////////////////////////////////////////////////////////
  381. STDMETHODIMP
  382. CEnumClusCfgManagedResources::Initialize(
  383. IUnknown * punkCallbackIn,
  384. LCID lcidIn
  385. )
  386. {
  387. TraceFunc( "[IClusCfgInitialize]" );
  388. Assert( m_picccCallback == NULL );
  389. HRESULT hr = S_OK;
  390. m_lcid = lcidIn;
  391. if ( punkCallbackIn == NULL )
  392. {
  393. hr = THR( E_POINTER );
  394. goto Cleanup;
  395. } // if:
  396. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  397. Cleanup:
  398. HRETURN( hr );
  399. } //*** CEnumClusCfgManagedResources::Initialize
  400. //*************************************************************************//
  401. /////////////////////////////////////////////////////////////////////////////
  402. // CEnumClusCfgManagedResources -- IEnumClusCfgManagedResources interface.
  403. /////////////////////////////////////////////////////////////////////////////
  404. //////////////////////////////////////////////////////////////////////////////
  405. //++
  406. //
  407. // CEnumClusCfgManagedResources::Next
  408. //
  409. // Description:
  410. //
  411. // Arguments:
  412. //
  413. // Return Value:
  414. //
  415. // Remarks:
  416. // None.
  417. //
  418. //--
  419. //////////////////////////////////////////////////////////////////////////////
  420. STDMETHODIMP
  421. CEnumClusCfgManagedResources::Next(
  422. ULONG cNumberRequestedIn
  423. , IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut
  424. , ULONG * pcNumberFetchedOut
  425. )
  426. {
  427. TraceFunc( "[IEnumClusCfgManagedResources]" );
  428. Assert( rgpManagedResourceInfoOut != NULL );
  429. Assert( ( cNumberRequestedIn <= 1 ) || ( pcNumberFetchedOut != NULL ) );
  430. HRESULT hr;
  431. ULONG cFetched = 0;
  432. if ( rgpManagedResourceInfoOut == NULL )
  433. {
  434. hr = THR( E_POINTER );
  435. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_Resources, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  436. goto Cleanup;
  437. } // if:
  438. //
  439. // pcNumberFetchedOut can only be NULL when the number requested is 1.
  440. //
  441. if ( ( pcNumberFetchedOut == NULL )
  442. && ( cNumberRequestedIn > 1 ) )
  443. {
  444. hr = THR( E_INVALIDARG );
  445. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_Resources, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  446. goto Cleanup;
  447. } // if:
  448. if ( m_fLoadedDevices == FALSE )
  449. {
  450. hr = THR( HrLoadEnum() );
  451. if ( FAILED( hr ) )
  452. {
  453. goto Cleanup;
  454. } // if:
  455. } // if:
  456. hr = STHR( HrDoNext( cNumberRequestedIn, rgpManagedResourceInfoOut, &cFetched ) );
  457. if ( FAILED( hr ) )
  458. {
  459. goto Cleanup;
  460. } // if:
  461. //
  462. // Do they want the out count?
  463. //
  464. if ( pcNumberFetchedOut != NULL )
  465. {
  466. *pcNumberFetchedOut = cFetched;
  467. } // if:
  468. Cleanup:
  469. HRETURN( hr );
  470. } //*** CEnumClusCfgManagedResources::Next
  471. //////////////////////////////////////////////////////////////////////////////
  472. //++
  473. //
  474. // CEnumClusCfgManagedResources::Skip
  475. //
  476. // Description:
  477. //
  478. // Arguments:
  479. //
  480. // Return Value:
  481. //
  482. // Remarks:
  483. // None.
  484. //
  485. //--
  486. //////////////////////////////////////////////////////////////////////////////
  487. STDMETHODIMP
  488. CEnumClusCfgManagedResources::Skip( ULONG cNumberToSkipIn )
  489. {
  490. TraceFunc( "[IEnumClusCfgManagedResources]" );
  491. HRESULT hr = S_FALSE;
  492. if ( cNumberToSkipIn > 0 )
  493. {
  494. hr = STHR( HrDoSkip( cNumberToSkipIn ) );
  495. } // if:
  496. HRETURN( hr );
  497. } //*** CEnumClusCfgManagedResources::Skip
  498. //////////////////////////////////////////////////////////////////////////////
  499. //++
  500. //
  501. // CEnumClusCfgManagedResources::Reset
  502. //
  503. // Description:
  504. //
  505. // Arguments:
  506. //
  507. // Return Value:
  508. //
  509. // Remarks:
  510. // None.
  511. //
  512. //--
  513. //////////////////////////////////////////////////////////////////////////////
  514. STDMETHODIMP
  515. CEnumClusCfgManagedResources::Reset( void )
  516. {
  517. TraceFunc( "[IEnumClusCfgManagedResources]" );
  518. HRESULT hr;
  519. hr = STHR( HrDoReset() );
  520. HRETURN( hr );
  521. } //*** CEnumClusCfgManagedResources::Reset
  522. //////////////////////////////////////////////////////////////////////////////
  523. //++
  524. //
  525. // CEnumClusCfgManagedResources::Clone
  526. //
  527. // Description:
  528. //
  529. // Arguments:
  530. //
  531. // Return Value:
  532. //
  533. // Remarks:
  534. // None.
  535. //
  536. //--
  537. //////////////////////////////////////////////////////////////////////////////
  538. STDMETHODIMP
  539. CEnumClusCfgManagedResources::Clone(
  540. IEnumClusCfgManagedResources ** ppEnumClusCfgManagedResourcesOut
  541. )
  542. {
  543. TraceFunc( "[IEnumClusCfgManagedResources]" );
  544. HRESULT hr = S_OK;
  545. if ( ppEnumClusCfgManagedResourcesOut == NULL )
  546. {
  547. hr = THR( E_POINTER );
  548. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_Resources, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  549. goto Cleanup;
  550. } // else:
  551. hr = THR( HrDoClone( ppEnumClusCfgManagedResourcesOut ) );
  552. Cleanup:
  553. HRETURN( hr );
  554. } //*** CEnumClusCfgManagedResources::Clone
  555. //////////////////////////////////////////////////////////////////////////////
  556. //++
  557. //
  558. // CEnumClusCfgManagedResources::Count
  559. //
  560. // Description:
  561. //
  562. // Arguments:
  563. //
  564. // Return Value:
  565. //
  566. // Remarks:
  567. // None.
  568. //
  569. //--
  570. //////////////////////////////////////////////////////////////////////////////
  571. STDMETHODIMP
  572. CEnumClusCfgManagedResources::Count( DWORD * pnCountOut )
  573. {
  574. TraceFunc( "[IEnumClusCfgManagedResources]" );
  575. HRESULT hr = S_OK;
  576. if ( pnCountOut == NULL )
  577. {
  578. hr = THR( E_POINTER );
  579. goto Cleanup;
  580. } // if:
  581. if ( !m_fLoadedDevices )
  582. {
  583. hr = THR( HrLoadEnum() );
  584. if ( FAILED( hr ) )
  585. {
  586. goto Cleanup;
  587. } // if:
  588. } // if:
  589. *pnCountOut = m_cTotalResources;
  590. Cleanup:
  591. HRETURN( hr );
  592. } //*** CEnumClusCfgManagedResources::Count
  593. //*************************************************************************//
  594. /////////////////////////////////////////////////////////////////////////////
  595. // CEnumClusCfgManagedResources class -- Private Methods.
  596. /////////////////////////////////////////////////////////////////////////////
  597. //////////////////////////////////////////////////////////////////////////////
  598. //++
  599. //
  600. // CEnumClusCfgManagedResources::HrInit
  601. //
  602. // Description:
  603. // Initialize this component.
  604. //
  605. // Arguments:
  606. // None.
  607. //
  608. // Return Value:
  609. // S_OK - Success.
  610. // Other HRESULTs.
  611. //
  612. //--
  613. //////////////////////////////////////////////////////////////////////////////
  614. HRESULT
  615. CEnumClusCfgManagedResources::HrInit( void )
  616. {
  617. TraceFunc( "" );
  618. HRESULT hr = S_OK;
  619. // IUnknown
  620. Assert( m_cRef == 1 );
  621. hr = THR( HrGetComputerName(
  622. ComputerNameDnsHostname
  623. , &m_bstrNodeName
  624. , TRUE // fBestEffortIn
  625. ) );
  626. if ( FAILED( hr ) )
  627. {
  628. goto Cleanup;
  629. } // if:
  630. Cleanup:
  631. HRETURN( hr );
  632. } //*** CEnumClusCfgManagedResources::HrInit
  633. //////////////////////////////////////////////////////////////////////////////
  634. //++
  635. //
  636. // CEnumClusCfgManagedResources::HrLoadEnum
  637. //
  638. // Description:
  639. // Load this enumerator.
  640. //
  641. // Arguments:
  642. // None.
  643. //
  644. // Return Value:
  645. //
  646. //
  647. // Remarks:
  648. // None.
  649. //
  650. //--
  651. //////////////////////////////////////////////////////////////////////////////
  652. HRESULT
  653. CEnumClusCfgManagedResources::HrLoadEnum( void )
  654. {
  655. TraceFunc( "" );
  656. Assert( m_prgEnums == NULL );
  657. HRESULT hr = S_OK;
  658. IUnknown * punk = NULL;
  659. ICatInformation * pici = NULL;
  660. CATID rgCatIds[ 1 ];
  661. IEnumCLSID * pieclsids = NULL;
  662. IEnumClusCfgManagedResources * pieccmr = NULL;
  663. CLSID clsid;
  664. ULONG cFetched;
  665. WCHAR szGUID[ 64 ];
  666. int cch;
  667. BSTR bstrComponentName = NULL;
  668. rgCatIds[ 0 ] = CATID_EnumClusCfgManagedResources;
  669. hr = THR( CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatInformation, (void **) &pici ) );
  670. if ( FAILED( hr ) )
  671. {
  672. goto Cleanup;
  673. }
  674. hr = THR( pici->EnumClassesOfCategories( 1, rgCatIds, 0, NULL, &pieclsids ) );
  675. if ( FAILED( hr ) )
  676. {
  677. goto Cleanup;
  678. } // if:
  679. for ( ; ; )
  680. {
  681. //
  682. // Cleanup.
  683. //
  684. if ( punk != NULL )
  685. {
  686. punk->Release();
  687. punk = NULL;
  688. } // if:
  689. TraceSysFreeString( bstrComponentName );
  690. bstrComponentName = NULL;
  691. hr = STHR( pieclsids->Next( 1, &clsid, &cFetched ) );
  692. if ( FAILED( hr ) )
  693. {
  694. goto Cleanup;
  695. } // if:
  696. //
  697. // When hr is S_FALSE and the count is 0 then the enum is really
  698. // at the end.
  699. //
  700. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  701. {
  702. hr = S_OK;
  703. break;
  704. } // if:
  705. //
  706. // Create a GUID string for logging purposes...
  707. //
  708. cch = StringFromGUID2( clsid, szGUID, RTL_NUMBER_OF( szGUID ) );
  709. Assert( cch > 0 ); // 64 chars should always hold a guid!
  710. //
  711. // Get the best name we have available for the COM component. If for
  712. // any reason we cannot get the name then make one up and continue.
  713. //
  714. hr = THR( HrGetDefaultComponentNameFromRegistry( &clsid, &bstrComponentName ) );
  715. if ( FAILED( hr ) )
  716. {
  717. bstrComponentName = TraceSysAllocString( L"<Unknown> component" );
  718. if ( bstrComponentName == NULL )
  719. {
  720. hr = THR( E_OUTOFMEMORY );
  721. goto Cleanup;
  722. } // if:
  723. } // if:
  724. //
  725. // If we cannot create the component then log the error and continue. We should load as many components as we can.
  726. //
  727. hr = THR( HrCoCreateInternalInstance( clsid, NULL, CLSCTX_SERVER, IID_IEnumClusCfgManagedResources, (void **) &pieccmr ) );
  728. if ( FAILED( hr ) )
  729. {
  730. LOG_STATUS_REPORT_STRING_MINOR2( TASKID_Minor_MREnum_Cannot_Create_Component, L"Could not create component %1!ws! %2!ws!.", bstrComponentName, szGUID, hr );
  731. hr = S_OK;
  732. continue;
  733. } // if:
  734. //
  735. // If we cannot QI the component then log the error and continue. We should load as many components as we can.
  736. //
  737. hr = THR( pieccmr->TypeSafeQI( IUnknown, &punk ) );
  738. if ( FAILED( hr ) )
  739. {
  740. LOG_STATUS_REPORT_STRING_MINOR2( TASKID_Minor_MREnum_Cannot_QI_Component_For_Punk, L"Could not QI for IUnknown on component %1!ws! %2!ws!.", bstrComponentName, szGUID, hr );
  741. hr = S_OK;
  742. continue;
  743. } // if:
  744. punk = TraceInterface( L"IEnumClusCfgManagedResources", IUnknown, punk, 1 );
  745. pieccmr->Release();
  746. pieccmr = NULL;
  747. //
  748. // If this fails then simply skip it and move on...
  749. //
  750. hr = HrInitializeAndSaveEnum( punk, &clsid, bstrComponentName );
  751. if ( FAILED( hr ) )
  752. {
  753. LOG_STATUS_REPORT_STRING_MINOR2( TASKID_Minor_MREnum_Cannot_Save_Provider, L"Could not save enumerator component %1!ws! %2!ws!.", bstrComponentName, szGUID, hr );
  754. hr = S_OK;
  755. continue;
  756. } // if:
  757. if ( hr == S_OK )
  758. {
  759. m_fLoadedDevices = TRUE; // there is at least one provider loaded.
  760. } // if:
  761. } // for: each CLSID that implements our CATID...
  762. hr = STHR( HrLoadUnknownQuorumProvider() );
  763. if ( FAILED( hr ) )
  764. {
  765. goto Cleanup;
  766. } // if:
  767. Cleanup:
  768. if ( pieclsids != NULL )
  769. {
  770. pieclsids->Release();
  771. } // if:
  772. if ( pici != NULL )
  773. {
  774. pici->Release();
  775. } // if:
  776. if ( pieccmr != NULL )
  777. {
  778. pieccmr->Release();
  779. } // if:
  780. if ( punk != NULL )
  781. {
  782. punk->Release();
  783. } // if:
  784. TraceSysFreeString( bstrComponentName );
  785. HRETURN( hr );
  786. } //*** CEnumClusCfgManagedResources::HrLoadEnum
  787. //////////////////////////////////////////////////////////////////////////////
  788. //++
  789. //
  790. // CEnumClusCfgManagedResources::HrDoNext
  791. //
  792. // Description:
  793. // Gets the required number of elements from the contained physical disk
  794. // and optional 3rd party device enumerations.
  795. //
  796. // Arguments:
  797. //
  798. // Return Value:
  799. //
  800. // Remarks:
  801. // None.
  802. //
  803. //--
  804. //////////////////////////////////////////////////////////////////////////////
  805. HRESULT
  806. CEnumClusCfgManagedResources::HrDoNext(
  807. ULONG cNumberRequestedIn
  808. , IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut
  809. , ULONG * pcNumberFetchedOut
  810. )
  811. {
  812. TraceFunc( "" );
  813. Assert( rgpManagedResourceInfoOut != NULL );
  814. Assert( pcNumberFetchedOut != NULL );
  815. Assert( m_prgEnums != NULL );
  816. HRESULT hr = S_FALSE;
  817. IEnumClusCfgManagedResources * peccsd = NULL;
  818. ULONG cRequested = cNumberRequestedIn;
  819. ULONG cFetched = 0;
  820. ULONG cTotal = 0;
  821. IClusCfgManagedResourceInfo ** ppccmriTemp = rgpManagedResourceInfoOut;
  822. int cch;
  823. WCHAR szGUID[ 64 ];
  824. //
  825. // Call each enumerator in the list trying to get the number of requested
  826. // items. Note that we may call the same enumerator more than once in
  827. // this loop. The second call is to ensure that we are really at the
  828. // end of the enumerator.
  829. //
  830. LOG_STATUS_REPORT_STRING3( L"[SRV] Enumerating resources. Total Requested:%1!d!; Current enum index:%2!d!; Total Enums:%3!d!.", cNumberRequestedIn, m_idxCurrentEnum, m_idxNextEnum, hr );
  831. while ( m_idxCurrentEnum < m_idxNextEnum )
  832. {
  833. //
  834. // Cleanup.
  835. //
  836. if ( peccsd != NULL )
  837. {
  838. peccsd->Release();
  839. peccsd = NULL;
  840. } // if:
  841. cch = StringFromGUID2( (m_prgEnums[ m_idxCurrentEnum ]).clsid, szGUID, RTL_NUMBER_OF( szGUID ) );
  842. Assert( cch > 0 ); // 64 chars should always hold a guid!
  843. Assert( (m_prgEnums[ m_idxCurrentEnum ]).punk != NULL );
  844. hr = THR( (m_prgEnums[ m_idxCurrentEnum ]).punk->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  845. if ( FAILED( hr ) )
  846. {
  847. HRESULT hrTemp;
  848. //
  849. // Convert this into a warning in the UI...
  850. //
  851. hrTemp = MAKE_HRESULT( SEVERITY_SUCCESS, HRESULT_FACILITY( hr ), HRESULT_CODE( hr ) );
  852. //
  853. // If we cannot QI for the enum then move on to the next one.
  854. //
  855. STATUS_REPORT_STRING2_REF(
  856. TASKID_Major_Find_Devices
  857. , TASKID_Minor_Enum_Enum_QI_Failed
  858. , IDS_WARNING_SKIPPING_ENUM
  859. , (m_prgEnums[ m_idxCurrentEnum ]).bstrComponentName
  860. , szGUID
  861. , IDS_WARNING_SKIPPING_ENUM
  862. , hrTemp
  863. );
  864. m_idxCurrentEnum++;
  865. continue;
  866. } // if:
  867. hr = STHR( peccsd->Next( cRequested, ppccmriTemp, &cFetched ) );
  868. if ( FAILED( hr ) )
  869. {
  870. HRESULT hrTemp;
  871. //
  872. // Convert this into a warning in the UI...
  873. //
  874. hrTemp = MAKE_HRESULT( SEVERITY_SUCCESS, HRESULT_FACILITY( hr ), HRESULT_CODE( hr ) );
  875. //
  876. // If this enumerator fails for anyreason then we should skip it
  877. // and move on to the next one.
  878. //
  879. STATUS_REPORT_STRING2_REF(
  880. TASKID_Major_Find_Devices
  881. , TASKID_Minor_Enum_Enum_Next_Failed
  882. , IDS_WARNING_SKIPPING_ENUM
  883. , (m_prgEnums[ m_idxCurrentEnum ]).bstrComponentName
  884. , szGUID
  885. , IDS_WARNING_SKIPPING_ENUM
  886. , hrTemp
  887. );
  888. m_idxCurrentEnum++;
  889. continue;
  890. } // if:
  891. else if ( hr == S_OK )
  892. {
  893. cTotal += cFetched;
  894. //
  895. // We can only return S_OK if the number of elements returned is equal to
  896. // the number of elements requested. If the number request is greater than
  897. // the number returned then we must return S_FALSE.
  898. //
  899. Assert( cNumberRequestedIn == cTotal );
  900. *pcNumberFetchedOut = cTotal;
  901. break;
  902. } // else if: hr == S_OK
  903. else if ( hr == S_FALSE )
  904. {
  905. //
  906. // The only time that we can be certain that an enumerator is
  907. // empty is to get S_FALSE and no elements returned. Now that
  908. // the current enumerator empty move up to the next one in the
  909. // list.
  910. //
  911. if ( cFetched == 0 )
  912. {
  913. m_idxCurrentEnum++;
  914. continue;
  915. } // if:
  916. //
  917. // Update the totals...
  918. //
  919. cTotal += cFetched;
  920. *pcNumberFetchedOut = cTotal;
  921. cRequested -= cFetched;
  922. //
  923. // If we got some items and still got S_FALSE then we have to
  924. // retry the current enumerator.
  925. //
  926. if ( cRequested > 0 )
  927. {
  928. ppccmriTemp += cFetched;
  929. continue;
  930. } // if: Safety check... Ensure that we still need more elements...
  931. else
  932. {
  933. //
  934. // We should not have decremented requested items below zero!
  935. //
  936. hr = S_FALSE;
  937. LOG_STATUS_REPORT_MINOR( TASKID_Minor_MREnum_Negative_Item_Count, L"The managed resources enumerator tried to return more items than asked for.", hr );
  938. goto Cleanup;
  939. } // else: Should not get here...
  940. } // if: hr == S_FALSE
  941. else
  942. {
  943. //
  944. // Should not get here as we are in an unknown state...
  945. //
  946. LOG_STATUS_REPORT_MINOR( TASKID_Minor_MREnum_Unknown_State, L"The managed resources enumerator encountered an unknown state.", hr );
  947. goto Cleanup;
  948. } // else: unexpected hresult...
  949. } // while: more enumerators in the list
  950. //
  951. // If we haven't honored the complete request then we must return
  952. // S_FALSE;
  953. //
  954. if ( *pcNumberFetchedOut < cNumberRequestedIn )
  955. {
  956. hr = S_FALSE;
  957. } // if:
  958. Cleanup:
  959. if ( peccsd != NULL )
  960. {
  961. peccsd->Release();
  962. } // if:
  963. HRETURN( hr );
  964. } //*** CEnumClusCfgManagedResources::HrDoNext
  965. //////////////////////////////////////////////////////////////////////////////
  966. //++
  967. //
  968. // CEnumClusCfgManagedResources::HrDoSkip
  969. //
  970. // Description:
  971. // Skips the required number of elements in the contained physical disk
  972. // and optional 3rd party device enumerations.
  973. //
  974. // Arguments:
  975. //
  976. // Return Value:
  977. //
  978. // Remarks:
  979. // None.
  980. //
  981. //--
  982. //////////////////////////////////////////////////////////////////////////////
  983. HRESULT
  984. CEnumClusCfgManagedResources::HrDoSkip(
  985. ULONG cNumberToSkipIn
  986. )
  987. {
  988. TraceFunc( "" );
  989. Assert( m_prgEnums != NULL );
  990. HRESULT hr = S_FALSE;
  991. IEnumClusCfgManagedResources * peccsd = NULL;
  992. ULONG cSkipped = 0;
  993. for ( ; m_idxCurrentEnum < m_idxNextEnum; )
  994. {
  995. hr = THR( (m_prgEnums[ m_idxCurrentEnum ]).punk->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  996. if ( FAILED( hr ) )
  997. {
  998. goto Cleanup;
  999. } // if:
  1000. do
  1001. {
  1002. hr = STHR( peccsd->Skip( 1 ) );
  1003. if ( FAILED( hr ) )
  1004. {
  1005. goto Cleanup;
  1006. } // if:
  1007. if ( hr == S_FALSE )
  1008. {
  1009. m_idxCurrentEnum++;
  1010. break;
  1011. } // if:
  1012. }
  1013. while( cNumberToSkipIn >= (++cSkipped) );
  1014. peccsd->Release();
  1015. peccsd = NULL;
  1016. if ( FAILED( hr ) )
  1017. {
  1018. goto Cleanup;
  1019. } // if:
  1020. if ( cNumberToSkipIn == cSkipped )
  1021. {
  1022. break;
  1023. } // if:
  1024. } // for:
  1025. Cleanup:
  1026. if ( peccsd != NULL )
  1027. {
  1028. peccsd->Release();
  1029. } // if:
  1030. HRETURN( hr );
  1031. } //*** CEnumClusCfgManagedResources::HrDoSkip
  1032. //////////////////////////////////////////////////////////////////////////////
  1033. //++
  1034. //
  1035. // CEnumClusCfgManagedResources::HrDoReset
  1036. //
  1037. // Description:
  1038. // Resets the elements in the contained physical disk and optional 3rd
  1039. // party device enumerations.
  1040. //
  1041. // Arguments:
  1042. //
  1043. // Return Value:
  1044. //
  1045. // Remarks:
  1046. // None.
  1047. //
  1048. //--
  1049. //////////////////////////////////////////////////////////////////////////////
  1050. HRESULT
  1051. CEnumClusCfgManagedResources::HrDoReset( void )
  1052. {
  1053. TraceFunc( "" );
  1054. HRESULT hr = S_FALSE;
  1055. IEnumClusCfgManagedResources * peccsd;
  1056. ULONG idx;
  1057. m_idxCurrentEnum = 0;
  1058. for ( idx = m_idxCurrentEnum; idx < m_idxNextEnum; idx++ )
  1059. {
  1060. Assert( m_prgEnums != NULL );
  1061. hr = THR( (m_prgEnums[ idx ]).punk->TypeSafeQI( IEnumClusCfgManagedResources, &peccsd ) );
  1062. if ( FAILED( hr ) )
  1063. {
  1064. break;
  1065. } // if:
  1066. hr = STHR( peccsd->Reset() );
  1067. peccsd->Release();
  1068. if ( FAILED( hr ) )
  1069. {
  1070. break;
  1071. } // if:
  1072. } // for:
  1073. HRETURN( hr );
  1074. } //*** CEnumClusCfgManagedResources::HrDoReset
  1075. //////////////////////////////////////////////////////////////////////////////
  1076. //++
  1077. //
  1078. // CEnumClusCfgManagedResources::HrDoClone
  1079. //
  1080. // Description:
  1081. // Clones the elements in the contained physical disk and optional 3rd
  1082. // party device enumerations.
  1083. //
  1084. // Arguments:
  1085. //
  1086. // Return Value:
  1087. //
  1088. // Remarks:
  1089. // None.
  1090. //
  1091. //--
  1092. //////////////////////////////////////////////////////////////////////////////
  1093. HRESULT
  1094. CEnumClusCfgManagedResources::HrDoClone(
  1095. IEnumClusCfgManagedResources ** ppEnumClusCfgManagedResourcesOut
  1096. )
  1097. {
  1098. TraceFunc( "" );
  1099. HRESULT hr = THR( E_NOTIMPL );
  1100. HRETURN( hr );
  1101. } //*** CEnumClusCfgManagedResources::HrDoClone
  1102. /////////////////////////////////////////////////////////////////////////////
  1103. //++
  1104. //
  1105. // CEnumClusCfgManagedResources:HrAddToEnumsArray
  1106. //
  1107. // Description:
  1108. // Add the passed in punk to the array of punks that holds the enums.
  1109. //
  1110. // Arguments:
  1111. //
  1112. //
  1113. // Return Value:
  1114. // S_OK
  1115. // Success
  1116. //
  1117. // E_OUTOFMEMORY
  1118. // Couldn't allocate memeory.
  1119. //
  1120. // Remarks:
  1121. // None.
  1122. //
  1123. //--
  1124. //////////////////////////////////////////////////////////////////////////////
  1125. HRESULT
  1126. CEnumClusCfgManagedResources::HrAddToEnumsArray(
  1127. IUnknown * punkIn
  1128. , CLSID * pclsidIn
  1129. , BSTR bstrComponentNameIn
  1130. )
  1131. {
  1132. TraceFunc( "" );
  1133. Assert( punkIn != NULL );
  1134. Assert( pclsidIn != NULL );
  1135. Assert( bstrComponentNameIn != NULL );
  1136. HRESULT hr = S_OK;
  1137. SEnumInfo * prgEnums = NULL;
  1138. IEnumClusCfgManagedResources * pieccmr = NULL;
  1139. DWORD nAmountToAdd = 0;
  1140. hr = punkIn->TypeSafeQI( IEnumClusCfgManagedResources, &pieccmr );
  1141. if ( FAILED( hr ) )
  1142. {
  1143. goto Cleanup;
  1144. } // if:
  1145. hr = pieccmr->Count( &nAmountToAdd );
  1146. if ( FAILED( hr ) )
  1147. {
  1148. WCHAR szGUID[ 64 ];
  1149. int cch;
  1150. HRESULT hrTemp;
  1151. //
  1152. // Convert this into a warning in the UI...
  1153. //
  1154. hrTemp = MAKE_HRESULT( SEVERITY_SUCCESS, HRESULT_FACILITY( hr ), HRESULT_CODE( hr ) );
  1155. cch = StringFromGUID2( *pclsidIn, szGUID, RTL_NUMBER_OF( szGUID ) );
  1156. Assert( cch > 0 ); // 64 chars should always hold a guid!
  1157. STATUS_REPORT_STRING2_REF(
  1158. TASKID_Major_Find_Devices
  1159. , TASKID_Minor_Enum_Enum_Count_Failed
  1160. , IDS_WARNING_SKIPPING_ENUM
  1161. , bstrComponentNameIn
  1162. , szGUID
  1163. , IDS_WARNING_SKIPPING_ENUM
  1164. , hrTemp
  1165. );
  1166. goto Cleanup;
  1167. } // if:
  1168. prgEnums = (SEnumInfo *) TraceReAlloc( m_prgEnums, sizeof( SEnumInfo ) * ( m_idxNextEnum + 1 ), HEAP_ZERO_MEMORY );
  1169. if ( prgEnums == NULL )
  1170. {
  1171. hr = THR( E_OUTOFMEMORY );
  1172. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrAddToEnumsArray, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1173. goto Cleanup;
  1174. } // if:
  1175. m_prgEnums = prgEnums;
  1176. //
  1177. // Fill in the newly allocated struct.
  1178. //
  1179. (m_prgEnums[ m_idxNextEnum ]).punk = punkIn;
  1180. (m_prgEnums[ m_idxNextEnum ]).punk->AddRef();
  1181. CopyMemory( &((m_prgEnums[ m_idxNextEnum ]).clsid), pclsidIn, sizeof( ( m_prgEnums[ m_idxNextEnum ]).clsid ) );
  1182. //
  1183. // Capture the component name. We don't really care if this fails.
  1184. // Simply show the popup for anyone who may be watching and continue on.
  1185. //
  1186. (m_prgEnums[ m_idxNextEnum ]).bstrComponentName = TraceSysAllocString( bstrComponentNameIn );
  1187. if ( (m_prgEnums[ m_idxNextEnum ]).bstrComponentName == NULL )
  1188. {
  1189. THR( E_OUTOFMEMORY );
  1190. } // if:
  1191. //
  1192. // Increment the enum index pointer.
  1193. //
  1194. m_idxNextEnum++;
  1195. m_cTotalResources += nAmountToAdd;
  1196. Cleanup:
  1197. if ( pieccmr != NULL )
  1198. {
  1199. pieccmr->Release();
  1200. }
  1201. HRETURN( hr );
  1202. } //*** CEnumClusCfgManagedResources::HrAddToEnumsArray
  1203. /////////////////////////////////////////////////////////////////////////////
  1204. //++
  1205. //
  1206. // CEnumClusCfgManagedResources:HrLoadUnknownQuorumProvider
  1207. //
  1208. // Description:
  1209. // Since we cannot resonable expect every 3rd party quorum vender
  1210. // to write a "provider" for their device for this setup wizard
  1211. // we need a proxy to represent that quorum device. The "unknown"
  1212. // is just such a proxy.
  1213. //
  1214. // Arguments:
  1215. // None.
  1216. //
  1217. // Return Value:
  1218. // S_OK
  1219. // Success
  1220. //
  1221. // E_OUTOFMEMORY
  1222. // Couldn't allocate memeory.
  1223. //
  1224. // Remarks:
  1225. // If this node is clustered and we do not find a device that is
  1226. // already the quorum then we need to make the "unknown" quorum
  1227. // the quorum device.
  1228. //
  1229. //--
  1230. //////////////////////////////////////////////////////////////////////////////
  1231. HRESULT
  1232. CEnumClusCfgManagedResources::HrLoadUnknownQuorumProvider( void )
  1233. {
  1234. TraceFunc( "" );
  1235. HRESULT hr = S_OK;
  1236. IUnknown * punk = NULL;
  1237. BOOL fNeedQuorum = FALSE;
  1238. BOOL fQuormIsOwnedByThisNode = FALSE;
  1239. BSTR bstrQuorumResourceName = NULL;
  1240. BSTR bstrComponentName = NULL;
  1241. hr = STHR( HrIsClusterServiceRunning() );
  1242. if ( FAILED( hr ) )
  1243. {
  1244. goto Cleanup;
  1245. } // if:
  1246. if ( hr == S_OK )
  1247. {
  1248. hr = STHR( HrIsThereAQuorumDevice() );
  1249. if ( FAILED( hr ) )
  1250. {
  1251. goto Cleanup;
  1252. } // if:
  1253. if ( hr == S_FALSE )
  1254. {
  1255. fNeedQuorum = TRUE;
  1256. } // if:
  1257. hr = THR( HrGetQuorumResourceName( &bstrQuorumResourceName, &fQuormIsOwnedByThisNode ) );
  1258. if ( FAILED( hr ) )
  1259. {
  1260. goto Cleanup;
  1261. } // if:
  1262. } // if:
  1263. //
  1264. // If there was not already a quorum, and if this node owns the quorum resource
  1265. // then we need the unknown quorum proxy to be set as default to the quorum device.
  1266. //
  1267. // If we are not running on a cluster node then both are false and the unknown
  1268. // quorum proxy will not be set by default to be the quorum.
  1269. //
  1270. hr = THR( CEnumUnknownQuorum::S_HrCreateInstance( bstrQuorumResourceName, ( fNeedQuorum && fQuormIsOwnedByThisNode ), &punk ) );
  1271. if ( FAILED( hr ) )
  1272. {
  1273. goto Cleanup;
  1274. } // if:
  1275. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_ENUM_UNKNOWN_QUORUM_COMPONENT_NAME, &bstrComponentName ) );
  1276. if ( FAILED( hr ) )
  1277. {
  1278. goto Cleanup;
  1279. } // if:
  1280. hr = THR( HrInitializeAndSaveEnum( punk, const_cast< CLSID * >( &CLSID_EnumUnknownQuorum ), bstrComponentName ) );
  1281. if ( FAILED( hr ) )
  1282. {
  1283. goto Cleanup;
  1284. } // if:
  1285. Cleanup:
  1286. if ( punk != NULL )
  1287. {
  1288. punk->Release();
  1289. } // if:
  1290. TraceSysFreeString( bstrQuorumResourceName );
  1291. TraceSysFreeString( bstrComponentName );
  1292. HRETURN( hr );
  1293. } //*** CEnumClusCfgManagedResources::HrLoadUnknownQuorumProvider
  1294. /////////////////////////////////////////////////////////////////////////////
  1295. //++
  1296. //
  1297. // CEnumClusCfgManagedResources:HrIsClusterServiceRunning
  1298. //
  1299. // Description:
  1300. // Is this node a member of a cluster and is the serice running?
  1301. //
  1302. // Arguments:
  1303. // None.
  1304. //
  1305. // Return Value:
  1306. // S_OK
  1307. // The node is clustered and the serivce is running.
  1308. //
  1309. // S_FALSE
  1310. // The node is not clustered, or the serivce is not running.
  1311. //
  1312. // Win32 Error
  1313. // something failed.
  1314. //
  1315. // Remarks:
  1316. // None.
  1317. //
  1318. //--
  1319. //////////////////////////////////////////////////////////////////////////////
  1320. HRESULT
  1321. CEnumClusCfgManagedResources::HrIsClusterServiceRunning( void )
  1322. {
  1323. TraceFunc( "" );
  1324. HRESULT hr = S_FALSE;
  1325. DWORD sc;
  1326. DWORD dwClusterState;
  1327. //
  1328. // Get the cluster state of the node.
  1329. // Ignore the case where the service does not exist so that
  1330. // EvictCleanup can do its job.
  1331. //
  1332. sc = GetNodeClusterState( NULL, &dwClusterState );
  1333. if ( ( sc != ERROR_SUCCESS ) && ( sc != ERROR_SERVICE_DOES_NOT_EXIST ) )
  1334. {
  1335. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  1336. goto Cleanup;
  1337. } // if : GetClusterState() failed
  1338. if ( dwClusterState == ClusterStateRunning )
  1339. {
  1340. hr = S_OK;
  1341. } // if:
  1342. Cleanup:
  1343. HRETURN( hr );
  1344. } //*** CEnumClusCfgManagedResources::HrIsClusterServiceRunning
  1345. /////////////////////////////////////////////////////////////////////////////
  1346. //++
  1347. //
  1348. // CEnumClusCfgManagedResources:HrIsThereAQuorumDevice
  1349. //
  1350. // Description:
  1351. // Is there a quorum device in an enum somewhere?
  1352. //
  1353. // Arguments:
  1354. // None.
  1355. //
  1356. // Return Value:
  1357. // S_OK
  1358. // There is a quorum device.
  1359. //
  1360. // S_FALSE
  1361. // There is not a quorum device.
  1362. //
  1363. // Win32 Error
  1364. // something failed.
  1365. //
  1366. // Remarks:
  1367. // None.
  1368. //
  1369. //--
  1370. //////////////////////////////////////////////////////////////////////////////
  1371. HRESULT
  1372. CEnumClusCfgManagedResources::HrIsThereAQuorumDevice( void )
  1373. {
  1374. TraceFunc( "" );
  1375. Assert( m_idxCurrentEnum == 0 );
  1376. HRESULT hr = S_OK;
  1377. IClusCfgManagedResourceInfo * piccmri = NULL;
  1378. DWORD cFetched;
  1379. bool fFoundQuorum = false;
  1380. for ( ; ; )
  1381. {
  1382. hr = STHR( Next( 1, &piccmri, &cFetched ) );
  1383. if ( FAILED( hr ) )
  1384. {
  1385. goto Cleanup;
  1386. } // if:
  1387. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  1388. {
  1389. hr = S_OK;
  1390. break;
  1391. } // if:
  1392. hr = STHR( piccmri->IsQuorumResource() );
  1393. if ( FAILED( hr ) )
  1394. {
  1395. goto Cleanup;
  1396. } // if:
  1397. if ( hr == S_OK )
  1398. {
  1399. fFoundQuorum = true;
  1400. break;
  1401. } // if:
  1402. piccmri->Release();
  1403. piccmri = NULL;
  1404. } // for:
  1405. hr = THR( Reset() );
  1406. Cleanup:
  1407. if ( piccmri != NULL )
  1408. {
  1409. piccmri->Release();
  1410. } // if:
  1411. if ( SUCCEEDED( hr ) )
  1412. {
  1413. if ( fFoundQuorum )
  1414. {
  1415. hr = S_OK;
  1416. } // if:
  1417. else
  1418. {
  1419. hr = S_FALSE;
  1420. } // else:
  1421. } // if:
  1422. HRETURN( hr );
  1423. } //*** CEnumClusCfgManagedResources::HrIsThereAQuorumDevice
  1424. /////////////////////////////////////////////////////////////////////////////
  1425. //++
  1426. //
  1427. // CEnumClusCfgManagedResources:HrInitializeAndSaveEnum
  1428. //
  1429. // Description:
  1430. // Initialize the passed in enum and add it to the array of enums.
  1431. //
  1432. // Arguments:
  1433. //
  1434. // Return Value:
  1435. // S_OK
  1436. // Success.
  1437. //
  1438. // S_FALSE
  1439. // The provider was not saved.
  1440. //
  1441. // Win32 Error
  1442. // something failed.
  1443. //
  1444. // Remarks:
  1445. // None.
  1446. //
  1447. //--
  1448. //////////////////////////////////////////////////////////////////////////////
  1449. HRESULT
  1450. CEnumClusCfgManagedResources::HrInitializeAndSaveEnum(
  1451. IUnknown * punkIn
  1452. , CLSID * pclsidIn
  1453. , BSTR bstrComponentNameIn
  1454. )
  1455. {
  1456. TraceFunc( "" );
  1457. Assert( punkIn != NULL );
  1458. Assert( pclsidIn != NULL );
  1459. Assert( bstrComponentNameIn != NULL );
  1460. HRESULT hr = S_OK;
  1461. //
  1462. // KB: 13-JUN-2000 GalenB
  1463. //
  1464. // If S_FALSE is returned don't add this to the array. S_FALSE
  1465. // indicates that this enumerator should not be run now.
  1466. //
  1467. hr = STHR( HrSetInitialize( punkIn, m_picccCallback, m_lcid ) );
  1468. if ( FAILED( hr ) )
  1469. {
  1470. goto Cleanup;
  1471. } // if:
  1472. if ( hr == S_FALSE )
  1473. {
  1474. goto Cleanup;
  1475. } // if:
  1476. hr = HrSetWbemServices( punkIn, m_pIWbemServices );
  1477. if ( FAILED( hr ) )
  1478. {
  1479. goto Cleanup;
  1480. } // if:
  1481. hr = THR( HrAddToEnumsArray( punkIn, pclsidIn, bstrComponentNameIn ) );
  1482. if ( FAILED( hr ) )
  1483. {
  1484. goto Cleanup;
  1485. } // if:
  1486. Cleanup:
  1487. HRETURN( hr );
  1488. } //*** CEnumClusCfgManagedResources::HrInitializeAndSaveEnum
  1489. /////////////////////////////////////////////////////////////////////////////
  1490. //++
  1491. //
  1492. // CEnumClusCfgManagedResources:HrGetQuorumResourceName
  1493. //
  1494. // Description:
  1495. // Get the quorum resource name and return whether or not this node
  1496. // owns the quorum.
  1497. //
  1498. // Arguments:
  1499. //
  1500. // Return Value:
  1501. // S_OK
  1502. // Success.
  1503. //
  1504. // Win32 Error
  1505. // something failed.
  1506. //
  1507. // Remarks:
  1508. // None.
  1509. //
  1510. //--
  1511. //////////////////////////////////////////////////////////////////////////////
  1512. HRESULT
  1513. CEnumClusCfgManagedResources::HrGetQuorumResourceName(
  1514. BSTR * pbstrQuorumResourceNameOut
  1515. , BOOL * pfQuormIsOwnedByThisNodeOut
  1516. )
  1517. {
  1518. TraceFunc( "" );
  1519. Assert( pbstrQuorumResourceNameOut != NULL );
  1520. Assert( pfQuormIsOwnedByThisNodeOut != NULL );
  1521. HRESULT hr = S_OK;
  1522. DWORD sc;
  1523. HCLUSTER hCluster = NULL;
  1524. BSTR bstrQuorumResourceName = NULL;
  1525. BSTR bstrNodeName = NULL;
  1526. HRESOURCE hQuorumResource = NULL;
  1527. BSTR bstrLocalNetBIOSName = NULL;
  1528. //
  1529. // Get netbios name for clusapi calls.
  1530. //
  1531. hr = THR( HrGetComputerName( ComputerNameNetBIOS, &bstrLocalNetBIOSName, TRUE ) );
  1532. if ( FAILED( hr ) )
  1533. {
  1534. goto Cleanup;
  1535. } // if:
  1536. hCluster = OpenCluster( NULL );
  1537. if ( hCluster == NULL )
  1538. {
  1539. sc = TW32( GetLastError() );
  1540. hr = HRESULT_FROM_WIN32( sc );
  1541. goto Cleanup;
  1542. } // if:
  1543. hr = THR( HrGetClusterQuorumResource( hCluster, &bstrQuorumResourceName, NULL, NULL ) );
  1544. if ( FAILED( hr ) )
  1545. {
  1546. goto Cleanup;
  1547. } // if:
  1548. hQuorumResource = OpenClusterResource( hCluster, bstrQuorumResourceName );
  1549. if ( hQuorumResource == NULL )
  1550. {
  1551. sc = TW32( GetLastError() );
  1552. hr = HRESULT_FROM_WIN32( sc );
  1553. goto Cleanup;
  1554. } // if:
  1555. hr = THR( HrGetClusterResourceState( hQuorumResource, &bstrNodeName, NULL, NULL ) );
  1556. if ( FAILED( hr ) )
  1557. {
  1558. goto Cleanup;
  1559. } // if:
  1560. //
  1561. // Give ownership away.
  1562. //
  1563. Assert( bstrQuorumResourceName != NULL );
  1564. *pbstrQuorumResourceNameOut = bstrQuorumResourceName;
  1565. bstrQuorumResourceName = NULL;
  1566. *pfQuormIsOwnedByThisNodeOut = ( NBSTRCompareNoCase( bstrLocalNetBIOSName, bstrNodeName ) == 0 );
  1567. Cleanup:
  1568. if ( hQuorumResource != NULL )
  1569. {
  1570. CloseClusterResource( hQuorumResource );
  1571. } // if:
  1572. if ( hCluster != NULL )
  1573. {
  1574. CloseCluster( hCluster );
  1575. } // if:
  1576. TraceSysFreeString( bstrQuorumResourceName );
  1577. TraceSysFreeString( bstrLocalNetBIOSName );
  1578. TraceSysFreeString( bstrNodeName );
  1579. HRETURN( hr );
  1580. } //*** CEnumClusCfgManagedResources::HrGetQuorumResourceName