Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

741 lines
19 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Cluster.cpp
  7. //
  8. // Description:
  9. // Implementation of CCluster class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "Cluster.h"
  17. //****************************************************************************
  18. //
  19. // CCluster
  20. //
  21. //****************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // CCluster::CCluster(
  26. // LPCWSTR pwszNameIn,
  27. // CWbemServices * pNamespaceIn
  28. // )
  29. //
  30. // Description:
  31. // Constructor.
  32. //
  33. // Arguments:
  34. // pwszNameIn -- Class name
  35. // pNamespaceIn -- Namespace
  36. //
  37. // Return Values:
  38. // None.
  39. //
  40. //--
  41. //////////////////////////////////////////////////////////////////////////////
  42. CCluster::CCluster(
  43. LPCWSTR pwszNameIn,
  44. CWbemServices * pNamespaceIn
  45. )
  46. : CProvBase( pwszNameIn, pNamespaceIn )
  47. {
  48. } //*** CCluster::CCluster()
  49. //////////////////////////////////////////////////////////////////////////////
  50. //++
  51. //
  52. // static
  53. // CProvBase *
  54. // CCluster::S_CreateThis(
  55. // LPCWSTR pwszNameIn,
  56. // CWbemServices * pNamespaceIn,
  57. // DWORD dwEnumTypeIn
  58. // )
  59. //
  60. // Description:
  61. // Create a cluster object
  62. //
  63. // Arguments:
  64. // pwszNameIn -- Class name
  65. // pNamespaceIn -- Namespace
  66. // dwEnumTypeIn -- Type id
  67. //
  68. // Return Values:
  69. // pointer to the CProvBase
  70. //
  71. //--
  72. //////////////////////////////////////////////////////////////////////////////
  73. CProvBase *
  74. CCluster::S_CreateThis(
  75. LPCWSTR pwszNameIn,
  76. CWbemServices * pNamespaceIn,
  77. DWORD // dwEnumTypeIn
  78. )
  79. {
  80. return new CCluster( pwszNameIn, pNamespaceIn );
  81. } //*** CCluster::S_CreateThis()
  82. //////////////////////////////////////////////////////////////////////////////
  83. //++
  84. //
  85. // const SPropMapEntryArray *
  86. // CCluster::GetPropMap( void )
  87. //
  88. // Description:
  89. // Retrieve the property maping table of the cluster.
  90. //
  91. // Arguments:
  92. // None.
  93. //
  94. // Return Values:
  95. // reference to the array of property maping table
  96. //
  97. //--
  98. //////////////////////////////////////////////////////////////////////////////
  99. const SPropMapEntryArray *
  100. CCluster::RgGetPropMap( void )
  101. {
  102. static SPropMapEntry s_rgpm[] =
  103. {
  104. {
  105. PVD_PROP_CLUSTER_SECURITYDESCRIPTOR,
  106. CLUSREG_NAME_CLUS_SD,
  107. MULTI_SZ_TYPE,
  108. READWRITE
  109. },
  110. {
  111. PVD_PROP_CLUSTER_GROUPADMIN,
  112. CLUS_CLUS_GROUPADMIN,
  113. MULTI_SZ_TYPE,
  114. READWRITE
  115. },
  116. {
  117. PVD_PROP_CLUSTER_NETWORKADMIN,
  118. CLUS_CLUS_NETWORKADMIN,
  119. MULTI_SZ_TYPE,
  120. READWRITE
  121. },
  122. {
  123. PVD_PROP_CLUSTER_NETINTFACEADMIN,
  124. CLUS_CLUS_NETINTERFACEADMIN,
  125. MULTI_SZ_TYPE,
  126. READWRITE
  127. },
  128. {
  129. PVD_PROP_CLUSTER_NODEADMIN,
  130. CLUS_CLUS_NODEADMIN,
  131. MULTI_SZ_TYPE,
  132. READWRITE
  133. },
  134. {
  135. PVD_PROP_CLUSTER_RESADMIN,
  136. CLUS_CLUS_RESADMIN,
  137. MULTI_SZ_TYPE,
  138. READWRITE
  139. },
  140. {
  141. PVD_PROP_CLUSTER_RESTYPEADMIN,
  142. CLUS_CLUS_RESTYPEADMIN,
  143. MULTI_SZ_TYPE,
  144. READWRITE
  145. }
  146. };
  147. static SPropMapEntryArray s_pmea (
  148. sizeof( s_rgpm ) / sizeof( SPropMapEntry ),
  149. s_rgpm
  150. );
  151. return &s_pmea;
  152. } //*** CCluster::GetPropMap()
  153. //////////////////////////////////////////////////////////////////////////////
  154. //++
  155. //
  156. // SCODE
  157. // CCluster::EnumInstance(
  158. // long lFlagsIn,
  159. // IWbemCOntext * pCtxIn,
  160. // IWbemObjectSing * pHandlerIn
  161. // )
  162. //
  163. // Description:
  164. // Enum cluster instance.
  165. //
  166. // Arguments:
  167. // lFlagsIn -- WMI flag
  168. // pCtxIn -- WMI context
  169. // pHandlerIn -- WMI sink pointer
  170. //
  171. // Return Values:
  172. // WBEM_S_NO_ERROR
  173. //
  174. //--
  175. //////////////////////////////////////////////////////////////////////////////
  176. SCODE
  177. CCluster::EnumInstance(
  178. long lFlagsIn,
  179. IWbemContext * pCtxIn,
  180. IWbemObjectSink * pHandlerIn
  181. )
  182. {
  183. SAFECLUSTER shCluster;
  184. shCluster = OpenCluster( NULL );
  185. ClusterToWMI( shCluster, pHandlerIn );
  186. return WBEM_S_NO_ERROR;
  187. } //*** CCluster::EnumInstance()
  188. //////////////////////////////////////////////////////////////////////////////
  189. //++
  190. //
  191. // void
  192. // CCluster::ClusterToWMI(
  193. // HCLUSTER hClusterIn,
  194. // IWbemObjectSink * pHandlerIn
  195. // )
  196. //
  197. // Description:
  198. // Translate a cluster objects to WMI object.
  199. //
  200. // Arguments:
  201. // hClusterIn -- Handle to cluster
  202. // pHandlerIn -- Pointer to WMI sink
  203. //
  204. // Return Values:
  205. // WBEM_S_NO_ERROR
  206. // win32 error
  207. //
  208. //--
  209. //////////////////////////////////////////////////////////////////////////////
  210. void
  211. CCluster::ClusterToWMI(
  212. HCLUSTER hClusterIn,
  213. IWbemObjectSink * pHandlerIn
  214. )
  215. {
  216. static SGetControl s_rgControl[] =
  217. {
  218. { CLUSCTL_CLUSTER_GET_RO_COMMON_PROPERTIES, FALSE },
  219. { CLUSCTL_CLUSTER_GET_COMMON_PROPERTIES, FALSE },
  220. { CLUSCTL_CLUSTER_GET_RO_PRIVATE_PROPERTIES, TRUE },
  221. { CLUSCTL_CLUSTER_GET_PRIVATE_PROPERTIES, TRUE }
  222. };
  223. static UINT s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  224. DWORD dwError = ERROR_SUCCESS;
  225. CError er;
  226. UINT idx;
  227. CWbemClassObject wco;
  228. m_pClass->SpawnInstance( 0, &wco );
  229. for ( idx = 0 ; idx < s_cControl ; idx++ )
  230. {
  231. CClusPropList pl;
  232. er = pl.ScGetClusterProperties(
  233. hClusterIn,
  234. s_rgControl[ idx ].dwControl,
  235. NULL,
  236. 0
  237. );
  238. CClusterApi::GetObjectProperties(
  239. RgGetPropMap(),
  240. pl,
  241. wco,
  242. s_rgControl[ idx ].fPrivate
  243. );
  244. } // for: each common property type
  245. //
  246. // cluster name
  247. //
  248. {
  249. DWORD cchClusterName = MAX_PATH;
  250. CWstrBuf wsbClusterName;
  251. wsbClusterName.SetSize( cchClusterName );
  252. dwError = GetClusterInformation(
  253. hClusterIn,
  254. wsbClusterName,
  255. &cchClusterName,
  256. NULL
  257. );
  258. if ( dwError == ERROR_MORE_DATA )
  259. {
  260. wsbClusterName.SetSize( ++cchClusterName );
  261. er = GetClusterInformation(
  262. hClusterIn,
  263. wsbClusterName,
  264. &cchClusterName,
  265. NULL
  266. );
  267. } // if: buffer was too small
  268. wco.SetProperty( wsbClusterName, PVD_PROP_CLUSTER_NAME );
  269. }
  270. //
  271. // network priority
  272. //
  273. {
  274. LPCWSTR pwszNetworks;
  275. BSTR pbstrNetworks[ MAX_PATH ];
  276. UINT idx = 0;
  277. UINT cSize;
  278. CClusterEnum cluEnum( hClusterIn, CLUSTER_ENUM_INTERNAL_NETWORK );
  279. // bugbug can you always clean up
  280. while ( ( pwszNetworks = cluEnum.GetNext() ) != NULL )
  281. {
  282. pbstrNetworks[ idx ] = SysAllocString( pwszNetworks );
  283. idx++;
  284. }
  285. wco.SetProperty(
  286. idx,
  287. pbstrNetworks,
  288. PVD_PROP_CLUSTER_NETWORK
  289. );
  290. cSize = idx;
  291. for ( idx = 0 ; idx < cSize ; idx++ )
  292. {
  293. SysFreeString( pbstrNetworks[ idx ] );
  294. }
  295. }
  296. //
  297. // quorum resource
  298. //
  299. {
  300. CWstrBuf wsbName;
  301. DWORD cchName = MAX_PATH ;
  302. CWstrBuf wsbDeviceName;
  303. DWORD cchDeviceName = MAX_PATH;
  304. DWORD dwLogSize;
  305. wsbName.SetSize( cchName );
  306. wsbDeviceName.SetSize( cchDeviceName );
  307. dwError = GetClusterQuorumResource(
  308. hClusterIn,
  309. wsbName,
  310. &cchName,
  311. wsbDeviceName,
  312. &cchDeviceName,
  313. &dwLogSize
  314. );
  315. if ( dwError == ERROR_MORE_DATA )
  316. {
  317. wsbName.SetSize( ++cchName );
  318. wsbDeviceName.SetSize( ++cchDeviceName );
  319. er = GetClusterQuorumResource(
  320. hClusterIn,
  321. wsbName,
  322. &cchName,
  323. wsbDeviceName,
  324. &cchDeviceName,
  325. &dwLogSize
  326. );
  327. }
  328. wco.SetProperty( wsbDeviceName, PVD_PROP_CLUSTER_FILE );
  329. wco.SetProperty( dwLogSize, PVD_PROP_CLUSTER_LOGSIZE );
  330. }
  331. pHandlerIn->Indicate( 1, &wco );
  332. return;
  333. } //*** CCluster::ClusterToWMI()
  334. //////////////////////////////////////////////////////////////////////////////
  335. //++
  336. //
  337. // SCODE
  338. // CCluster::GetObject(
  339. // CObjPath & rObjPathIn,
  340. // long lFlagsIn,
  341. // IWbemContext * pCtxIn,
  342. // IWbemObjectSink * pHandlerIn
  343. // )
  344. //
  345. // Description:
  346. // retrieve cluster object based given object path
  347. //
  348. // Arguments:
  349. // rObjPathIn -- Object path to cluster object
  350. // lFlagsIn -- WMI flag
  351. // pCtxIn -- WMI context
  352. // pHandlerIn -- WMI sink pointer
  353. //
  354. // Return Values:
  355. // WBEM_S_NO_ERROR
  356. // win32 error
  357. //
  358. //--
  359. //////////////////////////////////////////////////////////////////////////////
  360. SCODE
  361. CCluster::GetObject(
  362. CObjPath & rObjPathIn,
  363. long lFlagsIn,
  364. IWbemContext * pCtxIn,
  365. IWbemObjectSink * pHandlerIn
  366. )
  367. {
  368. SAFECLUSTER shCluster;
  369. shCluster = OpenCluster(
  370. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  371. );
  372. ClusterToWMI( shCluster, pHandlerIn );
  373. return WBEM_S_NO_ERROR;
  374. } //*** CCluster::GetObject()
  375. //////////////////////////////////////////////////////////////////////////////
  376. //++
  377. //
  378. // SCODE
  379. // CCluster::ExecuteMethod(
  380. // CObjPath & rObjPathIn,
  381. // WCHAR * pwszMethodNameIn,
  382. // long lFlagIn,
  383. // IWbemClassObject * pParamsIn,
  384. // IWbemObjectSink * pHandlerIn
  385. // )
  386. //
  387. // Description:
  388. // execute methods defined in the mof for cluster
  389. //
  390. // Arguments:
  391. // rObjPathIn -- Object path to cluster object
  392. // pwszMethodNameIn -- Name of the method to be invoked
  393. // lFlagIn -- WMI flag
  394. // pParamsIn -- Input parameters for the method
  395. // pHandlerIn -- WMI sink pointer
  396. //
  397. // Return Values:
  398. // WBEM_S_NO_ERROR
  399. //
  400. //--
  401. //////////////////////////////////////////////////////////////////////////////
  402. SCODE
  403. CCluster::ExecuteMethod(
  404. CObjPath & rObjPathIn,
  405. WCHAR * pwszMethodNameIn,
  406. long lFlagIn,
  407. IWbemClassObject * pParamsIn,
  408. IWbemObjectSink * pHandlerIn
  409. )
  410. {
  411. SAFECLUSTER shCluster;
  412. CWbemClassObject InArgs( pParamsIn );
  413. CError er;
  414. shCluster = OpenCluster( NULL );
  415. if ( _wcsicmp( pwszMethodNameIn, PVD_MTH_CLUSTER_RENAME ) == 0 )
  416. {
  417. _bstr_t bstrName;
  418. DWORD dwReturn;
  419. InArgs.GetProperty( bstrName, PVD_MTH_CLUSTER_PARM_NEWNAME );
  420. dwReturn = SetClusterName( shCluster, bstrName );
  421. if ( dwReturn != ERROR_RESOURCE_PROPERTIES_STORED )
  422. {
  423. er = dwReturn;
  424. }
  425. } // if: create new group
  426. else if( _wcsicmp( pwszMethodNameIn, PVD_MTH_CLUSTER_SETQUORUM ) == 0 )
  427. {
  428. _bstr_t bstrName;
  429. SAFERESOURCE hResource;
  430. CObjPath opPath;
  431. InArgs.GetProperty( bstrName, PVD_MTH_CLUSTER_PARM_RESOURCE );
  432. opPath.Init( bstrName );
  433. bstrName = opPath.GetStringValueForProperty( PVD_PROP_RES_NAME );
  434. hResource = OpenClusterResource( shCluster, bstrName );
  435. er = SetClusterQuorumResource(
  436. hResource,
  437. NULL,
  438. 64000
  439. );
  440. } // else if: set quorum resource
  441. return WBEM_S_NO_ERROR;
  442. } //*** CCluster::ExecuteMethod()
  443. //////////////////////////////////////////////////////////////////////////////
  444. //++
  445. //
  446. // SCODE
  447. // CCluster::PutInstance(
  448. // CWbemClassObject & rInstToPutIn,
  449. // long lFlagIn,
  450. // IWbemContext * pCtxIn,
  451. // IWbemObjectSink * pHandlerIn
  452. // )
  453. //
  454. // Description:
  455. // save this instance
  456. //
  457. // Arguments:
  458. // rInstToPutIn -- WMI object to be saved
  459. // lFlagIn -- WMI flag
  460. // pCtxIn -- WMI context
  461. // pHandlerIn -- WMI sink pointer
  462. //
  463. // Return Values:
  464. // WBEM_S_NO_ERROR
  465. //
  466. //--
  467. //////////////////////////////////////////////////////////////////////////////
  468. SCODE
  469. CCluster::PutInstance(
  470. CWbemClassObject & rInstToPutIn,
  471. long lFlagIn,
  472. IWbemContext * pCtxIn,
  473. IWbemObjectSink * pHandlerIn
  474. )
  475. {
  476. static SGetSetControl s_rgControl[] =
  477. {
  478. {
  479. CLUSCTL_CLUSTER_GET_COMMON_PROPERTIES,
  480. CLUSCTL_CLUSTER_SET_COMMON_PROPERTIES,
  481. FALSE
  482. },
  483. {
  484. CLUSCTL_CLUSTER_GET_PRIVATE_PROPERTIES,
  485. CLUSCTL_CLUSTER_SET_PRIVATE_PROPERTIES,
  486. TRUE
  487. }
  488. };
  489. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  490. CError er;
  491. DWORD dwError;
  492. SAFECLUSTER shCluster;
  493. UINT idx;
  494. shCluster = OpenCluster( NULL );
  495. for ( idx = 0 ; idx < s_cControl ; idx++ )
  496. {
  497. CClusPropList plOld;
  498. CClusPropList plNew;
  499. er = plOld.ScGetClusterProperties(
  500. shCluster,
  501. s_rgControl[ idx ].dwGetControl,
  502. NULL,
  503. NULL,
  504. 0
  505. );
  506. CClusterApi::SetObjectProperties(
  507. RgGetPropMap(),
  508. plNew,
  509. plOld,
  510. rInstToPutIn,
  511. s_rgControl[ idx ].fPrivate
  512. );
  513. if ( plNew.Cprops() > 0 )
  514. {
  515. er = ClusterControl(
  516. shCluster,
  517. NULL,
  518. s_rgControl[ idx ].dwSetControl,
  519. plNew.PbPropList(),
  520. plNew.CbPropList(),
  521. NULL,
  522. 0,
  523. NULL
  524. );
  525. }
  526. } // for: each control code
  527. //
  528. // network
  529. //
  530. {
  531. CClusPropList plNetwork;
  532. DWORD cNetworks = 0;
  533. _bstr_t * pbstrNetworks = NULL;
  534. UINT idx = 0;
  535. HNETWORK * phNetworks = NULL;
  536. rInstToPutIn.GetProperty(
  537. &cNetworks,
  538. &pbstrNetworks,
  539. PVD_PROP_CLUSTER_NETWORK
  540. );
  541. try
  542. {
  543. phNetworks = new HNETWORK[ cNetworks ];
  544. for( idx = 0 ; idx < cNetworks ; idx++ )
  545. {
  546. *(phNetworks + idx) = NULL;
  547. }
  548. for ( idx = 0 ; idx < cNetworks ; idx++)
  549. {
  550. *( phNetworks + idx ) = OpenClusterNetwork(
  551. shCluster,
  552. *( pbstrNetworks + idx ) );
  553. if ( phNetworks == NULL )
  554. {
  555. throw CProvException( GetLastError() );
  556. }
  557. }
  558. er = SetClusterNetworkPriorityOrder(
  559. shCluster,
  560. cNetworks,
  561. phNetworks
  562. );
  563. } // try
  564. catch ( ... )
  565. {
  566. for ( idx = 0 ; idx < cNetworks ; idx++)
  567. {
  568. if ( *( phNetworks + idx ) )
  569. {
  570. CloseClusterNetwork( *( phNetworks + idx) );
  571. }
  572. }
  573. delete [] phNetworks;
  574. delete [] pbstrNetworks;
  575. throw;
  576. } // catch: ...
  577. //
  578. // clean up
  579. //
  580. for ( idx = 0 ; idx < cNetworks ; idx++)
  581. {
  582. if ( *( phNetworks + idx ) )
  583. {
  584. CloseClusterNetwork( *( phNetworks + idx) );
  585. }
  586. }
  587. delete [] phNetworks;
  588. delete [] pbstrNetworks;
  589. }
  590. //
  591. // quorum resource
  592. //
  593. {
  594. CWstrBuf wsbName;
  595. DWORD cchName = MAX_PATH;
  596. CWstrBuf wsbDeviceName;
  597. DWORD cchDeviceName = MAX_PATH;
  598. DWORD dwLogSize;
  599. _bstr_t bstrNewDeviceName;
  600. DWORD dwNewLogSize;
  601. SAFERESOURCE shResource;
  602. wsbName.SetSize( cchName );
  603. wsbDeviceName.SetSize( cchDeviceName );
  604. dwError = GetClusterQuorumResource(
  605. shCluster,
  606. wsbName,
  607. &cchName,
  608. wsbDeviceName,
  609. &cchDeviceName,
  610. &dwLogSize
  611. );
  612. if ( dwError == ERROR_MORE_DATA )
  613. {
  614. wsbName.SetSize( ++cchName );
  615. wsbDeviceName.SetSize( ++cchDeviceName );
  616. er = GetClusterQuorumResource(
  617. shCluster,
  618. wsbName,
  619. &cchName,
  620. wsbDeviceName,
  621. &cchDeviceName,
  622. &dwLogSize
  623. );
  624. } // if: buffer is too small
  625. rInstToPutIn.GetProperty( bstrNewDeviceName, PVD_PROP_CLUSTER_FILE );
  626. rInstToPutIn.GetProperty( &dwNewLogSize, PVD_PROP_CLUSTER_LOGSIZE );
  627. if ( _wcsicmp( wsbDeviceName, bstrNewDeviceName )
  628. || dwLogSize != dwNewLogSize )
  629. {
  630. shResource = OpenClusterResource( shCluster, wsbName );
  631. er = SetClusterQuorumResource(
  632. shResource,
  633. bstrNewDeviceName,
  634. dwNewLogSize
  635. );
  636. } // if:
  637. }
  638. return WBEM_S_NO_ERROR;
  639. } //*** CCluster::PutInstance()
  640. //////////////////////////////////////////////////////////////////////////////
  641. //++
  642. //
  643. // SCODE
  644. // CCluster::DeleteInstance(
  645. // CObjPath & rObjPathIn,
  646. // long lFlagIn,
  647. // IWbemContext * pCtxIn,
  648. // IWbemObjectSink * pHandlerIn
  649. // )
  650. //
  651. // Description:
  652. // save this instance
  653. //
  654. // Arguments:
  655. // rObjPathIn -- ObjPath for the instance to be deleted
  656. // lFlagIn -- WMI flag
  657. // pCtxIn -- WMI context
  658. // pHandlerIn -- WMI sink pointer
  659. //
  660. // Return Values:
  661. // WBEM_S_NO_ERROR
  662. //
  663. //--
  664. //////////////////////////////////////////////////////////////////////////////
  665. SCODE
  666. CCluster::DeleteInstance(
  667. CObjPath & rObjPathIn,
  668. long lFlagIn,
  669. IWbemContext * pCtxIn,
  670. IWbemObjectSink * pHandlerIn
  671. )
  672. {
  673. return WBEM_E_NOT_SUPPORTED;
  674. } //*** CCluster::DeleteInstance()