PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/osunix/osunix-gate
C | 1152 lines | 651 code | 177 blank | 324 comment | 167 complexity | d88255a622afdd436bf125fed3abb297 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_SCSIInterface.h"
  37. #define SCSI_GETINSTANCE "SCSI_INTERFACE,GET_INSTANCE"
  38. #define SCSI_ENUMINSTANCES "SCSI_INTERFACE,ENUM_INSTANCES"
  39. #define SCSI_ENUMINSTANCENAMES "SCSI_INTERFACE,ENUM_INSTANCENAMES"
  40. #define SCSI_CREATEINSTANCE "SCSI_INTERFACE,CREATE_INSTANCE"
  41. #define SCSI_DELETEINSTANCE "SCSI_INTERFACE,DELETE_INSTANCE"
  42. #define SCSI_SETINSTANCE "SCSI_INTERFACE,SET_INSTANCE"
  43. #define SCSI_GETPROPERTY "SCSI_INTERFACE,GET_PROPERTY"
  44. #define SCSI_SETPROPERTY "SCSI_INTERFACE,SET_PROPERTY"
  45. #define SCSI_INVOKEMETHOD "SCSI_INTERFACE,INVOKE_METHOD"
  46. #define SCSI_EXECQUERY "SCSI_INTERFACE,EXEC_QUERY"
  47. #define SCSI_ASSOCIATORS "SCSI_INTERFACE,ASSOCIATORS"
  48. #define SCSI_ASSOCIATORNAMES "SCSI_INTERFACE,ASSOCIATOR_NAMES"
  49. #define SCSI_REFERENCES "SCSI_INTERFACE,REFERENCES"
  50. #define SCSI_REFERENCENAMES "SCSI_INTERFACE,REFERENCE_NAMES"
  51. static
  52. CCIMInstanceList *
  53. scsiIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  54. CCIMObjectPathList *objList, cimchar *objRole, int *error);
  55. static
  56. CCIMInstance *
  57. scsiIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  58. CCIMObjectPath *obj2, cimchar *obj2Role, int *error);
  59. /*
  60. * Solaris_SCSIInterface 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_SCSIInterface
  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_SCSIInterface(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. pOP->mKeyProperties == NULL) {
  91. util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  92. NULL, &error);
  93. return ((CCIMInstance *)NULL);
  94. }
  95. pCurPropList = pOP->mKeyProperties;
  96. antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  97. ANTECEDENT, &error);
  98. if (error == 0) {
  99. depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
  100. DEPENDENT, &error);
  101. }
  102. if (error != 0) {
  103. util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  104. NULL, &error);
  105. return ((CCIMInstance *)NULL);
  106. }
  107. /*
  108. * Now, get the name of the antecedent from the object path.
  109. */
  110. if ((antOp->mKeyProperties) == NULL ||
  111. (depOp->mKeyProperties) == NULL) {
  112. util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
  113. NULL, NULL, &error);
  114. return ((CCIMInstance *)NULL);
  115. }
  116. pCurPropList = antOp->mKeyProperties;
  117. name = (char *)util_getKeyValue(pCurPropList, string, DEVICEID,
  118. &error);
  119. if (error != 0) {
  120. util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  121. NULL, &error);
  122. return ((CCIMInstance *)NULL);
  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 (error == ENODEV || c_descriptor == NULL) {
  136. return ((CCIMInstance *)NULL);
  137. }
  138. if (error != 0) {
  139. util_handleError(SCSI_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. pCurPropList = depOp->mKeyProperties;
  148. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  149. &error);
  150. if (error != 0) {
  151. util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
  152. NULL, &error);
  153. return ((CCIMInstance *)NULL);
  154. }
  155. d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name, &error);
  156. /*
  157. * Not found. Return a null instance.
  158. */
  159. if (error == ENODEV || d_descriptor == NULL) {
  160. return ((CCIMInstance *)NULL);
  161. }
  162. if (error != 0) {
  163. util_handleError(SCSI_GETINSTANCE, CIM_ERR_FAILED,
  164. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  165. return ((CCIMInstance*)NULL);
  166. }
  167. dm_free_descriptor(d_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 scsiinterface instance.
  172. */
  173. inst = scsiIntAssocToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);
  174. if (error != 0) {
  175. util_handleError(SCSI_GETINSTANCE, CIM_ERR_FAILED,
  176. SCSIINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
  177. return ((CCIMInstance *)NULL);
  178. }
  179. return (inst);
  180. }
  181. /*
  182. * Name: cp_enumInstances_Solaris_SCSIInterface
  183. *
  184. * Description: Returns a linked list of instances of
  185. * Solaris_SCSIInterface 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 instances are found. NULL otherwise.
  192. */
  193. /* ARGSUSED */
  194. CCIMInstanceList*
  195. cp_enumInstances_Solaris_SCSIInterface(CCIMObjectPath* pOP)
  196. {
  197. CCIMInstanceList *instList = NULL;
  198. CCIMObjectPathList *cObjList;
  199. CCIMObjectPathList *tmpObjList;
  200. CCIMObjectPath *objPath;
  201. CCIMInstance *inst;
  202. CCIMException *ex;
  203. dm_descriptor_t *d_descriptorp = NULL;
  204. int error = 0;
  205. /*
  206. * Get the list of SCSI Controllers. Then get the associated drives
  207. * via the device api.
  208. */
  209. objPath = cim_createEmptyObjectPath(SCSI_CONTROLLER);
  210. if (objPath == NULL) {
  211. ex = cim_getLastError();
  212. util_handleError(SCSI_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. if (cObjList == NULL) {
  219. ex = cim_getLastError();
  220. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  221. ENUM_INSTANCENAMES_FAILURE, ex, &error);
  222. return ((CCIMInstanceList *)NULL);
  223. }
  224. /*
  225. * If no controllers of this type, then no interfaces.
  226. */
  227. if (cObjList->mDataObject == NULL) {
  228. return ((CCIMInstanceList *)NULL);
  229. }
  230. instList = cim_createInstanceList();
  231. if (instList == NULL) {
  232. ex = cim_getLastError();
  233. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  234. CREATE_INSTANCE_LIST_FAILURE, ex, &error);
  235. return ((CCIMInstanceList *)NULL);
  236. }
  237. /*
  238. * Loop through all of these controller objects and get the associated
  239. * disks.
  240. */
  241. for (tmpObjList = cObjList; tmpObjList != NULL;
  242. tmpObjList = tmpObjList->mNext) {
  243. char *name = NULL;
  244. CCIMObjectPath *cOp;
  245. CCIMInstanceList *tmpList;
  246. CCIMInstanceList *tmpList1;
  247. CCIMPropertyList *pCurPropList;
  248. CCIMObjectPathList *dObjList;
  249. CCIMInstanceList *tL;
  250. dm_descriptor_t c_descriptor;
  251. cOp = tmpObjList->mDataObject;
  252. if ((pCurPropList = cOp->mKeyProperties) == NULL) {
  253. util_handleError(SCSI_ENUMINSTANCES,
  254. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  255. cim_freeObjectPathList(cObjList);
  256. cim_freeInstanceList(instList);
  257. return ((CCIMInstanceList *)NULL);
  258. }
  259. name = (cimchar *)util_getKeyValue(pCurPropList, string,
  260. DEVICEID, &error);
  261. if (error != 0 || name == NULL) {
  262. util_handleError(SCSI_ENUMINSTANCES,
  263. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  264. cim_freeInstanceList(instList);
  265. cim_freeObjectPathList(cObjList);
  266. return ((CCIMInstanceList *)NULL);
  267. }
  268. c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
  269. &error);
  270. if (error == ENODEV || c_descriptor == NULL) {
  271. continue;
  272. }
  273. if (error != 0) {
  274. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  275. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  276. cim_freeInstanceList(instList);
  277. cim_freeObjectPathList(cObjList);
  278. return ((CCIMInstanceList *)NULL);
  279. }
  280. d_descriptorp = dm_get_associated_descriptors(c_descriptor,
  281. DM_DRIVE, &error);
  282. dm_free_descriptor(c_descriptor);
  283. /*
  284. * If there are no drives associated with this controller,
  285. * continue on to the next controller.
  286. */
  287. if (d_descriptorp == NULL) {
  288. continue;
  289. }
  290. if (d_descriptorp[0] == NULL) {
  291. dm_free_descriptors(d_descriptorp);
  292. continue;
  293. }
  294. if (error != 0) {
  295. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  296. DM_GET_ASSOC_FAILURE, NULL, &error);
  297. cim_freeInstanceList(instList);
  298. cim_freeObjectPathList(cObjList);
  299. return ((CCIMInstanceList *)NULL);
  300. }
  301. tmpList = drive_descriptors_toCCIMObjPathInstList(
  302. DISK_DRIVE, d_descriptorp, &error);
  303. dm_free_descriptors(d_descriptorp);
  304. if (error != 0) {
  305. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  306. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  307. cim_freeInstanceList(instList);
  308. cim_freeObjectPathList(cObjList);
  309. return ((CCIMInstanceList *)NULL);
  310. }
  311. if (tmpList == NULL) {
  312. continue;
  313. }
  314. dObjList = cim_createObjectPathList(tmpList);
  315. cim_freeInstanceList(tmpList);
  316. if (dObjList == NULL) {
  317. ex = cim_getLastError();
  318. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  319. CREATE_OBJECT_PATH_FAILURE, ex, &error);
  320. cim_freeInstanceList(instList);
  321. cim_freeObjectPathList(cObjList);
  322. return ((CCIMInstanceList *)NULL);
  323. }
  324. tmpList1 = scsiIntAssocToInstList(
  325. cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
  326. cim_freeObjectPathList(dObjList);
  327. if (error != 0) {
  328. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  329. DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  330. cim_freeInstanceList(instList);
  331. cim_freeObjectPathList(cObjList);
  332. return ((CCIMInstanceList *)NULL);
  333. }
  334. tL = tmpList1;
  335. do {
  336. inst = cim_copyInstance(tL->mDataObject);
  337. instList = cim_addInstance(instList, inst);
  338. if (instList == NULL) {
  339. util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED,
  340. ADD_INSTANCE_FAILURE, NULL, &error);
  341. cim_freeObjectPathList(cObjList);
  342. cim_freeObjectPathList(tmpList1);
  343. return ((CCIMInstanceList *)NULL);
  344. }
  345. tL = tL->mNext;
  346. } while (tL);
  347. cim_freeInstanceList(tmpList1);
  348. } /* end for */
  349. /*
  350. * It is possible I will have an empty instance list at
  351. * this point. So, I must check and NULL this out if
  352. * there are no entries.
  353. */
  354. cim_freeObjectPathList(cObjList);
  355. if (instList->mDataObject == NULL) {
  356. cim_freeInstanceList(instList);
  357. instList = NULL;
  358. }
  359. return (instList);
  360. }
  361. /*
  362. * Name: cp_enumInstanceNames_Solaris_SCSIInterface
  363. *
  364. * Description: Returns a linked list of CCIMObjectPath *
  365. * of Solaris_SCSIInterface 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. NULL otherwise.
  372. */
  373. /* ARGSUSED */
  374. CCIMObjectPathList*
  375. cp_enumInstanceNames_Solaris_SCSIInterface(CCIMObjectPath * pOP) {
  376. CCIMInstanceList *instList;
  377. CCIMObjectPathList *objList = NULL;
  378. int error;
  379. if (pOP == NULL) {
  380. util_handleError(SCSI_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_SCSIInterface(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_SCSIInterface is not supported.
  397. */
  398. /* ARGSUSED */
  399. CCIMObjectPath*
  400. cp_createInstance_Solaris_SCSIInterface(CCIMObjectPath* pOP,
  401. CCIMInstance* pInst)
  402. {
  403. int error;
  404. util_handleError(SCSI_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  405. NULL, &error);
  406. return ((CCIMObjectPath *)NULL);
  407. }
  408. /*
  409. * Deleting an instance of a Solaris_SCSIInterface is not supported.
  410. */
  411. /* ARGSUSED */
  412. CIMBool
  413. cp_deleteInstance_Solaris_SCSIInterface(CCIMObjectPath* pInst)
  414. {
  415. int error;
  416. util_handleError(SCSI_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  417. NULL, &error);
  418. return (cim_false);
  419. }
  420. /*
  421. * Name: cp_getProperty_Solaris_SCSIInterface
  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_SCSIInterface(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(SCSI_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
  441. NULL, &error);
  442. return ((CCIMProperty *)NULL);
  443. }
  444. inst = cp_getInstance_Solaris_SCSIInterface(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_SCSIInterface is not supported.
  454. */
  455. /* ARGSUSED */
  456. CIMBool
  457. cp_setInstance_Solaris_SCSIInterface(CCIMObjectPath* pOP, CCIMInstance* pInst)
  458. {
  459. int error;
  460. util_handleError(SCSI_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
  461. NULL, &error);
  462. return (cim_false);
  463. }
  464. /*
  465. * Setting a property on a Solaris_SCSIInterface is not supported.
  466. */
  467. /* ARGSUSED */
  468. CIMBool
  469. cp_setProperty_Solaris_SCSIInterface(CCIMObjectPath* pOP, CCIMProperty* pProp)
  470. {
  471. int error;
  472. util_handleError(SCSI_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
  473. NULL, &error);
  474. return (cim_false);
  475. }
  476. /*
  477. * No Methods for Solaris_SCSIInterface.
  478. */
  479. /* ARGSUSED */
  480. CCIMProperty*
  481. cp_invokeMethod_Solaris_SCSIInterface(
  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_SCSIInterface
  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_SCSIInterface(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(SCSI_EXECQUERY, CIM_ERR_INVALID_PARAMETER,
  522. NULL, NULL, &error);
  523. return ((CCIMInstanceList *)NULL);
  524. }
  525. instList = cp_enumInstances_Solaris_SCSIInterface(op);
  526. if (instList == NULL) {
  527. return (instList);
  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(SCSI_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(SCSI_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(SCSI_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_SCSIInterface
  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.
  594. * NULL is returned on error as well as for an empty list.
  595. */
  596. /* ARGSUSED */
  597. CCIMInstanceList *
  598. cp_associators_Solaris_SCSIInterface(CCIMObjectPath *pAssocName,
  599. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  600. cimchar *pResultRole)
  601. {
  602. CCIMPropertyList *pCurPropList;
  603. CCIMInstanceList *instList = NULL;
  604. CCIMException *ex;
  605. dm_descriptor_t *assoc_descriptors;
  606. dm_descriptor_t obj_desc;
  607. char *name;
  608. int error = 0;
  609. int isAntecedent = 0;
  610. if (pObjectName == NULL ||
  611. pObjectName->mName == NULL ||
  612. pObjectName->mKeyProperties == NULL) {
  613. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER,
  614. NULL, NULL, &error);
  615. return ((CCIMInstanceList *)NULL);
  616. }
  617. if (strcasecmp(pObjectName->mName, SCSI_CONTROLLER) == 0) {
  618. isAntecedent = 1;
  619. }
  620. if (pRole != NULL) {
  621. if (strcasecmp(pRole, ANTECEDENT) == 0) {
  622. if (isAntecedent != 1) {
  623. util_handleError(SCSI_ASSOCIATORS,
  624. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  625. return ((CCIMInstanceList *)NULL);
  626. }
  627. } else if (strcasecmp(pRole, DEPENDENT) == 0) {
  628. if (isAntecedent == 1) {
  629. util_handleError(SCSI_ASSOCIATORS,
  630. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  631. return ((CCIMInstanceList *)NULL);
  632. }
  633. }
  634. }
  635. /*
  636. * Both scsi controller and disk drive have deviceid as the
  637. * key.
  638. */
  639. pCurPropList = pObjectName->mKeyProperties;
  640. name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
  641. &error);
  642. /*
  643. * We went through the whole list and didn't find the necessary
  644. * key value.
  645. */
  646. if (error != 0 || name == NULL) {
  647. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
  648. NULL, &error);
  649. return ((CCIMInstanceList *)NULL);
  650. }
  651. if (isAntecedent) {
  652. obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name, &error);
  653. } else {
  654. obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name, &error);
  655. }
  656. /*
  657. * Device not found, return NULL list.
  658. */
  659. if (error == ENODEV || obj_desc == NULL) {
  660. return ((CCIMInstanceList *)NULL);
  661. }
  662. if (error != 0) {
  663. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_FAILED,
  664. DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
  665. return ((CCIMInstanceList *)NULL);
  666. }
  667. if (isAntecedent) {
  668. /*
  669. * Controller calling this method, return instances of the
  670. * disk drives associated with this controller.
  671. */
  672. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  673. DM_DRIVE, &error);
  674. dm_free_descriptor(obj_desc);
  675. if (assoc_descriptors == NULL) {
  676. return ((CCIMInstanceList *)NULL);
  677. }
  678. if (assoc_descriptors[0] == NULL) {
  679. dm_free_descriptors(assoc_descriptors);
  680. return ((CCIMInstanceList *)NULL);
  681. }
  682. if (error != 0) {
  683. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_FAILED,
  684. DM_GET_ASSOC_FAILURE, NULL, &error);
  685. return ((CCIMInstanceList *)NULL);
  686. }
  687. /*
  688. * Generate the inst list of the associated disk drives.
  689. */
  690. instList = drive_descriptors_toCCIMObjPathInstList(DISK_DRIVE,
  691. assoc_descriptors, &error);
  692. dm_free_descriptors(assoc_descriptors);
  693. if (error != 0) {
  694. ex = cim_getLastError();
  695. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_FAILED,
  696. DRIVE_DESC_TO_INSTANCE_FAILURE, ex, &error);
  697. return ((CCIMInstanceList *)NULL);
  698. }
  699. } else {
  700. /*
  701. * This is the disk drive calling this function. Return the
  702. * controllers that are associated with this disk.
  703. */
  704. assoc_descriptors = dm_get_associated_descriptors(obj_desc,
  705. DM_CONTROLLER, &error);
  706. dm_free_descriptor(obj_desc);
  707. if (assoc_descriptors == NULL) {
  708. return (instList);
  709. }
  710. if (assoc_descriptors[0] == NULL) {
  711. dm_free_descriptors(assoc_descriptors);
  712. return (instList);
  713. }
  714. if (error != 0) {
  715. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_FAILED,
  716. DM_GET_ASSOC_FAILURE, NULL, &error);
  717. return ((CCIMInstanceList *)NULL);
  718. }
  719. instList = ctrl_descriptors_toCCIMInstanceList(SCSI_CONTROLLER,
  720. assoc_descriptors, &error, 1, "scsi");
  721. dm_free_descriptors(assoc_descriptors);
  722. if (error != 0) {
  723. util_handleError(SCSI_ASSOCIATORS, CIM_ERR_FAILED,
  724. SCSICTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
  725. return ((CCIMInstanceList *)NULL);
  726. }
  727. }
  728. return (instList);
  729. }
  730. /*
  731. * Name: cp_associatorNames_Solaris_SCSIInterface
  732. *
  733. * Description:
  734. * Returns a list of objects associated with the passed in
  735. * object if there are any via the object CCIMObjectPath.
  736. *
  737. * Parameters:
  738. *
  739. * CCIMObjectPath *pAssocName - The name of the association that
  740. * the client wants information about.
  741. *
  742. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  743. * information on the class for which to find the associated instances.
  744. *
  745. * cimchar *pResultClass - If specified, only return instances that
  746. * are of this class type.
  747. *
  748. * cimchar *pRole - If specified, must be valid for the object path
  749. * passed in requesting the associated instances.
  750. *
  751. * cimchar *pResultRole - If specified, only return instances that
  752. * are playing this role in the association.
  753. *
  754. *
  755. * Returns:
  756. * CCIMObjectPathList * if associated objects are found. NULL otherwise.
  757. */
  758. /* ARGSUSED */
  759. CCIMObjectPathList *
  760. cp_associatorNames_Solaris_SCSIInterface(CCIMObjectPath *pAssocName,
  761. CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
  762. cimchar *pResultRole)
  763. {
  764. CCIMInstanceList *instList = NULL;
  765. CCIMObjectPathList *objList = NULL;
  766. int error;
  767. if (pObjectName == NULL) {
  768. util_handleError(SCSI_ASSOCIATORNAMES,
  769. CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
  770. return ((CCIMObjectPathList *)NULL);
  771. }
  772. instList =
  773. cp_associators_Solaris_SCSIInterface(
  774. pAssocName, pObjectName, pResultClass, pRole, pResultRole);
  775. if (instList != NULL) {
  776. objList = cim_createObjectPathList(instList);
  777. cim_freeInstanceList(instList);
  778. }
  779. return (objList);
  780. }
  781. /*
  782. * Name: cp_references_Solaris_SCSIInterface
  783. *
  784. * Description:
  785. * Returns a instances of objects that have references to the passed in
  786. * object if there are any.
  787. *
  788. * Parameters:
  789. *
  790. * CCIMObjectPath *pAssocName - The name of the association that
  791. * the client wants information about.
  792. *
  793. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  794. * information on the class for which to find the associated instances.
  795. *
  796. * cimchar *pRole - If specified, must be valid for the object path
  797. * passed in requesting the associated instances.
  798. *
  799. * Returns:
  800. * CCIMObjectPathList * if associated objects are found. This list
  801. * may be empty. NULL is returned on error. If empty list, NULL
  802. * is returned also. An error is set for CIMOM if an error occurs
  803. * to notify CIMOM that the NULL means error.
  804. */
  805. /* ARGSUSED */
  806. CCIMInstanceList *
  807. cp_references_Solaris_SCSIInterface(CCIMObjectPath *pAssocName,
  808. CCIMObjectPath *pObjectName, char *pRole)
  809. {
  810. CCIMInstanceList *instList = NULL;
  811. CCIMObjectPathList *objList = NULL;
  812. int error;
  813. if (pObjectName == NULL) {
  814. util_handleError(SCSI_REFERENCES, CIM_ERR_INVALID_PARAMETER,
  815. NULL, NULL, &error);
  816. return ((CCIMInstanceList *)NULL);
  817. }
  818. /*
  819. * Get the list of those objects that are referred to by
  820. * the calling object.
  821. */
  822. objList =
  823. cp_associatorNames_Solaris_SCSIInterface(
  824. pAssocName, pObjectName, NULL, NULL, NULL);
  825. if (objList == NULL) {
  826. return ((CCIMInstanceList *)NULL);
  827. }
  828. /*
  829. * Now generate the list of instances to return.
  830. */
  831. if ((strcasecmp(pObjectName->mName, SCSI_CONTROLLER)) == 0) {
  832. instList = scsiIntAssocToInstList(pObjectName,
  833. ANTECEDENT, objList, DEPENDENT, &error);
  834. } else {
  835. instList = scsiIntAssocToInstList(pObjectName,
  836. DEPENDENT, objList, ANTECEDENT, &error);
  837. }
  838. cim_freeObjectPathList(objList);
  839. return (instList);
  840. }
  841. /*
  842. * Name: cp_referenceNames_Solaris_SCSIInterface
  843. *
  844. * Description:
  845. * Returns a instances of objects that have references to the passed in
  846. * object if there are any.
  847. *
  848. * Parameters:
  849. *
  850. * CCIMObjectPath *pAssocName - The name of the association that
  851. * the client wants information about.
  852. *
  853. * CCIMObjectPath *pObjectName - An CCIMObjectPath * which contains the
  854. * information on the class for which to find the associated instances.
  855. *
  856. * cimchar *pRole - If specified, must be valid for the object path
  857. * passed in requesting the associated instances.
  858. *
  859. *
  860. * Returns:
  861. * CCIMObjectPathList * if associated objects are found. This list
  862. * may be empty. NULL is returned on error and for an empty list.
  863. * An error is set for CIMOM to determine if NULL means error.
  864. *
  865. */
  866. /* ARGSUSED */
  867. CCIMObjectPathList *
  868. cp_referenceNames_Solaris_SCSIInterface(CCIMObjectPath *pAssocName,
  869. CCIMObjectPath *pObjectName, cimchar *pRole)
  870. {
  871. CCIMInstanceList *instList;
  872. CCIMObjectPathList *objList = NULL;
  873. int error;
  874. if (pObjectName == NULL) {
  875. util_handleError(SCSI_REFERENCENAMES, CIM_ERR_INVALID_PARAMETER,
  876. NULL, NULL, &error);
  877. return ((CCIMObjectPathList *)NULL);
  878. }
  879. instList =
  880. cp_references_Solaris_SCSIInterface(pAssocName, pObjectName, pRole);
  881. if (instList != NULL) {
  882. objList = cim_createObjectPathList(instList);
  883. cim_freeInstanceList(instList);
  884. }
  885. return (objList);
  886. }
  887. /*
  888. * Create the association class with the passed in attributes.
  889. */
  890. static
  891. CCIMInstanceList *
  892. scsiIntAssocToInstList(CCIMObjectPath *pObjectName, cimchar *pObjectNameRole,
  893. CCIMObjectPathList *objList, cimchar *objRole, int *error)
  894. {
  895. CCIMObjectPathList *tmpList;
  896. CCIMInstanceList *instList = NULL;
  897. CCIMInstance *inst;
  898. CCIMObjectPath *obj1;
  899. CCIMObjectPath *obj2;
  900. CCIMException *ex;
  901. *error = 0;
  902. if (objList == NULL) {
  903. return ((CCIMInstanceList *)NULL);
  904. }
  905. instList = cim_createInstanceList();
  906. if (instList == NULL) {
  907. ex = cim_getLastError();
  908. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  909. CREATE_INSTANCE_FAILURE, ex, error);
  910. return ((CCIMInstanceList *)NULL);
  911. }
  912. tmpList = objList;
  913. while (tmpList != NULL) {
  914. obj1 = tmpList->mDataObject;
  915. obj2 = cim_copyObjectPath(pObjectName);
  916. if (obj2 == NULL) {
  917. ex = cim_getLastError();
  918. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  919. COPY_OBJPATH_FAILURE, ex, error);
  920. return ((CCIMInstanceList *)NULL);
  921. }
  922. inst = scsiIntAssocToInst(obj1, objRole, obj2, pObjectNameRole,
  923. error);
  924. cim_freeObjectPath(obj2);
  925. if (*error != 0) {
  926. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  927. SCSIINT_ASSOC_TO_INSTANCE_FAILURE, NULL, error);
  928. cim_freeInstanceList(instList);
  929. return ((CCIMInstanceList *)NULL);
  930. }
  931. instList = cim_addInstance(instList, inst);
  932. if (instList == NULL) {
  933. ex = cim_getLastError();
  934. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  935. ADD_INSTANCE_FAILURE, ex, error);
  936. cim_freeInstance(inst);
  937. return ((CCIMInstanceList *)NULL);
  938. }
  939. tmpList = tmpList->mNext;
  940. }
  941. return (instList);
  942. }
  943. static
  944. CCIMInstance *
  945. scsiIntAssocToInst(CCIMObjectPath *obj1, cimchar *obj1Role,
  946. CCIMObjectPath *obj2, cimchar *obj2Role, int *error)
  947. {
  948. CCIMInstance *inst = NULL;
  949. CCIMException *ex;
  950. *error = 0;
  951. inst = cim_createInstance(SCSI_INTERFACE);
  952. if (inst == NULL) {
  953. ex = cim_getLastError();
  954. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  955. SCSIINT_ASSOC_TO_INSTANCE_FAILURE, ex, error);
  956. return ((CCIMInstance *)NULL);
  957. }
  958. util_doReferenceProperty(obj2Role, obj2, cim_true, inst, error);
  959. if (*error != 0) {
  960. ex = cim_getLastError();
  961. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  962. CREATE_REFPROP_FAILURE, ex, error);
  963. cim_freeInstance(inst);
  964. return ((CCIMInstance *)NULL);
  965. }
  966. util_doReferenceProperty(obj1Role, obj1, cim_true, inst, error);
  967. if (*error != 0) {
  968. ex = cim_getLastError();
  969. util_handleError(SCSI_INTERFACE, CIM_ERR_FAILED,
  970. CREATE_REFPROP_FAILURE, ex, error);
  971. cim_freeInstance(inst);
  972. return ((CCIMInstance *)NULL);
  973. }
  974. return (inst);
  975. }