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 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29#include <unistd.h> 30#include <netdb.h> 31#include <errno.h> 32 33#include "util.h" 34#include "cimKeys.h" 35#include "ctrl_descriptors.h" 36#include "providerNames.h" 37#include "messageStrings.h" 38#include "Solaris_SCSIController.h" 39 40#define SCSI_GETINSTANCE "SCSI_CONTROLLER,GET_INSTANCE" 41#define SCSI_ENUMINSTANCES "SCSI_CONTROLLER,ENUM_INSTANCES" 42#define SCSI_ENUMINSTANCENAMES "SCSI_CONTROLLER,ENUM_INSTANCENAMES" 43#define SCSI_CREATEINSTANCE "SCSI_CONTROLLER,CREATE_INSTANCE" 44#define SCSI_DELETEINSTANCE "SCSI_CONTROLLER,DELETE_INSTANCE" 45#define SCSI_SETINSTANCE "SCSI_CONTROLLER,SET_INSTANCE" 46#define SCSI_GETPROPERTY "SCSI_CONTROLLER,GET_PROPERTY" 47#define SCSI_SETPROPERTY "SCSI_CONTROLLER,SET_PROPERTY" 48#define SCSI_INVOKEMETHOD "SCSI_CONTROLLER,INVOKE_METHOD" 49#define SCSI_EXECQUERY "SCSI_CONTROLLER,EXEC_QUERY" 50 51/* 52 * Solaris_SCSIController provider 53 * 54 * It is important to note that all memory allocated by these functions 55 * and passed to the CIMOM, is freed by the CIMOM as the caller. 56 */ 57 58/* 59 * Name: cp_getInstance_Solaris_SCSIController 60 * 61 * Description: Returns an instance which matches the passed in object path 62 * if found. 63 * 64 * Parameters: 65 * pOP - An CCIMObjectPath * which contains the information on 66 * the class for which to find the instance. 67 * Returns: 68 * CCIMInstance * if matched instance is found. Otherwise, NULL. 69 */ 70 71/* ARGSUSED */ 72CCIMInstance* 73cp_getInstance_Solaris_SCSIController(CCIMObjectPath* pOP) 74{ 75 CCIMInstance *inst = NULL; 76 CCIMPropertyList *pCurPropList; 77 dm_descriptor_t scsictrl_descriptor; 78 char *name; 79 int error; 80 81 if (pOP == NULL || 82 pOP->mKeyProperties == NULL) { 83 util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL, 84 NULL, &error); 85 return ((CCIMInstance *)NULL); 86 } 87 88 pCurPropList = pOP->mKeyProperties; 89 name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID, 90 &error); 91 if (error != 0 || name == NULL) { 92 util_handleError(SCSI_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL, 93 NULL, &error); 94 return ((CCIMInstance*)NULL); 95 } 96 97 scsictrl_descriptor = 98 dm_get_descriptor_by_name(DM_CONTROLLER, name, &error); 99 /* 100 * Not found. Return a null instance. 101 */ 102 103 if (error == ENODEV) { 104 return ((CCIMInstance *)NULL); 105 } 106 107 if (error != 0) { 108 util_handleError(SCSI_GETINSTANCE, CIM_ERR_FAILED, 109 DM_GET_DESC_BYNAME_FAILURE, NULL, &error); 110 return ((CCIMInstance*)NULL); 111 } 112 /* Turn this descriptor in to a scsi controller instance */ 113 114 inst = ctrl_descriptor_toCCIMInstance( 115 hostName, scsictrl_descriptor, SCSI_CONTROLLER, &error); 116 dm_free_descriptor(scsictrl_descriptor); 117 118 if (error != 0) { 119 util_handleError(SCSI_GETINSTANCE, CIM_ERR_FAILED, 120 SCSICTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error); 121 return ((CCIMInstance*)NULL); 122 } 123 124 return (inst); 125} 126 127/* 128 * Name: cp_enumInstances_Solaris_SCSIController 129 * 130 * Description: Returns an instancelist of SCSI controllers, if found. 131 * 132 * Parameters: 133 * pOP - An CCIMObjectPath * which contains the information on 134 * the class for which to find the instance. 135 * Returns: 136 * CCIMInstanceList * if matched instances are found. Otherwise, NULL. 137 */ 138 139/* ARGSUSED */ 140CCIMInstanceList* 141cp_enumInstances_Solaris_SCSIController(CCIMObjectPath* pOP) 142{ 143 CCIMInstanceList *instList = NULL; 144 dm_descriptor_t *scsictrl_descriptorp; 145 int error; 146 int filter[1]; 147 148 filter[0] = DM_FILTER_END; 149 150 scsictrl_descriptorp = dm_get_descriptors(DM_CONTROLLER, filter, 151 &error); 152 153 if (scsictrl_descriptorp == NULL || 154 scsictrl_descriptorp[0] == NULL) { 155 return ((CCIMInstanceList *)NULL); 156 } 157 158 if (error != 0) { 159 util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED, 160 DM_GET_DESCRIPTORS, NULL, &error); 161 return ((CCIMInstanceList *)NULL); 162 } 163 164 /* convert controller to CCIMInstanceList */ 165 instList = ctrl_descriptors_toCCIMInstanceList(SCSI_CONTROLLER, 166 scsictrl_descriptorp, &error, 2, "scsi", "fibre channel"); 167 dm_free_descriptors(scsictrl_descriptorp); 168 169 if (error != 0) { 170 util_handleError(SCSI_ENUMINSTANCES, CIM_ERR_FAILED, 171 SCSICTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error); 172 return ((CCIMInstanceList *)NULL); 173 } 174 175 return (instList); 176} 177 178/* 179 * Name: cp_enumInstanceNames_Solaris_SCSIController 180 * 181 * Description: Returns an object path list of SCSI controllers, if found. 182 * 183 * Parameters: 184 * pOP - An CCIMObjectPath * which contains the information on 185 * the class for which to find the instance. 186 * Returns: 187 * CCIMObjectPathList * if matched instances are found. Otherwise, NULL. 188 */ 189 190/* ARGSUSED */ 191CCIMObjectPathList* 192cp_enumInstanceNames_Solaris_SCSIController(CCIMObjectPath * pOP) { 193 194 CCIMInstanceList *instList; 195 CCIMObjectPathList *objList = NULL; 196 int error; 197 198 if (pOP == NULL) { 199 util_handleError(SCSI_ENUMINSTANCENAMES, CIM_ERR_INVALID_PARAMETER, 200 NULL, NULL, &error); 201 return ((CCIMObjectPathList *)NULL); 202 } 203 204 /* 205 * Call in to enumInstances and then convert the instance list in 206 * to an object list. 207 */ 208 209 instList = cp_enumInstances_Solaris_SCSIController(pOP); 210 211 if (instList != NULL) { 212 objList = cim_createObjectPathList(instList); 213 cim_freeInstanceList(instList); 214 } 215 216 return (objList); 217} 218 219/* 220 * Creating an instance of a Solaris_SCSIController is not supported. 221 */ 222 223/* ARGSUSED */ 224CCIMObjectPath* 225cp_createInstance_Solaris_SCSIController( 226 CCIMObjectPath* pOP, CCIMInstance* pInst) 227{ 228 int error; 229 230 util_handleError(SCSI_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, 231 NULL, &error); 232 return ((CCIMObjectPath*)NULL); 233} 234 235/* 236 * Deleting an instance of a Solaris_SCSIController is not supported. 237 */ 238 239/* ARGSUSED */ 240CIMBool 241cp_deleteInstance_Solaris_SCSIController(CCIMObjectPath* pInst) 242{ 243 244 int error; 245 246 util_handleError(SCSI_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED, 247 NULL, NULL, &error); 248 return (cim_false); 249} 250 251/* 252 * Name: cp_getProperty_Solaris_SCSIController 253 * 254 * Description: Returns the property requested, if found. 255 * 256 * Parameters: 257 * pOP - An CCIMObjectPath * which contains the information on 258 * the class for which to find the instances. 259 * Returns: 260 * CCIMProperty * if found. 261 */ 262 263/* ARGSUSED */ 264CCIMProperty * 265cp_getProperty_Solaris_SCSIController(CCIMObjectPath *pOP, 266 char *pPropName) 267{ 268 269 CCIMProperty *prop = NULL; 270 CCIMInstance *inst = NULL; 271 int error = 0; 272 273 if (pOP == NULL) { 274 util_handleError(SCSI_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL, 275 NULL, &error); 276 return ((CCIMProperty *)NULL); 277 } 278 279 inst = cp_getInstance_Solaris_SCSIController(pOP); 280 if (inst == NULL) { 281 return ((CCIMProperty *)NULL); 282 } 283 284 prop = cim_getProperty(inst, pPropName); 285 cim_freeInstance(inst); 286 return (prop); 287} 288 289/* 290 * Setting an instance of a Solaris_SCSIController is not supported. 291 */ 292 293/* ARGSUSED */ 294CIMBool 295cp_setInstance_Solaris_SCSIController(CCIMObjectPath* pOP, CCIMInstance* pInst) 296{ 297 298 int error; 299 300 util_handleError(SCSI_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL, 301 NULL, &error); 302 return (cim_false); 303} 304 305/* 306 * Setting a property of a Solaris_SCSIController is not supported. 307 */ 308 309/* ARGSUSED */ 310CIMBool 311cp_setProperty_Solaris_SCSIController(CCIMObjectPath* pOP, CCIMProperty* pProp) 312{ 313 314 int error; 315 316 util_handleError(SCSI_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, 317 NULL, NULL, &error); 318 return (cim_false); 319} 320 321/* 322 * No methods available for Solaris_SCSIController. 323 */ 324 325/* ARGSUSED */ 326CCIMProperty* 327cp_invokeMethod_Solaris_SCSIController(CCIMObjectPath* op, cimchar* methodName, 328 CCIMPropertyList* inParams, CCIMPropertyList* outParams) 329{ 330 CCIMProperty *retVal = (CCIMProperty*)NULL; 331 return (retVal); 332} 333 334/* 335 * Name: cp_execQuery_Solaris_SCSIController 336 * 337 * Description: 338 * Returns an instance list which matches the query if any are found. 339 * 340 * Parameters: 341 * CCIMObjectPath *op - An CCIMObjectPath * which contains the 342 * information on the class for which to find the instances. 343 * 344 * selectList - Not used 345 * nonJoinExp - Not used 346 * 347 * Returns: 348 * CCIMInstanceList * if matched instances are found. Otherwise, NULL. 349 */ 350 351/* 352 * Currently, there is no WQL parser for the C providers. As a result, 353 * what is returned to the CIMOM is a list of instances with 354 * a NULL value at the beginning of the list. This NULL value indicates 355 * to the CIMOM that it must do the filtering for the client. 356 */ 357 358/* ARGSUSED */ 359CCIMInstanceList* 360cp_execQuery_Solaris_SCSIController(CCIMObjectPath *op, cimchar *selectList, 361 cimchar *nonJoinExp, cimchar *queryExp, int queryType) 362{ 363 CCIMInstanceList *instList = NULL; 364 CCIMInstanceList *result; 365 CCIMInstance *emptyInst; 366 CCIMException *ex; 367 int error; 368 369 if (op == NULL) { 370 util_handleError(SCSI_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL, 371 NULL, &error); 372 return ((CCIMInstanceList *)NULL); 373 } 374 375 instList = cp_enumInstances_Solaris_SCSIController(op); 376 377 if (instList == NULL) { 378 return ((CCIMInstanceList *)NULL); 379 } 380 /* 381 * Create a null instance and add it to the beginning 382 * of the list to indicate to the CIMOM that no filtering 383 * was done. 384 */ 385 386 emptyInst = cim_createInstance(""); 387 if (emptyInst == NULL) { 388 ex = cim_getLastError(); 389 util_handleError(SCSI_EXECQUERY, CIM_ERR_FAILED, 390 CREATE_INSTANCE_FAILURE, ex, &error); 391 cim_freeInstanceList(instList); 392 return ((CCIMInstanceList *)NULL); 393 } 394 395 result = cim_createInstanceList(); 396 if (result == NULL) { 397 ex = cim_getLastError(); 398 util_handleError(SCSI_EXECQUERY, CIM_ERR_FAILED, 399 CREATE_INSTANCE_LIST_FAILURE, ex, &error); 400 cim_freeInstance(emptyInst); 401 cim_freeInstanceList(instList); 402 return ((CCIMInstanceList *)NULL); 403 } 404 405 result = cim_addInstance(result, emptyInst); 406 if (result == NULL) { 407 ex = cim_getLastError(); 408 util_handleError(SCSI_EXECQUERY, CIM_ERR_FAILED, 409 ADD_INSTANCE_FAILURE, ex, &error); 410 cim_freeInstanceList(instList); 411 cim_freeInstance(emptyInst); 412 return ((CCIMInstanceList *)NULL); 413 } 414 415 /* 416 * Since copying the original list to the new list will 417 * leave no way to free the original list, manually 418 * concatenate the original list to the new one. 419 */ 420 421 result->mNext = instList; 422 return (result); 423} 424