PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/osunix/osunix-gate
C | 1183 lines | 689 code | 167 blank | 327 comment | 188 complexity | 98103da80a8b9a3f39dfac8c5bd385cf 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 <errno.h>
  29. #include "util.h"
  30. #include "cimKeys.h"
  31. #include "providerNames.h"
  32. #include "messageStrings.h"
  33. #include "drive_descriptors.h"
  34. #include "ctrl_descriptors.h"
  35. #include "Solaris_IDEInterface.h"
  36. #define IDE_GETINSTANCE "IDE_INTERFACE,GET_INSTANCE"
  37. #define IDE_ENUMINSTANCES "IDE_INTERFACE,ENUM_INSTANCES"
  38. #define IDE_ENUMINSTANCENAMES "IDE_INTERFACE,ENUM_INSTANCENAMES"
  39. #define IDE_CREATEINSTANCE "IDE_INTERFACE,CREATE_INSTANCE"
  40. #define IDE_DELETEINSTANCE "IDE_INTERFACE,DELETE_INSTANCE"
  41. #define IDE_SETINSTANCE "IDE_INTERFACE,SET_INSTANCE"
  42. #define IDE_GETPROPERTY "IDE_INTERFACE,GET_PROPERTY"
  43. #define IDE_SETPROPERTY "IDE_INTERFACE,SET_PROPERTY"
  44. #define IDE_INVOKEMETHOD "IDE_INTERFACE,INVOKE_METHOD"
  45. #define IDE_EXECQUERY "IDE_INTERFACE,EXEC_QUERY"
  46. #define IDE_ASSOCIATORS "IDE_INTERFACE,ASSOCIATORS"
  47. #define IDE_ASSOCIATORNAMES "IDE_INTERFACE,ASSOCIATOR_NAMES"
  48. #define IDE_REFERENCES "IDE_INTERFACE,REFERENCES"
  49. #define IDE_REFERENCENAMES "IDE_INTERFACE,REFERENCE_NAMES"
  50. static
  51. CCIMInstanceList *
  52. ideIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  53. CCIMObjectPathList *objList, cimchar *objRole, int *error);
  54. static
  55. CCIMInstance *
  56. ideIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  57. CCIMObjectPath *obj2, cimchar *obj2Role, int *error);
  58. /*
  59. * Solaris_IDEInterface 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_IDEInterface
  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_IDEInterface(CCIMObjectPath* pOP)
  80. {
  81. CCIMInstance* inst = NULL;
  82. CCIMPropertyList* pCurPropList;
  83. dm_descriptor_t d_descriptor;
  84. dm_descriptor_t c_descriptor;
  85. CCIMObjectPath *antOp = NULL;
  86. CCIMObjectPath *depOp = NULL;
  87. int error;
  88. char *name;
  89. if (pOP == NULL) {
  90. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  91. NULL, &error);
  92. return ((CCIMInstance *)NULL);
  93. }
  94. if ((pCurPropList = pOP->mKeyProperties) == NULL) {
  95. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  96. NULL, &error);
  97. return ((CCIMInstance *)NULL);
  98. }
  99. antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  100. ANTECEDENT, &error);
  101. if (error == 0) {
  102. depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  103. DEPENDENT, &error);
  104. }
  105. if (error != 0) {
  106. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
  107. NULL, NULL, &error);
  108. return ((CCIMInstance *)NULL);
  109. }
  110. /*
  111. * Now, get the name of the antecedent from the object path.
  112. */
  113. if ((pCurPropList = antOp->mKeyProperties) == NULL) {
  114. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  115. NULL, &error);
  116. return ((CCIMInstance *)NULL);
  117. }
  118. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  119. &error);
  120. if (error != 0) {
  121. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
  122. NULL, NULL, &error);
  123. }
  124. /*
  125. * The only reason it is needed to get the descriptor for these
  126. * two devices is to verify that they still exist and are valid.
  127. * If they are not found, then getting the instance for this
  128. * association as passed in by the client is not possible.
  129. */
  130. c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  131. &error);
  132. /*
  133. * Not found. Return a null instance.
  134. */
  135. if (c_descriptor == NULL || error == ENODEV) {
  136. return ((CCIMInstance *)NULL);
  137. }
  138. if (error != 0) {
  139. util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
  140. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  141. return ((CCIMInstance*)NULL);
  142. }
  143. dm_free_descriptor(c_descriptor);
  144. /*
  145. * Now, get the name of the dependent from the object path.
  146. */
  147. if ((pCurPropList = depOp->mKeyProperties) == NULL) {
  148. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  149. NULL, &error);
  150. return ((CCIMInstance *)NULL);
  151. }
  152. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  153. &error);
  154. if (error != 0) {
  155. util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
  156. NULL, NULL, &error);
  157. return ((CCIMInstance *)NULL);
  158. }
  159. d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name,
  160. &error);
  161. /*
  162. * Not found. Return a null instance.
  163. */
  164. if (d_descriptor == NULL || error == ENODEV) {
  165. d_descriptor = dm_get_descriptor_by_name(DM_ALIAS, name,
  166. &error);
  167. if (d_descriptor == NULL || error == ENODEV) {
  168. util_handleError(IDE_GETINSTANCE, CIM_ERR_NOT_FOUND,
  169. NULL, NULL, &error);
  170. return ((CCIMInstance *)NULL);
  171. }
  172. }
  173. if (error != 0) {
  174. util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
  175. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  176. return ((CCIMInstance *)NULL);
  177. }
  178. dm_free_descriptor(d_descriptor);
  179. /*
  180. * At this point I have verified I have the two devices that
  181. * are part of this association. Use the object paths I got
  182. * earlier to create the ideinterface instance.
  183. */
  184. inst = ideIntAssocToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);
  185. if (error != 0) {
  186. util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
  187. IDEINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
  188. return ((CCIMInstance *)NULL);
  189. }
  190. return (inst);
  191. }
  192. /*
  193. * Name: cp_enumInstances_Solaris_IDEInterface
  194. *
  195. * Description: Returns a linked list of instances of
  196. * Solaris_IDEInterface if found.
  197. *
  198. * Parameters:
  199. * pOP - An CCIMObjectPath * which contains the information on
  200. * the class for which to find the instances.
  201. * Returns:
  202. * CCIMInstanceList * if istances are found. If no instances,
  203. * NULL is returned. On error, NULL is returned.
  204. */
  205. /* ARGSUSED */
  206. CCIMInstanceList*
  207. cp_enumInstances_Solaris_IDEInterface(CCIMObjectPath* pOP)
  208. {
  209. CCIMInstanceList *instList = NULL;
  210. CCIMObjectPathList *cObjList = NULL;
  211. CCIMObjectPathList *tmpObjList;
  212. CCIMObjectPath *objPath;
  213. CCIMInstance *inst;
  214. CCIMException *ex;
  215. dm_descriptor_t *d_descriptorp = NULL;
  216. int error = 0;
  217. /*
  218. * Get the list of IDE Controllers. Then get the associated drives
  219. * via the device api.
  220. */
  221. objPath = cim_createEmptyObjectPath(IDE_CONTROLLER);
  222. if (objPath == NULL) {
  223. ex = cim_getLastError();
  224. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  225. CREATE_OBJECT_PATH, ex, &error);
  226. return ((CCIMInstanceList *)NULL);
  227. }
  228. cObjList = cimom_enumerateInstanceNames(objPath, cim_false);
  229. cim_freeObjectPath(objPath);
  230. /*
  231. * NULL means error.
  232. */
  233. if (cObjList == NULL) {
  234. ex = cim_getLastError();
  235. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  236. ENUM_INSTANCENAMES_FAILURE, ex, &error);
  237. return ((CCIMInstanceList *)NULL);
  238. }
  239. if (cObjList->mDataObject == NULL) {
  240. return ((CCIMInstanceList *)NULL);
  241. }
  242. instList = cim_createInstanceList();
  243. if (instList == NULL) {
  244. ex = cim_getLastError();
  245. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  246. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  247. return ((CCIMInstanceList *)NULL);
  248. }
  249. /*
  250. * Loop through all of these controller objects and get the associated
  251. * disks.
  252. */
  253. for (tmpObjList = cObjList;
  254. tmpObjList != NULL && tmpObjList->mDataObject != NULL;
  255. tmpObjList = tmpObjList->mNext) {
  256. char *name = NULL;
  257. CCIMObjectPath *cOp;
  258. CCIMInstanceList *tmpList = NULL;
  259. CCIMInstanceList *tmpList1;
  260. CCIMPropertyList *pCurPropList;
  261. CCIMObjectPathList *dObjList;
  262. CCIMInstanceList *tL;
  263. dm_descriptor_t c_descriptor = NULL;
  264. error = 0;
  265. cOp = tmpObjList->mDataObject;
  266. if ((pCurPropList = cOp->mKeyProperties) == NULL) {
  267. util_handleError(IDE_ENUMINSTANCES,
  268. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  269. cim_freeObjectPathList(cObjList);
  270. cim_freeInstanceList(instList);
  271. return ((CCIMInstanceList *)NULL);
  272. }
  273. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  274. &error);
  275. if (error != 0) {
  276. util_handleError(IDE_ENUMINSTANCES,
  277. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  278. cim_freeObjectPathList(cObjList);
  279. cim_freeInstanceList(instList);
  280. return ((CCIMInstanceList *)NULL);
  281. }
  282. c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  283. &error);
  284. if (c_descriptor == NULL || error == ENODEV) {
  285. continue;
  286. }
  287. if (error != 0) {
  288. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  289. DM_GET_DESC_BYNAME_FAILURE, NULL,
  290. &error);
  291. cim_freeObjectPathList(cObjList);
  292. cim_freeInstanceList(instList);
  293. return ((CCIMInstanceList *)NULL);
  294. }
  295. d_descriptorp = dm_get_associated_descriptors(c_descriptor,
  296. DM_DRIVE, &error);
  297. dm_free_descriptor(c_descriptor);
  298. /*
  299. * If there are no drives associated with this controller,
  300. * continue on to the next controller.
  301. */
  302. if (d_descriptorp == NULL) {
  303. continue;
  304. }
  305. if (d_descriptorp[0] == NULL) {
  306. dm_free_descriptors(d_descriptorp);
  307. continue;
  308. }
  309. if (error == ENODEV) {
  310. continue;
  311. }
  312. if (error != 0) {
  313. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  314. DM_GET_ASSOC_FAILURE, NULL, &error);
  315. cim_freeInstanceList(instList);
  316. cim_freeObjectPathList(cObjList);
  317. return ((CCIMInstanceList *)NULL);
  318. }
  319. tmpList = drive_descriptors_toCCIMObjPathInstList(
  320. DISK_DRIVE, d_descriptorp, &error);
  321. dm_free_descriptors(d_descriptorp);
  322. d_descriptorp = NULL;
  323. if (error != 0) {
  324. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  325. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  326. cim_freeInstanceList(instList);
  327. cim_freeObjectPathList(cObjList);
  328. return ((CCIMInstanceList *)NULL);
  329. }
  330. /*
  331. * It is possible that the controller does not have a drive
  332. * associated with it. If this is true, the list will be
  333. * NULL.
  334. */
  335. if (tmpList == NULL) {
  336. continue;
  337. }
  338. dObjList = cim_createObjectPathList(tmpList);
  339. cim_freeInstanceList(tmpList);
  340. if (dObjList == NULL) {
  341. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  342. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  343. cim_freeInstanceList(instList);
  344. cim_freeObjectPathList(cObjList);
  345. return ((CCIMInstanceList *)NULL);
  346. }
  347. tmpList1 = ideIntAssocToInstList(
  348. cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
  349. cim_freeObjectPathList(dObjList);
  350. if (error != 0) {
  351. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  352. IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  353. cim_freeInstanceList(instList);
  354. cim_freeObjectPathList(cObjList);
  355. return ((CCIMInstanceList *)NULL);
  356. }
  357. tL = tmpList1;
  358. do {
  359. inst = cim_copyInstance(tL->mDataObject);
  360. instList = cim_addInstance(instList, inst);
  361. if (instList == NULL) {
  362. util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
  363. ADD_INSTANCE_FAILURE, NULL, &error);
  364. cim_freeObjectPathList(cObjList);
  365. cim_freeObjectPathList(tmpList1);
  366. return ((CCIMInstanceList *)NULL);
  367. }
  368. tL = tL->mNext;
  369. } while (tL && tL->mDataObject != NULL);
  370. cim_freeInstanceList(tmpList1);
  371. } /* end for */
  372. cim_freeObjectPathList(cObjList);
  373. /*
  374. * It is possible I will have an empty instance list at
  375. * this point. So, I must check and NULL this out if
  376. * there are no entries.
  377. */
  378. if (instList->mDataObject == NULL) {
  379. cim_freeInstanceList(instList);
  380. instList = NULL;
  381. }
  382. return (instList);
  383. }
  384. /*
  385. * Name: cp_enumInstanceNames_Solaris_IDEInterface
  386. *
  387. * Description: Returns a linked list of CCIMObjectPath *
  388. * of Solaris_IDEInterface if found.
  389. *
  390. * Parameters:
  391. * pOP - An CCIMObjectPath * which contains the information on
  392. * the class for which to find the instances.
  393. * Returns:
  394. * CCIMObjectPathList * if objects are found. If no objects,
  395. * an empty list is returned. On error, NULL is returned.
  396. */
  397. CCIMObjectPathList*
  398. cp_enumInstanceNames_Solaris_IDEInterface(CCIMObjectPath * pOP) {
  399. CCIMInstanceList *instList;
  400. CCIMObjectPathList *objList = NULL;
  401. int error;
  402. if (pOP == NULL) {
  403. util_handleError(IDE_ENUMINSTANCENAMES,
  404. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  405. return ((CCIMObjectPathList *)NULL);
  406. }
  407. /*
  408. * Call in to enumInstances and then convert the instance list in
  409. * to an object list.
  410. */
  411. instList = cp_enumInstances_Solaris_IDEInterface(pOP);
  412. if (instList != NULL) {
  413. objList = cim_createObjectPathList(instList);
  414. cim_freeInstanceList(instList);
  415. }
  416. return (objList);
  417. }
  418. /*
  419. * Creating an instance of a Solaris_IDEInterface is not supported.
  420. */
  421. /* ARGSUSED */
  422. CCIMObjectPath*
  423. cp_createInstance_Solaris_IDEInterface(CCIMObjectPath* pOP,
  424. CCIMInstance* pInst)
  425. {
  426. int error;
  427. util_handleError(IDE_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  428. NULL, &error);
  429. return ((CCIMObjectPath *)NULL);
  430. }
  431. /*
  432. * Deleting an instance of a Solaris_IDEInterface is not supported.
  433. */
  434. /* ARGSUSED */
  435. CIMBool
  436. cp_deleteInstance_Solaris_IDEInterface(CCIMObjectPath* pInst)
  437. {
  438. int error;
  439. util_handleError(
  440. IDE_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
  441. return (cim_false);
  442. }
  443. /*
  444. * Name: cp_getProperty_Solaris_IIDEInterface
  445. *
  446. * Description: Returns the property requested, if found.
  447. *
  448. * Parameters:
  449. * pOP - An CCIMObjectPath * which contains the information on
  450. * the class for which to find the instances.
  451. * Returns:
  452. * CCIMProperty * if found.
  453. */
  454. /* ARGSUSED */
  455. CCIMProperty *
  456. cp_getProperty_Solaris_IDEInterface(CCIMObjectPath *pOP,
  457. char *pPropName)
  458. {
  459. CCIMProperty *prop = NULL;
  460. CCIMInstance *inst = NULL;
  461. int error = 0;
  462. if (pOP == NULL) {
  463. util_handleError(IDE_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
  464. NULL, &error);
  465. return ((CCIMProperty *)NULL);
  466. }
  467. inst = cp_getInstance_Solaris_IDEInterface(pOP);
  468. if (inst == NULL) {
  469. return ((CCIMProperty *)NULL);
  470. }
  471. prop = cim_getProperty(inst, pPropName);
  472. cim_freeInstance(inst);
  473. return (prop);
  474. }
  475. /*
  476. * Setting an instance of a Solaris_IDEInterface is not supported.
  477. */
  478. /* ARGSUSED */
  479. CIMBool
  480. cp_setInstance_Solaris_IDEInterface(CCIMObjectPath* pOP, CCIMInstance* pInst)
  481. {
  482. int error;
  483. util_handleError(
  484. IDE_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
  485. return (cim_false);
  486. }
  487. /*
  488. * Setting a property on a Solaris_IDEInterface is not supported.
  489. */
  490. /* ARGSUSED */
  491. CIMBool
  492. cp_setProperty_Solaris_IDEInterface(CCIMObjectPath* pOP, CCIMProperty* pProp)
  493. {
  494. int error;
  495. util_handleError(
  496. IDE_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
  497. return (cim_false);
  498. }
  499. /*
  500. * No Methods for Solaris_IDEInterface.
  501. */
  502. /* ARGSUSED */
  503. CCIMProperty*
  504. cp_invokeMethod_Solaris_IDEInterface(
  505. CCIMObjectPath* op, cimchar* methodName,
  506. CCIMPropertyList* inParams, CCIMPropertyList* outParams)
  507. {
  508. CCIMProperty *retVal = (CCIMProperty *)NULL;
  509. return (retVal);
  510. }
  511. /*
  512. * Name: cp_execQuery_Solaris_IDEInterface
  513. *
  514. * Description:
  515. * Returns an instance list which matches the query if any are found.
  516. *
  517. * Parameters:
  518. * CCIMObjectPath *op - An CCIMObjectPath * which contains the
  519. * information on the class for which to find the instances.
  520. *
  521. * selectList - Not used
  522. * nonJoinExp - Not used
  523. *
  524. * Returns:
  525. * CCIMInstanceList * if matched instance is found. Otherwise, NULL.
  526. */
  527. /*
  528. * Currently, there is no WQL parser for the C providers. As a result,
  529. * what is returned to the CIMOM is a list of instances with
  530. * a NULL value at the beginning of the list. This NULL value indicates
  531. * to the CIMOM that it must do the filtering for the client.
  532. */
  533. /* ARGSUSED */
  534. CCIMInstanceList*
  535. cp_execQuery_Solaris_IDEInterface(CCIMObjectPath *op,
  536. cimchar *selectList, cimchar *nonJoinExp, cimchar *queryExp, int queryType)
  537. {
  538. CCIMInstanceList *instList = NULL;
  539. CCIMInstanceList *result;
  540. CCIMInstance *emptyInst;
  541. CCIMException *ex;
  542. int error;
  543. if (op == NULL) {
  544. util_handleError(IDE_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
  545. NULL, &error);
  546. return ((CCIMInstanceList *)NULL);
  547. }
  548. instList = cimom_enumerateInstances(op, cim_false, cim_false, cim_false,
  549. cim_false, cim_false, NULL, 0);
  550. /*
  551. * NULL means error.
  552. */
  553. if (instList == NULL) {
  554. ex = cim_getLastError();
  555. util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
  556. ENUM_INSTANCES_FAILURE, ex, &error);
  557. return ((CCIMInstanceList *)NULL);
  558. }
  559. if (instList->mDataObject == NULL) {
  560. return ((CCIMInstanceList *)NULL);
  561. }
  562. /*
  563. * Create a null instance and add it to the beginning
  564. * of the list to indicate to the CIMOM that no filtering
  565. * was done.
  566. */
  567. emptyInst = cim_createInstance("");
  568. if (emptyInst == NULL) {
  569. ex = cim_getLastError();
  570. util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
  571. CREATE_INSTANCE_FAILURE, ex, &error);
  572. return ((CCIMInstanceList *)NULL);
  573. }
  574. result = cim_createInstanceList();
  575. if (result == NULL) {
  576. ex = cim_getLastError();
  577. util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
  578. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  579. cim_freeInstance(emptyInst);
  580. cim_freeInstanceList(instList);
  581. return ((CCIMInstanceList *)NULL);
  582. }
  583. result = cim_addInstance(result, emptyInst);
  584. if (result == NULL) {
  585. ex = cim_getLastError();
  586. util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
  587. ADD_INSTANCE_FAILURE, ex, &error);
  588. cim_freeInstance(emptyInst);
  589. cim_freeInstanceList(instList);
  590. return ((CCIMInstanceList *)NULL);
  591. }
  592. /*
  593. * Since copying the original list to the new list will
  594. * leave no way to free the original list, manually
  595. * concatenate the original list to the new one.
  596. */
  597. result->mNext = instList;
  598. return (result);
  599. }
  600. /*
  601. * Name: cp_associators_Solaris_IDEInterface
  602. *
  603. * Description:
  604. * Returns instances of objects associated with the passed in
  605. * object if there are any.
  606. *
  607. * Parameters:
  608. *
  609. * CCIMObjectPath *pAssocName - The name of the association that
  610. * the client wants information about.
  611. *
  612. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  613. * information on the class for which to find the associated instances.
  614. *
  615. * cimchar *pResultClass - If specified, only return instances that
  616. * are of this class type.
  617. *
  618. * cimchar *pRole - If specified, must be valid for the object path
  619. * passed in requesting the associated instances.
  620. *
  621. * cimchar *pResultRole - If specified, only return instances that
  622. * are playing this role in the association.
  623. *
  624. *
  625. * Returns:
  626. * CCIMInstanceList * if associated objects are found. Thist list
  627. * may be empty. NULL is returned on error.
  628. */
  629. /* ARGSUSED */
  630. CCIMInstanceList *
  631. cp_associators_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
  632. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  633. cimchar *pResultRole)
  634. {
  635. CCIMPropertyList *pCurPropList;
  636. CCIMInstanceList *instList = NULL;
  637. dm_descriptor_t *assoc_descriptors = NULL;
  638. dm_descriptor_t *tmpList = NULL;
  639. dm_descriptor_t obj_desc = NULL;
  640. char *name;
  641. int error = 0;
  642. int isAntecedent = 0;
  643. int isAlias = 0;
  644. if ((pObjectName == NULL ||
  645. (pCurPropList = pObjectName->mKeyProperties) == NULL)) {
  646. util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  647. NULL, &error);
  648. return ((CCIMInstanceList *)NULL);
  649. }
  650. if (strcasecmp(pObjectName->mName, IDE_CONTROLLER) == 0) {
  651. isAntecedent = 1;
  652. }
  653. if (pRole != NULL) {
  654. if (strcasecmp(pRole, ANTECEDENT) == 0) {
  655. if (isAntecedent != 1) {
  656. util_handleError(IDE_ASSOCIATORS,
  657. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  658. return ((CCIMInstanceList *)NULL);
  659. }
  660. } else if (strcasecmp(pRole, DEPENDENT) == 0) {
  661. if (isAntecedent == 1) {
  662. util_handleError(IDE_ASSOCIATORS,
  663. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  664. return ((CCIMInstanceList *)NULL);
  665. }
  666. }
  667. }
  668. /*
  669. * Both ide controller and disk drive have deviceid as the
  670. * key.
  671. */
  672. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  673. &error);
  674. if (error != 0) {
  675. util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  676. NULL, &error);
  677. return ((CCIMInstanceList *)NULL);
  678. }
  679. if (isAntecedent) {
  680. obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  681. &error);
  682. } else {
  683. obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name,
  684. &error);
  685. if (obj_desc == NULL || error == ENODEV) {
  686. isAlias = 1;
  687. obj_desc = dm_get_descriptor_by_name(DM_ALIAS, name, &error);
  688. }
  689. }
  690. if (obj_desc == NULL) {
  691. return ((CCIMInstanceList *)NULL);
  692. }
  693. if (error != 0) {
  694. util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
  695. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  696. return ((CCIMInstanceList *)NULL);
  697. }
  698. if (isAlias) {
  699. tmpList = dm_get_associated_descriptors(obj_desc, DM_DRIVE,
  700. &error);
  701. if (tmpList == NULL) {
  702. return ((CCIMInstanceList *)NULL);
  703. }
  704. if (tmpList[0] == NULL) {
  705. dm_free_descriptors(tmpList);
  706. return ((CCIMInstanceList *)NULL);
  707. }
  708. }
  709. if (isAntecedent) {
  710. /*
  711. * Get associated descriptors.
  712. */
  713. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  714. DM_DRIVE, &error);
  715. dm_free_descriptor(obj_desc);
  716. if (assoc_descriptors == NULL) {
  717. return (instList);
  718. }
  719. if (assoc_descriptors[0] == NULL) {
  720. dm_free_descriptors(assoc_descriptors);
  721. return (instList);
  722. }
  723. if (error != 0) {
  724. util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
  725. DM_GET_ASSOC_FAILURE, NULL, &error);
  726. return ((CCIMInstanceList *)NULL);
  727. }
  728. /*
  729. * Generate the inst list of the associated disk drives.
  730. */
  731. instList = drive_descriptors_toCCIMObjPathInstList(DISK_DRIVE,
  732. assoc_descriptors, &error);
  733. dm_free_descriptors(assoc_descriptors);
  734. if (error != 0) {
  735. util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
  736. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  737. return ((CCIMInstanceList *)NULL);
  738. }
  739. } else {
  740. /*
  741. * This is the disk drive calling this function. Return the
  742. * controllers that are associated with this disk.
  743. */
  744. if (tmpList == NULL && obj_desc == NULL) {
  745. return ((CCIMInstanceList *)NULL);
  746. }
  747. if (tmpList != NULL) {
  748. assoc_descriptors = dm_get_associated_descriptors(tmpList[0],
  749. DM_CONTROLLER, &error);
  750. dm_free_descriptors(tmpList);
  751. } else {
  752. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  753. DM_CONTROLLER, &error);
  754. dm_free_descriptor(obj_desc);
  755. }
  756. if (assoc_descriptors == NULL) {
  757. return ((CCIMInstanceList *)NULL);
  758. }
  759. if (assoc_descriptors[0] == NULL) {
  760. dm_free_descriptors(assoc_descriptors);
  761. return ((CCIMInstanceList *)NULL);
  762. }
  763. if (error != 0) {
  764. util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
  765. DM_GET_ASSOC_FAILURE, NULL, &error);
  766. return ((CCIMInstanceList *)NULL);
  767. }
  768. instList = ctrl_descriptors_toCCIMInstanceList(IDE_CONTROLLER,
  769. assoc_descriptors, &error, 2, "ata", "pcata");
  770. dm_free_descriptors(assoc_descriptors);
  771. if (error != 0) {
  772. util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
  773. IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  774. return ((CCIMInstanceList *)NULL);
  775. }
  776. }
  777. return (instList);
  778. }
  779. /*
  780. * Name: cp_associatorNames_Solaris_IDEInterface
  781. *
  782. * Description:
  783. * Returns a list of objects associated with the passed in
  784. * object if there are any via the object CCIMObjectPath.
  785. *
  786. * Parameters:
  787. *
  788. * CCIMObjectPath *pAssocName - The name of the association that
  789. * the client wants information about.
  790. *
  791. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  792. * information on the class for which to find the associated instances.
  793. *
  794. * cimchar *pResultClass - If specified, only return instances that
  795. * are of this class type.
  796. *
  797. * cimchar *pRole - If specified, must be valid for the object path
  798. * passed in requesting the associated instances.
  799. *
  800. * cimchar *pResultRole - If specified, only return instances that
  801. * are playing this role in the association.
  802. *
  803. *
  804. * Returns:
  805. * CCIMObjectPathList * if associated objects are found. Thist list
  806. * may be empty. NULL is returned on error.
  807. */
  808. /* ARGSUSED */
  809. CCIMObjectPathList *
  810. cp_associatorNames_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
  811. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  812. cimchar *pResultRole)
  813. {
  814. CCIMInstanceList *instList;
  815. CCIMObjectPathList *objList = NULL;
  816. int error;
  817. if (pObjectName == NULL) {
  818. util_handleError(IDE_ASSOCIATORNAMES,
  819. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  820. return ((CCIMObjectPathList *)NULL);
  821. }
  822. instList =
  823. cp_associators_Solaris_IDEInterface(
  824. pAssocName, pObjectName, pResultClass, pRole, pResultRole);
  825. if (instList != NULL) {
  826. objList = cim_createObjectPathList(instList);
  827. cim_freeInstanceList(instList);
  828. }
  829. return (objList);
  830. }
  831. /*
  832. * Name: cp_references_Solaris_IDEInterface
  833. *
  834. * Description:
  835. * Returns instances of objects that have references to the passed in
  836. * object if there are any.
  837. *
  838. * Parameters:
  839. *
  840. * CCIMObjectPath *pAssocName - The name of the association that
  841. * the client wants information about.
  842. *
  843. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  844. * information on the class for which to find the associated instances.
  845. *
  846. * cimchar *pRole - If specified, must be valid for the object path
  847. * passed in requesting the associated instances.
  848. *
  849. * Returns:
  850. * CCIMInstanceList * if associated objects are found. Thist list
  851. * may be empty. NULL is returned on error.
  852. */
  853. /* ARGSUSED */
  854. CCIMInstanceList *
  855. cp_references_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
  856. CCIMObjectPath *pObjectName, char *pRole)
  857. {
  858. CCIMInstanceList *instList = NULL;
  859. CCIMObjectPathList *objList;
  860. int error;
  861. if (pObjectName == NULL) {
  862. util_handleError(IDE_REFERENCES, CIM_ERR_INVALID_PARAMETER,
  863. NULL, NULL, &error);
  864. return ((CCIMInstanceList *)NULL);
  865. }
  866. /*
  867. * Get the list of those objects that are referred to by
  868. * the calling object.
  869. */
  870. objList =
  871. cp_associatorNames_Solaris_IDEInterface(
  872. pAssocName, pObjectName, NULL, NULL, NULL);
  873. if (objList == NULL) {
  874. return ((CCIMInstanceList *)NULL);
  875. }
  876. /*
  877. * Now generate the list of instances to return.
  878. */
  879. if ((strcasecmp(pObjectName->mName, IDE_CONTROLLER)) == 0) {
  880. instList = ideIntAssocToInstList(pObjectName,
  881. ANTECEDENT, objList, DEPENDENT, &error);
  882. } else {
  883. instList = ideIntAssocToInstList(pObjectName,
  884. DEPENDENT, objList, ANTECEDENT, &error);
  885. }
  886. cim_freeObjectPathList(objList);
  887. return (instList);
  888. }
  889. /*
  890. * Name: cp_referenceNames_Solaris_IDEInterface
  891. *
  892. * Description:
  893. * Returns a instances of objects that have references to the passed in
  894. * object if there are any.
  895. *
  896. * Parameters:
  897. *
  898. * CCIMObjectPath *pAssocName - The name of the association that
  899. * the client wants information about.
  900. *
  901. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  902. * information on the class for which to find the associated instances.
  903. *
  904. * cimchar *pRole - If specified, must be valid for the object path
  905. * passed in requesting the associated instances.
  906. *
  907. *
  908. * Returns:
  909. * CCIMInstanceList * if associated objects are found. Thist list
  910. * may be empty. NULL is returned on error.
  911. *
  912. */
  913. /* ARGSUSED */
  914. CCIMObjectPathList *
  915. cp_referenceNames_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
  916. CCIMObjectPath *pObjectName, cimchar *pRole)
  917. {
  918. CCIMInstanceList *instList;
  919. CCIMObjectPathList *objList = NULL;
  920. int error;
  921. if (pObjectName == NULL) {
  922. util_handleError(IDE_REFERENCENAMES,
  923. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  924. return ((CCIMObjectPathList *)NULL);
  925. }
  926. instList =
  927. cp_references_Solaris_IDEInterface(pAssocName, pObjectName, pRole);
  928. if (instList != NULL) {
  929. objList = cim_createObjectPathList(instList);
  930. cim_freeInstanceList(instList);
  931. }
  932. return (objList);
  933. }
  934. /*
  935. * Create the association class with the passed in attributes.
  936. */
  937. static
  938. CCIMInstanceList *
  939. ideIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  940. CCIMObjectPathList *objList, cimchar *objRole, int *error)
  941. {
  942. CCIMObjectPathList *tmpList;
  943. CCIMInstanceList *instList = NULL;
  944. CCIMInstance *inst;
  945. CCIMObjectPath *obj1;
  946. CCIMObjectPath *obj2;
  947. CCIMException *ex;
  948. *error = 0;
  949. if (objList == NULL) {
  950. return ((CCIMInstanceList *)NULL);
  951. }
  952. instList = cim_createInstanceList();
  953. if (instList == NULL) {
  954. ex = cim_getLastError();
  955. util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
  956. CREATE_INSTANCE_FAILURE, ex, error);
  957. return ((CCIMInstanceList *)NULL);
  958. }
  959. tmpList = objList;
  960. while (tmpList != NULL) {
  961. obj1 = tmpList->mDataObject;
  962. obj2 = cim_copyObjectPath(pObjectName);
  963. if (obj2 == NULL) {
  964. ex = cim_getLastError();
  965. util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
  966. COPY_OBJPATH_FAILURE, ex, error);
  967. return ((CCIMInstanceList *)NULL);
  968. }
  969. inst = ideIntAssocToInst(obj1, objRole, obj2, pObjectNameRole,
  970. error);
  971. cim_freeObjectPath(obj2);
  972. if (*error != 0) {
  973. cim_freeInstanceList(instList);
  974. return ((CCIMInstanceList *)NULL);
  975. }
  976. instList = cim_addInstance(instList, inst);
  977. if (instList == NULL) {
  978. ex = cim_getLastError();
  979. util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
  980. ADD_INSTANCE_FAILURE, ex, error);
  981. cim_freeInstance(inst);
  982. return ((CCIMInstanceList *)NULL);
  983. }
  984. tmpList = tmpList->mNext;
  985. }
  986. return (instList);
  987. }
  988. /*
  989. * Create an instance of the class with the passed in attributes.
  990. */
  991. static
  992. CCIMInstance *
  993. ideIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  994. CCIMObjectPath *obj2, cimchar *obj2Role, int *error)
  995. {
  996. CCIMInstance *inst = NULL;
  997. CCIMException *ex;
  998. *error = 0;
  999. inst = cim_createInstance(IDE_INTERFACE);
  1000. if (inst == NULL) {
  1001. ex = cim_getLastError();
  1002. util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
  1003. IDEINT_ASSOC_TO_INSTANCE_FAILURE, ex, error);
  1004. return ((CCIMInstance *)NULL);
  1005. }
  1006. util_doReferenceProperty(obj2Role, obj2, cim_true, inst, error);
  1007. util_doReferenceProperty(obj1Role, obj1, cim_true, inst, error);
  1008. if (*error != 0) {
  1009. ex = cim_getLastError();
  1010. util_handleError(IDE_INTERFACE, CIM_ERR_FAILED,
  1011. CREATE_REFPROP_FAILURE, ex, error);
  1012. cim_freeInstance(inst);
  1013. return ((CCIMInstance *)NULL);
  1014. }
  1015. return (inst);
  1016. }