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