PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/usr/src/cmd/wbem/provider/c/wbem_disk/assoc/Solaris_MPXIOComponent.c

https://bitbucket.org/osunix/osunix-gate
C | 1095 lines | 638 code | 136 blank | 321 comment | 160 complexity | 9f77345c087c5a39c61f23276f157a12 MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, MPL-2.0-no-copyleft-exception, BSD-3-Clause, BSD-2-Clause, LGPL-3.0, 0BSD, GPL-2.0, LGPL-2.0, AGPL-1.0, AGPL-3.0, GPL-3.0, LGPL-2.1
  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License, Version 1.0 only
  6. * (the "License"). You may not use this file except in compliance
  7. * with the License.
  8. *
  9. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. * or http://www.opensolaris.org/os/licensing.
  11. * See the License for the specific language governing permissions
  12. * and limitations under the License.
  13. *
  14. * When distributing Covered Code, include this CDDL HEADER in each
  15. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. * If applicable, add the following below this CDDL HEADER, with the
  17. * fields enclosed by brackets "[]" replaced with your own identifying
  18. * information: Portions Copyright [yyyy] [name of copyright owner]
  19. *
  20. * CDDL HEADER END
  21. */
  22. /*
  23. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  24. * Use is subject to license terms.
  25. */
  26. #pragma ident "%Z%%M% %I% %E% SMI"
  27. #include <unistd.h>
  28. #include <netdb.h>
  29. #include <errno.h>
  30. #include "util.h"
  31. #include "cimKeys.h"
  32. #include "providerNames.h"
  33. #include "messageStrings.h"
  34. #include "ctrl_descriptors.h"
  35. #include "Solaris_MPXIOComponent.h"
  36. #define MPXIO_GETINSTANCE "MPXIO_COMPONENT,GET_INSTANCE"
  37. #define MPXIO_ENUMINSTANCES "MPXIO_COMPONENT,ENUM_INSTANCES"
  38. #define MPXIO_ENUMINSTANCENAMES "MPXIO_COMPONENT,ENUM_INSTANCENAMES"
  39. #define MPXIO_CREATEINSTANCE "MPXIO_COMPONENT,CREATE_INSTANCE"
  40. #define MPXIO_DELETEINSTANCE "MPXIO_COMPONENT,DELETE_INSTANCE"
  41. #define MPXIO_SETINSTANCE "MPXIO_COMPONENT,SET_INSTANCE"
  42. #define MPXIO_GETPROPERTY "MPXIO_COMPONENT,GET_PROPERTY"
  43. #define MPXIO_SETPROPERTY "MPXIO_COMPONENT,SET_PROPERTY"
  44. #define MPXIO_INVOKEMETHOD "MPXIO_COMPONENT,INVOKE_METHOD"
  45. #define MPXIO_EXECQUERY "MPXIO_COMPONENT,EXEC_QUERY"
  46. #define MPXIO_ASSOCIATORS "MPXIO_COMPONENT,ASSOCIATORS"
  47. #define MPXIO_ASSOCIATORNAMES "MPXIO_COMPONENT,ASSOCIATOR_NAMES"
  48. #define MPXIO_REFERENCES "MPXIO_COMPONENT,REFERENCES"
  49. #define MPXIO_REFERENCENAMES "MPXIO_COMPONENT,REFERENCE_NAMES"
  50. static
  51. CCIMInstanceList *
  52. mpxioCompToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  53. CCIMObjectPathList *objList, cimchar *objRole, int *error);
  54. static
  55. CCIMInstance *
  56. mpxioCompToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  57. CCIMObjectPath *obj2, cimchar *obj2Role, int *error);
  58. /*
  59. * Solaris_MPXIOComponent provider
  60. *
  61. * It is important to note that all memory allocated by these functions
  62. * and passed to the CIMOM, is freed by the door process prior to
  63. * sending a copy of the data to the CIMOM.
  64. */
  65. /*
  66. * Name: cp_getInstance_Solaris_MPXIOComponent
  67. *
  68. * Description: Returns an instance which matches the passed in object path
  69. * if found.
  70. *
  71. * Parameters:
  72. * pOP - An CCIMObjectPath * which contains the information on
  73. * the class for which to find the instance.
  74. * Returns:
  75. * CCIMInstance * if matched instance is found. Otherwise, NULL.
  76. */
  77. /* ARGSUSED */
  78. CCIMInstance*
  79. cp_getInstance_Solaris_MPXIOComponent(CCIMObjectPath* pOP)
  80. {
  81. CCIMInstance *inst = NULL;
  82. CCIMPropertyList *pCurPropList;
  83. CCIMObjectPath *antOp = NULL;
  84. CCIMObjectPath *depOp = NULL;
  85. dm_descriptor_t m_descriptor;
  86. dm_descriptor_t c_descriptor;
  87. char *name;
  88. int error;
  89. if (pOP == NULL ||
  90. (pCurPropList = pOP->mKeyProperties) == NULL) {
  91. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  92. NULL, &error);
  93. return ((CCIMInstance*)NULL);
  94. }
  95. antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  96. GROUP, &error);
  97. if (error == 0) {
  98. depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  99. PART, &error);
  100. }
  101. if (error != 0) {
  102. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  103. NULL, &error);
  104. return ((CCIMInstance*)NULL);
  105. }
  106. /*
  107. * Now, get the name of the antecedent from the object path.
  108. */
  109. if ((pCurPropList = antOp->mKeyProperties) == NULL ||
  110. (pCurPropList = depOp->mKeyProperties) == NULL) {
  111. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  112. NULL, &error);
  113. return ((CCIMInstance *)NULL);
  114. }
  115. pCurPropList = antOp->mKeyProperties;
  116. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  117. &error);
  118. if (error != 0 || name == NULL) {
  119. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  120. NULL, &error);
  121. return ((CCIMInstance *)NULL);
  122. }
  123. /*
  124. * The only reason it is needed to get the descriptor for these
  125. * two devices is to verify that they still exist and are valid.
  126. * If they are not found, then getting the instance for this
  127. * association as passed in by the client is not possible.
  128. */
  129. m_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  130. &error);
  131. /*
  132. * Not found. Return a null instance.
  133. */
  134. if (error == ENODEV || m_descriptor == NULL) {
  135. return ((CCIMInstance *)NULL);
  136. }
  137. if (error != 0) {
  138. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
  139. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  140. return ((CCIMInstance*)NULL);
  141. }
  142. dm_free_descriptor(m_descriptor);
  143. /*
  144. * Now, get the name of the dependent from the object path.
  145. */
  146. pCurPropList = depOp->mKeyProperties;
  147. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  148. &error);
  149. if (error != 0 || name == NULL) {
  150. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  151. NULL, &error);
  152. return ((CCIMInstance *)NULL);
  153. }
  154. c_descriptor = dm_get_descriptor_by_name(DM_PATH, name,
  155. &error);
  156. /*
  157. * Not found. Return a null instance.
  158. */
  159. if (error == ENODEV || c_descriptor == NULL) {
  160. return ((CCIMInstance *)NULL);
  161. }
  162. if (error != 0) {
  163. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
  164. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  165. return ((CCIMInstance*)NULL);
  166. }
  167. dm_free_descriptor(c_descriptor);
  168. /*
  169. * At this point I have verified I have the two devices that
  170. * are part of this association. Use the object paths I got
  171. * earlier to create the mpxiointerface instance.
  172. */
  173. inst = mpxioCompToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);
  174. if (error != 0) {
  175. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
  176. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
  177. return ((CCIMInstance *)NULL);
  178. }
  179. return (inst);
  180. }
  181. /*
  182. * Name: cp_enumInstances_Solaris_MPXIOComponent
  183. *
  184. * Description: Returns a linked list of instances of
  185. * Solaris_MPXIOComponent if found.
  186. *
  187. * Parameters:
  188. * pOP - An CCIMObjectPath * which contains the information on
  189. * the class for which to find the instances.
  190. * Returns:
  191. * CCIMInstanceList * if istances are found.
  192. * Otherwise, NULL is returned.
  193. */
  194. /* ARGSUSED */
  195. CCIMInstanceList*
  196. cp_enumInstances_Solaris_MPXIOComponent(CCIMObjectPath* pOP)
  197. {
  198. CCIMInstanceList *instList = NULL;
  199. CCIMObjectPathList *cObjList;
  200. CCIMObjectPathList *tmpObjList;
  201. CCIMObjectPath *objPath;
  202. CCIMInstance *inst;
  203. CCIMException *ex;
  204. int error = 0;
  205. /*
  206. * Get the list of MPXIO Controllers. Then get the associated paths
  207. * via the device api.
  208. */
  209. objPath = cim_createEmptyObjectPath(MPXIO_CONTROLLER);
  210. if (objPath == NULL) {
  211. ex = cim_getLastError();
  212. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  213. CREATE_OBJECT_PATH, ex, &error);
  214. return ((CCIMInstanceList *)NULL);
  215. }
  216. cObjList = cimom_enumerateInstanceNames(objPath, cim_false);
  217. cim_freeObjectPath(objPath);
  218. /*
  219. * NULL means error, empty list does not.
  220. */
  221. if (cObjList == NULL) {
  222. ex = cim_getLastError();
  223. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  224. ENUM_INSTANCENAMES_FAILURE, ex,
  225. &error);
  226. return ((CCIMInstanceList *)NULL);
  227. }
  228. if (cObjList->mDataObject == NULL) {
  229. return ((CCIMInstanceList *)NULL);
  230. }
  231. /*
  232. * Loop through all of these controller objects and get the associated
  233. * paths.
  234. */
  235. instList = cim_createInstanceList();
  236. if (instList == NULL) {
  237. ex = cim_getLastError();
  238. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  239. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  240. return ((CCIMInstanceList *)NULL);
  241. }
  242. for (tmpObjList = cObjList; tmpObjList != NULL;
  243. tmpObjList = tmpObjList->mNext) {
  244. char *name = NULL;
  245. CCIMObjectPath *cOp;
  246. CCIMInstanceList *tmpList;
  247. CCIMInstanceList *tmpList1;
  248. CCIMPropertyList *pCurPropList;
  249. CCIMObjectPathList *dObjList;
  250. CCIMInstanceList *tL;
  251. dm_descriptor_t m_descriptor;
  252. dm_descriptor_t *c_descriptorp = NULL;
  253. cOp = tmpObjList->mDataObject;
  254. if ((pCurPropList = cOp->mKeyProperties) == NULL) {
  255. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_INVALID_PARAMETER,
  256. NULL, NULL, &error);
  257. cim_freeInstanceList(instList);
  258. cim_freeObjectPathList(cObjList);
  259. return ((CCIMInstanceList *)NULL);
  260. }
  261. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  262. &error);
  263. if (error != 0 || name == NULL) {
  264. util_handleError(MPXIO_ENUMINSTANCES,
  265. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  266. cim_freeInstanceList(instList);
  267. cim_freeObjectPathList(cObjList);
  268. return ((CCIMInstanceList *)NULL);
  269. }
  270. m_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  271. &error);
  272. if (error == ENODEV || m_descriptor == NULL) {
  273. continue;
  274. }
  275. if (error != 0) {
  276. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  277. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  278. cim_freeInstanceList(instList);
  279. cim_freeObjectPathList(cObjList);
  280. return ((CCIMInstanceList *)NULL);
  281. }
  282. c_descriptorp = dm_get_associated_descriptors(m_descriptor,
  283. DM_PATH, &error);
  284. dm_free_descriptor(m_descriptor);
  285. /*
  286. * If there are no paths associated with this mpxio controller,
  287. * continue on to the next controller.
  288. */
  289. if (c_descriptorp == NULL) {
  290. continue;
  291. }
  292. if (c_descriptorp[0] == NULL) {
  293. dm_free_descriptors(c_descriptorp);
  294. continue;
  295. }
  296. if (error != 0) {
  297. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  298. DM_GET_ASSOC_FAILURE, NULL, &error);
  299. cim_freeInstanceList(instList);
  300. cim_freeObjectPathList(cObjList);
  301. return ((CCIMInstanceList *)NULL);
  302. }
  303. tmpList = ctrl_descriptors_toCCIMInstanceList(
  304. SCSI_CONTROLLER, c_descriptorp, &error, 5, "scsi");
  305. dm_free_descriptors(c_descriptorp);
  306. if (error != 0) {
  307. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  308. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  309. cim_freeInstanceList(instList);
  310. cim_freeObjectPathList(cObjList);
  311. return ((CCIMInstanceList *)NULL);
  312. }
  313. dObjList = cim_createObjectPathList(tmpList);
  314. cim_freeInstanceList(tmpList);
  315. if (dObjList == NULL) {
  316. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  317. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  318. cim_freeInstanceList(instList);
  319. cim_freeObjectPathList(cObjList);
  320. return ((CCIMInstanceList *)NULL);
  321. }
  322. tmpList1 = mpxioCompToInstList(
  323. cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
  324. cim_freeObjectPathList(dObjList);
  325. if (error != 0) {
  326. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  327. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  328. cim_freeInstanceList(instList);
  329. cim_freeObjectPathList(cObjList);
  330. return ((CCIMInstanceList *)NULL);
  331. }
  332. tL = tmpList1;
  333. do {
  334. inst = cim_copyInstance(tL->mDataObject);
  335. instList = cim_addInstance(instList, inst);
  336. if (instList == NULL) {
  337. ex = cim_getLastError();
  338. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  339. ADD_INSTANCE_FAILURE, ex, &error);
  340. cim_freeObjectPathList(cObjList);
  341. cim_freeInstance(inst);
  342. cim_freeObjectPathList(tmpList1);
  343. return ((CCIMInstanceList *)NULL);
  344. }
  345. tL = tL->mNext;
  346. } while (tL);
  347. cim_freeObjectPathList(tmpList1);
  348. } /* end for */
  349. cim_freeObjectPathList(cObjList);
  350. /*
  351. * It is possible I will have an empty instance list at
  352. * this point. So, I must check and NULL this out if
  353. * there are no entries.
  354. */
  355. if (instList->mDataObject == NULL) {
  356. cim_freeInstanceList(instList);
  357. instList = NULL;
  358. }
  359. return (instList);
  360. }
  361. /*
  362. * Name: cp_enumInstanceNames_Solaris_MPXIOComponent
  363. *
  364. * Description: Returns a linked list of CCIMObjectPath *
  365. * of Solaris_MPXIOComponent if found.
  366. *
  367. * Parameters:
  368. * pOP - An CCIMObjectPath * which contains the information on
  369. * the class for which to find the instances.
  370. * Returns:
  371. * CCIMObjectPathList * if objects are found.
  372. * Otherwise, NULL is returned.
  373. */
  374. CCIMObjectPathList*
  375. cp_enumInstanceNames_Solaris_MPXIOComponent(CCIMObjectPath * pOP) {
  376. CCIMInstanceList *instList;
  377. CCIMObjectPathList *objList = NULL;
  378. int error;
  379. if (pOP == NULL) {
  380. util_handleError(MPXIO_ENUMINSTANCENAMES,
  381. CIM_ERR_INVALID_PARAMETER, NULL,
  382. NULL, &error);
  383. return ((CCIMObjectPathList *)NULL);
  384. }
  385. /*
  386. * Call in to enumInstances and then convert the instance list in
  387. * to an object list.
  388. */
  389. instList = cp_enumInstances_Solaris_MPXIOComponent(pOP);
  390. if (instList->mDataObject != NULL) {
  391. objList = cim_createObjectPathList(instList);
  392. cim_freeInstanceList(instList);
  393. }
  394. return (objList);
  395. }
  396. /*
  397. * Creating an instance of a Solaris_MPXIOComponent is not supported.
  398. */
  399. /* ARGSUSED */
  400. CCIMObjectPath*
  401. cp_createInstance_Solaris_MPXIOComponent(CCIMObjectPath* pOP,
  402. CCIMInstance* pInst)
  403. {
  404. int error;
  405. util_handleError(MPXIO_COMPONENT, CIM_ERR_NOT_SUPPORTED, NULL,
  406. NULL, &error);
  407. return ((CCIMObjectPath *)NULL);
  408. }
  409. /*
  410. * Deleting an instance of a Solaris_MPXIOComponent is not supported.
  411. */
  412. /* ARGSUSED */
  413. CIMBool
  414. cp_deleteInstance_Solaris_MPXIOComponent(CCIMObjectPath* pInst)
  415. {
  416. int error;
  417. util_handleError(MPXIO_COMPONENT, CIM_ERR_NOT_SUPPORTED, NULL,
  418. NULL, &error);
  419. return (cim_false);
  420. }
  421. /*
  422. * Name: cp_getProperty_Solaris_MPXIOComponent
  423. *
  424. * Description: Returns the property requested, if found.
  425. *
  426. * Parameters:
  427. * pOP - An CCIMObjectPath * which contains the information on
  428. * the class for which to find the instances.
  429. * Returns:
  430. * CCIMProperty * if found.
  431. */
  432. /* ARGSUSED */
  433. CCIMProperty *
  434. cp_getProperty_Solaris_MPXIOComponent(CCIMObjectPath *pOP,
  435. char *pPropName)
  436. {
  437. CCIMProperty *prop = NULL;
  438. CCIMInstance *inst = NULL;
  439. int error = 0;
  440. if (pOP == NULL) {
  441. util_handleError(MPXIO_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
  442. NULL, &error);
  443. return ((CCIMProperty *)NULL);
  444. }
  445. inst = cp_getInstance_Solaris_MPXIOComponent(pOP);
  446. if (inst == NULL) {
  447. return ((CCIMProperty *)NULL);
  448. }
  449. prop = cim_getProperty(inst, pPropName);
  450. cim_freeInstance(inst);
  451. return (prop);
  452. }
  453. /*
  454. * Setting an instance of a Solaris_MPXIOComponent is not supported.
  455. */
  456. /* ARGSUSED */
  457. CIMBool
  458. cp_setInstance_Solaris_MPXIOComponent(CCIMObjectPath* pOP, CCIMInstance* pInst)
  459. {
  460. int error;
  461. util_handleError(MPXIO_COMPONENT, CIM_ERR_NOT_SUPPORTED, NULL,
  462. NULL, &error);
  463. return (cim_false);
  464. }
  465. /*
  466. * Setting a property on a Solaris_MPXIOComponent is not supported.
  467. */
  468. /* ARGSUSED */
  469. CIMBool
  470. cp_setProperty_Solaris_MPXIOComponent(CCIMObjectPath* pOP, CCIMProperty* pProp)
  471. {
  472. int error;
  473. util_handleError(MPXIO_COMPONENT, CIM_ERR_NOT_SUPPORTED, NULL,
  474. NULL, &error);
  475. return (cim_false);
  476. }
  477. /*
  478. * No Methods for Solaris_MPXIOComponent.
  479. */
  480. /* ARGSUSED */
  481. CCIMProperty*
  482. cp_invokeMethod_Solaris_MPXIOComponent(
  483. CCIMObjectPath* op, cimchar* methodName,
  484. CCIMPropertyList* inParams, CCIMPropertyList* outParams)
  485. {
  486. CCIMProperty *retVal = (CCIMProperty *)NULL;
  487. return (retVal);
  488. }
  489. /*
  490. * Name: cp_execQuery_Solaris_MPXIOComponent
  491. *
  492. * Description:
  493. * Returns an instance list which matches the query if any are found.
  494. *
  495. * Parameters:
  496. * CCIMObjectPath *op - An CCIMObjectPath * which contains the
  497. * information on the class for which to find the instances.
  498. *
  499. * selectList - Not used
  500. * nonJoinExp - Not used
  501. *
  502. * Returns:
  503. * CCIMInstance * if matched instance is found. Otherwise, NULL.
  504. */
  505. /*
  506. * Currently, there is no WQL parser for the C providers. As a result,
  507. * what is returned to the CIMOM is a list of instances with
  508. * a NULL value at the beginning of the list. This NULL value indicates
  509. * to the CIMOM that it must do the filtering for the client.
  510. */
  511. /* ARGSUSED */
  512. CCIMInstanceList*
  513. cp_execQuery_Solaris_MPXIOComponent(CCIMObjectPath *op,
  514. cimchar *selectList, cimchar *nonJoinExp, cimchar *queryExp, int queryType)
  515. {
  516. CCIMInstanceList *instList = NULL;
  517. CCIMInstanceList *result;
  518. CCIMInstance *emptyInst;
  519. CCIMException *ex;
  520. int error;
  521. if (op == NULL) {
  522. util_handleError(MPXIO_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
  523. NULL, &error);
  524. return ((CCIMInstanceList *)NULL);
  525. }
  526. instList = cp_enumInstances_Solaris_MPXIOComponent(op);
  527. if (instList == NULL) {
  528. return ((CCIMInstanceList *)NULL);
  529. }
  530. /*
  531. * Create a null instance and add it to the beginning
  532. * of the list to indicate to the CIMOM that no filtering
  533. * was done.
  534. */
  535. emptyInst = cim_createInstance("");
  536. if (emptyInst == NULL) {
  537. ex = cim_getLastError();
  538. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  539. CREATE_INSTANCE_FAILURE, ex, &error);
  540. return ((CCIMInstanceList *)NULL);
  541. }
  542. result = cim_createInstanceList();
  543. if (result == NULL) {
  544. ex = cim_getLastError();
  545. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  546. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  547. cim_freeInstance(emptyInst);
  548. cim_freeInstanceList(instList);
  549. return ((CCIMInstanceList *)NULL);
  550. }
  551. result = cim_addInstance(result, emptyInst);
  552. if (result == NULL) {
  553. ex = cim_getLastError();
  554. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  555. ADD_INSTANCE_FAILURE, ex, &error);
  556. cim_freeInstance(emptyInst);
  557. cim_freeInstanceList(instList);
  558. return ((CCIMInstanceList *)NULL);
  559. }
  560. /*
  561. * Since copying the original list to the new list will
  562. * leave no way to free the original list, manually
  563. * concatenate the original list to the new one.
  564. */
  565. result->mNext = instList;
  566. return (result);
  567. }
  568. /*
  569. * Name: cp_associators_Solaris_MPXIOComponent
  570. *
  571. * Description:
  572. * Returns instances of objects associated with the passed in
  573. * object if there are any.
  574. *
  575. * Parameters:
  576. *
  577. * CCIMObjectPath *pAssocName - The name of the association that
  578. * the client wants information about.
  579. *
  580. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  581. * information on the class for which to find the associated instances.
  582. *
  583. * cimchar *pResultClass - If specified, only return instances that
  584. * are of this class type.
  585. *
  586. * cimchar *pRole - If specified, must be valid for the object path
  587. * passed in requesting the associated instances.
  588. *
  589. * cimchar *pResultRole - If specified, only return instances that
  590. * are playing this role in the association.
  591. *
  592. *
  593. * Returns:
  594. * CCIMInstanceList * if associated objects are found.
  595. * Otherwise, NULL is returned.
  596. */
  597. /* ARGSUSED */
  598. CCIMInstanceList *
  599. cp_associators_Solaris_MPXIOComponent(CCIMObjectPath *pAssocName,
  600. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  601. cimchar *pResultRole)
  602. {
  603. CCIMPropertyList *pCurPropList;
  604. CCIMInstanceList *instList = NULL;
  605. CCIMException *ex;
  606. dm_descriptor_t *assoc_descriptors;
  607. dm_descriptor_t obj_desc;
  608. char *name;
  609. int error = 0;
  610. int isGroup = 0;
  611. if (pObjectName == NULL ||
  612. ((pCurPropList = pObjectName->mKeyProperties) == NULL)) {
  613. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  614. NULL, &error);
  615. return ((CCIMInstanceList *)NULL);
  616. }
  617. if (strcasecmp(pObjectName->mName, MPXIO_CONTROLLER) == 0) {
  618. isGroup = 1;
  619. }
  620. if (pRole != NULL) {
  621. if (strcasecmp(pRole, GROUP) == 0) {
  622. if (isGroup != 1) {
  623. util_handleError(MPXIO_ASSOCIATORS,
  624. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  625. return ((CCIMInstanceList *)NULL);
  626. }
  627. }
  628. }
  629. /*
  630. * Both mpxio controller and the paths have deviceid as the
  631. * key.
  632. */
  633. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  634. &error);
  635. if (error != 0) {
  636. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  637. NULL, &error);
  638. return ((CCIMInstanceList *)NULL);
  639. }
  640. if (isGroup == 1) {
  641. obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  642. &error);
  643. } else {
  644. obj_desc = dm_get_descriptor_by_name(DM_PATH, name,
  645. &error);
  646. }
  647. if (error == ENODEV || obj_desc == NULL) {
  648. return ((CCIMInstanceList *)NULL);
  649. }
  650. if (error != 0) {
  651. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  652. DM_GET_ASSOC_FAILURE, NULL, &error);
  653. return ((CCIMInstanceList *)NULL);
  654. }
  655. if (isGroup) {
  656. /*
  657. * Get associated descriptors.
  658. */
  659. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  660. DM_PATH, &error);
  661. dm_free_descriptor(obj_desc);
  662. if (assoc_descriptors == NULL) {
  663. return ((CCIMInstanceList *)NULL);
  664. }
  665. if (assoc_descriptors[0] == NULL) {
  666. dm_free_descriptors(assoc_descriptors);
  667. return ((CCIMInstanceList *)NULL);
  668. }
  669. if (error != 0) {
  670. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  671. DM_GET_ASSOC_FAILURE, NULL, &error);
  672. return ((CCIMInstanceList *)NULL);
  673. }
  674. /*
  675. * Generate the inst list of the associated paths.
  676. */
  677. instList = ctrl_descriptors_toCCIMInstanceList(SCSI_CONTROLLER,
  678. assoc_descriptors, &error, 1, "scsi");
  679. dm_free_descriptors(assoc_descriptors);
  680. if (error != 0) {
  681. ex = cim_getLastError();
  682. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  683. SCSICTRL_DESC_TO_INSTANCE_FAILURE, ex, &error);
  684. return ((CCIMInstanceList *)NULL);
  685. }
  686. } else {
  687. /*
  688. * This is the underlying ctrl calling this function. Return
  689. * the controllers that are associated with this disk.
  690. */
  691. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  692. DM_CONTROLLER, &error);
  693. dm_free_descriptor(obj_desc);
  694. if (assoc_descriptors == NULL) {
  695. return ((CCIMInstanceList *)NULL);
  696. }
  697. if (assoc_descriptors[0] == NULL) {
  698. dm_free_descriptors(assoc_descriptors);
  699. return ((CCIMInstanceList *)NULL);
  700. }
  701. if (error != 0) {
  702. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  703. DM_GET_ASSOC_FAILURE, NULL, &error);
  704. return ((CCIMInstanceList *)NULL);
  705. }
  706. instList = ctrl_descriptors_toCCIMInstanceList(MPXIO_CONTROLLER,
  707. assoc_descriptors, &error, 1, "scsi_vhci");
  708. dm_free_descriptors(assoc_descriptors);
  709. if (error != 0) {
  710. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  711. MPXIOCTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  712. return ((CCIMInstanceList *)NULL);
  713. }
  714. }
  715. return (instList);
  716. }
  717. /*
  718. * Name: cp_associatorNames_Solaris_MPXIOComponent
  719. *
  720. * Description:
  721. * Returns a list of objects associated with the passed in
  722. * object if there are any via the object CCIMObjectPath.
  723. *
  724. * Parameters:
  725. *
  726. * CCIMObjectPath *pAssocName - The name of the association that
  727. * the client wants information about.
  728. *
  729. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  730. * information on the class for which to find the associated instances.
  731. *
  732. * cimchar *pResultClass - If specified, only return instances that
  733. * are of this class type.
  734. *
  735. * cimchar *pRole - If specified, must be valid for the object path
  736. * passed in requesting the associated instances.
  737. *
  738. * cimchar *pResultRole - If specified, only return instances that
  739. * are playing this role in the association.
  740. *
  741. *
  742. * Returns:
  743. * CCIMObjectPathList * if associated objects are found.
  744. * Otherwise, NULL is returned.
  745. */
  746. /* ARGSUSED */
  747. CCIMObjectPathList *
  748. cp_associatorNames_Solaris_MPXIOComponent(CCIMObjectPath *pAssocName,
  749. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  750. cimchar *pResultRole)
  751. {
  752. CCIMInstanceList *instList;
  753. CCIMObjectPathList *objList = NULL;
  754. int error;
  755. if (pObjectName == NULL) {
  756. util_handleError(MPXIO_ASSOCIATORNAMES,
  757. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  758. return ((CCIMObjectPathList *)NULL);
  759. }
  760. instList =
  761. cp_associators_Solaris_MPXIOComponent(
  762. pAssocName, pObjectName, pResultClass, pRole, pResultRole);
  763. if (instList != NULL) {
  764. objList = cim_createObjectPathList(instList);
  765. cim_freeInstanceList(instList);
  766. }
  767. return (objList);
  768. }
  769. /*
  770. * Name: cp_references_Solaris_MPXIOComponent
  771. *
  772. * Description:
  773. * Returns instances of objects that have references to the passed in
  774. * object if there are any.
  775. *
  776. * Parameters:
  777. *
  778. * CCIMObjectPath *pAssocName - The name of the association that
  779. * the client wants information about.
  780. *
  781. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  782. * information on the class for which to find the associated instances.
  783. *
  784. * cimchar *pRole - If specified, must be valid for the object path
  785. * passed in requesting the associated instances.
  786. *
  787. * Returns:
  788. * CCIMInstanceList * if associated objects are found. Thist list
  789. * may be empty. NULL is returned on error.
  790. */
  791. /* ARGSUSED */
  792. CCIMInstanceList *
  793. cp_references_Solaris_MPXIOComponent(CCIMObjectPath *pAssocName,
  794. CCIMObjectPath *pObjectName, char *pRole)
  795. {
  796. CCIMInstanceList *instList = NULL;
  797. CCIMObjectPathList *objList;
  798. int error;
  799. if (pObjectName == NULL) {
  800. util_handleError(MPXIO_REFERENCES, CIM_ERR_INVALID_PARAMETER,
  801. NULL, NULL, &error);
  802. return ((CCIMInstanceList *)NULL);
  803. }
  804. /*
  805. * Get the list of those objects that are referred to by
  806. * the calling object.
  807. */
  808. objList =
  809. cp_associatorNames_Solaris_MPXIOComponent(
  810. pAssocName, pObjectName, NULL, NULL, NULL);
  811. if (objList == NULL) {
  812. return ((CCIMInstanceList *)NULL);
  813. }
  814. /*
  815. * Now generate the list of instances to return.
  816. */
  817. if ((strcasecmp(pObjectName->mName, MPXIO_CONTROLLER)) == 0) {
  818. instList = mpxioCompToInstList(pObjectName,
  819. ANTECEDENT, objList, DEPENDENT, &error);
  820. } else {
  821. instList = mpxioCompToInstList(pObjectName,
  822. DEPENDENT, objList, ANTECEDENT, &error);
  823. }
  824. cim_freeObjectPathList(objList);
  825. return (instList);
  826. }
  827. /*
  828. * Name: cp_referenceNames_Solaris_MPXIOComponent
  829. *
  830. * Description:
  831. * Returns a instances of objects that have references to the passed in
  832. * object if there are any.
  833. *
  834. * Parameters:
  835. *
  836. * CCIMObjectPath *pAssocName - The name of the association that
  837. * the client wants information about.
  838. *
  839. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  840. * information on the class for which to find the associated instances.
  841. *
  842. * cimchar *pRole - If specified, must be valid for the object path
  843. * passed in requesting the associated instances.
  844. *
  845. *
  846. * Returns:
  847. * CCIMObjectPathList * if associated objects are found. Otherwise, NULL.
  848. *
  849. */
  850. /* ARGSUSED */
  851. CCIMObjectPathList *
  852. cp_referenceNames_Solaris_MPXIOComponent(CCIMObjectPath *pAssocName,
  853. CCIMObjectPath *pObjectName, cimchar *pRole)
  854. {
  855. CCIMInstanceList *instList;
  856. CCIMObjectPathList *objList = NULL;
  857. int error;
  858. if (pObjectName == NULL) {
  859. util_handleError(MPXIO_REFERENCENAMES,
  860. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  861. return ((CCIMObjectPathList *)NULL);
  862. }
  863. instList =
  864. cp_references_Solaris_MPXIOComponent(pAssocName,
  865. pObjectName, pRole);
  866. if (instList != NULL) {
  867. objList = cim_createObjectPathList(instList);
  868. cim_freeInstanceList(instList);
  869. }
  870. return (objList);
  871. }
  872. /*
  873. * Create the association class with the passed in attributes.
  874. */
  875. static
  876. CCIMInstanceList *
  877. mpxioCompToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  878. CCIMObjectPathList *objList, cimchar *objRole, int *error)
  879. {
  880. CCIMObjectPathList *tmpList;
  881. CCIMInstanceList *instList = NULL;
  882. CCIMInstance *inst;
  883. CCIMObjectPath *obj1;
  884. CCIMObjectPath *obj2;
  885. CCIMException *ex;
  886. *error = 0;
  887. /*
  888. * If no objects associated with this one, return NULL.
  889. */
  890. if (objList == NULL) {
  891. return ((CCIMInstanceList *)NULL);
  892. }
  893. instList = cim_createInstanceList();
  894. if (instList == NULL) {
  895. ex = cim_getLastError();
  896. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  897. CREATE_INSTANCE_FAILURE, ex, error);
  898. return ((CCIMInstanceList *)NULL);
  899. }
  900. tmpList = objList;
  901. while (tmpList != NULL) {
  902. obj1 = tmpList->mDataObject;
  903. obj2 = cim_copyObjectPath(pObjectName);
  904. if (obj2 == NULL) {
  905. ex = cim_getLastError();
  906. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  907. COPY_OBJPATH_FAILURE, ex, error);
  908. return ((CCIMInstanceList *)NULL);
  909. }
  910. inst = mpxioCompToInst(obj1, objRole, obj2, pObjectNameRole,
  911. error);
  912. cim_freeObjectPath(obj2);
  913. if (*error != 0) {
  914. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  915. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, NULL, error);
  916. cim_freeInstanceList(instList);
  917. return ((CCIMInstanceList *)NULL);
  918. }
  919. instList = cim_addInstance(instList, inst);
  920. if (instList == NULL) {
  921. ex = cim_getLastError();
  922. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  923. ADD_INSTANCE_FAILURE, ex, error);
  924. cim_freeInstance(inst);
  925. return ((CCIMInstanceList *)NULL);
  926. }
  927. tmpList = tmpList->mNext;
  928. }
  929. return (instList);
  930. }
  931. /*
  932. * Create an instance of an mpxio group object.
  933. */
  934. static
  935. CCIMInstance *
  936. mpxioCompToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  937. CCIMObjectPath *obj2, cimchar *obj2Role, int *error)
  938. {
  939. CCIMInstance *inst = NULL;
  940. CCIMException *ex;
  941. *error = 0;
  942. inst = cim_createInstance(MPXIO_COMPONENT);
  943. if (inst == NULL) {
  944. ex = cim_getLastError();
  945. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  946. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, ex, error);
  947. return ((CCIMInstance *)NULL);
  948. }
  949. util_doReferenceProperty(obj2Role, obj2, cim_true, inst, error);
  950. util_doReferenceProperty(obj1Role, obj1, cim_true, inst, error);
  951. if (*error != 0) {
  952. ex = cim_getLastError();
  953. util_handleError(MPXIO_COMPONENT, CIM_ERR_FAILED,
  954. CREATE_REFPROP_FAILURE, ex, error);
  955. cim_freeInstance(inst);
  956. return ((CCIMInstance *)NULL);
  957. }
  958. return (inst);
  959. }