PageRenderTime 29ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/osunix/osunix-gate
C | 1101 lines | 643 code | 138 blank | 320 comment | 163 complexity | 54db1f1cb84d2beb7b07eb615a65a10f 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 "drive_descriptors.h"
  35. #include "ctrl_descriptors.h"
  36. #include "Solaris_MPXIOInterface.h"
  37. #define MPXIO_GETINSTANCE "MPXIO_INTERFACE,GET_INSTANCE"
  38. #define MPXIO_ENUMINSTANCES "MPXIO_INTERFACE,ENUM_INSTANCES"
  39. #define MPXIO_ENUMINSTANCENAMES "MPXIO_INTERFACE,ENUM_INSTANCENAMES"
  40. #define MPXIO_CREATEINSTANCE "MPXIO_INTERFACE,CREATE_INSTANCE"
  41. #define MPXIO_DELETEINSTANCE "MPXIO_INTERFACE,DELETE_INSTANCE"
  42. #define MPXIO_SETINSTANCE "MPXIO_INTERFACE,SET_INSTANCE"
  43. #define MPXIO_GETPROPERTY "MPXIO_INTERFACE,GET_PROPERTY"
  44. #define MPXIO_SETPROPERTY "MPXIO_INTERFACE,SET_PROPERTY"
  45. #define MPXIO_INVOKEMETHOD "MPXIO_INTERFACE,INVOKE_METHOD"
  46. #define MPXIO_EXECQUERY "MPXIO_INTERFACE,EXEC_QUERY"
  47. #define MPXIO_ASSOCIATORS "MPXIO_INTERFACE,ASSOCIATORS"
  48. #define MPXIO_ASSOCIATORNAMES "MPXIO_INTERFACE,ASSOCIATOR_NAMES"
  49. #define MPXIO_REFERENCES "MPXIO_INTERFACE,REFERENCES"
  50. #define MPXIO_REFERENCENAMES "MPXIO_INTERFACE,REFERENCE_NAMES"
  51. static
  52. CCIMInstanceList *
  53. mpxioIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  54. CCIMObjectPathList *objList, cimchar *objRole, int *error);
  55. static
  56. CCIMInstance *
  57. mpxioIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  58. CCIMObjectPath *obj2, cimchar *obj2Role, int *error);
  59. /*
  60. * Solaris_MPXIOInterface provider
  61. *
  62. * It is important to note that all memory allocated by these functions
  63. * and passed to the CIMOM, is freed by the door process prior to
  64. * sending a copy of the data to the CIMOM.
  65. */
  66. /*
  67. * Name: cp_getInstance_Solaris_MPXIOInterface
  68. *
  69. * Description: Returns an instance which matches the passed in object path
  70. * if found.
  71. *
  72. * Parameters:
  73. * pOP - An CCIMObjectPath * which contains the information on
  74. * the class for which to find the instance.
  75. * Returns:
  76. * CCIMInstance * if matched instance is found. Otherwise, NULL.
  77. */
  78. CCIMInstance*
  79. cp_getInstance_Solaris_MPXIOInterface(CCIMObjectPath* pOP)
  80. {
  81. CCIMInstance* inst = NULL;
  82. CCIMPropertyList* pCurPropList;
  83. CCIMObjectPath *antOp = NULL;
  84. CCIMObjectPath *depOp = NULL;
  85. dm_descriptor_t d_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,
  92. NULL, NULL, &error);
  93. return ((CCIMInstance *)NULL);
  94. }
  95. antOp = (CCIMObjectPath *)util_getKeyValue(
  96. pCurPropList, reference, ANTECEDENT, &error);
  97. if (error == 0) {
  98. depOp = (CCIMObjectPath *)util_getKeyValue(
  99. pCurPropList, reference, DEPENDENT, &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,
  117. DEVICEID, &error);
  118. if (error != 0) {
  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. c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  130. &error);
  131. /*
  132. * Not found. Return a null instance.
  133. */
  134. if (error == ENODEV || c_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(c_descriptor);
  143. pCurPropList = depOp->mKeyProperties;
  144. name = (cimchar *)util_getKeyValue(pCurPropList, string,
  145. DEVICEID, &error);
  146. if (error != 0) {
  147. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
  148. NULL, NULL, &error);
  149. return ((CCIMInstance *)NULL);
  150. }
  151. d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name, &error);
  152. /*
  153. * Not found. Return a null instance.
  154. */
  155. if (error == ENODEV || d_descriptor == NULL) {
  156. return ((CCIMInstance *)NULL);
  157. }
  158. if (error != 0) {
  159. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
  160. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  161. return ((CCIMInstance*)NULL);
  162. }
  163. dm_free_descriptor(d_descriptor);
  164. /*
  165. * At this point I have verified I have the two devices that
  166. * are part of this association. Use the object paths I got
  167. * earlier to create the mpxiointerface instance.
  168. */
  169. inst = mpxioIntAssocToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);
  170. if (error != 0) {
  171. util_handleError(MPXIO_GETINSTANCE, CIM_ERR_FAILED,
  172. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
  173. return ((CCIMInstance *)NULL);
  174. }
  175. return (inst);
  176. }
  177. /*
  178. * Name: cp_enumInstances_Solaris_MPXIOInterface
  179. *
  180. * Description: Returns a linked list of instances of
  181. * Solaris_MPXIOInterface if found.
  182. *
  183. * Parameters:
  184. * pOP - An CCIMObjectPath * which contains the information on
  185. * the class for which to find the instances.
  186. * Returns:
  187. * CCIMInstanceList * if istances are found. NULL otherwise.
  188. */
  189. /* ARGSUSED */
  190. CCIMInstanceList*
  191. cp_enumInstances_Solaris_MPXIOInterface(CCIMObjectPath* pOP)
  192. {
  193. CCIMInstanceList *instList = NULL;
  194. CCIMObjectPathList *cObjList;
  195. CCIMObjectPathList *tmpObjList;
  196. CCIMObjectPath *objPath;
  197. CCIMInstance *inst;
  198. CCIMException *ex;
  199. dm_descriptor_t *d_descriptorp = NULL;
  200. int error = 0;
  201. objPath = cim_createEmptyObjectPath(MPXIO_CONTROLLER);
  202. if (objPath == NULL) {
  203. ex = cim_getLastError();
  204. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  205. CREATE_OBJECT_PATH, ex, &error);
  206. return ((CCIMInstanceList *)NULL);
  207. }
  208. cObjList = cimom_enumerateInstanceNames(objPath, cim_false);
  209. cim_freeObjectPath(objPath);
  210. /*
  211. * NULL is an error. Empty list is not.
  212. */
  213. if (cObjList == NULL) {
  214. ex = cim_getLastError();
  215. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  216. ENUM_INSTANCENAMES_FAILURE, ex, &error);
  217. return ((CCIMInstanceList *)NULL);
  218. }
  219. if (cObjList->mDataObject == NULL) {
  220. return ((CCIMInstanceList *)NULL);
  221. }
  222. /*
  223. * Loop through all of these controller objects and get the associated
  224. * disks.
  225. */
  226. instList = cim_createInstanceList();
  227. if (instList == NULL) {
  228. ex = cim_getLastError();
  229. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  230. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  231. return ((CCIMInstanceList *)NULL);
  232. }
  233. for (tmpObjList = cObjList; tmpObjList != NULL &&
  234. tmpObjList->mDataObject != NULL;
  235. tmpObjList = tmpObjList->mNext) {
  236. CCIMObjectPath *cOp;
  237. CCIMInstanceList *tmpList;
  238. CCIMInstanceList *tmpList1 = NULL;
  239. CCIMPropertyList *pCurPropList;
  240. CCIMObjectPathList *dObjList;
  241. CCIMInstanceList *tL;
  242. dm_descriptor_t c_descriptor;
  243. char *name = NULL;
  244. cOp = tmpObjList->mDataObject;
  245. if ((pCurPropList = cOp->mKeyProperties) == NULL) {
  246. util_handleError(MPXIO_ENUMINSTANCES,
  247. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  248. cim_freeInstanceList(instList);
  249. cim_freeObjectPathList(cObjList);
  250. return ((CCIMInstanceList *)NULL);
  251. }
  252. name = (cimchar *)util_getKeyValue(pCurPropList, string,
  253. DEVICEID, &error);
  254. if (error != 0 || name == 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. c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  262. &error);
  263. if (error == ENODEV || c_descriptor == NULL) {
  264. continue;
  265. }
  266. if (error != 0) {
  267. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  268. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  269. cim_freeInstanceList(instList);
  270. cim_freeObjectPathList(cObjList);
  271. return ((CCIMInstanceList *)NULL);
  272. }
  273. d_descriptorp = dm_get_associated_descriptors(c_descriptor,
  274. DM_DRIVE, &error);
  275. dm_free_descriptor(c_descriptor);
  276. /*
  277. * If there are no drives associated with this controller,
  278. * continue on to the next controller.
  279. */
  280. if (d_descriptorp == NULL ||
  281. d_descriptorp[0] == NULL) {
  282. continue;
  283. }
  284. if (error != 0) {
  285. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  286. DM_GET_ASSOC_FAILURE, NULL, &error);
  287. cim_freeInstanceList(instList);
  288. cim_freeObjectPathList(cObjList);
  289. return ((CCIMInstanceList *)NULL);
  290. }
  291. tmpList = drive_descriptors_toCCIMObjPathInstList(
  292. DISK_DRIVE, d_descriptorp, &error);
  293. dm_free_descriptors(d_descriptorp);
  294. if (error != 0) {
  295. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  296. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  297. cim_freeInstanceList(instList);
  298. cim_freeObjectPathList(cObjList);
  299. return ((CCIMInstanceList *)NULL);
  300. }
  301. if (tmpList == NULL) {
  302. continue;
  303. }
  304. dObjList = cim_createObjectPathList(tmpList);
  305. cim_freeInstanceList(tmpList);
  306. if (dObjList == NULL) {
  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. tmpList1 = mpxioIntAssocToInstList(
  314. cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
  315. cim_freeObjectPathList(dObjList);
  316. if (error != 0) {
  317. util_handleError(MPXIO_ENUMINSTANCES, CIM_ERR_FAILED,
  318. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  319. cim_freeInstanceList(instList);
  320. cim_freeObjectPathList(cObjList);
  321. return ((CCIMInstanceList *)NULL);
  322. }
  323. /*
  324. * Assign a pointer to the tmplist. Traverse the list with
  325. * this pointer so as not to disturb the original value of
  326. * the instance list. This is needed for freeing the list
  327. * later.
  328. */
  329. tL = tmpList1;
  330. do {
  331. inst = cim_copyInstance(tL->mDataObject);
  332. instList = cim_addInstance(instList, inst);
  333. if (instList == NULL) {
  334. /*
  335. * In this case we do not free the indivual instance
  336. * added to the instance list. On error, the original
  337. * instance list is freed.
  338. */
  339. util_handleError(MPXIO_ENUMINSTANCENAMES, CIM_ERR_FAILED,
  340. ADD_INSTANCE_FAILURE, NULL, &error);
  341. cim_freeInstance(inst);
  342. cim_freeObjectPathList(cObjList);
  343. cim_freeInstanceList(tmpList1);
  344. return ((CCIMInstanceList *)NULL);
  345. }
  346. tL = tL->mNext;
  347. } while (tL);
  348. cim_freeInstanceList(tmpList1);
  349. } /* end for */
  350. cim_freeObjectPathList(cObjList);
  351. /*
  352. * It is possible I will have an empty instance list at
  353. * this point. So, I must check and NULL this out if
  354. * there are no entries.
  355. */
  356. if (instList->mDataObject == NULL) {
  357. cim_freeInstanceList(instList);
  358. instList = NULL;
  359. }
  360. return (instList);
  361. }
  362. /*
  363. * Name: cp_enumInstanceNames_Solaris_MPXIOInterface
  364. *
  365. * Description: Returns a linked list of CCIMObjectPath *
  366. * of Solaris_MPXIOInterface if found.
  367. *
  368. * Parameters:
  369. * pOP - An CCIMObjectPath * which contains the information on
  370. * the class for which to find the instances.
  371. * Returns:
  372. * CCIMObjectPathList * if objects are found. NULL otherwise.
  373. */
  374. CCIMObjectPathList*
  375. cp_enumInstanceNames_Solaris_MPXIOInterface(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, NULL, &error);
  382. return ((CCIMObjectPathList *)NULL);
  383. }
  384. /*
  385. * Call in to enumInstances and then convert the instance list in
  386. * to an object list.
  387. */
  388. instList = cp_enumInstances_Solaris_MPXIOInterface(pOP);
  389. if (instList != NULL) {
  390. objList = cim_createObjectPathList(instList);
  391. cim_freeInstanceList(instList);
  392. }
  393. return (objList);
  394. }
  395. /*
  396. * Creating an instance of a Solaris_MPXIOInterface is not supported.
  397. */
  398. /* ARGSUSED */
  399. CCIMObjectPath*
  400. cp_createInstance_Solaris_MPXIOInterface(CCIMObjectPath* pOP,
  401. CCIMInstance* pInst)
  402. {
  403. int error;
  404. util_handleError(MPXIO_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  405. NULL, &error);
  406. return ((CCIMObjectPath *)NULL);
  407. }
  408. /*
  409. * Deleting an instance of a Solaris_MPXIOInterface is not supported.
  410. */
  411. /* ARGSUSED */
  412. CIMBool
  413. cp_deleteInstance_Solaris_MPXIOInterface(CCIMObjectPath* pInst)
  414. {
  415. int error;
  416. util_handleError(MPXIO_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  417. NULL, &error);
  418. return (cim_false);
  419. }
  420. /*
  421. * Name: cp_getProperty_Solaris_MPXIOInterface
  422. *
  423. * Description: Returns the property requested, if found.
  424. *
  425. * Parameters:
  426. * pOP - An CCIMObjectPath * which contains the information on
  427. * the class for which to find the instances.
  428. * Returns:
  429. * CCIMProperty * if found.
  430. */
  431. /* ARGSUSED */
  432. CCIMProperty *
  433. cp_getProperty_Solaris_MPXIOInterface(CCIMObjectPath *pOP,
  434. char *pPropName)
  435. {
  436. CCIMProperty *prop = NULL;
  437. CCIMInstance *inst = NULL;
  438. int error = 0;
  439. if (pOP == NULL) {
  440. util_handleError(MPXIO_GETPROPERTY,
  441. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  442. return ((CCIMProperty *)NULL);
  443. }
  444. inst = cp_getInstance_Solaris_MPXIOInterface(pOP);
  445. if (inst == NULL) {
  446. return ((CCIMProperty *)NULL);
  447. }
  448. prop = cim_getProperty(inst, pPropName);
  449. cim_freeInstance(inst);
  450. return (prop);
  451. }
  452. /*
  453. * Setting an instance of a Solaris_MPXIOInterface is not supported.
  454. */
  455. /* ARGSUSED */
  456. CIMBool
  457. cp_setInstance_Solaris_MPXIOInterface(CCIMObjectPath* pOP, CCIMInstance* pInst)
  458. {
  459. int error;
  460. util_handleError(MPXIO_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  461. NULL, &error);
  462. return (cim_false);
  463. }
  464. /*
  465. * Setting a property on a Solaris_MPXIOInterface is not supported.
  466. */
  467. /* ARGSUSED */
  468. CIMBool
  469. cp_setProperty_Solaris_MPXIOInterface(CCIMObjectPath* pOP, CCIMProperty* pProp)
  470. {
  471. int error;
  472. util_handleError(MPXIO_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
  473. NULL, &error);
  474. return (cim_false);
  475. }
  476. /*
  477. * No Methods for Solaris_MPXIOInterface.
  478. */
  479. /* ARGSUSED */
  480. CCIMProperty*
  481. cp_invokeMethod_Solaris_MPXIOInterface(
  482. CCIMObjectPath* op, cimchar* methodName,
  483. CCIMPropertyList* inParams, CCIMPropertyList* outParams)
  484. {
  485. CCIMProperty *retVal = (CCIMProperty *)NULL;
  486. return (retVal);
  487. }
  488. /*
  489. * Name: cp_execQuery_Solaris_MPXIOInterface
  490. *
  491. * Description:
  492. * Returns an instance list which matches the query if any are found.
  493. *
  494. * Parameters:
  495. * CCIMObjectPath *op - An CCIMObjectPath * which contains the
  496. * information on the class for which to find the instances.
  497. *
  498. * selectList - Not used
  499. * nonJoinExp - Not used
  500. *
  501. * Returns:
  502. * CCIMInstance * if matched instance is found. Otherwise, NULL.
  503. */
  504. /*
  505. * Currently, there is no WQL parser for the C providers. As a result,
  506. * what is returned to the CIMOM is a list of instances with
  507. * a NULL value at the beginning of the list. This NULL value indicates
  508. * to the CIMOM that it must do the filtering for the client.
  509. */
  510. /* ARGSUSED */
  511. CCIMInstanceList*
  512. cp_execQuery_Solaris_MPXIOInterface(CCIMObjectPath *op,
  513. cimchar *selectList, cimchar *nonJoinExp, cimchar *queryExp, int queryType)
  514. {
  515. CCIMInstanceList *instList = NULL;
  516. CCIMInstanceList *result;
  517. CCIMInstance *emptyInst;
  518. CCIMException *ex;
  519. int error;
  520. if (op == NULL) {
  521. util_handleError(MPXIO_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
  522. NULL, &error);
  523. return ((CCIMInstanceList *)NULL);
  524. }
  525. instList = cp_enumInstances_Solaris_MPXIOInterface(op);
  526. if (instList == NULL) {
  527. return ((CCIMInstanceList *)NULL);
  528. }
  529. /*
  530. * Create a null instance and add it to the beginning
  531. * of the list to indicate to the CIMOM that no filtering
  532. * was done.
  533. */
  534. emptyInst = cim_createInstance("");
  535. if (emptyInst == NULL) {
  536. ex = cim_getLastError();
  537. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  538. CREATE_INSTANCE_FAILURE, ex, &error);
  539. return ((CCIMInstanceList *)NULL);
  540. }
  541. result = cim_createInstanceList();
  542. if (result == NULL) {
  543. ex = cim_getLastError();
  544. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  545. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  546. cim_freeInstance(emptyInst);
  547. cim_freeInstanceList(instList);
  548. return ((CCIMInstanceList *)NULL);
  549. }
  550. result = cim_addInstance(result, emptyInst);
  551. if (result == NULL) {
  552. ex = cim_getLastError();
  553. util_handleError(MPXIO_EXECQUERY, CIM_ERR_FAILED,
  554. ADD_INSTANCE_FAILURE, ex, &error);
  555. cim_freeInstance(emptyInst);
  556. cim_freeInstanceList(instList);
  557. return ((CCIMInstanceList *)NULL);
  558. }
  559. /*
  560. * Since copying the original list to the new list will
  561. * leave no way to free the original list, manually
  562. * concatenate the original list to the new one.
  563. */
  564. result->mNext = instList;
  565. return (result);
  566. }
  567. /*
  568. * Name: cp_associators_Solaris_MPXIOInterface
  569. *
  570. * Description:
  571. * Returns a instances of objects associated with the passed in
  572. * object if there are any.
  573. *
  574. * Parameters:
  575. *
  576. * CCIMObjectPath *pAssocName - The name of the association that
  577. * the client wants information about.
  578. *
  579. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  580. * information on the class for which to find the associated instances.
  581. *
  582. * cimchar *pResultClass - If specified, only return instances that
  583. * are of this class type.
  584. *
  585. * cimchar *pRole - If specified, must be valid for the object path
  586. * passed in requesting the associated instances.
  587. *
  588. * cimchar *pResultRole - If specified, only return instances that
  589. * are playing this role in the association.
  590. *
  591. *
  592. * Returns:
  593. * CCIMInstanceList * if associated objects are found. NULL otherwise.
  594. */
  595. /* ARGSUSED */
  596. CCIMInstanceList *
  597. cp_associators_Solaris_MPXIOInterface(CCIMObjectPath *pAssocName,
  598. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  599. cimchar *pResultRole)
  600. {
  601. CCIMPropertyList *pCurPropList;
  602. CCIMInstanceList *instList = NULL;
  603. dm_descriptor_t *assoc_descriptors;
  604. dm_descriptor_t obj_desc;
  605. char *name;
  606. int error = 0;
  607. int isAntecedent = 0;
  608. if (pObjectName == NULL ||
  609. pObjectName->mName == NULL ||
  610. ((pCurPropList = pObjectName->mKeyProperties) == NULL)) {
  611. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER,
  612. NULL, NULL, &error);
  613. return ((CCIMInstanceList *)NULL);
  614. }
  615. if (strcasecmp(pObjectName->mName, MPXIO_CONTROLLER) == 0) {
  616. isAntecedent = 1;
  617. }
  618. if (pRole != NULL) {
  619. if (strcasecmp(pRole, ANTECEDENT) == 0) {
  620. if (isAntecedent != 1) {
  621. util_handleError(MPXIO_ASSOCIATORS,
  622. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  623. return ((CCIMInstanceList *)NULL);
  624. }
  625. } else if (strcasecmp(pRole, DEPENDENT) == 0) {
  626. if (isAntecedent == 1) {
  627. util_handleError(MPXIO_ASSOCIATORS,
  628. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  629. return ((CCIMInstanceList *)NULL);
  630. }
  631. }
  632. }
  633. /*
  634. * Both mpxio controller and disk drive have deviceid as the
  635. * key.
  636. */
  637. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  638. &error);
  639. if (error != 0) {
  640. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  641. NULL, &error);
  642. return ((CCIMInstanceList *)NULL);
  643. }
  644. if (isAntecedent) {
  645. obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  646. &error);
  647. } else {
  648. obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name,
  649. &error);
  650. }
  651. /*
  652. * No device found.
  653. */
  654. if (error == ENODEV || obj_desc == NULL) {
  655. return ((CCIMInstanceList *)NULL);
  656. }
  657. if (error != 0) {
  658. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  659. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  660. return ((CCIMInstanceList *)NULL);
  661. }
  662. if (isAntecedent) {
  663. /*
  664. * Controller calling this method, return instances of the
  665. * disk drives associatied with this controller.
  666. */
  667. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  668. DM_DRIVE, &error);
  669. dm_free_descriptor(obj_desc);
  670. if (assoc_descriptors == NULL ||
  671. assoc_descriptors[0] == NULL) {
  672. return ((CCIMInstanceList *)NULL);
  673. }
  674. if (error != 0) {
  675. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  676. DM_GET_ASSOC_FAILURE, NULL, &error);
  677. return ((CCIMInstanceList *)NULL);
  678. }
  679. /*
  680. * Generate the inst list of the associated disk drives.
  681. */
  682. instList = drive_descriptors_toCCIMObjPathInstList(DISK_DRIVE,
  683. assoc_descriptors, &error);
  684. dm_free_descriptors(assoc_descriptors);
  685. if (error != 0) {
  686. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  687. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  688. return ((CCIMInstanceList *)NULL);
  689. }
  690. } else {
  691. /*
  692. * This is the disk drive calling this function. Return the
  693. * controllers that are associated with this disk.
  694. */
  695. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  696. DM_CONTROLLER, &error);
  697. dm_free_descriptor(obj_desc);
  698. if (assoc_descriptors == NULL ||
  699. assoc_descriptors[0] == NULL) {
  700. return ((CCIMInstanceList *)NULL);
  701. }
  702. if (error != 0) {
  703. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  704. DM_GET_ASSOC_FAILURE, NULL, &error);
  705. return ((CCIMInstanceList *)NULL);
  706. }
  707. instList = ctrl_descriptors_toCCIMInstanceList(MPXIO_CONTROLLER,
  708. assoc_descriptors, &error, 1, "scsi_vhci");
  709. dm_free_descriptors(assoc_descriptors);
  710. if (error != 0) {
  711. util_handleError(MPXIO_ASSOCIATORS, CIM_ERR_FAILED,
  712. MPXIOCTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  713. return ((CCIMInstanceList *)NULL);
  714. }
  715. }
  716. return (instList);
  717. }
  718. /*
  719. * Name: cp_associatorNames_Solaris_MPXIOInterface
  720. *
  721. * Description:
  722. * Returns a list of objects associated with the passed in
  723. * object if there are any via the object CCIMObjectPath.
  724. *
  725. * Parameters:
  726. *
  727. * CCIMObjectPath *pAssocName - The name of the association that
  728. * the client wants information about.
  729. *
  730. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  731. * information on the class for which to find the associated instances.
  732. *
  733. * cimchar *pResultClass - If specified, only return instances that
  734. * are of this class type.
  735. *
  736. * cimchar *pRole - If specified, must be valid for the object path
  737. * passed in requesting the associated instances.
  738. *
  739. * cimchar *pResultRole - If specified, only return instances that
  740. * are playing this role in the association.
  741. *
  742. *
  743. * Returns:
  744. * CCIMObjectPathList * if associated objects are found. Otherwise, NULL.
  745. */
  746. /* ARGSUSED */
  747. CCIMObjectPathList *
  748. cp_associatorNames_Solaris_MPXIOInterface(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_MPXIOInterface(
  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_MPXIOInterface
  771. *
  772. * Description:
  773. * Returns a 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. NULL otherwise.
  789. */
  790. /* ARGSUSED */
  791. CCIMInstanceList *
  792. cp_references_Solaris_MPXIOInterface(CCIMObjectPath *pAssocName,
  793. CCIMObjectPath *pObjectName, char *pRole)
  794. {
  795. CCIMInstanceList *instList = NULL;
  796. CCIMObjectPathList *objList;
  797. int error;
  798. if (pObjectName == NULL) {
  799. util_handleError(MPXIO_REFERENCES, CIM_ERR_INVALID_PARAMETER,
  800. NULL, NULL, &error);
  801. return ((CCIMInstanceList *)NULL);
  802. }
  803. /*
  804. * Get the list of those objects that are referred to by
  805. * the calling object.
  806. */
  807. objList =
  808. cp_associatorNames_Solaris_MPXIOInterface(
  809. pAssocName, pObjectName, NULL, NULL, NULL);
  810. if (objList == NULL) {
  811. return ((CCIMInstanceList *)NULL);
  812. }
  813. /*
  814. * Now generate the list of instances to return.
  815. */
  816. if ((strcasecmp(pObjectName->mName, MPXIO_CONTROLLER)) == 0) {
  817. instList = mpxioIntAssocToInstList(pObjectName,
  818. ANTECEDENT, objList, DEPENDENT, &error);
  819. } else {
  820. instList = mpxioIntAssocToInstList(pObjectName,
  821. DEPENDENT, objList, ANTECEDENT, &error);
  822. }
  823. cim_freeObjectPathList(objList);
  824. return (instList);
  825. }
  826. /*
  827. * Name: cp_referenceNames_Solaris_MPXIOInterface
  828. *
  829. * Description:
  830. * Returns a instances of objects that have references to the passed in
  831. * object if there are any.
  832. *
  833. * Parameters:
  834. *
  835. * CCIMObjectPath *pAssocName - The name of the association that
  836. * the client wants information about.
  837. *
  838. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  839. * information on the class for which to find the associated instances.
  840. *
  841. * cimchar *pRole - If specified, must be valid for the object path
  842. * passed in requesting the associated instances.
  843. *
  844. *
  845. * Returns:
  846. * CCIMObjectPathList * if associated objects are found. NULL otherwise.
  847. *
  848. */
  849. /* ARGSUSED */
  850. CCIMObjectPathList *
  851. cp_referenceNames_Solaris_MPXIOInterface(CCIMObjectPath *pAssocName,
  852. CCIMObjectPath *pObjectName, cimchar *pRole)
  853. {
  854. CCIMInstanceList *instList;
  855. CCIMObjectPathList *objList = NULL;
  856. int error;
  857. if (pObjectName == NULL) {
  858. util_handleError(MPXIO_REFERENCENAMES,
  859. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  860. return ((CCIMObjectPathList *)NULL);
  861. }
  862. instList =
  863. cp_references_Solaris_MPXIOInterface(pAssocName,
  864. pObjectName, pRole);
  865. if (instList != NULL) {
  866. objList = cim_createObjectPathList(instList);
  867. cim_freeInstanceList(instList);
  868. }
  869. return (objList);
  870. }
  871. /*
  872. * Create the association class with the passed in attributes.
  873. */
  874. static
  875. CCIMInstanceList *
  876. mpxioIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  877. CCIMObjectPathList *objList, cimchar *objRole, int *error)
  878. {
  879. CCIMObjectPathList *tmpList;
  880. CCIMInstanceList *instList = NULL;
  881. CCIMInstance *inst;
  882. CCIMObjectPath *obj1;
  883. CCIMObjectPath *obj2;
  884. CCIMException *ex;
  885. *error = 0;
  886. /*
  887. * If no objects associated with this one, return NULL.
  888. */
  889. if (objList == NULL) {
  890. return ((CCIMInstanceList *)NULL);
  891. }
  892. instList = cim_createInstanceList();
  893. if (instList == NULL) {
  894. ex = cim_getLastError();
  895. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  896. CREATE_INSTANCE_FAILURE, ex, error);
  897. return ((CCIMInstanceList *)NULL);
  898. }
  899. tmpList = objList;
  900. while (tmpList != NULL) {
  901. obj1 = tmpList->mDataObject;
  902. obj2 = cim_copyObjectPath(pObjectName);
  903. if (obj2 == NULL) {
  904. ex = cim_getLastError();
  905. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  906. COPY_OBJPATH_FAILURE, ex, error);
  907. return ((CCIMInstanceList *)NULL);
  908. }
  909. inst = mpxioIntAssocToInst(obj1, objRole, obj2, pObjectNameRole,
  910. error);
  911. cim_freeObjectPath(obj2);
  912. if (*error != 0) {
  913. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  914. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, NULL, error);
  915. cim_freeInstanceList(instList);
  916. return ((CCIMInstanceList *)NULL);
  917. }
  918. instList = cim_addInstance(instList, inst);
  919. if (instList == NULL) {
  920. ex = cim_getLastError();
  921. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  922. ADD_INSTANCE_FAILURE, ex, error);
  923. cim_freeInstance(inst);
  924. return ((CCIMInstanceList *)NULL);
  925. }
  926. tmpList = tmpList->mNext;
  927. }
  928. return (instList);
  929. }
  930. static
  931. CCIMInstance *
  932. mpxioIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  933. CCIMObjectPath *obj2, cimchar *obj2Role, int *error)
  934. {
  935. CCIMInstance *inst = NULL;
  936. CCIMException *ex;
  937. *error = 0;
  938. inst = cim_createInstance(MPXIO_INTERFACE);
  939. if (inst == NULL) {
  940. ex = cim_getLastError();
  941. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  942. MPXIOINT_ASSOC_TO_INSTANCE_FAILURE, ex, error);
  943. return ((CCIMInstance *)NULL);
  944. }
  945. util_doReferenceProperty(obj2Role, obj2, cim_true, inst, error);
  946. if (*error != 0) {
  947. ex = cim_getLastError();
  948. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  949. CREATE_REFPROP_FAILURE, ex, error);
  950. cim_freeInstance(inst);
  951. return ((CCIMInstance *)NULL);
  952. }
  953. util_doReferenceProperty(obj1Role, obj1, cim_true, inst,
  954. error);
  955. if (*error != 0) {
  956. ex = cim_getLastError();
  957. util_handleError(MPXIO_INTERFACE, CIM_ERR_FAILED,
  958. CREATE_REFPROP_FAILURE, ex, error);
  959. cim_freeInstance(inst);
  960. return ((CCIMInstance *)NULL);
  961. }
  962. return (inst);
  963. }