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.

1199 lines
28 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumMajorityNodeSet.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumMajorityNodeSet
  10. // class.
  11. //
  12. // The class CEnumMajorityNodeSet is the enumeration of cluster
  13. // majority node set devices. It implements the IEnumClusCfgManagedResources
  14. // interface.
  15. //
  16. // Maintained By:
  17. // Galen Barbee (GalenB) 13-MAR-2001
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Include Files
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "Pch.h"
  24. #include <PropList.h>
  25. #include "CEnumMajorityNodeSet.h"
  26. #include "CMajorityNodeSet.h"
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Constant Definitions
  29. //////////////////////////////////////////////////////////////////////////////
  30. DEFINE_THISCLASS( "CEnumMajorityNodeSet" );
  31. //*************************************************************************//
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CEnumMajorityNodeSet class
  34. /////////////////////////////////////////////////////////////////////////////
  35. //////////////////////////////////////////////////////////////////////////////
  36. //++
  37. //
  38. // CEnumMajorityNodeSet::S_HrCreateInstance
  39. //
  40. // Description:
  41. // Create a CEnumMajorityNodeSet instance.
  42. //
  43. // Arguments:
  44. // None.
  45. //
  46. // Return Values:
  47. // S_OK
  48. // Success.
  49. //
  50. // E_POINTER
  51. // The passed in ppunk is NULL.
  52. //
  53. // other HRESULTs
  54. // Object creation failed.
  55. //
  56. //--
  57. //////////////////////////////////////////////////////////////////////////////
  58. HRESULT
  59. CEnumMajorityNodeSet::S_HrCreateInstance( IUnknown ** ppunkOut )
  60. {
  61. TraceFunc( "" );
  62. HRESULT hr = S_OK;
  63. CEnumMajorityNodeSet * pemns = NULL;
  64. if ( ppunkOut == NULL )
  65. {
  66. hr = THR( E_POINTER );
  67. goto Cleanup;
  68. } // if:
  69. pemns = new CEnumMajorityNodeSet();
  70. if ( pemns == NULL )
  71. {
  72. hr = THR( E_OUTOFMEMORY );
  73. goto Cleanup;
  74. } // if: error allocating object
  75. hr = THR( pemns->HrInit() );
  76. if ( FAILED( hr ) )
  77. {
  78. goto Cleanup;
  79. } // if: HrInit() failed
  80. hr = THR( pemns->TypeSafeQI( IUnknown, ppunkOut ) );
  81. if ( FAILED( hr ) )
  82. {
  83. goto Cleanup;
  84. } // if: QI failed
  85. Cleanup:
  86. if ( FAILED( hr ) )
  87. {
  88. LogMsg( L"[SRV] CEnumMajorityNodeSet::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  89. } // if:
  90. if ( pemns != NULL )
  91. {
  92. pemns->Release();
  93. } // if:
  94. HRETURN( hr );
  95. } //*** CEnumMajorityNodeSet::S_HrCreateInstance
  96. //////////////////////////////////////////////////////////////////////////////
  97. //++
  98. //
  99. // IUnknown *
  100. // CEnumMajorityNodeSet::S_RegisterCatIDSupport
  101. //
  102. // Description:
  103. // Registers/unregisters this class with the categories that it belongs
  104. // to.
  105. //
  106. // Arguments:
  107. // IN ICatRegister * picrIn
  108. // Used to register/unregister our CATID support.
  109. //
  110. // IN BOOL fCreateIn
  111. // When true we are registering the server. When false we are
  112. // un-registering the server.
  113. //
  114. // Return Values:
  115. // S_OK
  116. // Success.
  117. //
  118. // E_INVALIDARG
  119. // The passed in ICatRgister pointer was NULL.
  120. //
  121. // other HRESULTs
  122. // Registration/Unregistration failed.
  123. //
  124. //--
  125. //////////////////////////////////////////////////////////////////////////////
  126. HRESULT
  127. CEnumMajorityNodeSet::S_RegisterCatIDSupport(
  128. ICatRegister * picrIn,
  129. BOOL fCreateIn
  130. )
  131. {
  132. TraceFunc( "" );
  133. HRESULT hr = S_OK;
  134. CATID rgCatIds[ 1 ];
  135. if ( picrIn == NULL )
  136. {
  137. hr = THR( E_INVALIDARG );
  138. goto Cleanup;
  139. } // if:
  140. rgCatIds[ 0 ] = CATID_EnumClusCfgManagedResources;
  141. if ( fCreateIn )
  142. {
  143. hr = THR( picrIn->RegisterClassImplCategories( CLSID_EnumMajorityNodeSet, 1, rgCatIds ) );
  144. } // if:
  145. Cleanup:
  146. HRETURN( hr );
  147. } //*** CEnumMajorityNodeSet::S_RegisterCatIDSupport
  148. /////////////////////////////////////////////////////////////////////////////
  149. //++
  150. //
  151. // CEnumMajorityNodeSet:HrNodeResourceCallback
  152. //
  153. // Description:
  154. // Called by CClusterUtils::HrEnumNodeResources() when it finds a
  155. // resource for this node.
  156. //
  157. // Arguments:
  158. //
  159. //
  160. // Return Value:
  161. // S_OK
  162. // Success.
  163. //
  164. // Win32 Error
  165. // something failed.
  166. //
  167. // Remarks:
  168. // None.
  169. //
  170. //--
  171. //////////////////////////////////////////////////////////////////////////////
  172. HRESULT
  173. CEnumMajorityNodeSet::HrNodeResourceCallback(
  174. HCLUSTER hClusterIn
  175. , HRESOURCE hResourceIn
  176. )
  177. {
  178. TraceFunc( "" );
  179. HRESULT hr = S_OK;
  180. BOOL fIsQuorum;
  181. IUnknown * punk = NULL;
  182. IClusCfgManagedResourceInfo * pcccmri = NULL;
  183. CClusPropList cplCommonRO;
  184. CLUSPROP_BUFFER_HELPER cpbh;
  185. DWORD sc = ERROR_SUCCESS;
  186. CClusPropList cplPrivate;
  187. IClusCfgManagedResourceData * piccmrd = NULL;
  188. hr = STHR( HrIsResourceOfType( hResourceIn, L"Majority Node Set" ) );
  189. if ( FAILED( hr ) )
  190. {
  191. goto Cleanup;
  192. } // if:
  193. //
  194. // If this resource is not a majority node set then we simply want to
  195. // skip it.
  196. //
  197. if ( hr == S_FALSE )
  198. {
  199. goto Cleanup;
  200. } // if:
  201. hr = STHR( HrIsCoreResource( hResourceIn ) );
  202. if ( FAILED( hr ) )
  203. {
  204. goto Cleanup;
  205. } // if:
  206. fIsQuorum = ( hr == S_OK );
  207. hr = THR( CMajorityNodeSet::S_HrCreateInstance( &punk ) );
  208. if ( FAILED( hr ) )
  209. {
  210. goto Cleanup;
  211. } // if:
  212. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  213. if ( FAILED( hr ) )
  214. {
  215. goto Cleanup;
  216. } // if:
  217. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, &pcccmri ) );
  218. if ( FAILED( hr ) )
  219. {
  220. goto Cleanup;
  221. } // if:
  222. //
  223. // If a MNS resource is found, ie we get here, then the
  224. // MNS resource exists and is managed by default by
  225. // the cluster.
  226. //
  227. hr = THR( pcccmri->SetManagedByDefault( TRUE ) );
  228. if ( FAILED( hr ) )
  229. {
  230. goto Cleanup;
  231. } // if:
  232. //
  233. // If a MNS resource is found, ie we get here, then the
  234. // MNS resource exists and is in the cluster.
  235. //
  236. hr = THR( pcccmri->SetManaged( TRUE ) );
  237. if ( FAILED( hr ) )
  238. {
  239. goto Cleanup;
  240. } // if:
  241. hr = THR( pcccmri->SetQuorumResource( fIsQuorum ) );
  242. if ( FAILED( hr ) )
  243. {
  244. goto Cleanup;
  245. } // if:
  246. //
  247. // Get the name of this resource.
  248. //
  249. sc = TW32( cplCommonRO.ScGetResourceProperties( hResourceIn, CLUSCTL_RESOURCE_GET_RO_COMMON_PROPERTIES ) );
  250. if ( sc != ERROR_SUCCESS )
  251. {
  252. hr = HRESULT_FROM_WIN32( sc );
  253. goto Cleanup;
  254. } // if:
  255. sc = TW32( cplCommonRO.ScMoveToPropertyByName( L"Name" ) );
  256. if ( sc != ERROR_SUCCESS )
  257. {
  258. hr = HRESULT_FROM_WIN32( sc );
  259. goto Cleanup;
  260. } // if:
  261. cpbh = cplCommonRO.CbhCurrentValue();
  262. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  263. hr = THR( pcccmri->SetName( cpbh.pStringValue->sz ) );
  264. if ( FAILED( hr ) )
  265. {
  266. goto Cleanup;
  267. } // if:
  268. /*
  269. //
  270. // Only gather the private properties when MNS is the quorum resource. The properties are needed
  271. // later to validate that the nodes being added to the cluster can host this resource.
  272. //
  273. if ( fIsQuorum )
  274. {
  275. //
  276. // Get the private properties of this resource and store them as private data.
  277. //
  278. sc = TW32( cplPrivate.ScGetResourceProperties( hResourceIn, CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES ) );
  279. if ( sc != ERROR_SUCCESS )
  280. {
  281. hr = HRESULT_FROM_WIN32( sc );
  282. goto Cleanup;
  283. } // if:
  284. if ( cplPrivate.BIsListEmpty() )
  285. {
  286. hr = HRESULT_FROM_WIN32( TW32( ERROR_NOT_FOUND ) );
  287. STATUS_REPORT_REF(
  288. TASKID_Major_Find_Devices
  289. , TASKID_Minor_MNS_Missing_Private_Properties
  290. , IDS_ERROR_MNS_MISSING_PRIVATE_PROPERTIES
  291. , IDS_ERROR_MNS_MISSING_PRIVATE_PROPERTIES_REF
  292. , hr
  293. );
  294. goto Cleanup;
  295. } // if:
  296. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceData, &piccmrd ) );
  297. if ( FAILED( hr ) )
  298. {
  299. goto Cleanup;
  300. } // if:
  301. hr = THR( piccmrd->SetResourcePrivateData( (const BYTE *) cplPrivate.Plist(), (DWORD) cplPrivate.CbPropList() ) );
  302. if ( FAILED( hr ) )
  303. {
  304. goto Cleanup;
  305. } // if:
  306. } // if:
  307. */
  308. hr = THR( HrAddResourceToArray( punk ) );
  309. if ( FAILED( hr ) )
  310. {
  311. goto Cleanup;
  312. } // if:
  313. Cleanup:
  314. if ( piccmrd != NULL )
  315. {
  316. piccmrd->Release();
  317. } // if:
  318. if ( pcccmri != NULL )
  319. {
  320. pcccmri->Release();
  321. } // if:
  322. if ( punk != NULL )
  323. {
  324. punk->Release();
  325. } // if:
  326. HRETURN( hr );
  327. } //*** CEnumMajorityNodeSet::HrNodeResourceCallback
  328. //*************************************************************************//
  329. /////////////////////////////////////////////////////////////////////////////
  330. // CEnumMajorityNodeSet class -- Private Methods.
  331. /////////////////////////////////////////////////////////////////////////////
  332. //////////////////////////////////////////////////////////////////////////////
  333. //++
  334. //
  335. // CEnumMajorityNodeSet::CEnumMajorityNodeSet
  336. //
  337. // Description:
  338. // Constructor of the CEnumMajorityNodeSet class. This initializes
  339. // the m_cRef variable to 1 instead of 0 to account of possible
  340. // QueryInterface failure in DllGetClassObject.
  341. //
  342. // Arguments:
  343. // None.
  344. //
  345. // Return Value:
  346. // None.
  347. //
  348. // Remarks:
  349. // None.
  350. //
  351. //--
  352. //////////////////////////////////////////////////////////////////////////////
  353. CEnumMajorityNodeSet::CEnumMajorityNodeSet( void )
  354. : m_cRef( 1 )
  355. , m_lcid( LOCALE_NEUTRAL )
  356. {
  357. TraceFunc( "" );
  358. // Increment the count of components in memory so the DLL hosting this
  359. // object cannot be unloaded.
  360. InterlockedIncrement( &g_cObjects );
  361. Assert( m_picccCallback == NULL );
  362. Assert( m_prgQuorums == NULL );
  363. Assert( m_idxNext == 0 );
  364. Assert( m_idxEnumNext == 0 );
  365. Assert( m_bstrNodeName == NULL );
  366. Assert( !m_fEnumLoaded );
  367. TraceFuncExit();
  368. } //*** CEnumMajorityNodeSet::CEnumMajorityNodeSet
  369. //////////////////////////////////////////////////////////////////////////////
  370. //++
  371. //
  372. // CEnumMajorityNodeSet::~CEnumMajorityNodeSet
  373. //
  374. // Description:
  375. // Desstructor of the CEnumMajorityNodeSet class.
  376. //
  377. // Arguments:
  378. // None.
  379. //
  380. // Return Value:
  381. // None.
  382. //
  383. // Remarks:
  384. // None.
  385. //
  386. //--
  387. //////////////////////////////////////////////////////////////////////////////
  388. CEnumMajorityNodeSet::~CEnumMajorityNodeSet( void )
  389. {
  390. TraceFunc( "" );
  391. ULONG idx;
  392. if ( m_picccCallback != NULL )
  393. {
  394. m_picccCallback->Release();
  395. } // if:
  396. for ( idx = 0; idx < m_idxNext; idx++ )
  397. {
  398. if ( (*m_prgQuorums)[ idx ] != NULL )
  399. {
  400. ((*m_prgQuorums)[ idx ])->Release();
  401. } // end if:
  402. } // for:
  403. TraceFree( m_prgQuorums );
  404. TraceSysFreeString( m_bstrNodeName );
  405. // There's going to be one less component in memory. Decrement component count.
  406. InterlockedDecrement( &g_cObjects );
  407. TraceFuncExit();
  408. } //*** CEnumMajorityNodeSet::~CEnumMajorityNodeSet
  409. //////////////////////////////////////////////////////////////////////////////
  410. //++
  411. //
  412. // CEnumMajorityNodeSet::HrInit
  413. //
  414. // Description:
  415. // Initialize this component.
  416. //
  417. // Arguments:
  418. // None.
  419. //
  420. // Return Value:
  421. //
  422. //
  423. // Remarks:
  424. // None.
  425. //
  426. //--
  427. //////////////////////////////////////////////////////////////////////////////
  428. HRESULT
  429. CEnumMajorityNodeSet::HrInit( void )
  430. {
  431. TraceFunc( "" );
  432. // IUnknown
  433. Assert( m_cRef == 1 );
  434. HRETURN( S_OK );
  435. } //*** CEnumMajorityNodeSet::HrInit
  436. //////////////////////////////////////////////////////////////////////////////
  437. //++
  438. //
  439. // CEnumMajorityNodeSet::HrLoadResources
  440. //
  441. // Description:
  442. // Initialize this component.
  443. //
  444. // Arguments:
  445. // None.
  446. //
  447. // Return Value:
  448. //
  449. //
  450. // Remarks:
  451. // None.
  452. //
  453. //--
  454. //////////////////////////////////////////////////////////////////////////////
  455. HRESULT
  456. CEnumMajorityNodeSet::HrLoadResources( void )
  457. {
  458. TraceFunc( "" );
  459. HRESULT hr = S_OK;
  460. BSTR bstrLocalNetBIOSName = NULL;
  461. //
  462. // Get netbios name for clusapi calls.
  463. //
  464. hr = THR( HrGetComputerName( ComputerNameNetBIOS, &bstrLocalNetBIOSName, TRUE ) );
  465. if ( FAILED( hr ) )
  466. {
  467. goto Cleanup;
  468. } // if:
  469. //
  470. // If the cluster service is running then load any majority node set
  471. // resources that might exist.
  472. //
  473. hr = STHR( HrIsClusterServiceRunning() );
  474. if ( hr == S_OK )
  475. {
  476. hr = THR( HrEnumNodeResources( bstrLocalNetBIOSName ) );
  477. if ( FAILED( hr ) )
  478. {
  479. goto Cleanup;
  480. } // if:
  481. //
  482. // If this node doesn't own an instance of this resource then we need
  483. // to create a dummy resource for MiddleTier analysis.
  484. //
  485. if ( m_idxNext == 0 )
  486. {
  487. LogMsg( L"[SRV] This node does not own a Majority Node Set resource. Creating a dummy resource." );
  488. hr = THR( HrCreateDummyObject() );
  489. } // if:
  490. } // if:
  491. else if ( hr == S_FALSE )
  492. {
  493. //
  494. // If cluster service isn't running then we need to create a dummy resource
  495. // for MiddleTier analysis and for EvictCleanup.
  496. //
  497. LogMsg( L"[SRV] The cluster service is not running. Creating a dummy Majority Node Set resource." );
  498. hr = THR( HrCreateDummyObject() );
  499. } // else if:
  500. Cleanup:
  501. TraceSysFreeString( bstrLocalNetBIOSName );
  502. HRETURN( hr );
  503. } //*** CEnumMajorityNodeSet::HrLoadResources
  504. /////////////////////////////////////////////////////////////////////////////
  505. //++
  506. //
  507. // CEnumMajorityNodeSet:HrAddResourceToArray
  508. //
  509. // Description:
  510. // Add the passed in majority node set to the array of punks that holds the
  511. // list of majority node sets.
  512. //
  513. // Arguments:
  514. //
  515. //
  516. // Return Value:
  517. // S_OK
  518. // Success
  519. //
  520. // E_OUTOFMEMORY
  521. // Couldn't allocate memeory.
  522. //
  523. // Remarks:
  524. // None.
  525. //
  526. //--
  527. //////////////////////////////////////////////////////////////////////////////
  528. HRESULT
  529. CEnumMajorityNodeSet::HrAddResourceToArray( IUnknown * punkIn )
  530. {
  531. TraceFunc( "" );
  532. Assert( punkIn != NULL );
  533. HRESULT hr = S_OK;
  534. IUnknown * ((*prgpunks)[]) = NULL;
  535. prgpunks = (IUnknown *((*)[])) TraceReAlloc( m_prgQuorums, sizeof( IUnknown * ) * ( m_idxNext + 1 ), HEAP_ZERO_MEMORY );
  536. if ( prgpunks == NULL )
  537. {
  538. hr = THR( E_OUTOFMEMORY );
  539. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrAddResourceToArray, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  540. goto Cleanup;
  541. } // if:
  542. m_prgQuorums = prgpunks;
  543. (*m_prgQuorums)[ m_idxNext++ ] = punkIn;
  544. punkIn->AddRef();
  545. m_cQuorumCount += 1;
  546. Cleanup:
  547. HRETURN( hr );
  548. } //*** CEnumMajorityNodeSet::HrAddResourceToArray
  549. //////////////////////////////////////////////////////////////////////////////
  550. //++
  551. //
  552. // CEnumMajorityNodeSet::HrCreateDummyObject
  553. //
  554. // Description:
  555. // Create a dummy object so the MiddleTier will be happy.
  556. //
  557. // Arguments:
  558. // None.
  559. //
  560. // Return Value:
  561. //
  562. // Remarks:
  563. // None.
  564. //
  565. //--
  566. //////////////////////////////////////////////////////////////////////////////
  567. HRESULT
  568. CEnumMajorityNodeSet::HrCreateDummyObject( void )
  569. {
  570. TraceFunc( "" );
  571. HRESULT hr = S_OK;
  572. IUnknown * punk = NULL;
  573. hr = THR( CMajorityNodeSet::S_HrCreateInstance( &punk ) );
  574. if ( FAILED( hr ) )
  575. {
  576. goto Cleanup;
  577. } // if:
  578. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  579. if ( FAILED( hr ) )
  580. {
  581. goto Cleanup;
  582. } // if:
  583. hr = THR( HrAddResourceToArray( punk ) );
  584. Cleanup:
  585. if ( punk != NULL )
  586. {
  587. punk->Release();
  588. } // if:
  589. HRETURN( hr );
  590. } //*** CEnumMajorityNodeSet::HrCreateDummyObject
  591. //*************************************************************************//
  592. /////////////////////////////////////////////////////////////////////////////
  593. // CEnumMajorityNodeSet -- IUknkown interface.
  594. /////////////////////////////////////////////////////////////////////////////
  595. //////////////////////////////////////////////////////////////////////////////
  596. //++
  597. //
  598. // CEnumMajorityNodeSet::AddRef
  599. //
  600. // Description:
  601. // Increment the reference count of this object by one.
  602. //
  603. // Arguments:
  604. // None.
  605. //
  606. // Return Value:
  607. // The new reference count.
  608. //
  609. // Remarks:
  610. // None.
  611. //
  612. //--
  613. //////////////////////////////////////////////////////////////////////////////
  614. STDMETHODIMP_( ULONG )
  615. CEnumMajorityNodeSet::AddRef( void )
  616. {
  617. TraceFunc( "[IUnknown]" );
  618. InterlockedIncrement( &m_cRef );
  619. CRETURN( m_cRef );
  620. } //*** CEnumMajorityNodeSet::AddRef
  621. //////////////////////////////////////////////////////////////////////////////
  622. //++
  623. //
  624. // CEnumMajorityNodeSet::Release
  625. //
  626. // Description:
  627. // Decrement the reference count of this object by one.
  628. //
  629. // Arguments:
  630. // None.
  631. //
  632. // Return Value:
  633. // The new reference count.
  634. //
  635. // Remarks:
  636. // None.
  637. //
  638. //--
  639. //////////////////////////////////////////////////////////////////////////////
  640. STDMETHODIMP_( ULONG )
  641. CEnumMajorityNodeSet::Release( void )
  642. {
  643. TraceFunc( "[IUnknown]" );
  644. LONG cRef;
  645. cRef = InterlockedDecrement( &m_cRef );
  646. if ( cRef == 0 )
  647. {
  648. TraceDo( delete this );
  649. } // if: reference count equal to zero
  650. CRETURN( cRef );
  651. } //*** CEnumMajorityNodeSet::Release
  652. //////////////////////////////////////////////////////////////////////////////
  653. //++
  654. //
  655. // CEnumMajorityNodeSet::QueryInterface
  656. //
  657. // Description:
  658. // Query this object for the passed in interface.
  659. //
  660. // Arguments:
  661. // riidIn
  662. // Id of interface requested.
  663. //
  664. // ppvOut
  665. // Pointer to the requested interface.
  666. //
  667. // Return Value:
  668. // S_OK
  669. // If the interface is available on this object.
  670. //
  671. // E_NOINTERFACE
  672. // If the interface is not available.
  673. //
  674. // E_POINTER
  675. // ppvOut was NULL.
  676. //
  677. // Remarks:
  678. // None.
  679. //
  680. //--
  681. //////////////////////////////////////////////////////////////////////////////
  682. STDMETHODIMP
  683. CEnumMajorityNodeSet::QueryInterface(
  684. REFIID riidIn
  685. , void ** ppvOut
  686. )
  687. {
  688. TraceQIFunc( riidIn, ppvOut );
  689. HRESULT hr = S_OK;
  690. //
  691. // Validate arguments.
  692. //
  693. Assert( ppvOut != NULL );
  694. if ( ppvOut == NULL )
  695. {
  696. hr = THR( E_POINTER );
  697. goto Cleanup;
  698. }
  699. //
  700. // Handle known interfaces.
  701. //
  702. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  703. {
  704. *ppvOut = static_cast< IEnumClusCfgManagedResources * >( this );
  705. } // if: IUnknown
  706. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgManagedResources ) )
  707. {
  708. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgManagedResources, this, 0 );
  709. } // else if: IEnumClusCfgManagedResources
  710. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  711. {
  712. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  713. } // else if: IClusCfgInitialize
  714. else
  715. {
  716. *ppvOut = NULL;
  717. hr = E_NOINTERFACE;
  718. }
  719. //
  720. // Add a reference to the interface if successful.
  721. //
  722. if ( SUCCEEDED( hr ) )
  723. {
  724. ((IUnknown *) *ppvOut)->AddRef();
  725. } // if: success
  726. Cleanup:
  727. QIRETURN_IGNORESTDMARSHALLING1( hr, riidIn, IID_IClusCfgWbemServices );
  728. } //*** CEnumMajorityNodeSet::QueryInterface
  729. //*************************************************************************//
  730. /////////////////////////////////////////////////////////////////////////////
  731. // CEnumMajorityNodeSet -- IClusCfgInitialize interface.
  732. /////////////////////////////////////////////////////////////////////////////
  733. //////////////////////////////////////////////////////////////////////////////
  734. //++
  735. //
  736. // CEnumMajorityNodeSet::Initialize
  737. //
  738. // Description:
  739. // Initialize this component.
  740. //
  741. // Arguments:
  742. // punkCallbackIn
  743. // lcidIn
  744. //
  745. // Return Value:
  746. // S_OK - Success.
  747. // E_INVALIDARG - Required input argument not specified.
  748. // Other HRESULTs.
  749. //
  750. //--
  751. //////////////////////////////////////////////////////////////////////////////
  752. STDMETHODIMP
  753. CEnumMajorityNodeSet::Initialize(
  754. IUnknown * punkCallbackIn
  755. , LCID lcidIn
  756. )
  757. {
  758. TraceFunc( "[IClusCfgInitialize]" );
  759. Assert( m_picccCallback == NULL );
  760. HRESULT hr = S_OK;
  761. m_lcid = lcidIn;
  762. if ( punkCallbackIn == NULL )
  763. {
  764. hr = THR( E_INVALIDARG );
  765. goto Cleanup;
  766. } // if:
  767. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  768. if ( FAILED( hr ) )
  769. {
  770. goto Cleanup;
  771. } // if:
  772. hr = THR( HrGetComputerName(
  773. ComputerNameDnsHostname
  774. , &m_bstrNodeName
  775. , TRUE // fBestEffortIn
  776. ) );
  777. if ( FAILED( hr ) )
  778. {
  779. goto Cleanup;
  780. } // if:
  781. Cleanup:
  782. HRETURN( hr );
  783. } //*** CEnumMajorityNodeSet::Initialize
  784. //*************************************************************************//
  785. /////////////////////////////////////////////////////////////////////////////
  786. // CEnumMajorityNodeSet -- IEnumClusCfgManagedResources interface.
  787. /////////////////////////////////////////////////////////////////////////////
  788. //////////////////////////////////////////////////////////////////////////////
  789. //++
  790. //
  791. // CEnumMajorityNodeSet::Next
  792. //
  793. // Description:
  794. //
  795. // Arguments:
  796. //
  797. // Return Value:
  798. //
  799. // Remarks:
  800. // None.
  801. //
  802. //--
  803. //////////////////////////////////////////////////////////////////////////////
  804. STDMETHODIMP
  805. CEnumMajorityNodeSet::Next(
  806. ULONG cNumberRequestedIn,
  807. IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut,
  808. ULONG * pcNumberFetchedOut
  809. )
  810. {
  811. TraceFunc( "[IEnumClusCfgManagedResources]" );
  812. HRESULT hr = S_FALSE;
  813. ULONG cFetched = 0;
  814. IClusCfgManagedResourceInfo * pccsdi;
  815. IUnknown * punk;
  816. ULONG ulStop;
  817. if ( rgpManagedResourceInfoOut == NULL )
  818. {
  819. hr = THR( E_POINTER );
  820. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_MajorityNodeSet, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  821. goto Cleanup;
  822. } // if:
  823. if ( !m_fEnumLoaded )
  824. {
  825. hr = THR( HrLoadResources() );
  826. if ( FAILED( hr ) )
  827. {
  828. goto Cleanup;
  829. } // if:
  830. m_fEnumLoaded = true;
  831. } // if:
  832. ulStop = min( cNumberRequestedIn, ( m_idxNext - m_idxEnumNext ) );
  833. for ( hr = S_OK; ( cFetched < ulStop ) && ( m_idxEnumNext < m_idxNext ); m_idxEnumNext++ )
  834. {
  835. punk = (*m_prgQuorums)[ m_idxEnumNext ];
  836. if ( punk != NULL )
  837. {
  838. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, &pccsdi ) );
  839. if ( FAILED( hr ) )
  840. {
  841. break;
  842. } // if:
  843. rgpManagedResourceInfoOut[ cFetched++ ] = pccsdi;
  844. } // if:
  845. } // for:
  846. if ( FAILED( hr ) )
  847. {
  848. m_idxEnumNext -= cFetched;
  849. while ( cFetched != 0 )
  850. {
  851. (rgpManagedResourceInfoOut[ --cFetched ])->Release();
  852. } // for:
  853. goto Cleanup;
  854. } // if:
  855. if ( cFetched < cNumberRequestedIn )
  856. {
  857. hr = S_FALSE;
  858. } // if:
  859. Cleanup:
  860. if ( pcNumberFetchedOut != NULL )
  861. {
  862. *pcNumberFetchedOut = cFetched;
  863. } // if:
  864. HRETURN( hr );
  865. } //*** CEnumMajorityNodeSet::Next
  866. //////////////////////////////////////////////////////////////////////////////
  867. //++
  868. //
  869. // CEnumMajorityNodeSet::Skip
  870. //
  871. // Description:
  872. //
  873. // Arguments:
  874. //
  875. // Return Value:
  876. //
  877. // Remarks:
  878. // None.
  879. //
  880. //--
  881. //////////////////////////////////////////////////////////////////////////////
  882. STDMETHODIMP
  883. CEnumMajorityNodeSet::Skip( ULONG cNumberToSkipIn )
  884. {
  885. TraceFunc( "[IEnumClusCfgManagedResources]" );
  886. HRESULT hr = S_OK;
  887. m_idxEnumNext += cNumberToSkipIn;
  888. if ( m_idxEnumNext >= m_idxNext )
  889. {
  890. m_idxEnumNext = m_idxNext;
  891. hr = STHR( S_FALSE );
  892. } // if:
  893. HRETURN( hr );
  894. } //*** CEnumMajorityNodeSet::Skip
  895. //////////////////////////////////////////////////////////////////////////////
  896. //++
  897. //
  898. // CEnumMajorityNodeSet::Reset
  899. //
  900. // Description:
  901. //
  902. // Arguments:
  903. //
  904. // Return Value:
  905. //
  906. // Remarks:
  907. // None.
  908. //
  909. //--
  910. //////////////////////////////////////////////////////////////////////////////
  911. STDMETHODIMP
  912. CEnumMajorityNodeSet::Reset( void )
  913. {
  914. TraceFunc( "[IEnumClusCfgManagedResources]" );
  915. m_idxEnumNext = 0;
  916. HRETURN( S_OK );
  917. } //*** CEnumMajorityNodeSet::Reset
  918. //////////////////////////////////////////////////////////////////////////////
  919. //++
  920. //
  921. // CEnumMajorityNodeSet::Clone
  922. //
  923. // Description:
  924. //
  925. // Arguments:
  926. //
  927. // Return Value:
  928. //
  929. // Remarks:
  930. // None.
  931. //
  932. //--
  933. //////////////////////////////////////////////////////////////////////////////
  934. STDMETHODIMP
  935. CEnumMajorityNodeSet::Clone(
  936. IEnumClusCfgManagedResources ** ppEnumClusCfgStorageDevicesOut
  937. )
  938. {
  939. TraceFunc( "[IEnumClusCfgManagedResources]" );
  940. HRESULT hr = S_OK;
  941. if ( ppEnumClusCfgStorageDevicesOut == NULL )
  942. {
  943. hr = THR( E_POINTER );
  944. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_MajorityNodeSet, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  945. goto Cleanup;
  946. } // if:
  947. hr = THR( E_NOTIMPL );
  948. Cleanup:
  949. HRETURN( hr );
  950. } //*** CEnumMajorityNodeSet::Clone
  951. //////////////////////////////////////////////////////////////////////////////
  952. //++
  953. //
  954. // CEnumMajorityNodeSet::Count
  955. //
  956. // Description:
  957. //
  958. // Arguments:
  959. //
  960. // Return Value:
  961. //
  962. // Remarks:
  963. // None.
  964. //
  965. //--
  966. //////////////////////////////////////////////////////////////////////////////
  967. STDMETHODIMP
  968. CEnumMajorityNodeSet::Count( DWORD * pnCountOut )
  969. {
  970. TraceFunc( "[IEnumClusCfgManagedResources]" );
  971. HRESULT hr = S_OK;
  972. if ( pnCountOut == NULL )
  973. {
  974. hr = THR( E_POINTER );
  975. goto Cleanup;
  976. } // if:
  977. if ( !m_fEnumLoaded )
  978. {
  979. hr = THR( HrLoadResources() );
  980. if ( FAILED( hr ) )
  981. {
  982. goto Cleanup;
  983. } // if:
  984. m_fEnumLoaded = true;
  985. } // if:
  986. *pnCountOut = m_cQuorumCount;
  987. Cleanup:
  988. HRETURN( hr );
  989. } //*** CEnumMajorityNodeSet::Count