1*aff4bce5Syi zhang - Sun Microsystems - Beijing China /* 2*aff4bce5Syi zhang - Sun Microsystems - Beijing China * CDDL HEADER START 3*aff4bce5Syi zhang - Sun Microsystems - Beijing China * 4*aff4bce5Syi zhang - Sun Microsystems - Beijing China * The contents of this file are subject to the terms of the 5*aff4bce5Syi zhang - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License"). 6*aff4bce5Syi zhang - Sun Microsystems - Beijing China * You may not use this file except in compliance with the License. 7*aff4bce5Syi zhang - Sun Microsystems - Beijing China * 8*aff4bce5Syi zhang - Sun Microsystems - Beijing China * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*aff4bce5Syi zhang - Sun Microsystems - Beijing China * or http://www.opensolaris.org/os/licensing. 10*aff4bce5Syi zhang - Sun Microsystems - Beijing China * See the License for the specific language governing permissions 11*aff4bce5Syi zhang - Sun Microsystems - Beijing China * and limitations under the License. 12*aff4bce5Syi zhang - Sun Microsystems - Beijing China * 13*aff4bce5Syi zhang - Sun Microsystems - Beijing China * When distributing Covered Code, include this CDDL HEADER in each 14*aff4bce5Syi zhang - Sun Microsystems - Beijing China * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*aff4bce5Syi zhang - Sun Microsystems - Beijing China * If applicable, add the following below this CDDL HEADER, with the 16*aff4bce5Syi zhang - Sun Microsystems - Beijing China * fields enclosed by brackets "[]" replaced with your own identifying 17*aff4bce5Syi zhang - Sun Microsystems - Beijing China * information: Portions Copyright [yyyy] [name of copyright owner] 18*aff4bce5Syi zhang - Sun Microsystems - Beijing China * 19*aff4bce5Syi zhang - Sun Microsystems - Beijing China * CDDL HEADER END 20*aff4bce5Syi zhang - Sun Microsystems - Beijing China */ 21*aff4bce5Syi zhang - Sun Microsystems - Beijing China /* 22*aff4bce5Syi zhang - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*aff4bce5Syi zhang - Sun Microsystems - Beijing China * Use is subject to license terms. 24*aff4bce5Syi zhang - Sun Microsystems - Beijing China */ 25*aff4bce5Syi zhang - Sun Microsystems - Beijing China 26*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <dlfcn.h> 27*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <pthread.h> 28*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <string.h> 29*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <sys/sem.h> 30*aff4bce5Syi zhang - Sun Microsystems - Beijing China 31*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include "libsun_ima.h" 32*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include "ima.h" 33*aff4bce5Syi zhang - Sun Microsystems - Beijing China #include "ima-plugin.h" 34*aff4bce5Syi zhang - Sun Microsystems - Beijing China 35*aff4bce5Syi zhang - Sun Microsystems - Beijing China extern int number_of_plugins; 36*aff4bce5Syi zhang - Sun Microsystems - Beijing China extern int libMutex; 37*aff4bce5Syi zhang - Sun Microsystems - Beijing China extern IMA_PLUGIN_INFO plugintable[IMA_MAX_NUM_PLUGINS]; 38*aff4bce5Syi zhang - Sun Microsystems - Beijing China extern void InitLibrary(); 39*aff4bce5Syi zhang - Sun Microsystems - Beijing China 40*aff4bce5Syi zhang - Sun Microsystems - Beijing China static void os_obtainmutex(int semid); 41*aff4bce5Syi zhang - Sun Microsystems - Beijing China static void os_releasemutex(int semid); 42*aff4bce5Syi zhang - Sun Microsystems - Beijing China 43*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_API IMA_STATUS SUN_IMA_SetTunableProperties( 44*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_OID oid, 45*aff4bce5Syi zhang - Sun Microsystems - Beijing China ISCSI_TUNABLE_PARAM *param) { 46*aff4bce5Syi zhang - Sun Microsystems - Beijing China SUN_IMA_SetTunablePropertiesFn PassFunc; 47*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_UINT i; 48*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_STATUS status; 49*aff4bce5Syi zhang - Sun Microsystems - Beijing China 50*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (number_of_plugins == -1) { 51*aff4bce5Syi zhang - Sun Microsystems - Beijing China InitLibrary(); 52*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 53*aff4bce5Syi zhang - Sun Microsystems - Beijing China 54*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (param == NULL) { 55*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (IMA_ERROR_INVALID_PARAMETER); 56*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 57*aff4bce5Syi zhang - Sun Microsystems - Beijing China 58*aff4bce5Syi zhang - Sun Microsystems - Beijing China if ((oid.objectType != IMA_OBJECT_TYPE_LHBA) && 59*aff4bce5Syi zhang - Sun Microsystems - Beijing China (oid.objectType != IMA_OBJECT_TYPE_TARGET)) { 60*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 61*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 62*aff4bce5Syi zhang - Sun Microsystems - Beijing China 63*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_obtainmutex(libMutex); 64*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = IMA_ERROR_OBJECT_NOT_FOUND; 65*aff4bce5Syi zhang - Sun Microsystems - Beijing China 66*aff4bce5Syi zhang - Sun Microsystems - Beijing China for (i = 0; i < number_of_plugins; i++) { 67*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (plugintable[i].ownerId == oid.ownerId) { 68*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = IMA_ERROR_UNEXPECTED_OS_ERROR; 69*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_obtainmutex(plugintable[i].pluginMutex); 70*aff4bce5Syi zhang - Sun Microsystems - Beijing China #ifdef SOLARIS 71*aff4bce5Syi zhang - Sun Microsystems - Beijing China PassFunc = (SUN_IMA_SetTunablePropertiesFn) 72*aff4bce5Syi zhang - Sun Microsystems - Beijing China dlsym(plugintable[i].hPlugin, 73*aff4bce5Syi zhang - Sun Microsystems - Beijing China "SUN_IMA_SetTunableProperties"); 74*aff4bce5Syi zhang - Sun Microsystems - Beijing China #endif 75*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (PassFunc != NULL) { 76*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = PassFunc(oid, param); 77*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 78*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_releasemutex(plugintable[i].pluginMutex); 79*aff4bce5Syi zhang - Sun Microsystems - Beijing China break; 80*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 81*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 82*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_releasemutex(libMutex); 83*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (status); 84*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 85*aff4bce5Syi zhang - Sun Microsystems - Beijing China 86*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_API IMA_STATUS SUN_IMA_GetTunableProperties( 87*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_OID oid, 88*aff4bce5Syi zhang - Sun Microsystems - Beijing China ISCSI_TUNABLE_PARAM *param) { 89*aff4bce5Syi zhang - Sun Microsystems - Beijing China SUN_IMA_GetTunablePropertiesFn PassFunc = NULL; 90*aff4bce5Syi zhang - Sun Microsystems - Beijing China int i; 91*aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_STATUS status; 92*aff4bce5Syi zhang - Sun Microsystems - Beijing China 93*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (number_of_plugins == -1) { 94*aff4bce5Syi zhang - Sun Microsystems - Beijing China InitLibrary(); 95*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 96*aff4bce5Syi zhang - Sun Microsystems - Beijing China 97*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (param == NULL) { 98*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (IMA_ERROR_INVALID_PARAMETER); 99*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 100*aff4bce5Syi zhang - Sun Microsystems - Beijing China 101*aff4bce5Syi zhang - Sun Microsystems - Beijing China if ((oid.objectType != IMA_OBJECT_TYPE_LHBA) && 102*aff4bce5Syi zhang - Sun Microsystems - Beijing China (oid.objectType != IMA_OBJECT_TYPE_TARGET)) { 103*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 104*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 105*aff4bce5Syi zhang - Sun Microsystems - Beijing China 106*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_obtainmutex(libMutex); 107*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = IMA_ERROR_OBJECT_NOT_FOUND; 108*aff4bce5Syi zhang - Sun Microsystems - Beijing China for (i = 0; i < number_of_plugins; i++) { 109*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = IMA_ERROR_UNEXPECTED_OS_ERROR; 110*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (plugintable[i].ownerId == oid.ownerId) { 111*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_obtainmutex(plugintable[i].pluginMutex); 112*aff4bce5Syi zhang - Sun Microsystems - Beijing China #ifdef SOLARIS 113*aff4bce5Syi zhang - Sun Microsystems - Beijing China PassFunc = (SUN_IMA_GetTunablePropertiesFn) 114*aff4bce5Syi zhang - Sun Microsystems - Beijing China dlsym(plugintable[i].hPlugin, 115*aff4bce5Syi zhang - Sun Microsystems - Beijing China "SUN_IMA_GetTunableProperties"); 116*aff4bce5Syi zhang - Sun Microsystems - Beijing China #endif 117*aff4bce5Syi zhang - Sun Microsystems - Beijing China if (PassFunc != NULL) { 118*aff4bce5Syi zhang - Sun Microsystems - Beijing China status = PassFunc(oid, param); 119*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 120*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_releasemutex(plugintable[i].pluginMutex); 121*aff4bce5Syi zhang - Sun Microsystems - Beijing China break; 122*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 123*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 124*aff4bce5Syi zhang - Sun Microsystems - Beijing China os_releasemutex(libMutex); 125*aff4bce5Syi zhang - Sun Microsystems - Beijing China return (status); 126*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 127*aff4bce5Syi zhang - Sun Microsystems - Beijing China 128*aff4bce5Syi zhang - Sun Microsystems - Beijing China static void os_obtainmutex(int semid) { 129*aff4bce5Syi zhang - Sun Microsystems - Beijing China int retVal; 130*aff4bce5Syi zhang - Sun Microsystems - Beijing China struct sembuf sem_b; 131*aff4bce5Syi zhang - Sun Microsystems - Beijing China 132*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_num = 0; 133*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_op = -1; 134*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_flg = SEM_UNDO; 135*aff4bce5Syi zhang - Sun Microsystems - Beijing China retVal = semop(semid, &sem_b, 1); 136*aff4bce5Syi zhang - Sun Microsystems - Beijing China 137*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 138*aff4bce5Syi zhang - Sun Microsystems - Beijing China 139*aff4bce5Syi zhang - Sun Microsystems - Beijing China static void os_releasemutex(int semid) { 140*aff4bce5Syi zhang - Sun Microsystems - Beijing China int retVal; 141*aff4bce5Syi zhang - Sun Microsystems - Beijing China struct sembuf sem_b; 142*aff4bce5Syi zhang - Sun Microsystems - Beijing China 143*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_num = 0; 144*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_op = 1; 145*aff4bce5Syi zhang - Sun Microsystems - Beijing China sem_b.sem_flg = SEM_UNDO; 146*aff4bce5Syi zhang - Sun Microsystems - Beijing China retVal = semop(semid, &sem_b, 1); 147*aff4bce5Syi zhang - Sun Microsystems - Beijing China 148*aff4bce5Syi zhang - Sun Microsystems - Beijing China } 149