xref: /onnv-gate/usr/src/lib/mpapi/libmpapi/common/mpapi.c (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /******************************************************************************
2*7836SJohn.Forte@Sun.COM  *
3*7836SJohn.Forte@Sun.COM  * Description
4*7836SJohn.Forte@Sun.COM  * mpapi.c - Implements Multipath Management API Version 1.0
5*7836SJohn.Forte@Sun.COM  *
6*7836SJohn.Forte@Sun.COM  * License:
7*7836SJohn.Forte@Sun.COM  *  The contents of this file are subject to the SNIA Public License
8*7836SJohn.Forte@Sun.COM  *  Version 1.1 (the "License"); you may not use this file except in
9*7836SJohn.Forte@Sun.COM  *  compliance with the License. You may obtain a copy of the License at
10*7836SJohn.Forte@Sun.COM  *
11*7836SJohn.Forte@Sun.COM  *  http://mp-mgmt-api.sourceforge.net
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  *  Software distributed under the License is distributed on an "AS IS"
14*7836SJohn.Forte@Sun.COM  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15*7836SJohn.Forte@Sun.COM  *  the License for the specific language governing rights and limitations
16*7836SJohn.Forte@Sun.COM  *  under the License.
17*7836SJohn.Forte@Sun.COM  *
18*7836SJohn.Forte@Sun.COM  * The Original Code is  SNIA iSCSI Management API and Multipath Management
19*7836SJohn.Forte@Sun.COM  *	API header files.
20*7836SJohn.Forte@Sun.COM  *
21*7836SJohn.Forte@Sun.COM  * The Initial Developer of the Original Code is:
22*7836SJohn.Forte@Sun.COM  *	Benjamin F. Kuo Troika Networks, Inc. (benk@troikanetworks.com)
23*7836SJohn.Forte@Sun.COM  *	David Dillard	VERITAS Software(david.dillard@veritas.com)
24*7836SJohn.Forte@Sun.COM  *	Jeff Ding 	Adaptec, Inc. (jding@corp.adaptec.com)
25*7836SJohn.Forte@Sun.COM  *      Hyon Kim        Sun Microsystems(hyon.kim@sun.com)
26*7836SJohn.Forte@Sun.COM  *
27*7836SJohn.Forte@Sun.COM  * Contributor(s):
28*7836SJohn.Forte@Sun.COM  *	Paul von Behren Sun Microsystems(paul.vonbehren@sun.com)
29*7836SJohn.Forte@Sun.COM  *
30*7836SJohn.Forte@Sun.COM  ******************************************************************************
31*7836SJohn.Forte@Sun.COM  *
32*7836SJohn.Forte@Sun.COM  *   Changes:
33*7836SJohn.Forte@Sun.COM  *  1/15/2005	Implemented SNIA MP API specification 1.0
34*7836SJohn.Forte@Sun.COM  *  10/11/2005
35*7836SJohn.Forte@Sun.COM  * 		- License location was specified in the header comment.
36*7836SJohn.Forte@Sun.COM  *  	    	- validate_object() routine was updated per the latest
37*7836SJohn.Forte@Sun.COM  *		  specification.
38*7836SJohn.Forte@Sun.COM  *  		- is_zero_oid() routine was added.
39*7836SJohn.Forte@Sun.COM  *  		- MP_GetObjectType() was updated with validate_object().
40*7836SJohn.Forte@Sun.COM  *  		- pplist argument checking added in MP_GetMultipathLus().
41*7836SJohn.Forte@Sun.COM  *  		- Corrected typo in MP_GetTaregetPortGroupProperties()
42*7836SJohn.Forte@Sun.COM  *  		- MP_RegisterForObjectPropertyChanges() was updated with
43*7836SJohn.Forte@Sun.COM  *		  is_zero_oid() routine.
44*7836SJohn.Forte@Sun.COM  *  		- MP_DeregisterForObjectPropertyChanges() was updated with
45*7836SJohn.Forte@Sun.COM  *		  is_zero_oid() routine.
46*7836SJohn.Forte@Sun.COM  *		- MP_RegisterForObjectVisibilityChanges() was updated with
47*7836SJohn.Forte@Sun.COM  *		  is_zero_oid() routine.
48*7836SJohn.Forte@Sun.COM  *		- MP_DeregisterForObjectVisibilityChanges() was updated with
49*7836SJohn.Forte@Sun.COM  *		  is_zero_oid() routine.
50*7836SJohn.Forte@Sun.COM  *  		- Added stat() check in MP_RegisterPlugin() to validate the
51*7836SJohn.Forte@Sun.COM  *		  the given plugin file name.
52*7836SJohn.Forte@Sun.COM  *  		- Made MP_DeregisterPlugin() return MP_STATUS_UNKNOWN_FN
53*7836SJohn.Forte@Sun.COM  *		  to mach the specification description.
54*7836SJohn.Forte@Sun.COM  ******************************************************************************
55*7836SJohn.Forte@Sun.COM  */
56*7836SJohn.Forte@Sun.COM 
57*7836SJohn.Forte@Sun.COM #include <sys/sem.h>
58*7836SJohn.Forte@Sun.COM #include <dlfcn.h>
59*7836SJohn.Forte@Sun.COM #include <stdarg.h>
60*7836SJohn.Forte@Sun.COM #include <unistd.h>
61*7836SJohn.Forte@Sun.COM #include <sys/stat.h>
62*7836SJohn.Forte@Sun.COM #include <sys/types.h>
63*7836SJohn.Forte@Sun.COM #include <sys/mman.h>
64*7836SJohn.Forte@Sun.COM #include <errno.h>
65*7836SJohn.Forte@Sun.COM #include <stdio.h>
66*7836SJohn.Forte@Sun.COM #include <fcntl.h>
67*7836SJohn.Forte@Sun.COM #include <time.h>
68*7836SJohn.Forte@Sun.COM #include <pthread.h>
69*7836SJohn.Forte@Sun.COM #include "mpapi.h"
70*7836SJohn.Forte@Sun.COM #include "mpapi-sun.h"
71*7836SJohn.Forte@Sun.COM #include "mpapi-plugin.h"
72*7836SJohn.Forte@Sun.COM 
73*7836SJohn.Forte@Sun.COM #define LIBRARY_SUPPORTED_MP_VERSION	1
74*7836SJohn.Forte@Sun.COM #define LIBRARY_IMPLEMENTATION_VERSION	L"1.0.0"
75*7836SJohn.Forte@Sun.COM #define LIBRARY_VENDOR			L"Sun Microsystems Inc."
76*7836SJohn.Forte@Sun.COM 
77*7836SJohn.Forte@Sun.COM #define LIBRARY_FILE_NAME               "libMPAPI.so"
78*7836SJohn.Forte@Sun.COM 
79*7836SJohn.Forte@Sun.COM 
80*7836SJohn.Forte@Sun.COM MPPLUGININFO_T	plugintable[MP_MAX_NUM_PLUGINS];
81*7836SJohn.Forte@Sun.COM pthread_mutex_t mp_lib_mutex = PTHREAD_MUTEX_INITIALIZER;
82*7836SJohn.Forte@Sun.COM 
83*7836SJohn.Forte@Sun.COM static int	number_of_plugins = -1;
84*7836SJohn.Forte@Sun.COM 
85*7836SJohn.Forte@Sun.COM 
86*7836SJohn.Forte@Sun.COM void InitLibrary();
87*7836SJohn.Forte@Sun.COM void ExitLibrary();
88*7836SJohn.Forte@Sun.COM static int lock_register(int fd, int cmd, int type, off_t offset, int whence,
89*7836SJohn.Forte@Sun.COM 	    off_t len);
90*7836SJohn.Forte@Sun.COM static int search_line(MP_CHAR *buf, size_t buflen, MP_CHAR *srch_id,
91*7836SJohn.Forte@Sun.COM 	    size_t id_len, int *write_offset, int *bytes_left);
92*7836SJohn.Forte@Sun.COM static int is_zero_oid(MP_OID);
93*7836SJohn.Forte@Sun.COM 
94*7836SJohn.Forte@Sun.COM /**
95*7836SJohn.Forte@Sun.COM  ******************************************************************************
96*7836SJohn.Forte@Sun.COM  *
97*7836SJohn.Forte@Sun.COM  * Validate the oid.
98*7836SJohn.Forte@Sun.COM  *
99*7836SJohn.Forte@Sun.COM  * - Return MP_STATUS_OBJECT_NOT_FOUND when no plugin is found or the ownerId
100*7836SJohn.Forte@Sun.COM  *      of input OID is not found.
101*7836SJohn.Forte@Sun.COM  * - Return MP_STATUS_INVALID_OBJECT_TYPE when no plugin is found or
102*7836SJohn.Forte@Sun.COM  *      the type of input OID is not one of legitimate types defined SNIA
103*7836SJohn.Forte@Sun.COM  *      Multipath Management spec.
104*7836SJohn.Forte@Sun.COM  * - Return MP_STATUS_INVALID_PARAMETER when the type of input OID is
105*7836SJohn.Forte@Sun.COM  *	legitimate but its object type doesn't match with the object type
106*7836SJohn.Forte@Sun.COM  *      argument.
107*7836SJohn.Forte@Sun.COM  * - Otherwise return MP_STATUS_SUCCESS.
108*7836SJohn.Forte@Sun.COM  *
109*7836SJohn.Forte@Sun.COM  ******************************************************************************
110*7836SJohn.Forte@Sun.COM  */
validate_object(MP_OID obj,MP_OBJECT_TYPE objType,MP_UINT32 flag)111*7836SJohn.Forte@Sun.COM MP_STATUS validate_object(MP_OID obj, MP_OBJECT_TYPE objType,
112*7836SJohn.Forte@Sun.COM     MP_UINT32 flag)
113*7836SJohn.Forte@Sun.COM {
114*7836SJohn.Forte@Sun.COM 
115*7836SJohn.Forte@Sun.COM     if ((number_of_plugins == 0) ||
116*7836SJohn.Forte@Sun.COM 	(obj.ownerId > number_of_plugins || obj.ownerId <= 0)) {
117*7836SJohn.Forte@Sun.COM 	return (MP_STATUS_OBJECT_NOT_FOUND);
118*7836SJohn.Forte@Sun.COM     } else if (obj.objectType < 0 || obj.objectType > MP_OBJECT_TYPE_MAX) {
119*7836SJohn.Forte@Sun.COM 	return (MP_STATUS_INVALID_OBJECT_TYPE);
120*7836SJohn.Forte@Sun.COM     } else if (obj.objectType == MP_OBJECT_TYPE_PLUGIN) {
121*7836SJohn.Forte@Sun.COM 	if (obj.objectSequenceNumber != 0) {
122*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_OBJECT_NOT_FOUND);
123*7836SJohn.Forte@Sun.COM 	}
124*7836SJohn.Forte@Sun.COM     }
125*7836SJohn.Forte@Sun.COM 
126*7836SJohn.Forte@Sun.COM     if (flag == MP_OBJECT_TYPE_MATCH) {
127*7836SJohn.Forte@Sun.COM     	if (obj.objectType != objType) {
128*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
129*7836SJohn.Forte@Sun.COM         }
130*7836SJohn.Forte@Sun.COM     }
131*7836SJohn.Forte@Sun.COM     return (MP_STATUS_SUCCESS);
132*7836SJohn.Forte@Sun.COM }
133*7836SJohn.Forte@Sun.COM 
134*7836SJohn.Forte@Sun.COM /**
135*7836SJohn.Forte@Sun.COM  ******************************************************************************
136*7836SJohn.Forte@Sun.COM  *
137*7836SJohn.Forte@Sun.COM  * Check if an oid is ZERO_OID or not.
138*7836SJohn.Forte@Sun.COM  *
139*7836SJohn.Forte@Sun.COM  * - Return 1 if the input OID is ZERO_OID
140*7836SJohn.Forte@Sun.COM  *
141*7836SJohn.Forte@Sun.COM  * - Return 0 if not.
142*7836SJohn.Forte@Sun.COM  *
143*7836SJohn.Forte@Sun.COM  ******************************************************************************
144*7836SJohn.Forte@Sun.COM  */
is_zero_oid(MP_OID oid)145*7836SJohn.Forte@Sun.COM static int is_zero_oid(MP_OID oid)
146*7836SJohn.Forte@Sun.COM {
147*7836SJohn.Forte@Sun.COM 
148*7836SJohn.Forte@Sun.COM     if ((oid.objectType != MP_OBJECT_TYPE_UNKNOWN) || (oid.ownerId != 0) ||
149*7836SJohn.Forte@Sun.COM 	(oid.objectSequenceNumber != 0)) {
150*7836SJohn.Forte@Sun.COM 	return (0);
151*7836SJohn.Forte@Sun.COM     }
152*7836SJohn.Forte@Sun.COM 
153*7836SJohn.Forte@Sun.COM     return (1);
154*7836SJohn.Forte@Sun.COM }
155*7836SJohn.Forte@Sun.COM 
156*7836SJohn.Forte@Sun.COM /**
157*7836SJohn.Forte@Sun.COM  ******************************************************************************
158*7836SJohn.Forte@Sun.COM  *
159*7836SJohn.Forte@Sun.COM  * Initialize by loading plugin libraries and calling Initialize routine.
160*7836SJohn.Forte@Sun.COM  * Note: The build of libMPAPI.so should include a linker option to make this
161*7836SJohn.Forte@Sun.COM  *	 routine executed when it is loaded.
162*7836SJohn.Forte@Sun.COM  *
163*7836SJohn.Forte@Sun.COM  * - This routine bypasses a plugin library if it is not found.
164*7836SJohn.Forte@Sun.COM  * - The implementation of this routine is based on configuration file
165*7836SJohn.Forte@Sun.COM  *   /etc/mpapi.conf that contains a list of plugin libraries.
166*7836SJohn.Forte@Sun.COM  *
167*7836SJohn.Forte@Sun.COM  ******************************************************************************
168*7836SJohn.Forte@Sun.COM  */
InitLibrary()169*7836SJohn.Forte@Sun.COM void InitLibrary()
170*7836SJohn.Forte@Sun.COM {
171*7836SJohn.Forte@Sun.COM 	FILE *mpconf;
172*7836SJohn.Forte@Sun.COM 	int fd_mpconf;
173*7836SJohn.Forte@Sun.COM 	MP_WCHAR fullline[MAX_LINE_SIZE]; /* line read in from mpapi.conf */
174*7836SJohn.Forte@Sun.COM 	MP_WCHAR name[MAX_NAME_SIZE]; 	/* Read in from file mpapi.conf */
175*7836SJohn.Forte@Sun.COM 	char path[MAX_NAME_SIZE]; 	/* Read in from file mpapi.conf */
176*7836SJohn.Forte@Sun.COM 	char systemPath[MAX_NAME_SIZE], mpConfFilePath[MAX_NAME_SIZE];
177*7836SJohn.Forte@Sun.COM 	MP_WCHAR *charPtr;
178*7836SJohn.Forte@Sun.COM 	MP_WCHAR *sol;
179*7836SJohn.Forte@Sun.COM 	struct stat	stat_buf;
180*7836SJohn.Forte@Sun.COM 
181*7836SJohn.Forte@Sun.COM 	MP_UINT32 i = 0;	/* index for plugin table */
182*7836SJohn.Forte@Sun.COM 
183*7836SJohn.Forte@Sun.COM 	if(number_of_plugins != -1) {
184*7836SJohn.Forte@Sun.COM 		return;
185*7836SJohn.Forte@Sun.COM 	}
186*7836SJohn.Forte@Sun.COM 
187*7836SJohn.Forte@Sun.COM 	(void) pthread_mutex_lock(&mp_lib_mutex);
188*7836SJohn.Forte@Sun.COM 
189*7836SJohn.Forte@Sun.COM 	number_of_plugins = 0;
190*7836SJohn.Forte@Sun.COM 
191*7836SJohn.Forte@Sun.COM 	/* Open configuration file from known location */
192*7836SJohn.Forte@Sun.COM 	strncpy(mpConfFilePath, "/etc/mpapi.conf", MAX_NAME_SIZE);
193*7836SJohn.Forte@Sun.COM 
194*7836SJohn.Forte@Sun.COM 	if ((fd_mpconf = open(mpConfFilePath, O_RDONLY)) < 0) {
195*7836SJohn.Forte@Sun.COM 		(void) pthread_mutex_unlock(&mp_lib_mutex);
196*7836SJohn.Forte@Sun.COM 		return;
197*7836SJohn.Forte@Sun.COM 	}
198*7836SJohn.Forte@Sun.COM 
199*7836SJohn.Forte@Sun.COM 	if (lock_register(fd_mpconf, F_SETLKW, F_RDLCK, 0, SEEK_SET, 0) < 0) {
200*7836SJohn.Forte@Sun.COM 		close(fd_mpconf);
201*7836SJohn.Forte@Sun.COM 		(void) pthread_mutex_unlock(&mp_lib_mutex);
202*7836SJohn.Forte@Sun.COM 		return;
203*7836SJohn.Forte@Sun.COM 	}
204*7836SJohn.Forte@Sun.COM 
205*7836SJohn.Forte@Sun.COM 	if ((mpconf = fdopen(fd_mpconf, "r")) == NULL) {
206*7836SJohn.Forte@Sun.COM 		lock_register(fd_mpconf, F_SETLK, F_UNLCK, 0, SEEK_SET, 0);
207*7836SJohn.Forte@Sun.COM 		close(fd_mpconf);
208*7836SJohn.Forte@Sun.COM 		(void) pthread_mutex_unlock(&mp_lib_mutex);
209*7836SJohn.Forte@Sun.COM 		return;
210*7836SJohn.Forte@Sun.COM 	}
211*7836SJohn.Forte@Sun.COM 
212*7836SJohn.Forte@Sun.COM 	/* Read in each line and load library */
213*7836SJohn.Forte@Sun.COM 	while ((mpconf != NULL) &&
214*7836SJohn.Forte@Sun.COM 	    (charPtr = fgetws(fullline, MAX_LINE_SIZE, mpconf))) {
215*7836SJohn.Forte@Sun.COM 	    if ((*charPtr != L'#') && (*charPtr != L'\n')) {
216*7836SJohn.Forte@Sun.COM 		/* Take out the '\n' */
217*7836SJohn.Forte@Sun.COM 		if ((charPtr = wcschr(fullline, L'\n')) != NULL)
218*7836SJohn.Forte@Sun.COM 		    *charPtr = L'\0';
219*7836SJohn.Forte@Sun.COM 
220*7836SJohn.Forte@Sun.COM 		charPtr = fullline;
221*7836SJohn.Forte@Sun.COM 		/* remove leading blank or taps. */
222*7836SJohn.Forte@Sun.COM 		while ((fullline[0] == L' ') || (fullline[0] == L'\t'))
223*7836SJohn.Forte@Sun.COM 			charPtr++;
224*7836SJohn.Forte@Sun.COM 
225*7836SJohn.Forte@Sun.COM 		sol = charPtr;
226*7836SJohn.Forte@Sun.COM 
227*7836SJohn.Forte@Sun.COM 		/*
228*7836SJohn.Forte@Sun.COM 		 * look for first tab or space.
229*7836SJohn.Forte@Sun.COM 		 */
230*7836SJohn.Forte@Sun.COM 		if ((charPtr = wcschr(fullline, L'\t')) == NULL)
231*7836SJohn.Forte@Sun.COM 		    charPtr = wcschr(fullline, L' ');
232*7836SJohn.Forte@Sun.COM 
233*7836SJohn.Forte@Sun.COM 		/* Set Null termination for library name if found */
234*7836SJohn.Forte@Sun.COM 		if (charPtr != NULL) {
235*7836SJohn.Forte@Sun.COM 		    *charPtr++ = L'\0';
236*7836SJohn.Forte@Sun.COM 		    wcsncpy(name, sol, MAX_NAME_SIZE);
237*7836SJohn.Forte@Sun.COM 			/* Skip space and tab until the next character found */
238*7836SJohn.Forte@Sun.COM 		    while ((*charPtr == L' ') || (*charPtr == L'\t'))
239*7836SJohn.Forte@Sun.COM 			charPtr++;
240*7836SJohn.Forte@Sun.COM 		} else {
241*7836SJohn.Forte@Sun.COM 		    continue;	/* May be invalid entry */
242*7836SJohn.Forte@Sun.COM 		}
243*7836SJohn.Forte@Sun.COM 
244*7836SJohn.Forte@Sun.COM 		/* Copy library name and path */
245*7836SJohn.Forte@Sun.COM 		wcstombs(path, charPtr, MAX_NAME_SIZE);
246*7836SJohn.Forte@Sun.COM 
247*7836SJohn.Forte@Sun.COM 		/*
248*7836SJohn.Forte@Sun.COM 		 * Continue to the next line if library name or path is
249*7836SJohn.Forte@Sun.COM 		 * invalid
250*7836SJohn.Forte@Sun.COM 		 */
251*7836SJohn.Forte@Sun.COM 		if ((wcslen(name) == 0) ||
252*7836SJohn.Forte@Sun.COM 			(strlen(path) == 0))
253*7836SJohn.Forte@Sun.COM 		    continue;
254*7836SJohn.Forte@Sun.COM 
255*7836SJohn.Forte@Sun.COM 		/* Load the plugin now */
256*7836SJohn.Forte@Sun.COM 		if (stat(path, &stat_buf) != -1) {
257*7836SJohn.Forte@Sun.COM 		    plugintable[i].hdlPlugin = dlopen(path, RTLD_LAZY);
258*7836SJohn.Forte@Sun.COM 		} else {
259*7836SJohn.Forte@Sun.COM 		    continue;
260*7836SJohn.Forte@Sun.COM 		}
261*7836SJohn.Forte@Sun.COM 
262*7836SJohn.Forte@Sun.COM 		if (plugintable[i].hdlPlugin != NULL) {
263*7836SJohn.Forte@Sun.COM 		    InitializeFn PassFunc;
264*7836SJohn.Forte@Sun.COM 		    MP_STATUS status;
265*7836SJohn.Forte@Sun.COM 
266*7836SJohn.Forte@Sun.COM                     wcsncpy(plugintable[i].pluginName,
267*7836SJohn.Forte@Sun.COM                         name, MAX_NAME_SIZE);
268*7836SJohn.Forte@Sun.COM                     strncpy(plugintable[i].pluginPath,
269*7836SJohn.Forte@Sun.COM                         path, MAX_NAME_SIZE);
270*7836SJohn.Forte@Sun.COM 
271*7836SJohn.Forte@Sun.COM 		    plugintable[i].ownerId = i + 1;
272*7836SJohn.Forte@Sun.COM 
273*7836SJohn.Forte@Sun.COM 		    PassFunc = (InitializeFn)
274*7836SJohn.Forte@Sun.COM 			 dlsym(plugintable[i].hdlPlugin, "Initialize");
275*7836SJohn.Forte@Sun.COM 		    if (PassFunc != NULL) {
276*7836SJohn.Forte@Sun.COM 			status = PassFunc(plugintable[i].ownerId);
277*7836SJohn.Forte@Sun.COM 		    }
278*7836SJohn.Forte@Sun.COM 
279*7836SJohn.Forte@Sun.COM 		    i++;
280*7836SJohn.Forte@Sun.COM 		}
281*7836SJohn.Forte@Sun.COM 	    }
282*7836SJohn.Forte@Sun.COM 	}
283*7836SJohn.Forte@Sun.COM 
284*7836SJohn.Forte@Sun.COM 	if (lock_register(fd_mpconf, F_SETLK, F_UNLCK, 0, SEEK_SET, 0) < 0) {
285*7836SJohn.Forte@Sun.COM 	    fclose(mpconf);
286*7836SJohn.Forte@Sun.COM 	    close(fd_mpconf);
287*7836SJohn.Forte@Sun.COM 	    (void) pthread_mutex_unlock(&mp_lib_mutex);
288*7836SJohn.Forte@Sun.COM 	    return;
289*7836SJohn.Forte@Sun.COM 	}
290*7836SJohn.Forte@Sun.COM 	fclose(mpconf);
291*7836SJohn.Forte@Sun.COM 	close(fd_mpconf);
292*7836SJohn.Forte@Sun.COM 
293*7836SJohn.Forte@Sun.COM 	number_of_plugins = i;
294*7836SJohn.Forte@Sun.COM 	(void) pthread_mutex_unlock(&mp_lib_mutex);
295*7836SJohn.Forte@Sun.COM }
296*7836SJohn.Forte@Sun.COM 
297*7836SJohn.Forte@Sun.COM /**
298*7836SJohn.Forte@Sun.COM  ******************************************************************************
299*7836SJohn.Forte@Sun.COM  *
300*7836SJohn.Forte@Sun.COM  * Exit by calling Terminate routine of plugin libraries.
301*7836SJohn.Forte@Sun.COM  *
302*7836SJohn.Forte@Sun.COM  * Note: The build of libMPAPI.so should include a linker option to make this
303*7836SJohn.Forte@Sun.COM  *	 routine executed when it is unloaded.
304*7836SJohn.Forte@Sun.COM  *
305*7836SJohn.Forte@Sun.COM  ******************************************************************************
306*7836SJohn.Forte@Sun.COM  */
ExitLibrary()307*7836SJohn.Forte@Sun.COM void ExitLibrary()
308*7836SJohn.Forte@Sun.COM {
309*7836SJohn.Forte@Sun.COM     MP_UINT32 i, j;
310*7836SJohn.Forte@Sun.COM 
311*7836SJohn.Forte@Sun.COM     if(number_of_plugins == -1)
312*7836SJohn.Forte@Sun.COM         return;
313*7836SJohn.Forte@Sun.COM 
314*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
315*7836SJohn.Forte@Sun.COM     for (i = 0; i < number_of_plugins; i++) {
316*7836SJohn.Forte@Sun.COM         if (plugintable[i].hdlPlugin != NULL) {
317*7836SJohn.Forte@Sun.COM         TerminateFn ExitPassFunc;
318*7836SJohn.Forte@Sun.COM 
319*7836SJohn.Forte@Sun.COM         ExitPassFunc = (TerminateFn)
320*7836SJohn.Forte@Sun.COM             dlsym(plugintable[i].hdlPlugin, "Terminate");
321*7836SJohn.Forte@Sun.COM 
322*7836SJohn.Forte@Sun.COM         if (ExitPassFunc != NULL) {
323*7836SJohn.Forte@Sun.COM             ExitPassFunc();
324*7836SJohn.Forte@Sun.COM         }
325*7836SJohn.Forte@Sun.COM 
326*7836SJohn.Forte@Sun.COM         /* Unload plugin from memory */
327*7836SJohn.Forte@Sun.COM         dlclose(plugintable[i].hdlPlugin);
328*7836SJohn.Forte@Sun.COM         }
329*7836SJohn.Forte@Sun.COM     }
330*7836SJohn.Forte@Sun.COM 
331*7836SJohn.Forte@Sun.COM     number_of_plugins = -1;
332*7836SJohn.Forte@Sun.COM 
333*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
334*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_destroy(&mp_lib_mutex);
335*7836SJohn.Forte@Sun.COM }
336*7836SJohn.Forte@Sun.COM 
337*7836SJohn.Forte@Sun.COM /**
338*7836SJohn.Forte@Sun.COM  ******************************************************************************
339*7836SJohn.Forte@Sun.COM  *
340*7836SJohn.Forte@Sun.COM  * Gets the properties of the MP API library that is being used.
341*7836SJohn.Forte@Sun.COM  *
342*7836SJohn.Forte@Sun.COM  * @param pProps
343*7836SJohn.Forte@Sun.COM  *  A pointer to an @ref MP_LIBRARY_PROPERTIES structure allocated by
344*7836SJohn.Forte@Sun.COM  *  the caller.  On successful return this structure will contain the
345*7836SJohn.Forte@Sun.COM  *  properties of the MP library.
346*7836SJohn.Forte@Sun.COM  *
347*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or
348*7836SJohn.Forte@Sun.COM  *  if an error occurred.
349*7836SJohn.Forte@Sun.COM  *
350*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
351*7836SJohn.Forte@Sun.COM  *  Returned if the library properties were successfully returned.
352*7836SJohn.Forte@Sun.COM  *
353*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER Returned if @a pProps is NULL or
354*7836SJohn.Forte@Sun.COM  *  specifies a memory area to which data cannot be written.
355*7836SJohn.Forte@Sun.COM  *
356*7836SJohn.Forte@Sun.COM  ******************************************************************************
357*7836SJohn.Forte@Sun.COM  */
MP_GetLibraryProperties(MP_LIBRARY_PROPERTIES * pProps)358*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetLibraryProperties(
359*7836SJohn.Forte@Sun.COM     MP_LIBRARY_PROPERTIES *pProps)
360*7836SJohn.Forte@Sun.COM {
361*7836SJohn.Forte@Sun.COM     char mpPath[MAX_NAME_SIZE];
362*7836SJohn.Forte@Sun.COM 
363*7836SJohn.Forte@Sun.COM     if(pProps == NULL) {
364*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
365*7836SJohn.Forte@Sun.COM     }
366*7836SJohn.Forte@Sun.COM 
367*7836SJohn.Forte@Sun.COM     /* Fill in properties */
368*7836SJohn.Forte@Sun.COM     if (mbstowcs(pProps->buildTime, BUILD_TIME, 256) !=
369*7836SJohn.Forte@Sun.COM 	strlen(BUILD_TIME)) {
370*7836SJohn.Forte@Sun.COM 	return (MP_STATUS_INVALID_PARAMETER);
371*7836SJohn.Forte@Sun.COM     }
372*7836SJohn.Forte@Sun.COM     pProps->supportedMpVersion = LIBRARY_SUPPORTED_MP_VERSION;
373*7836SJohn.Forte@Sun.COM 
374*7836SJohn.Forte@Sun.COM     wcsncpy(pProps->implementationVersion,
375*7836SJohn.Forte@Sun.COM 	LIBRARY_IMPLEMENTATION_VERSION, MAX_NAME_SIZE);
376*7836SJohn.Forte@Sun.COM     wcsncpy(pProps->vendor, LIBRARY_VENDOR, MAX_NAME_SIZE);
377*7836SJohn.Forte@Sun.COM 
378*7836SJohn.Forte@Sun.COM     snprintf(pProps->fileName, MAX_NAME_SIZE, "%s",
379*7836SJohn.Forte@Sun.COM 	LIBRARY_FILE_NAME);
380*7836SJohn.Forte@Sun.COM 
381*7836SJohn.Forte@Sun.COM     return MP_STATUS_SUCCESS;
382*7836SJohn.Forte@Sun.COM }
383*7836SJohn.Forte@Sun.COM 
384*7836SJohn.Forte@Sun.COM 
385*7836SJohn.Forte@Sun.COM /**
386*7836SJohn.Forte@Sun.COM  ******************************************************************************
387*7836SJohn.Forte@Sun.COM  *
388*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all currently loaded plugins.
389*7836SJohn.Forte@Sun.COM  *
390*7836SJohn.Forte@Sun.COM  * @param ppList A pointer to a pointer to an @ref MP_OID_LIST.  On successful
391*7836SJohn.Forte@Sun.COM  *  return this will contain a pointer to an @ref MP_OID_LIST
392*7836SJohn.Forte@Sun.COM  *  which contains the object IDs of all of the plugins currently loaded
393*7836SJohn.Forte@Sun.COM  *  by the library.
394*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
395*7836SJohn.Forte@Sun.COM  * an error
396*7836SJohn.Forte@Sun.COM  *              occurred.
397*7836SJohn.Forte@Sun.COM  * @retval MP_SUCCESS Returned if the plugin ID list was successfully returned.
398*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER Returned if @a ppList is NULL or
399*7836SJohn.Forte@Sun.COM  * specifies a memory area to which data cannot be written.
400*7836SJohn.Forte@Sun.COM  *
401*7836SJohn.Forte@Sun.COM  ******************************************************************************
402*7836SJohn.Forte@Sun.COM  */
MP_GetPluginOidList(MP_OID_LIST ** ppList)403*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetPluginOidList(
404*7836SJohn.Forte@Sun.COM     MP_OID_LIST **ppList)
405*7836SJohn.Forte@Sun.COM {
406*7836SJohn.Forte@Sun.COM     MP_UINT32  i;
407*7836SJohn.Forte@Sun.COM 
408*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
409*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
410*7836SJohn.Forte@Sun.COM 
411*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
412*7836SJohn.Forte@Sun.COM 
413*7836SJohn.Forte@Sun.COM     if (number_of_plugins == 0) {
414*7836SJohn.Forte@Sun.COM         *ppList = (MP_OID_LIST*)calloc(1, sizeof(MP_OID_LIST));
415*7836SJohn.Forte@Sun.COM     } else {
416*7836SJohn.Forte@Sun.COM         *ppList = (MP_OID_LIST*)calloc(1,
417*7836SJohn.Forte@Sun.COM         sizeof(MP_OID_LIST) + (number_of_plugins - 1)* sizeof(MP_OID) );
418*7836SJohn.Forte@Sun.COM     }
419*7836SJohn.Forte@Sun.COM 
420*7836SJohn.Forte@Sun.COM     if ((*ppList) == NULL) {
421*7836SJohn.Forte@Sun.COM     	(void) pthread_mutex_unlock(&mp_lib_mutex);
422*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INSUFFICIENT_MEMORY);
423*7836SJohn.Forte@Sun.COM     }
424*7836SJohn.Forte@Sun.COM 
425*7836SJohn.Forte@Sun.COM     (*ppList)->oidCount = number_of_plugins;
426*7836SJohn.Forte@Sun.COM 
427*7836SJohn.Forte@Sun.COM     if (number_of_plugins != 0) {
428*7836SJohn.Forte@Sun.COM         for (i = 0; i < number_of_plugins; i++) {
429*7836SJohn.Forte@Sun.COM         (*ppList)->oids[i].objectType = MP_OBJECT_TYPE_PLUGIN;
430*7836SJohn.Forte@Sun.COM         (*ppList)->oids[i].ownerId = plugintable[i].ownerId;
431*7836SJohn.Forte@Sun.COM         (*ppList)->oids[i].objectSequenceNumber = 0;
432*7836SJohn.Forte@Sun.COM         }
433*7836SJohn.Forte@Sun.COM     }
434*7836SJohn.Forte@Sun.COM 
435*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
436*7836SJohn.Forte@Sun.COM     return MP_STATUS_SUCCESS;
437*7836SJohn.Forte@Sun.COM }
438*7836SJohn.Forte@Sun.COM 
439*7836SJohn.Forte@Sun.COM /**
440*7836SJohn.Forte@Sun.COM  *******************************************************************************
441*7836SJohn.Forte@Sun.COM  *
442*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified vendor plugin.
443*7836SJohn.Forte@Sun.COM  *
444*7836SJohn.Forte@Sun.COM  * @param  oid
445*7836SJohn.Forte@Sun.COM  *         The ID of the plugin whose properties are being retrieved.
446*7836SJohn.Forte@Sun.COM  *
447*7836SJohn.Forte@Sun.COM  * @param  pProps
448*7836SJohn.Forte@Sun.COM  *         A pointer to an @ref MP_PLUGIN_PROPERTIES structure allocated by
449*7836SJohn.Forte@Sun.COM  *         the caller.  On successful return this will contain the properties
450*7836SJohn.Forte@Sun.COM  *         of the plugin specified by pluginOid.
451*7836SJohn.Forte@Sun.COM  *
452*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if an
453*7836SJohn.Forte@Sun.COM  *         error occurred.
454*7836SJohn.Forte@Sun.COM  *
455*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
456*7836SJohn.Forte@Sun.COM  *         Returned if the plugin properties were successfully returned.
457*7836SJohn.Forte@Sun.COM  *
458*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
459*7836SJohn.Forte@Sun.COM  *         Returned if oid does not specify any valid object type.
460*7836SJohn.Forte@Sun.COM  *
461*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
462*7836SJohn.Forte@Sun.COM  *         Returned if oid has an owner that is not currently known to
463*7836SJohn.Forte@Sun.COM  *     the system.
464*7836SJohn.Forte@Sun.COM  *
465*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
466*7836SJohn.Forte@Sun.COM  *         Returned if 'pProps' is NULL or specifies a memory area to
467*7836SJohn.Forte@Sun.COM  *         which data cannot be written.
468*7836SJohn.Forte@Sun.COM  *
469*7836SJohn.Forte@Sun.COM  *******************************************************************************
470*7836SJohn.Forte@Sun.COM  */
MP_GetPluginProperties(MP_OID pluginOid,MP_PLUGIN_PROPERTIES * pProps)471*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetPluginProperties(
472*7836SJohn.Forte@Sun.COM     MP_OID pluginOid,
473*7836SJohn.Forte@Sun.COM     MP_PLUGIN_PROPERTIES *pProps)
474*7836SJohn.Forte@Sun.COM {
475*7836SJohn.Forte@Sun.COM     MP_GetPluginPropertiesPluginFn PassFunc;
476*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
477*7836SJohn.Forte@Sun.COM     MP_STATUS status;
478*7836SJohn.Forte@Sun.COM 
479*7836SJohn.Forte@Sun.COM     if(pProps == NULL)
480*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
481*7836SJohn.Forte@Sun.COM 
482*7836SJohn.Forte@Sun.COM     if ((status = validate_object(pluginOid, MP_OBJECT_TYPE_PLUGIN,
483*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
484*7836SJohn.Forte@Sun.COM         return (status);
485*7836SJohn.Forte@Sun.COM     }
486*7836SJohn.Forte@Sun.COM 
487*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
488*7836SJohn.Forte@Sun.COM 
489*7836SJohn.Forte@Sun.COM     index = pluginOid.ownerId - 1;
490*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
491*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetPluginPropertiesPluginFn)
492*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin, "MP_GetPluginPropertiesPlugin");
493*7836SJohn.Forte@Sun.COM 
494*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
495*7836SJohn.Forte@Sun.COM             status = PassFunc(pProps);
496*7836SJohn.Forte@Sun.COM         } else {
497*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
498*7836SJohn.Forte@Sun.COM         }
499*7836SJohn.Forte@Sun.COM     } else {
500*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
501*7836SJohn.Forte@Sun.COM     }
502*7836SJohn.Forte@Sun.COM 
503*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
504*7836SJohn.Forte@Sun.COM     return status;
505*7836SJohn.Forte@Sun.COM }
506*7836SJohn.Forte@Sun.COM 
507*7836SJohn.Forte@Sun.COM /**
508*7836SJohn.Forte@Sun.COM  *******************************************************************************
509*7836SJohn.Forte@Sun.COM  *
510*7836SJohn.Forte@Sun.COM  * Gets the object ID for the plugin associated with the specified object ID.
511*7836SJohn.Forte@Sun.COM  *
512*7836SJohn.Forte@Sun.COM  * @param  oid
513*7836SJohn.Forte@Sun.COM  *         The object ID of an object that has been received from a previous
514*7836SJohn.Forte@Sun.COM  *         library call.
515*7836SJohn.Forte@Sun.COM  *
516*7836SJohn.Forte@Sun.COM  * @param  pPluginOid
517*7836SJohn.Forte@Sun.COM  *         A pointer to an MP_OID structure allocated by the caller.  On
518*7836SJohn.Forte@Sun.COM  *         successful return this will contain the object ID of the plugin
519*7836SJohn.Forte@Sun.COM  *         associated with the object specified by @a objectId.
520*7836SJohn.Forte@Sun.COM  *
521*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
522*7836SJohn.Forte@Sun.COM  *         an error occurred.
523*7836SJohn.Forte@Sun.COM  *
524*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
525*7836SJohn.Forte@Sun.COM  *          Returned if the associated plugin ID was successfully returned.
526*7836SJohn.Forte@Sun.COM  *
527*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
528*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify a plugin that is currently known to
529*7836SJohn.Forte@Sun.COM  *     the system.
530*7836SJohn.Forte@Sun.COM  *
531*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
532*7836SJohn.Forte@Sun.COM  *          Returned if 'oid' specifies an object not owned by a plugin or
533*7836SJohn.Forte@Sun.COM  *     if pPluginOid is NULL or specifies a memory area to which data
534*7836SJohn.Forte@Sun.COM  *     cannot be written.
535*7836SJohn.Forte@Sun.COM  *
536*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
537*7836SJohn.Forte@Sun.COM  *         Returned if 'oid' specifies an object with an invalid type.
538*7836SJohn.Forte@Sun.COM  *
539*7836SJohn.Forte@Sun.COM  *******************************************************************************
540*7836SJohn.Forte@Sun.COM  */
MP_GetAssociatedPluginOid(MP_OID objectId,MP_OID * pPluginId)541*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetAssociatedPluginOid(
542*7836SJohn.Forte@Sun.COM     MP_OID objectId,
543*7836SJohn.Forte@Sun.COM     MP_OID *pPluginId)
544*7836SJohn.Forte@Sun.COM {
545*7836SJohn.Forte@Sun.COM     MP_UINT32 i;
546*7836SJohn.Forte@Sun.COM     MP_STATUS status;
547*7836SJohn.Forte@Sun.COM 
548*7836SJohn.Forte@Sun.COM     if (pPluginId == NULL)
549*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
550*7836SJohn.Forte@Sun.COM 
551*7836SJohn.Forte@Sun.COM     if ((status = validate_object(objectId, 0, MP_OBJECT_TYPE_ANY)) !=
552*7836SJohn.Forte@Sun.COM             MP_STATUS_SUCCESS) {
553*7836SJohn.Forte@Sun.COM         return (status);
554*7836SJohn.Forte@Sun.COM     }
555*7836SJohn.Forte@Sun.COM 
556*7836SJohn.Forte@Sun.COM     pPluginId->objectType = MP_OBJECT_TYPE_PLUGIN;
557*7836SJohn.Forte@Sun.COM     pPluginId->ownerId = objectId.ownerId;
558*7836SJohn.Forte@Sun.COM     pPluginId->objectSequenceNumber = 0;
559*7836SJohn.Forte@Sun.COM 
560*7836SJohn.Forte@Sun.COM     return (MP_STATUS_SUCCESS);
561*7836SJohn.Forte@Sun.COM }
562*7836SJohn.Forte@Sun.COM 
563*7836SJohn.Forte@Sun.COM /**
564*7836SJohn.Forte@Sun.COM  *******************************************************************************
565*7836SJohn.Forte@Sun.COM  *
566*7836SJohn.Forte@Sun.COM  * Gets the object type of an initialized object ID.
567*7836SJohn.Forte@Sun.COM  *
568*7836SJohn.Forte@Sun.COM  * @param  oid
569*7836SJohn.Forte@Sun.COM  *         The object ID of an object that has been received from a previous
570*7836SJohn.Forte@Sun.COM  *         library call.
571*7836SJohn.Forte@Sun.COM  *
572*7836SJohn.Forte@Sun.COM  * @param  pObjectType
573*7836SJohn.Forte@Sun.COM  *         A pointer to an MP_OBJECT_TYPE variable allocated by the caller.
574*7836SJohn.Forte@Sun.COM  *         On successful return this will contain the object type of oid.
575*7836SJohn.Forte@Sun.COM  *
576*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or
577*7836SJohn.Forte@Sun.COM  *         if an error occurred.
578*7836SJohn.Forte@Sun.COM  *
579*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
580*7836SJohn.Forte@Sun.COM  *      Returned if oid has an owner that is not currently known to
581*7836SJohn.Forte@Sun.COM  *      the system.
582*7836SJohn.Forte@Sun.COM  *
583*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
584*7836SJohn.Forte@Sun.COM  *      Returned if oid does not specify any valid object type.
585*7836SJohn.Forte@Sun.COM  *
586*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
587*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
588*7836SJohn.Forte@Sun.COM  *
589*7836SJohn.Forte@Sun.COM  *******************************************************************************
590*7836SJohn.Forte@Sun.COM  */
MP_GetObjectType(MP_OID oid,MP_OBJECT_TYPE * pObjectType)591*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetObjectType(
592*7836SJohn.Forte@Sun.COM     MP_OID oid,
593*7836SJohn.Forte@Sun.COM     MP_OBJECT_TYPE *pObjectType)
594*7836SJohn.Forte@Sun.COM {
595*7836SJohn.Forte@Sun.COM     MP_STATUS status;
596*7836SJohn.Forte@Sun.COM 
597*7836SJohn.Forte@Sun.COM     if (pObjectType == NULL)
598*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
599*7836SJohn.Forte@Sun.COM 
600*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, 0, MP_OBJECT_TYPE_ANY))
601*7836SJohn.Forte@Sun.COM 	!= MP_STATUS_SUCCESS) {
602*7836SJohn.Forte@Sun.COM         return (status);
603*7836SJohn.Forte@Sun.COM     }
604*7836SJohn.Forte@Sun.COM 
605*7836SJohn.Forte@Sun.COM     *pObjectType = oid.objectType;
606*7836SJohn.Forte@Sun.COM     return MP_STATUS_SUCCESS;
607*7836SJohn.Forte@Sun.COM }
608*7836SJohn.Forte@Sun.COM 
609*7836SJohn.Forte@Sun.COM /**
610*7836SJohn.Forte@Sun.COM  *******************************************************************************
611*7836SJohn.Forte@Sun.COM  *
612*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all the device product properties
613*7836SJohn.Forte@Sun.COM  *       associated with this plugin.
614*7836SJohn.Forte@Sun.COM  *
615*7836SJohn.Forte@Sun.COM  * @param  oid
616*7836SJohn.Forte@Sun.COM  *         The object ID of plugin.
617*7836SJohn.Forte@Sun.COM  *
618*7836SJohn.Forte@Sun.COM  * @param  ppList
619*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
620*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
621*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the device
622*7836SJohn.Forte@Sun.COM  *      product descriptors associated with the specified plugin.
623*7836SJohn.Forte@Sun.COM  *
624*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
625*7836SJohn.Forte@Sun.COM  *         an error occurred.
626*7836SJohn.Forte@Sun.COM  *
627*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
628*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
629*7836SJohn.Forte@Sun.COM  *
630*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
631*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
632*7836SJohn.Forte@Sun.COM  *      the device product list is found to be invalid.
633*7836SJohn.Forte@Sun.COM  *
634*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
635*7836SJohn.Forte@Sun.COM  *         Returned if oid does not specify any valid object type.
636*7836SJohn.Forte@Sun.COM  *
637*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
638*7836SJohn.Forte@Sun.COM  *         Returned when the plugin for the specified oid is not found.
639*7836SJohn.Forte@Sun.COM  *
640*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
641*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
642*7836SJohn.Forte@Sun.COM  *
643*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
644*7836SJohn.Forte@Sun.COM  *      Returned when the API is not supported.
645*7836SJohn.Forte@Sun.COM  *
646*7836SJohn.Forte@Sun.COM  *******************************************************************************
647*7836SJohn.Forte@Sun.COM  */
MP_GetDeviceProductOidList(MP_OID oid,MP_OID_LIST ** ppList)648*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetDeviceProductOidList(
649*7836SJohn.Forte@Sun.COM     MP_OID oid,
650*7836SJohn.Forte@Sun.COM     MP_OID_LIST **ppList)
651*7836SJohn.Forte@Sun.COM {
652*7836SJohn.Forte@Sun.COM     MP_GetDeviceProductOidListPluginFn PassFunc;
653*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
654*7836SJohn.Forte@Sun.COM     MP_STATUS status;
655*7836SJohn.Forte@Sun.COM 
656*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
657*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
658*7836SJohn.Forte@Sun.COM 
659*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
660*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
661*7836SJohn.Forte@Sun.COM         return (status);
662*7836SJohn.Forte@Sun.COM     }
663*7836SJohn.Forte@Sun.COM 
664*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
665*7836SJohn.Forte@Sun.COM 
666*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
667*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
668*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetDeviceProductOidListPluginFn)
669*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
670*7836SJohn.Forte@Sun.COM         "MP_GetDeviceProductOidListPlugin");
671*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
672*7836SJohn.Forte@Sun.COM 	    status = PassFunc(ppList);
673*7836SJohn.Forte@Sun.COM         } else {
674*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
675*7836SJohn.Forte@Sun.COM         }
676*7836SJohn.Forte@Sun.COM     } else {
677*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
678*7836SJohn.Forte@Sun.COM     }
679*7836SJohn.Forte@Sun.COM 
680*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
681*7836SJohn.Forte@Sun.COM     return status;
682*7836SJohn.Forte@Sun.COM }
683*7836SJohn.Forte@Sun.COM 
684*7836SJohn.Forte@Sun.COM /**
685*7836SJohn.Forte@Sun.COM  *******************************************************************************
686*7836SJohn.Forte@Sun.COM  *
687*7836SJohn.Forte@Sun.COM  * Gets the device product properties of the specified plugin oid.
688*7836SJohn.Forte@Sun.COM  *
689*7836SJohn.Forte@Sun.COM  * @param  oid
690*7836SJohn.Forte@Sun.COM  *         The object ID of the plugin.
691*7836SJohn.Forte@Sun.COM  *
692*7836SJohn.Forte@Sun.COM  * @param  ppProps
693*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_DEVICE_PRODUCT_PROPERTIES structure
694*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return it will contain
695*7836SJohn.Forte@Sun.COM  *      a pointer to an MP_DEVICE_PRODUCT_PROPERTIES structure allocated
696*7836SJohn.Forte@Sun.COM  *      by the library.
697*7836SJohn.Forte@Sun.COM  *
698*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
699*7836SJohn.Forte@Sun.COM  *         an error occurred.
700*7836SJohn.Forte@Sun.COM  *
701*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
702*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
703*7836SJohn.Forte@Sun.COM  *
704*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
705*7836SJohn.Forte@Sun.COM  *      Returned if ppProps pointer passed as placeholder for holding
706*7836SJohn.Forte@Sun.COM  *      the device product properties is found to be invalid.
707*7836SJohn.Forte@Sun.COM  *
708*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
709*7836SJohn.Forte@Sun.COM  *         Returned if oid does not specify any valid object type.
710*7836SJohn.Forte@Sun.COM  *
711*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
712*7836SJohn.Forte@Sun.COM  *         Returned when the plugin for the specified oid is not found.
713*7836SJohn.Forte@Sun.COM  *
714*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
715*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
716*7836SJohn.Forte@Sun.COM  *
717*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
718*7836SJohn.Forte@Sun.COM  *      Returned when the API is not supported.
719*7836SJohn.Forte@Sun.COM  *
720*7836SJohn.Forte@Sun.COM  *******************************************************************************
721*7836SJohn.Forte@Sun.COM  */
MP_GetDeviceProductProperties(MP_OID oid,MP_DEVICE_PRODUCT_PROPERTIES * pProps)722*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetDeviceProductProperties(
723*7836SJohn.Forte@Sun.COM         MP_OID oid,
724*7836SJohn.Forte@Sun.COM         MP_DEVICE_PRODUCT_PROPERTIES *pProps)
725*7836SJohn.Forte@Sun.COM {
726*7836SJohn.Forte@Sun.COM     MP_GetDeviceProductPropertiesFn PassFunc;
727*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
728*7836SJohn.Forte@Sun.COM     MP_STATUS status;
729*7836SJohn.Forte@Sun.COM 
730*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
731*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
732*7836SJohn.Forte@Sun.COM 
733*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_DEVICE_PRODUCT,
734*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
735*7836SJohn.Forte@Sun.COM         return (status);
736*7836SJohn.Forte@Sun.COM     }
737*7836SJohn.Forte@Sun.COM 
738*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
739*7836SJohn.Forte@Sun.COM 
740*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
741*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
742*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetDeviceProductPropertiesFn)
743*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
744*7836SJohn.Forte@Sun.COM         "MP_GetDeviceProductProperties");
745*7836SJohn.Forte@Sun.COM 
746*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
747*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
748*7836SJohn.Forte@Sun.COM         } else {
749*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
750*7836SJohn.Forte@Sun.COM         }
751*7836SJohn.Forte@Sun.COM     } else {
752*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
753*7836SJohn.Forte@Sun.COM     }
754*7836SJohn.Forte@Sun.COM 
755*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
756*7836SJohn.Forte@Sun.COM     return status;
757*7836SJohn.Forte@Sun.COM }
758*7836SJohn.Forte@Sun.COM 
759*7836SJohn.Forte@Sun.COM /**
760*7836SJohn.Forte@Sun.COM  *******************************************************************************
761*7836SJohn.Forte@Sun.COM  *
762*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all the initiator ports associated
763*7836SJohn.Forte@Sun.COM  * with this plugin.
764*7836SJohn.Forte@Sun.COM  *
765*7836SJohn.Forte@Sun.COM  * @param  oid
766*7836SJohn.Forte@Sun.COM  *         The object ID of plugin.
767*7836SJohn.Forte@Sun.COM  *
768*7836SJohn.Forte@Sun.COM  * @param  ppList
769*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
770*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
771*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the initiator
772*7836SJohn.Forte@Sun.COM  *      ports associated with the specified plugin.
773*7836SJohn.Forte@Sun.COM  *
774*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
775*7836SJohn.Forte@Sun.COM  *         an error occurred.
776*7836SJohn.Forte@Sun.COM  *
777*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
778*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
779*7836SJohn.Forte@Sun.COM  *
780*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
781*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
782*7836SJohn.Forte@Sun.COM  *      the initiator port list is found to be invalid.
783*7836SJohn.Forte@Sun.COM  *
784*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
785*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
786*7836SJohn.Forte@Sun.COM  *
787*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
788*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
789*7836SJohn.Forte@Sun.COM  *
790*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
791*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
792*7836SJohn.Forte@Sun.COM  *
793*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
794*7836SJohn.Forte@Sun.COM  *      Returned when the API is not supported.
795*7836SJohn.Forte@Sun.COM  *
796*7836SJohn.Forte@Sun.COM  *******************************************************************************
797*7836SJohn.Forte@Sun.COM  */
MP_GetInitiatorPortOidList(MP_OID oid,MP_OID_LIST ** ppList)798*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetInitiatorPortOidList(
799*7836SJohn.Forte@Sun.COM         MP_OID oid,
800*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
801*7836SJohn.Forte@Sun.COM {
802*7836SJohn.Forte@Sun.COM     MP_GetInitiatorPortOidListPluginFn PassFunc;
803*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
804*7836SJohn.Forte@Sun.COM     MP_STATUS status;
805*7836SJohn.Forte@Sun.COM 
806*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
807*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
808*7836SJohn.Forte@Sun.COM 
809*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
810*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
811*7836SJohn.Forte@Sun.COM         return (status);
812*7836SJohn.Forte@Sun.COM     }
813*7836SJohn.Forte@Sun.COM 
814*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
815*7836SJohn.Forte@Sun.COM 
816*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
817*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
818*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetDeviceProductOidListPluginFn)
819*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin, "MP_GetInitiatorPortOidListPlugin");
820*7836SJohn.Forte@Sun.COM 
821*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
822*7836SJohn.Forte@Sun.COM 	    status = PassFunc(ppList);
823*7836SJohn.Forte@Sun.COM         } else {
824*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
825*7836SJohn.Forte@Sun.COM         }
826*7836SJohn.Forte@Sun.COM     } else {
827*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
828*7836SJohn.Forte@Sun.COM     }
829*7836SJohn.Forte@Sun.COM 
830*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
831*7836SJohn.Forte@Sun.COM     return (status);
832*7836SJohn.Forte@Sun.COM }
833*7836SJohn.Forte@Sun.COM 
834*7836SJohn.Forte@Sun.COM /**
835*7836SJohn.Forte@Sun.COM  *******************************************************************************
836*7836SJohn.Forte@Sun.COM  *
837*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified initiator port.
838*7836SJohn.Forte@Sun.COM  *
839*7836SJohn.Forte@Sun.COM  * @param  oid
840*7836SJohn.Forte@Sun.COM  *         The object ID of the initiator port.
841*7836SJohn.Forte@Sun.COM  *
842*7836SJohn.Forte@Sun.COM  * @param  pProps
843*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_INITIATOR_PORT_PROPERTIES structure
844*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
845*7836SJohn.Forte@Sun.COM  *      will contain the properties of the port specified by oid.
846*7836SJohn.Forte@Sun.COM  *
847*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
848*7836SJohn.Forte@Sun.COM  *         an error occurred.
849*7836SJohn.Forte@Sun.COM  *
850*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
851*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
852*7836SJohn.Forte@Sun.COM  *
853*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
854*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
855*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
856*7836SJohn.Forte@Sun.COM  *
857*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
858*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
859*7836SJohn.Forte@Sun.COM  *
860*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
861*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
862*7836SJohn.Forte@Sun.COM  *      the system.
863*7836SJohn.Forte@Sun.COM  *
864*7836SJohn.Forte@Sun.COM  *******************************************************************************
865*7836SJohn.Forte@Sun.COM  */
MP_GetInitiatorPortProperties(MP_OID oid,MP_INITIATOR_PORT_PROPERTIES * pProps)866*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetInitiatorPortProperties(
867*7836SJohn.Forte@Sun.COM         MP_OID oid,
868*7836SJohn.Forte@Sun.COM         MP_INITIATOR_PORT_PROPERTIES *pProps)
869*7836SJohn.Forte@Sun.COM {
870*7836SJohn.Forte@Sun.COM     MP_GetInitiatorPortPropertiesFn PassFunc;
871*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
872*7836SJohn.Forte@Sun.COM     MP_STATUS status;
873*7836SJohn.Forte@Sun.COM 
874*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
875*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
876*7836SJohn.Forte@Sun.COM 
877*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_INITIATOR_PORT,
878*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
879*7836SJohn.Forte@Sun.COM         return (status);
880*7836SJohn.Forte@Sun.COM     }
881*7836SJohn.Forte@Sun.COM 
882*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
883*7836SJohn.Forte@Sun.COM 
884*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
885*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
886*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetInitiatorPortPropertiesFn)
887*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
888*7836SJohn.Forte@Sun.COM         "MP_GetInitiatorPortProperties");
889*7836SJohn.Forte@Sun.COM 
890*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
891*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
892*7836SJohn.Forte@Sun.COM         } else {
893*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
894*7836SJohn.Forte@Sun.COM         }
895*7836SJohn.Forte@Sun.COM     } else {
896*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
897*7836SJohn.Forte@Sun.COM     }
898*7836SJohn.Forte@Sun.COM 
899*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
900*7836SJohn.Forte@Sun.COM     return status;
901*7836SJohn.Forte@Sun.COM }
902*7836SJohn.Forte@Sun.COM 
903*7836SJohn.Forte@Sun.COM /**
904*7836SJohn.Forte@Sun.COM  *******************************************************************************
905*7836SJohn.Forte@Sun.COM  *
906*7836SJohn.Forte@Sun.COM  * Gets a list of multipath logical units associated to a plugin.
907*7836SJohn.Forte@Sun.COM  *
908*7836SJohn.Forte@Sun.COM  * @param  oid
909*7836SJohn.Forte@Sun.COM  *         The object ID of plugin.
910*7836SJohn.Forte@Sun.COM  *
911*7836SJohn.Forte@Sun.COM  * @param  ppList
912*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
913*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
914*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the multipath
915*7836SJohn.Forte@Sun.COM  *      logical units associated with the specified plugin.
916*7836SJohn.Forte@Sun.COM  *
917*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
918*7836SJohn.Forte@Sun.COM  *         an error occurred.
919*7836SJohn.Forte@Sun.COM  *
920*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
921*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
922*7836SJohn.Forte@Sun.COM  *
923*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
924*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
925*7836SJohn.Forte@Sun.COM  *      the multipath logical unit list is found to be invalid.
926*7836SJohn.Forte@Sun.COM  *
927*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
928*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
929*7836SJohn.Forte@Sun.COM  *
930*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
931*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
932*7836SJohn.Forte@Sun.COM  *
933*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
934*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
935*7836SJohn.Forte@Sun.COM  *
936*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
937*7836SJohn.Forte@Sun.COM  *      Returned when the API is not supported.
938*7836SJohn.Forte@Sun.COM  *
939*7836SJohn.Forte@Sun.COM  *******************************************************************************
940*7836SJohn.Forte@Sun.COM  */
MP_GetMultipathLus(MP_OID oid,MP_OID_LIST ** ppList)941*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetMultipathLus(
942*7836SJohn.Forte@Sun.COM         MP_OID oid,
943*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
944*7836SJohn.Forte@Sun.COM {
945*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
946*7836SJohn.Forte@Sun.COM     MP_STATUS status;
947*7836SJohn.Forte@Sun.COM 
948*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
949*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
950*7836SJohn.Forte@Sun.COM 
951*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
952*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
953*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_DEVICE_PRODUCT,
954*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
955*7836SJohn.Forte@Sun.COM         return (status);
956*7836SJohn.Forte@Sun.COM     }
957*7836SJohn.Forte@Sun.COM 
958*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
959*7836SJohn.Forte@Sun.COM 
960*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
961*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
962*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
963*7836SJohn.Forte@Sun.COM 	    MP_GetMultipathLusPluginFn PassFunc;
964*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_GetMultipathLusPluginFn)
965*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
966*7836SJohn.Forte@Sun.COM         	"MP_GetMultipathLusPlugin");
967*7836SJohn.Forte@Sun.COM 
968*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
969*7836SJohn.Forte@Sun.COM 		status = PassFunc(ppList);
970*7836SJohn.Forte@Sun.COM 	    } else {
971*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
972*7836SJohn.Forte@Sun.COM 	    }
973*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_DEVICE_PRODUCT) {
974*7836SJohn.Forte@Sun.COM 	    MP_GetMultipathLusDevProdFn PassFunc;
975*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_GetMultipathLusDevProdFn)
976*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
977*7836SJohn.Forte@Sun.COM         	"MP_GetMultipathLusDevProd");
978*7836SJohn.Forte@Sun.COM 
979*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
980*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid, ppList);
981*7836SJohn.Forte@Sun.COM 	    } else {
982*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
983*7836SJohn.Forte@Sun.COM 	    }
984*7836SJohn.Forte@Sun.COM 	} else {
985*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
986*7836SJohn.Forte@Sun.COM 	}
987*7836SJohn.Forte@Sun.COM     }
988*7836SJohn.Forte@Sun.COM 
989*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
990*7836SJohn.Forte@Sun.COM     return (status);
991*7836SJohn.Forte@Sun.COM }
992*7836SJohn.Forte@Sun.COM 
993*7836SJohn.Forte@Sun.COM 
994*7836SJohn.Forte@Sun.COM /**
995*7836SJohn.Forte@Sun.COM  *******************************************************************************
996*7836SJohn.Forte@Sun.COM  *
997*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified logical unit.
998*7836SJohn.Forte@Sun.COM  *
999*7836SJohn.Forte@Sun.COM  * @param  oid
1000*7836SJohn.Forte@Sun.COM  *         The object ID of the multipath logical unit.
1001*7836SJohn.Forte@Sun.COM  *
1002*7836SJohn.Forte@Sun.COM  * @param  pProps
1003*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES structure
1004*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
1005*7836SJohn.Forte@Sun.COM  *      will contain the properties of the port specified by oid.
1006*7836SJohn.Forte@Sun.COM  *
1007*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1008*7836SJohn.Forte@Sun.COM  *         an error occurred.
1009*7836SJohn.Forte@Sun.COM  *
1010*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1011*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1012*7836SJohn.Forte@Sun.COM  *
1013*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1014*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
1015*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
1016*7836SJohn.Forte@Sun.COM  *
1017*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1018*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1019*7836SJohn.Forte@Sun.COM  *
1020*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1021*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1022*7836SJohn.Forte@Sun.COM  *      the system.
1023*7836SJohn.Forte@Sun.COM  *
1024*7836SJohn.Forte@Sun.COM  *******************************************************************************
1025*7836SJohn.Forte@Sun.COM  */
MP_GetMPLogicalUnitProperties(MP_OID oid,MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES * pProps)1026*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetMPLogicalUnitProperties(
1027*7836SJohn.Forte@Sun.COM         MP_OID oid,
1028*7836SJohn.Forte@Sun.COM         MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES *pProps)
1029*7836SJohn.Forte@Sun.COM {
1030*7836SJohn.Forte@Sun.COM     MP_GetMPLogicalUnitPropertiesFn PassFunc;
1031*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1032*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1033*7836SJohn.Forte@Sun.COM 
1034*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
1035*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1036*7836SJohn.Forte@Sun.COM 
1037*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
1038*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1039*7836SJohn.Forte@Sun.COM         return (status);
1040*7836SJohn.Forte@Sun.COM     }
1041*7836SJohn.Forte@Sun.COM 
1042*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1043*7836SJohn.Forte@Sun.COM 
1044*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1045*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1046*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetMPLogicalUnitPropertiesFn)
1047*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1048*7836SJohn.Forte@Sun.COM         "MP_GetMPLogicalUnitProperties");
1049*7836SJohn.Forte@Sun.COM 
1050*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1051*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
1052*7836SJohn.Forte@Sun.COM         } else {
1053*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1054*7836SJohn.Forte@Sun.COM         }
1055*7836SJohn.Forte@Sun.COM     } else {
1056*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1057*7836SJohn.Forte@Sun.COM     }
1058*7836SJohn.Forte@Sun.COM 
1059*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1060*7836SJohn.Forte@Sun.COM     return (status);
1061*7836SJohn.Forte@Sun.COM }
1062*7836SJohn.Forte@Sun.COM 
1063*7836SJohn.Forte@Sun.COM /**
1064*7836SJohn.Forte@Sun.COM  *******************************************************************************
1065*7836SJohn.Forte@Sun.COM  *
1066*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all the path logical units associated
1067*7836SJohn.Forte@Sun.COM  * with the specified multipath logical unit, initiator port, or target port.
1068*7836SJohn.Forte@Sun.COM  *
1069*7836SJohn.Forte@Sun.COM  * @param  oid
1070*7836SJohn.Forte@Sun.COM  *         The object ID of multipath logical unit, initiator port, or
1071*7836SJohn.Forte@Sun.COM  *     target port.
1072*7836SJohn.Forte@Sun.COM  *
1073*7836SJohn.Forte@Sun.COM  * @param  ppList
1074*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
1075*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
1076*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the mp path
1077*7836SJohn.Forte@Sun.COM  *      logical units associated with the specified OID.
1078*7836SJohn.Forte@Sun.COM  *
1079*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1080*7836SJohn.Forte@Sun.COM  *         an error occurred.
1081*7836SJohn.Forte@Sun.COM  *
1082*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1083*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1084*7836SJohn.Forte@Sun.COM  *
1085*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1086*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
1087*7836SJohn.Forte@Sun.COM  *      the device product list is found to be invalid.
1088*7836SJohn.Forte@Sun.COM  *
1089*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1090*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1091*7836SJohn.Forte@Sun.COM  *
1092*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
1093*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
1094*7836SJohn.Forte@Sun.COM  *
1095*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
1096*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
1097*7836SJohn.Forte@Sun.COM  *
1098*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1099*7836SJohn.Forte@Sun.COM  *      Returned if oid has an owner that is not currently known to
1100*7836SJohn.Forte@Sun.COM  *      the system.
1101*7836SJohn.Forte@Sun.COM  *
1102*7836SJohn.Forte@Sun.COM  *******************************************************************************
1103*7836SJohn.Forte@Sun.COM  */
MP_GetAssociatedPathOidList(MP_OID oid,MP_OID_LIST ** ppList)1104*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetAssociatedPathOidList(
1105*7836SJohn.Forte@Sun.COM         MP_OID oid,
1106*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
1107*7836SJohn.Forte@Sun.COM {
1108*7836SJohn.Forte@Sun.COM     MP_GetAssociatedPathOidListFn PassFunc;
1109*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1110*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1111*7836SJohn.Forte@Sun.COM 
1112*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
1113*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1114*7836SJohn.Forte@Sun.COM 
1115*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_INITIATOR_PORT,
1116*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
1117*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_TARGET_PORT,
1118*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
1119*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
1120*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
1121*7836SJohn.Forte@Sun.COM         return (status);
1122*7836SJohn.Forte@Sun.COM     }
1123*7836SJohn.Forte@Sun.COM 
1124*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1125*7836SJohn.Forte@Sun.COM 
1126*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1127*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1128*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetAssociatedPathOidListFn)
1129*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1130*7836SJohn.Forte@Sun.COM         "MP_GetAssociatedPathOidList");
1131*7836SJohn.Forte@Sun.COM 
1132*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1133*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, ppList);
1134*7836SJohn.Forte@Sun.COM         } else {
1135*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1136*7836SJohn.Forte@Sun.COM         }
1137*7836SJohn.Forte@Sun.COM     } else {
1138*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1139*7836SJohn.Forte@Sun.COM     }
1140*7836SJohn.Forte@Sun.COM 
1141*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1142*7836SJohn.Forte@Sun.COM     return (status);
1143*7836SJohn.Forte@Sun.COM }
1144*7836SJohn.Forte@Sun.COM 
1145*7836SJohn.Forte@Sun.COM /**
1146*7836SJohn.Forte@Sun.COM  *******************************************************************************
1147*7836SJohn.Forte@Sun.COM  *
1148*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified path logical unit.
1149*7836SJohn.Forte@Sun.COM  *
1150*7836SJohn.Forte@Sun.COM  * @param  oid
1151*7836SJohn.Forte@Sun.COM  *         The object ID of the path logical unit.
1152*7836SJohn.Forte@Sun.COM  *
1153*7836SJohn.Forte@Sun.COM  * @param  pProps
1154*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_PATH_LOGICAL_UNIT_PROPERTIES structure
1155*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
1156*7836SJohn.Forte@Sun.COM  *      will contain the properties of the port specified by oid.
1157*7836SJohn.Forte@Sun.COM  *
1158*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1159*7836SJohn.Forte@Sun.COM  *         an error occurred.
1160*7836SJohn.Forte@Sun.COM  *
1161*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1162*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1163*7836SJohn.Forte@Sun.COM  *
1164*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1165*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
1166*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
1167*7836SJohn.Forte@Sun.COM  *
1168*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1169*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1170*7836SJohn.Forte@Sun.COM  *
1171*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1172*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1173*7836SJohn.Forte@Sun.COM  *      the system.
1174*7836SJohn.Forte@Sun.COM  *
1175*7836SJohn.Forte@Sun.COM  *******************************************************************************
1176*7836SJohn.Forte@Sun.COM  */
MP_GetPathLogicalUnitProperties(MP_OID oid,MP_PATH_LOGICAL_UNIT_PROPERTIES * pProps)1177*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetPathLogicalUnitProperties(
1178*7836SJohn.Forte@Sun.COM         MP_OID oid,
1179*7836SJohn.Forte@Sun.COM         MP_PATH_LOGICAL_UNIT_PROPERTIES *pProps)
1180*7836SJohn.Forte@Sun.COM {
1181*7836SJohn.Forte@Sun.COM     MP_GetPathLogicalUnitPropertiesFn PassFunc;
1182*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1183*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1184*7836SJohn.Forte@Sun.COM 
1185*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
1186*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1187*7836SJohn.Forte@Sun.COM 
1188*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PATH_LU,
1189*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1190*7836SJohn.Forte@Sun.COM         return (status);
1191*7836SJohn.Forte@Sun.COM     }
1192*7836SJohn.Forte@Sun.COM 
1193*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1194*7836SJohn.Forte@Sun.COM 
1195*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1196*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1197*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetPathLogicalUnitPropertiesFn)
1198*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1199*7836SJohn.Forte@Sun.COM         "MP_GetPathLogicalUnitProperties");
1200*7836SJohn.Forte@Sun.COM 
1201*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1202*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
1203*7836SJohn.Forte@Sun.COM         } else {
1204*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1205*7836SJohn.Forte@Sun.COM         }
1206*7836SJohn.Forte@Sun.COM     } else {
1207*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1208*7836SJohn.Forte@Sun.COM     }
1209*7836SJohn.Forte@Sun.COM 
1210*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1211*7836SJohn.Forte@Sun.COM     return (status);
1212*7836SJohn.Forte@Sun.COM }
1213*7836SJohn.Forte@Sun.COM 
1214*7836SJohn.Forte@Sun.COM /**
1215*7836SJohn.Forte@Sun.COM  *******************************************************************************
1216*7836SJohn.Forte@Sun.COM  *
1217*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all the target port group associated
1218*7836SJohn.Forte@Sun.COM  * with the specified multipath logical unit.
1219*7836SJohn.Forte@Sun.COM  *
1220*7836SJohn.Forte@Sun.COM  * @param  oid
1221*7836SJohn.Forte@Sun.COM  *         The object ID of the multiple logical unit.
1222*7836SJohn.Forte@Sun.COM  *
1223*7836SJohn.Forte@Sun.COM  * @param  ppList
1224*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
1225*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
1226*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the target
1227*7836SJohn.Forte@Sun.COM  *      port group associated with the specified multipath logical unit.
1228*7836SJohn.Forte@Sun.COM  *
1229*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1230*7836SJohn.Forte@Sun.COM  *         an error occurred.
1231*7836SJohn.Forte@Sun.COM  *
1232*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1233*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1234*7836SJohn.Forte@Sun.COM  *
1235*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1236*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
1237*7836SJohn.Forte@Sun.COM  *      the target port group list is found to be invalid.
1238*7836SJohn.Forte@Sun.COM  *
1239*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1240*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1241*7836SJohn.Forte@Sun.COM  *
1242*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
1243*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
1244*7836SJohn.Forte@Sun.COM  *
1245*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
1246*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
1247*7836SJohn.Forte@Sun.COM  *
1248*7836SJohn.Forte@Sun.COM  *
1249*7836SJohn.Forte@Sun.COM  *******************************************************************************
1250*7836SJohn.Forte@Sun.COM  */
MP_GetAssociatedTPGOidList(MP_OID oid,MP_OID_LIST ** ppList)1251*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetAssociatedTPGOidList(
1252*7836SJohn.Forte@Sun.COM         MP_OID oid,
1253*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
1254*7836SJohn.Forte@Sun.COM {
1255*7836SJohn.Forte@Sun.COM     MP_GetAssociatedTPGOidListFn PassFunc;
1256*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1257*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1258*7836SJohn.Forte@Sun.COM 
1259*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
1260*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1261*7836SJohn.Forte@Sun.COM 
1262*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
1263*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1264*7836SJohn.Forte@Sun.COM         return (status);
1265*7836SJohn.Forte@Sun.COM     }
1266*7836SJohn.Forte@Sun.COM 
1267*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1268*7836SJohn.Forte@Sun.COM 
1269*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1270*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1271*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetAssociatedTPGOidListFn)
1272*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1273*7836SJohn.Forte@Sun.COM         "MP_GetAssociatedTPGOidList");
1274*7836SJohn.Forte@Sun.COM 
1275*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1276*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, ppList);
1277*7836SJohn.Forte@Sun.COM         } else {
1278*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1279*7836SJohn.Forte@Sun.COM         }
1280*7836SJohn.Forte@Sun.COM     } else {
1281*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1282*7836SJohn.Forte@Sun.COM     }
1283*7836SJohn.Forte@Sun.COM 
1284*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1285*7836SJohn.Forte@Sun.COM     return (status);
1286*7836SJohn.Forte@Sun.COM }
1287*7836SJohn.Forte@Sun.COM 
1288*7836SJohn.Forte@Sun.COM /**
1289*7836SJohn.Forte@Sun.COM  *******************************************************************************
1290*7836SJohn.Forte@Sun.COM  *
1291*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified target port group.
1292*7836SJohn.Forte@Sun.COM  *
1293*7836SJohn.Forte@Sun.COM  * @param  oid
1294*7836SJohn.Forte@Sun.COM  *         The object ID of the target port group.
1295*7836SJohn.Forte@Sun.COM  *
1296*7836SJohn.Forte@Sun.COM  * @param  pProps
1297*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_TARGET_PORT_GROUP_PROPERTIES structure
1298*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
1299*7836SJohn.Forte@Sun.COM  *      will contain the properties of the port specified by oid.
1300*7836SJohn.Forte@Sun.COM  *
1301*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1302*7836SJohn.Forte@Sun.COM  *         an error occurred.
1303*7836SJohn.Forte@Sun.COM  *
1304*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1305*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1306*7836SJohn.Forte@Sun.COM  *
1307*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1308*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
1309*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
1310*7836SJohn.Forte@Sun.COM  *
1311*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1312*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1313*7836SJohn.Forte@Sun.COM  *
1314*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1315*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1316*7836SJohn.Forte@Sun.COM  *      the system.
1317*7836SJohn.Forte@Sun.COM  *
1318*7836SJohn.Forte@Sun.COM  *******************************************************************************
1319*7836SJohn.Forte@Sun.COM  */
MP_GetTargetPortGroupProperties(MP_OID oid,MP_TARGET_PORT_GROUP_PROPERTIES * pProps)1320*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetTargetPortGroupProperties(
1321*7836SJohn.Forte@Sun.COM         MP_OID oid,
1322*7836SJohn.Forte@Sun.COM         MP_TARGET_PORT_GROUP_PROPERTIES *pProps)
1323*7836SJohn.Forte@Sun.COM {
1324*7836SJohn.Forte@Sun.COM     MP_GetTargetPortGroupPropertiesFn PassFunc;
1325*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1326*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1327*7836SJohn.Forte@Sun.COM 
1328*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
1329*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1330*7836SJohn.Forte@Sun.COM 
1331*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_TARGET_PORT_GROUP,
1332*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1333*7836SJohn.Forte@Sun.COM         return (status);
1334*7836SJohn.Forte@Sun.COM     }
1335*7836SJohn.Forte@Sun.COM 
1336*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1337*7836SJohn.Forte@Sun.COM 
1338*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1339*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1340*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetTargetPortGroupPropertiesFn)
1341*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1342*7836SJohn.Forte@Sun.COM         "MP_GetTargetPortGroupProperties");
1343*7836SJohn.Forte@Sun.COM 
1344*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1345*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
1346*7836SJohn.Forte@Sun.COM         } else {
1347*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1348*7836SJohn.Forte@Sun.COM         }
1349*7836SJohn.Forte@Sun.COM     } else {
1350*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1351*7836SJohn.Forte@Sun.COM     }
1352*7836SJohn.Forte@Sun.COM 
1353*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1354*7836SJohn.Forte@Sun.COM     return (status);
1355*7836SJohn.Forte@Sun.COM }
1356*7836SJohn.Forte@Sun.COM 
1357*7836SJohn.Forte@Sun.COM /**
1358*7836SJohn.Forte@Sun.COM  *******************************************************************************
1359*7836SJohn.Forte@Sun.COM  *
1360*7836SJohn.Forte@Sun.COM  * Gets a list of multipath logical units associated with the specific target
1361*7836SJohn.Forte@Sun.COM  *  port group.
1362*7836SJohn.Forte@Sun.COM  *
1363*7836SJohn.Forte@Sun.COM  * @param  oid
1364*7836SJohn.Forte@Sun.COM  *         The object ID of the target port group.
1365*7836SJohn.Forte@Sun.COM  *
1366*7836SJohn.Forte@Sun.COM  * @param  ppList
1367*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
1368*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
1369*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the multipath
1370*7836SJohn.Forte@Sun.COM  *      logical units associated with the specified target port group.
1371*7836SJohn.Forte@Sun.COM  *
1372*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1373*7836SJohn.Forte@Sun.COM  *         an error occurred.
1374*7836SJohn.Forte@Sun.COM  *
1375*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1376*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1377*7836SJohn.Forte@Sun.COM  *
1378*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1379*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
1380*7836SJohn.Forte@Sun.COM  *      the multipath logical unit list is found to be invalid.
1381*7836SJohn.Forte@Sun.COM  *
1382*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1383*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1384*7836SJohn.Forte@Sun.COM  *
1385*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
1386*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
1387*7836SJohn.Forte@Sun.COM  *
1388*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
1389*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
1390*7836SJohn.Forte@Sun.COM  *
1391*7836SJohn.Forte@Sun.COM  *******************************************************************************
1392*7836SJohn.Forte@Sun.COM  */
MP_GetMPLuOidListFromTPG(MP_OID oid,MP_OID_LIST ** ppList)1393*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetMPLuOidListFromTPG(
1394*7836SJohn.Forte@Sun.COM         MP_OID oid,
1395*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
1396*7836SJohn.Forte@Sun.COM {
1397*7836SJohn.Forte@Sun.COM     MP_GetMPLuOidListFromTPGFn PassFunc;
1398*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1399*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1400*7836SJohn.Forte@Sun.COM 
1401*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
1402*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1403*7836SJohn.Forte@Sun.COM 
1404*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_TARGET_PORT_GROUP,
1405*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1406*7836SJohn.Forte@Sun.COM         return (status);
1407*7836SJohn.Forte@Sun.COM     }
1408*7836SJohn.Forte@Sun.COM 
1409*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1410*7836SJohn.Forte@Sun.COM 
1411*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1412*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1413*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetMPLuOidListFromTPGFn)
1414*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1415*7836SJohn.Forte@Sun.COM         "MP_GetMPLuOidListFromTPG");
1416*7836SJohn.Forte@Sun.COM 
1417*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1418*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, ppList);
1419*7836SJohn.Forte@Sun.COM         } else {
1420*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1421*7836SJohn.Forte@Sun.COM         }
1422*7836SJohn.Forte@Sun.COM     } else {
1423*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1424*7836SJohn.Forte@Sun.COM     }
1425*7836SJohn.Forte@Sun.COM 
1426*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1427*7836SJohn.Forte@Sun.COM     return (status);
1428*7836SJohn.Forte@Sun.COM }
1429*7836SJohn.Forte@Sun.COM 
1430*7836SJohn.Forte@Sun.COM /**
1431*7836SJohn.Forte@Sun.COM  *******************************************************************************
1432*7836SJohn.Forte@Sun.COM  *
1433*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of all the proprietary load balance
1434*7836SJohn.Forte@Sun.COM  * algorithms associated with this plugin.
1435*7836SJohn.Forte@Sun.COM  *
1436*7836SJohn.Forte@Sun.COM  * @param  oid
1437*7836SJohn.Forte@Sun.COM  *         The object ID of the plugin.
1438*7836SJohn.Forte@Sun.COM  *
1439*7836SJohn.Forte@Sun.COM  * @param  ppList
1440*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
1441*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
1442*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the proprietary
1443*7836SJohn.Forte@Sun.COM  *      load balance algorithms associated with the specified plugin.
1444*7836SJohn.Forte@Sun.COM  *
1445*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1446*7836SJohn.Forte@Sun.COM  *         an error occurred.
1447*7836SJohn.Forte@Sun.COM  *
1448*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1449*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1450*7836SJohn.Forte@Sun.COM  *
1451*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1452*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
1453*7836SJohn.Forte@Sun.COM  *      the proprietary load balance oid list is found to be invalid.
1454*7836SJohn.Forte@Sun.COM  *
1455*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1456*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1457*7836SJohn.Forte@Sun.COM  *
1458*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
1459*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
1460*7836SJohn.Forte@Sun.COM  *
1461*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
1462*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
1463*7836SJohn.Forte@Sun.COM  *
1464*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
1465*7836SJohn.Forte@Sun.COM  *      Returned when the API is not supported.
1466*7836SJohn.Forte@Sun.COM  *
1467*7836SJohn.Forte@Sun.COM  *******************************************************************************
1468*7836SJohn.Forte@Sun.COM  */
MP_GetProprietaryLoadBalanceOidList(MP_OID oid,MP_OID_LIST ** ppList)1469*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetProprietaryLoadBalanceOidList(
1470*7836SJohn.Forte@Sun.COM         MP_OID oid,
1471*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
1472*7836SJohn.Forte@Sun.COM {
1473*7836SJohn.Forte@Sun.COM     MP_GetProprietaryLoadBalanceOidListPluginFn PassFunc;
1474*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1475*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1476*7836SJohn.Forte@Sun.COM 
1477*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
1478*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1479*7836SJohn.Forte@Sun.COM 
1480*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
1481*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1482*7836SJohn.Forte@Sun.COM         return (status);
1483*7836SJohn.Forte@Sun.COM     }
1484*7836SJohn.Forte@Sun.COM 
1485*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1486*7836SJohn.Forte@Sun.COM 
1487*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1488*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1489*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetProprietaryLoadBalanceOidListPluginFn)
1490*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1491*7836SJohn.Forte@Sun.COM         "MP_GetProprietaryLoadBalanceOidListPlugin");
1492*7836SJohn.Forte@Sun.COM 
1493*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1494*7836SJohn.Forte@Sun.COM 	    status = PassFunc(ppList);
1495*7836SJohn.Forte@Sun.COM         } else {
1496*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1497*7836SJohn.Forte@Sun.COM         }
1498*7836SJohn.Forte@Sun.COM     } else {
1499*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1500*7836SJohn.Forte@Sun.COM     }
1501*7836SJohn.Forte@Sun.COM 
1502*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1503*7836SJohn.Forte@Sun.COM     return (status);
1504*7836SJohn.Forte@Sun.COM }
1505*7836SJohn.Forte@Sun.COM 
1506*7836SJohn.Forte@Sun.COM /**
1507*7836SJohn.Forte@Sun.COM  *******************************************************************************
1508*7836SJohn.Forte@Sun.COM  *
1509*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified load balance properties structure.
1510*7836SJohn.Forte@Sun.COM  *
1511*7836SJohn.Forte@Sun.COM  * @param  oid
1512*7836SJohn.Forte@Sun.COM  *         The object ID of the load balance properties structure.
1513*7836SJohn.Forte@Sun.COM  *
1514*7836SJohn.Forte@Sun.COM  * @param  pProps
1515*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_LOAD_BALANCE_PROPRIETARY_TYPE structure
1516*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
1517*7836SJohn.Forte@Sun.COM  *      will contain the properties of the proprietary load balance algorithm
1518*7836SJohn.Forte@Sun.COM  *	specified by oid.
1519*7836SJohn.Forte@Sun.COM  *
1520*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1521*7836SJohn.Forte@Sun.COM  *         an error occurred.
1522*7836SJohn.Forte@Sun.COM  *
1523*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1524*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1525*7836SJohn.Forte@Sun.COM  *
1526*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1527*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
1528*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
1529*7836SJohn.Forte@Sun.COM  *
1530*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1531*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1532*7836SJohn.Forte@Sun.COM  *
1533*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1534*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1535*7836SJohn.Forte@Sun.COM  *      the system.
1536*7836SJohn.Forte@Sun.COM  *
1537*7836SJohn.Forte@Sun.COM  *******************************************************************************
1538*7836SJohn.Forte@Sun.COM  */
MP_GetProprietaryLoadBalanceProperties(MP_OID oid,MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES * pProps)1539*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetProprietaryLoadBalanceProperties (
1540*7836SJohn.Forte@Sun.COM         MP_OID oid,
1541*7836SJohn.Forte@Sun.COM         MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES *pProps)
1542*7836SJohn.Forte@Sun.COM {
1543*7836SJohn.Forte@Sun.COM     MP_GetProprietaryLoadBalancePropertiesFn PassFunc;
1544*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1545*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1546*7836SJohn.Forte@Sun.COM 
1547*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
1548*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1549*7836SJohn.Forte@Sun.COM 
1550*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE,
1551*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1552*7836SJohn.Forte@Sun.COM         return (status);
1553*7836SJohn.Forte@Sun.COM     }
1554*7836SJohn.Forte@Sun.COM 
1555*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1556*7836SJohn.Forte@Sun.COM 
1557*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1558*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1559*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetProprietaryLoadBalancePropertiesFn)
1560*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1561*7836SJohn.Forte@Sun.COM         "MP_GetProprietaryLoadBalanceProperties");
1562*7836SJohn.Forte@Sun.COM 
1563*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1564*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
1565*7836SJohn.Forte@Sun.COM         } else {
1566*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1567*7836SJohn.Forte@Sun.COM         }
1568*7836SJohn.Forte@Sun.COM     } else {
1569*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1570*7836SJohn.Forte@Sun.COM     }
1571*7836SJohn.Forte@Sun.COM 
1572*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1573*7836SJohn.Forte@Sun.COM     return (status);
1574*7836SJohn.Forte@Sun.COM }
1575*7836SJohn.Forte@Sun.COM 
1576*7836SJohn.Forte@Sun.COM /**
1577*7836SJohn.Forte@Sun.COM  *******************************************************************************
1578*7836SJohn.Forte@Sun.COM  *
1579*7836SJohn.Forte@Sun.COM  * Gets a list of the object IDs of the target ports in the specified target
1580*7836SJohn.Forte@Sun.COM  * port group.
1581*7836SJohn.Forte@Sun.COM  *
1582*7836SJohn.Forte@Sun.COM  * @param  oid
1583*7836SJohn.Forte@Sun.COM  *         The object ID of the target port group.
1584*7836SJohn.Forte@Sun.COM  *
1585*7836SJohn.Forte@Sun.COM  * @param  ppList
1586*7836SJohn.Forte@Sun.COM  *      A pointer to a pointer to an MP_OID_LIST structure.
1587*7836SJohn.Forte@Sun.COM  *      On a successful return, this will contain a pointer to
1588*7836SJohn.Forte@Sun.COM  *      an MP_OID_LIST that contains the object IDs of all the target ports
1589*7836SJohn.Forte@Sun.COM  *      associated with the specified target port group.
1590*7836SJohn.Forte@Sun.COM  *
1591*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1592*7836SJohn.Forte@Sun.COM  *         an error occurred.
1593*7836SJohn.Forte@Sun.COM  *
1594*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1595*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1596*7836SJohn.Forte@Sun.COM  *
1597*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1598*7836SJohn.Forte@Sun.COM  *      Returned if ppList pointer passed as placeholder for holding
1599*7836SJohn.Forte@Sun.COM  *      the multipath logical unit list is found to be invalid.
1600*7836SJohn.Forte@Sun.COM  *
1601*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1602*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1603*7836SJohn.Forte@Sun.COM  *
1604*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
1605*7836SJohn.Forte@Sun.COM  *          Returned when the plugin for the specified oid is not found.
1606*7836SJohn.Forte@Sun.COM  *
1607*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INSUFFICIENT_MEMORY
1608*7836SJohn.Forte@Sun.COM  *      Returned when memory allocation failure occurs
1609*7836SJohn.Forte@Sun.COM  *
1610*7836SJohn.Forte@Sun.COM  *******************************************************************************
1611*7836SJohn.Forte@Sun.COM  */
MP_GetTargetPortOidList(MP_OID oid,MP_OID_LIST ** ppList)1612*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetTargetPortOidList(
1613*7836SJohn.Forte@Sun.COM         MP_OID oid,
1614*7836SJohn.Forte@Sun.COM         MP_OID_LIST **ppList)
1615*7836SJohn.Forte@Sun.COM {
1616*7836SJohn.Forte@Sun.COM     MP_GetTargetPortOidListFn PassFunc;
1617*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1618*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1619*7836SJohn.Forte@Sun.COM 
1620*7836SJohn.Forte@Sun.COM     if (ppList == NULL)
1621*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1622*7836SJohn.Forte@Sun.COM 
1623*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_TARGET_PORT_GROUP,
1624*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1625*7836SJohn.Forte@Sun.COM         return (status);
1626*7836SJohn.Forte@Sun.COM     }
1627*7836SJohn.Forte@Sun.COM 
1628*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1629*7836SJohn.Forte@Sun.COM 
1630*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1631*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1632*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetTargetPortOidListFn)
1633*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1634*7836SJohn.Forte@Sun.COM         "MP_GetTargetPortOidList");
1635*7836SJohn.Forte@Sun.COM 
1636*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1637*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, ppList);
1638*7836SJohn.Forte@Sun.COM         } else {
1639*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1640*7836SJohn.Forte@Sun.COM         }
1641*7836SJohn.Forte@Sun.COM     } else {
1642*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1643*7836SJohn.Forte@Sun.COM     }
1644*7836SJohn.Forte@Sun.COM 
1645*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1646*7836SJohn.Forte@Sun.COM     return (status);
1647*7836SJohn.Forte@Sun.COM }
1648*7836SJohn.Forte@Sun.COM 
1649*7836SJohn.Forte@Sun.COM /**
1650*7836SJohn.Forte@Sun.COM  *******************************************************************************
1651*7836SJohn.Forte@Sun.COM  *
1652*7836SJohn.Forte@Sun.COM  * Gets the properties of the specified target port.
1653*7836SJohn.Forte@Sun.COM  *
1654*7836SJohn.Forte@Sun.COM  * @param  oid
1655*7836SJohn.Forte@Sun.COM  *         The object ID of the target port.
1656*7836SJohn.Forte@Sun.COM  *
1657*7836SJohn.Forte@Sun.COM  * @param  pProps
1658*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_TARGET_PORT_PROPERTIES structure
1659*7836SJohn.Forte@Sun.COM  *      allocated by the caller. On successful return, this structure
1660*7836SJohn.Forte@Sun.COM  *      will contain the properties of the port specified by oid.
1661*7836SJohn.Forte@Sun.COM  *
1662*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1663*7836SJohn.Forte@Sun.COM  *         an error occurred.
1664*7836SJohn.Forte@Sun.COM  *
1665*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1666*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1667*7836SJohn.Forte@Sun.COM  *
1668*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1669*7836SJohn.Forte@Sun.COM  *      Returned if pProps is NULL or specifies a memory area to
1670*7836SJohn.Forte@Sun.COM  *      which data cannot be written.
1671*7836SJohn.Forte@Sun.COM  *
1672*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1673*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1674*7836SJohn.Forte@Sun.COM  *
1675*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1676*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1677*7836SJohn.Forte@Sun.COM  *      the system.
1678*7836SJohn.Forte@Sun.COM  *
1679*7836SJohn.Forte@Sun.COM  *******************************************************************************
1680*7836SJohn.Forte@Sun.COM  */
MP_GetTargetPortProperties(MP_OID oid,MP_TARGET_PORT_PROPERTIES * pProps)1681*7836SJohn.Forte@Sun.COM MP_STATUS MP_GetTargetPortProperties(
1682*7836SJohn.Forte@Sun.COM         MP_OID oid,
1683*7836SJohn.Forte@Sun.COM         MP_TARGET_PORT_PROPERTIES *pProps)
1684*7836SJohn.Forte@Sun.COM {
1685*7836SJohn.Forte@Sun.COM     MP_GetTargetPortPropertiesFn PassFunc;
1686*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1687*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1688*7836SJohn.Forte@Sun.COM 
1689*7836SJohn.Forte@Sun.COM     if (pProps == NULL)
1690*7836SJohn.Forte@Sun.COM         return MP_STATUS_INVALID_PARAMETER;
1691*7836SJohn.Forte@Sun.COM 
1692*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_TARGET_PORT,
1693*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1694*7836SJohn.Forte@Sun.COM         return (status);
1695*7836SJohn.Forte@Sun.COM     }
1696*7836SJohn.Forte@Sun.COM 
1697*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1698*7836SJohn.Forte@Sun.COM 
1699*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1700*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1701*7836SJohn.Forte@Sun.COM         PassFunc = (MP_GetTargetPortPropertiesFn)
1702*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1703*7836SJohn.Forte@Sun.COM         "MP_GetTargetPortProperties");
1704*7836SJohn.Forte@Sun.COM 
1705*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1706*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, pProps);
1707*7836SJohn.Forte@Sun.COM         } else {
1708*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1709*7836SJohn.Forte@Sun.COM         }
1710*7836SJohn.Forte@Sun.COM     } else {
1711*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1712*7836SJohn.Forte@Sun.COM     }
1713*7836SJohn.Forte@Sun.COM 
1714*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1715*7836SJohn.Forte@Sun.COM     return (status);
1716*7836SJohn.Forte@Sun.COM }
1717*7836SJohn.Forte@Sun.COM 
1718*7836SJohn.Forte@Sun.COM 
1719*7836SJohn.Forte@Sun.COM /**
1720*7836SJohn.Forte@Sun.COM  *******************************************************************************
1721*7836SJohn.Forte@Sun.COM  *
1722*7836SJohn.Forte@Sun.COM  * Assign a multipath logical unit to a target port group.
1723*7836SJohn.Forte@Sun.COM  *
1724*7836SJohn.Forte@Sun.COM  * @param  tpgOid
1725*7836SJohn.Forte@Sun.COM  *      An MP_TARGET_PORT_GROUP oid. The target port group currently in
1726*7836SJohn.Forte@Sun.COM  *      active access state that the administrator would like the LU
1727*7836SJohn.Forte@Sun.COM  *      assigned to.
1728*7836SJohn.Forte@Sun.COM  *
1729*7836SJohn.Forte@Sun.COM  * @param  luOid
1730*7836SJohn.Forte@Sun.COM  *      An MP_MULTIPATH_LOGICAL_UNIT oid.
1731*7836SJohn.Forte@Sun.COM  *
1732*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1733*7836SJohn.Forte@Sun.COM  *         an error occurred.
1734*7836SJohn.Forte@Sun.COM  *
1735*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1736*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1737*7836SJohn.Forte@Sun.COM  *
1738*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1739*7836SJohn.Forte@Sun.COM  *      Returned when luOid is not associated with tpgOid.
1740*7836SJohn.Forte@Sun.COM  *
1741*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1742*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1743*7836SJohn.Forte@Sun.COM  *
1744*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1745*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1746*7836SJohn.Forte@Sun.COM  *      the system.
1747*7836SJohn.Forte@Sun.COM  *
1748*7836SJohn.Forte@Sun.COM  *******************************************************************************
1749*7836SJohn.Forte@Sun.COM  */
MP_AssignLogicalUnitToTPG(MP_OID tpgOid,MP_OID luOid)1750*7836SJohn.Forte@Sun.COM MP_STATUS MP_AssignLogicalUnitToTPG(
1751*7836SJohn.Forte@Sun.COM         MP_OID tpgOid,
1752*7836SJohn.Forte@Sun.COM         MP_OID luOid)
1753*7836SJohn.Forte@Sun.COM {
1754*7836SJohn.Forte@Sun.COM     MP_AssignLogicalUnitToTPGFn PassFunc;
1755*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1756*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1757*7836SJohn.Forte@Sun.COM 
1758*7836SJohn.Forte@Sun.COM     if (luOid.ownerId != tpgOid.ownerId) {
1759*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
1760*7836SJohn.Forte@Sun.COM     }
1761*7836SJohn.Forte@Sun.COM 
1762*7836SJohn.Forte@Sun.COM     if ((status = validate_object(tpgOid, MP_OBJECT_TYPE_TARGET_PORT_GROUP,
1763*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1764*7836SJohn.Forte@Sun.COM         return (status);
1765*7836SJohn.Forte@Sun.COM     }
1766*7836SJohn.Forte@Sun.COM 
1767*7836SJohn.Forte@Sun.COM     if ((status = validate_object(luOid, MP_OBJECT_TYPE_MULTIPATH_LU,
1768*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1769*7836SJohn.Forte@Sun.COM         return (status);
1770*7836SJohn.Forte@Sun.COM     }
1771*7836SJohn.Forte@Sun.COM 
1772*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1773*7836SJohn.Forte@Sun.COM 
1774*7836SJohn.Forte@Sun.COM     index = tpgOid.ownerId - 1;
1775*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1776*7836SJohn.Forte@Sun.COM         PassFunc = (MP_AssignLogicalUnitToTPGFn)
1777*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1778*7836SJohn.Forte@Sun.COM         "MP_AssignLogicalUnitToTPG");
1779*7836SJohn.Forte@Sun.COM 
1780*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1781*7836SJohn.Forte@Sun.COM             status = PassFunc(tpgOid, luOid);
1782*7836SJohn.Forte@Sun.COM         } else {
1783*7836SJohn.Forte@Sun.COM             status = MP_STATUS_UNSUPPORTED;
1784*7836SJohn.Forte@Sun.COM         }
1785*7836SJohn.Forte@Sun.COM     } else {
1786*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1787*7836SJohn.Forte@Sun.COM     }
1788*7836SJohn.Forte@Sun.COM 
1789*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1790*7836SJohn.Forte@Sun.COM     return (status);
1791*7836SJohn.Forte@Sun.COM }
1792*7836SJohn.Forte@Sun.COM 
1793*7836SJohn.Forte@Sun.COM /**
1794*7836SJohn.Forte@Sun.COM  *******************************************************************************
1795*7836SJohn.Forte@Sun.COM  *
1796*7836SJohn.Forte@Sun.COM  * Manually override the path for a logical unit. The path exclusively used to
1797*7836SJohn.Forte@Sun.COM  * access the logical unit until cleared.
1798*7836SJohn.Forte@Sun.COM  *
1799*7836SJohn.Forte@Sun.COM  * @param  logicalUnitOid
1800*7836SJohn.Forte@Sun.COM  *      The object ID of the multipath logical unit.
1801*7836SJohn.Forte@Sun.COM  *
1802*7836SJohn.Forte@Sun.COM  * @param  pathOid
1803*7836SJohn.Forte@Sun.COM  *      The object ID of the path logical unit.
1804*7836SJohn.Forte@Sun.COM  *
1805*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1806*7836SJohn.Forte@Sun.COM  *         an error occurred.
1807*7836SJohn.Forte@Sun.COM  *
1808*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1809*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1810*7836SJohn.Forte@Sun.COM  *
1811*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1812*7836SJohn.Forte@Sun.COM  *      Returned if the oid of the object is not valid
1813*7836SJohn.Forte@Sun.COM  *
1814*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
1815*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
1816*7836SJohn.Forte@Sun.COM  *
1817*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1818*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1819*7836SJohn.Forte@Sun.COM  *
1820*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_PATH_NONOPERATIONAL
1821*7836SJohn.Forte@Sun.COM  *          Returned when the driver cannot communicate through selected path.
1822*7836SJohn.Forte@Sun.COM  *
1823*7836SJohn.Forte@Sun.COM  *******************************************************************************
1824*7836SJohn.Forte@Sun.COM  */
MP_SetOverridePath(MP_OID logicalUnitOid,MP_OID pathOid)1825*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetOverridePath(
1826*7836SJohn.Forte@Sun.COM     MP_OID logicalUnitOid,
1827*7836SJohn.Forte@Sun.COM     MP_OID pathOid)
1828*7836SJohn.Forte@Sun.COM {
1829*7836SJohn.Forte@Sun.COM     MP_SetOverridePathFn PassFunc;
1830*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1831*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1832*7836SJohn.Forte@Sun.COM 
1833*7836SJohn.Forte@Sun.COM     if ((status = validate_object(logicalUnitOid, MP_OBJECT_TYPE_MULTIPATH_LU,
1834*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1835*7836SJohn.Forte@Sun.COM         return (status);
1836*7836SJohn.Forte@Sun.COM     }
1837*7836SJohn.Forte@Sun.COM     if ((status = validate_object(pathOid, MP_OBJECT_TYPE_PATH_LU,
1838*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1839*7836SJohn.Forte@Sun.COM         return (status);
1840*7836SJohn.Forte@Sun.COM     }
1841*7836SJohn.Forte@Sun.COM 
1842*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1843*7836SJohn.Forte@Sun.COM 
1844*7836SJohn.Forte@Sun.COM     index = pathOid.ownerId - 1;
1845*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1846*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetOverridePathFn)
1847*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1848*7836SJohn.Forte@Sun.COM         "MP_SetOverridePath");
1849*7836SJohn.Forte@Sun.COM 
1850*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1851*7836SJohn.Forte@Sun.COM 	    status = PassFunc(logicalUnitOid, pathOid);
1852*7836SJohn.Forte@Sun.COM         } else {
1853*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1854*7836SJohn.Forte@Sun.COM         }
1855*7836SJohn.Forte@Sun.COM     } else {
1856*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1857*7836SJohn.Forte@Sun.COM     }
1858*7836SJohn.Forte@Sun.COM 
1859*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1860*7836SJohn.Forte@Sun.COM     return (status);
1861*7836SJohn.Forte@Sun.COM }
1862*7836SJohn.Forte@Sun.COM 
1863*7836SJohn.Forte@Sun.COM /**
1864*7836SJohn.Forte@Sun.COM  *******************************************************************************
1865*7836SJohn.Forte@Sun.COM  *
1866*7836SJohn.Forte@Sun.COM  * Cancel a path override and re-enable load balancing.
1867*7836SJohn.Forte@Sun.COM  *
1868*7836SJohn.Forte@Sun.COM  * @param  luOid
1869*7836SJohn.Forte@Sun.COM  *         An MP_MULTIPATH_LOGICAL_UNIT oid.
1870*7836SJohn.Forte@Sun.COM  *
1871*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1872*7836SJohn.Forte@Sun.COM  *         an error occurred.
1873*7836SJohn.Forte@Sun.COM  *
1874*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1875*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1876*7836SJohn.Forte@Sun.COM  *
1877*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1878*7836SJohn.Forte@Sun.COM  *      Returned if MP_MULTIPATH_LOGICAL_UNIT with the luOid is not found.
1879*7836SJohn.Forte@Sun.COM  *
1880*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1881*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1882*7836SJohn.Forte@Sun.COM  *
1883*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
1884*7836SJohn.Forte@Sun.COM  *          Returned if oid has an owner that is not currently known to
1885*7836SJohn.Forte@Sun.COM  *      the system.
1886*7836SJohn.Forte@Sun.COM  *
1887*7836SJohn.Forte@Sun.COM  *******************************************************************************
1888*7836SJohn.Forte@Sun.COM  */
MP_CancelOverridePath(MP_OID luOid)1889*7836SJohn.Forte@Sun.COM MP_STATUS MP_CancelOverridePath(
1890*7836SJohn.Forte@Sun.COM         MP_OID luOid)
1891*7836SJohn.Forte@Sun.COM {
1892*7836SJohn.Forte@Sun.COM     MP_CancelOverridePathFn PassFunc;
1893*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1894*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1895*7836SJohn.Forte@Sun.COM 
1896*7836SJohn.Forte@Sun.COM     if ((status = validate_object(luOid, MP_OBJECT_TYPE_MULTIPATH_LU,
1897*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
1898*7836SJohn.Forte@Sun.COM         return (status);
1899*7836SJohn.Forte@Sun.COM     }
1900*7836SJohn.Forte@Sun.COM 
1901*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1902*7836SJohn.Forte@Sun.COM 
1903*7836SJohn.Forte@Sun.COM     index = luOid.ownerId - 1;
1904*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1905*7836SJohn.Forte@Sun.COM         PassFunc = (MP_CancelOverridePathFn)
1906*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
1907*7836SJohn.Forte@Sun.COM         "MP_CancelOverridePath");
1908*7836SJohn.Forte@Sun.COM 
1909*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
1910*7836SJohn.Forte@Sun.COM 	    status = PassFunc(luOid);
1911*7836SJohn.Forte@Sun.COM         } else {
1912*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
1913*7836SJohn.Forte@Sun.COM         }
1914*7836SJohn.Forte@Sun.COM     } else {
1915*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
1916*7836SJohn.Forte@Sun.COM     }
1917*7836SJohn.Forte@Sun.COM 
1918*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1919*7836SJohn.Forte@Sun.COM     return (status);
1920*7836SJohn.Forte@Sun.COM }
1921*7836SJohn.Forte@Sun.COM 
1922*7836SJohn.Forte@Sun.COM /**
1923*7836SJohn.Forte@Sun.COM  *******************************************************************************
1924*7836SJohn.Forte@Sun.COM  *
1925*7836SJohn.Forte@Sun.COM  * Enables Auto-failback.
1926*7836SJohn.Forte@Sun.COM  *
1927*7836SJohn.Forte@Sun.COM  * @param  oid
1928*7836SJohn.Forte@Sun.COM  *      The oid of the plugin.
1929*7836SJohn.Forte@Sun.COM  *
1930*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
1931*7836SJohn.Forte@Sun.COM  *         an error occurred.
1932*7836SJohn.Forte@Sun.COM  *
1933*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
1934*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
1935*7836SJohn.Forte@Sun.COM  *
1936*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
1937*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
1938*7836SJohn.Forte@Sun.COM  *	a valid plugin oid.
1939*7836SJohn.Forte@Sun.COM  *
1940*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
1941*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
1942*7836SJohn.Forte@Sun.COM  *
1943*7836SJohn.Forte@Sun.COM  *******************************************************************************
1944*7836SJohn.Forte@Sun.COM  */
MP_EnableAutoFailback(MP_OID oid)1945*7836SJohn.Forte@Sun.COM MP_STATUS MP_EnableAutoFailback(
1946*7836SJohn.Forte@Sun.COM     MP_OID oid)
1947*7836SJohn.Forte@Sun.COM {
1948*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
1949*7836SJohn.Forte@Sun.COM     MP_STATUS status;
1950*7836SJohn.Forte@Sun.COM 
1951*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
1952*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
1953*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
1954*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
1955*7836SJohn.Forte@Sun.COM         return (status);
1956*7836SJohn.Forte@Sun.COM     }
1957*7836SJohn.Forte@Sun.COM 
1958*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
1959*7836SJohn.Forte@Sun.COM 
1960*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
1961*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
1962*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
1963*7836SJohn.Forte@Sun.COM 	    MP_EnableAutoFailbackPluginFn PassFunc;
1964*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_EnableAutoFailbackPluginFn)
1965*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
1966*7836SJohn.Forte@Sun.COM         	"MP_EnableAutoFailbackPlugin");
1967*7836SJohn.Forte@Sun.COM 
1968*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
1969*7836SJohn.Forte@Sun.COM 		status = PassFunc();
1970*7836SJohn.Forte@Sun.COM 	    } else {
1971*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
1972*7836SJohn.Forte@Sun.COM 	    }
1973*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
1974*7836SJohn.Forte@Sun.COM 	    MP_EnableAutoFailbackLuFn PassFunc;
1975*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_EnableAutoFailbackLuFn)
1976*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
1977*7836SJohn.Forte@Sun.COM         	"MP_EnableAutoFailbackLu");
1978*7836SJohn.Forte@Sun.COM 
1979*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
1980*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid);
1981*7836SJohn.Forte@Sun.COM 	    } else {
1982*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
1983*7836SJohn.Forte@Sun.COM 	    }
1984*7836SJohn.Forte@Sun.COM 	} else {
1985*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
1986*7836SJohn.Forte@Sun.COM 	}
1987*7836SJohn.Forte@Sun.COM     }
1988*7836SJohn.Forte@Sun.COM 
1989*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
1990*7836SJohn.Forte@Sun.COM     return (status);
1991*7836SJohn.Forte@Sun.COM }
1992*7836SJohn.Forte@Sun.COM 
1993*7836SJohn.Forte@Sun.COM /**
1994*7836SJohn.Forte@Sun.COM  *******************************************************************************
1995*7836SJohn.Forte@Sun.COM  *
1996*7836SJohn.Forte@Sun.COM  * Enables Auto-probing.
1997*7836SJohn.Forte@Sun.COM  *
1998*7836SJohn.Forte@Sun.COM  * @param  oid
1999*7836SJohn.Forte@Sun.COM  *      The oid of the plugin or the multipath logical unit.
2000*7836SJohn.Forte@Sun.COM  *
2001*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2002*7836SJohn.Forte@Sun.COM  *         an error occurred.
2003*7836SJohn.Forte@Sun.COM  *
2004*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2005*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2006*7836SJohn.Forte@Sun.COM  *
2007*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2008*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
2009*7836SJohn.Forte@Sun.COM  *      a valid plugin oid.
2010*7836SJohn.Forte@Sun.COM  *
2011*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2012*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2013*7836SJohn.Forte@Sun.COM  *
2014*7836SJohn.Forte@Sun.COM  *******************************************************************************
2015*7836SJohn.Forte@Sun.COM  */
MP_EnableAutoProbing(MP_OID oid)2016*7836SJohn.Forte@Sun.COM MP_STATUS MP_EnableAutoProbing(
2017*7836SJohn.Forte@Sun.COM     MP_OID oid)
2018*7836SJohn.Forte@Sun.COM {
2019*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2020*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2021*7836SJohn.Forte@Sun.COM 
2022*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2023*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2024*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2025*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2026*7836SJohn.Forte@Sun.COM         return (status);
2027*7836SJohn.Forte@Sun.COM     }
2028*7836SJohn.Forte@Sun.COM 
2029*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2030*7836SJohn.Forte@Sun.COM 
2031*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2032*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2033*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
2034*7836SJohn.Forte@Sun.COM 	    MP_EnableAutoProbingPluginFn PassFunc;
2035*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_EnableAutoProbingPluginFn)
2036*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2037*7836SJohn.Forte@Sun.COM         	"MP_EnableAutoProbingPlugin");
2038*7836SJohn.Forte@Sun.COM 
2039*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2040*7836SJohn.Forte@Sun.COM 		status = PassFunc();
2041*7836SJohn.Forte@Sun.COM 	    } else {
2042*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2043*7836SJohn.Forte@Sun.COM 	    }
2044*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
2045*7836SJohn.Forte@Sun.COM 	    MP_EnableAutoProbingLuFn PassFunc;
2046*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_EnableAutoProbingLuFn)
2047*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2048*7836SJohn.Forte@Sun.COM         	"MP_EnableAutoProbingLu");
2049*7836SJohn.Forte@Sun.COM 
2050*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2051*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid);
2052*7836SJohn.Forte@Sun.COM 	    } else {
2053*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2054*7836SJohn.Forte@Sun.COM 	    }
2055*7836SJohn.Forte@Sun.COM 	} else {
2056*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
2057*7836SJohn.Forte@Sun.COM 	}
2058*7836SJohn.Forte@Sun.COM     }
2059*7836SJohn.Forte@Sun.COM 
2060*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2061*7836SJohn.Forte@Sun.COM     return (status);
2062*7836SJohn.Forte@Sun.COM }
2063*7836SJohn.Forte@Sun.COM 
2064*7836SJohn.Forte@Sun.COM /**
2065*7836SJohn.Forte@Sun.COM  *******************************************************************************
2066*7836SJohn.Forte@Sun.COM  *
2067*7836SJohn.Forte@Sun.COM  * Disables Auto-failback.
2068*7836SJohn.Forte@Sun.COM  *
2069*7836SJohn.Forte@Sun.COM  * @param  oid
2070*7836SJohn.Forte@Sun.COM  *      The oid of the plugin.
2071*7836SJohn.Forte@Sun.COM  *
2072*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2073*7836SJohn.Forte@Sun.COM  *         an error occurred.
2074*7836SJohn.Forte@Sun.COM  *
2075*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2076*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2077*7836SJohn.Forte@Sun.COM  *
2078*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2079*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
2080*7836SJohn.Forte@Sun.COM  *      a valid plugin oid.
2081*7836SJohn.Forte@Sun.COM  *
2082*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2083*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2084*7836SJohn.Forte@Sun.COM  *
2085*7836SJohn.Forte@Sun.COM  *******************************************************************************
2086*7836SJohn.Forte@Sun.COM  */
MP_DisableAutoFailback(MP_OID oid)2087*7836SJohn.Forte@Sun.COM MP_STATUS MP_DisableAutoFailback(
2088*7836SJohn.Forte@Sun.COM     MP_OID oid)
2089*7836SJohn.Forte@Sun.COM {
2090*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2091*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2092*7836SJohn.Forte@Sun.COM 
2093*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2094*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2095*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2096*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2097*7836SJohn.Forte@Sun.COM         return (status);
2098*7836SJohn.Forte@Sun.COM     }
2099*7836SJohn.Forte@Sun.COM 
2100*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2101*7836SJohn.Forte@Sun.COM 
2102*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2103*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2104*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
2105*7836SJohn.Forte@Sun.COM 	    MP_DisableAutoFailbackPluginFn PassFunc;
2106*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_DisableAutoFailbackPluginFn)
2107*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2108*7836SJohn.Forte@Sun.COM         	"MP_DisableAutoFailbackPlugin");
2109*7836SJohn.Forte@Sun.COM 
2110*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2111*7836SJohn.Forte@Sun.COM 		status = PassFunc();
2112*7836SJohn.Forte@Sun.COM 	    } else {
2113*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2114*7836SJohn.Forte@Sun.COM 	    }
2115*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
2116*7836SJohn.Forte@Sun.COM 	    MP_DisableAutoFailbackLuFn PassFunc;
2117*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_DisableAutoFailbackLuFn)
2118*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2119*7836SJohn.Forte@Sun.COM         	"MP_DisableAutoFailbackLu");
2120*7836SJohn.Forte@Sun.COM 
2121*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2122*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid);
2123*7836SJohn.Forte@Sun.COM 	    } else {
2124*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2125*7836SJohn.Forte@Sun.COM 	    }
2126*7836SJohn.Forte@Sun.COM 	} else {
2127*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
2128*7836SJohn.Forte@Sun.COM 	}
2129*7836SJohn.Forte@Sun.COM     }
2130*7836SJohn.Forte@Sun.COM 
2131*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2132*7836SJohn.Forte@Sun.COM     return (status);
2133*7836SJohn.Forte@Sun.COM }
2134*7836SJohn.Forte@Sun.COM 
2135*7836SJohn.Forte@Sun.COM /**
2136*7836SJohn.Forte@Sun.COM  *******************************************************************************
2137*7836SJohn.Forte@Sun.COM  *
2138*7836SJohn.Forte@Sun.COM  * Disables Auto-probing.
2139*7836SJohn.Forte@Sun.COM  *
2140*7836SJohn.Forte@Sun.COM  * @param  oid
2141*7836SJohn.Forte@Sun.COM  *      The oid of the plugin or the multipath logical unit.
2142*7836SJohn.Forte@Sun.COM  *
2143*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2144*7836SJohn.Forte@Sun.COM  *         an error occurred.
2145*7836SJohn.Forte@Sun.COM  *
2146*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2147*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2148*7836SJohn.Forte@Sun.COM  *
2149*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2150*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
2151*7836SJohn.Forte@Sun.COM  *      a valid plugin oid.
2152*7836SJohn.Forte@Sun.COM  *
2153*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2154*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2155*7836SJohn.Forte@Sun.COM  *
2156*7836SJohn.Forte@Sun.COM  *******************************************************************************
2157*7836SJohn.Forte@Sun.COM  */
MP_DisableAutoProbing(MP_OID oid)2158*7836SJohn.Forte@Sun.COM MP_STATUS MP_DisableAutoProbing(
2159*7836SJohn.Forte@Sun.COM     MP_OID oid)
2160*7836SJohn.Forte@Sun.COM {
2161*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2162*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2163*7836SJohn.Forte@Sun.COM 
2164*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2165*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2166*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2167*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2168*7836SJohn.Forte@Sun.COM         return (status);
2169*7836SJohn.Forte@Sun.COM     }
2170*7836SJohn.Forte@Sun.COM 
2171*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2172*7836SJohn.Forte@Sun.COM 
2173*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2174*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2175*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
2176*7836SJohn.Forte@Sun.COM 	    MP_DisableAutoProbingPluginFn PassFunc;
2177*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_DisableAutoProbingPluginFn)
2178*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2179*7836SJohn.Forte@Sun.COM         	"MP_DisableAutoProbingPlugin");
2180*7836SJohn.Forte@Sun.COM 
2181*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2182*7836SJohn.Forte@Sun.COM 		status = PassFunc();
2183*7836SJohn.Forte@Sun.COM 	    } else {
2184*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2185*7836SJohn.Forte@Sun.COM 	    }
2186*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
2187*7836SJohn.Forte@Sun.COM 	    MP_DisableAutoFailbackLuFn PassFunc;
2188*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_DisableAutoProbingLuFn)
2189*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2190*7836SJohn.Forte@Sun.COM         	"MP_DisableAutoProbingLu");
2191*7836SJohn.Forte@Sun.COM 
2192*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2193*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid);
2194*7836SJohn.Forte@Sun.COM 	    } else {
2195*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2196*7836SJohn.Forte@Sun.COM 	    }
2197*7836SJohn.Forte@Sun.COM 	} else {
2198*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
2199*7836SJohn.Forte@Sun.COM 	}
2200*7836SJohn.Forte@Sun.COM     }
2201*7836SJohn.Forte@Sun.COM 
2202*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2203*7836SJohn.Forte@Sun.COM     return (status);
2204*7836SJohn.Forte@Sun.COM }
2205*7836SJohn.Forte@Sun.COM 
2206*7836SJohn.Forte@Sun.COM /**
2207*7836SJohn.Forte@Sun.COM  *******************************************************************************
2208*7836SJohn.Forte@Sun.COM  *
2209*7836SJohn.Forte@Sun.COM  * Enables a path. This API may cause failover in a logical unit with
2210*7836SJohn.Forte@Sun.COM  * asymmetric access.
2211*7836SJohn.Forte@Sun.COM  *
2212*7836SJohn.Forte@Sun.COM  * @param  oid
2213*7836SJohn.Forte@Sun.COM  *      The oid of the path.
2214*7836SJohn.Forte@Sun.COM  *
2215*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2216*7836SJohn.Forte@Sun.COM  *         an error occurred.
2217*7836SJohn.Forte@Sun.COM  *
2218*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2219*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2220*7836SJohn.Forte@Sun.COM  *
2221*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2222*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
2223*7836SJohn.Forte@Sun.COM  *      a valid path oid.
2224*7836SJohn.Forte@Sun.COM  *
2225*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2226*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2227*7836SJohn.Forte@Sun.COM  *
2228*7836SJohn.Forte@Sun.COM  *******************************************************************************
2229*7836SJohn.Forte@Sun.COM  */
MP_EnablePath(MP_OID oid)2230*7836SJohn.Forte@Sun.COM MP_STATUS MP_EnablePath(
2231*7836SJohn.Forte@Sun.COM     MP_OID oid)
2232*7836SJohn.Forte@Sun.COM {
2233*7836SJohn.Forte@Sun.COM     MP_EnablePathFn PassFunc;
2234*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2235*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2236*7836SJohn.Forte@Sun.COM 
2237*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PATH_LU,
2238*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2239*7836SJohn.Forte@Sun.COM         return (status);
2240*7836SJohn.Forte@Sun.COM     }
2241*7836SJohn.Forte@Sun.COM 
2242*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2243*7836SJohn.Forte@Sun.COM 
2244*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2245*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2246*7836SJohn.Forte@Sun.COM         PassFunc = (MP_EnablePathFn)
2247*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2248*7836SJohn.Forte@Sun.COM         "MP_EnablePath");
2249*7836SJohn.Forte@Sun.COM 
2250*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2251*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid);
2252*7836SJohn.Forte@Sun.COM         } else {
2253*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2254*7836SJohn.Forte@Sun.COM         }
2255*7836SJohn.Forte@Sun.COM     } else {
2256*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2257*7836SJohn.Forte@Sun.COM     }
2258*7836SJohn.Forte@Sun.COM 
2259*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2260*7836SJohn.Forte@Sun.COM     return (status);
2261*7836SJohn.Forte@Sun.COM }
2262*7836SJohn.Forte@Sun.COM 
2263*7836SJohn.Forte@Sun.COM /**
2264*7836SJohn.Forte@Sun.COM  *******************************************************************************
2265*7836SJohn.Forte@Sun.COM  *
2266*7836SJohn.Forte@Sun.COM  * Disables a path. This API may cause failover in a logical unit with
2267*7836SJohn.Forte@Sun.COM  * asymmetric access. This API may cause a logical unit to become unavailable.
2268*7836SJohn.Forte@Sun.COM  *
2269*7836SJohn.Forte@Sun.COM  * @param  oid
2270*7836SJohn.Forte@Sun.COM  *      The oid of the path.
2271*7836SJohn.Forte@Sun.COM  *
2272*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2273*7836SJohn.Forte@Sun.COM  *         an error occurred.
2274*7836SJohn.Forte@Sun.COM  *
2275*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2276*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2277*7836SJohn.Forte@Sun.COM  *
2278*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2279*7836SJohn.Forte@Sun.COM  *      Returned if oid is NULL or specifies a memory area that is not
2280*7836SJohn.Forte@Sun.COM  *      a valid path oid.
2281*7836SJohn.Forte@Sun.COM  *
2282*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2283*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2284*7836SJohn.Forte@Sun.COM  *
2285*7836SJohn.Forte@Sun.COM  *******************************************************************************
2286*7836SJohn.Forte@Sun.COM  */
MP_DisablePath(MP_OID oid)2287*7836SJohn.Forte@Sun.COM MP_STATUS MP_DisablePath(
2288*7836SJohn.Forte@Sun.COM     MP_OID oid)
2289*7836SJohn.Forte@Sun.COM {
2290*7836SJohn.Forte@Sun.COM     MP_DisablePathFn PassFunc;
2291*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2292*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2293*7836SJohn.Forte@Sun.COM 
2294*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PATH_LU,
2295*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2296*7836SJohn.Forte@Sun.COM         return (status);
2297*7836SJohn.Forte@Sun.COM     }
2298*7836SJohn.Forte@Sun.COM 
2299*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2300*7836SJohn.Forte@Sun.COM 
2301*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2302*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2303*7836SJohn.Forte@Sun.COM         PassFunc = (MP_DisablePathFn)
2304*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2305*7836SJohn.Forte@Sun.COM         "MP_DisablePath");
2306*7836SJohn.Forte@Sun.COM 
2307*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2308*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid);
2309*7836SJohn.Forte@Sun.COM         } else {
2310*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2311*7836SJohn.Forte@Sun.COM         }
2312*7836SJohn.Forte@Sun.COM     } else {
2313*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2314*7836SJohn.Forte@Sun.COM     }
2315*7836SJohn.Forte@Sun.COM 
2316*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2317*7836SJohn.Forte@Sun.COM     return (status);
2318*7836SJohn.Forte@Sun.COM }
2319*7836SJohn.Forte@Sun.COM 
2320*7836SJohn.Forte@Sun.COM /**
2321*7836SJohn.Forte@Sun.COM  *******************************************************************************
2322*7836SJohn.Forte@Sun.COM  *
2323*7836SJohn.Forte@Sun.COM  * Set the multipath logical unit s load balancing policy.
2324*7836SJohn.Forte@Sun.COM  *
2325*7836SJohn.Forte@Sun.COM  * @param  logicalUnitoid
2326*7836SJohn.Forte@Sun.COM  *      The object ID of the multipath logical unit.
2327*7836SJohn.Forte@Sun.COM  *
2328*7836SJohn.Forte@Sun.COM  * @param  loadBanlance
2329*7836SJohn.Forte@Sun.COM  *      The desired load balance policy for the specified logical unit.
2330*7836SJohn.Forte@Sun.COM  *
2331*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2332*7836SJohn.Forte@Sun.COM  *         an error occurred.
2333*7836SJohn.Forte@Sun.COM  *
2334*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2335*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2336*7836SJohn.Forte@Sun.COM  *
2337*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2338*7836SJohn.Forte@Sun.COM  *      Returned if no MP_MULTIPATH_LOGICAL_UNIT associated with
2339*7836SJohn.Forte@Sun.COM  *      @ref ligicalUnitrOid is found or invalid MP_LOAD_BALANCE_TYPE is
2340*7836SJohn.Forte@Sun.COM  *      specified.
2341*7836SJohn.Forte@Sun.COM  *
2342*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
2343*7836SJohn.Forte@Sun.COM  *      Returned when the specified loadBalance type cannot be handled
2344*7836SJohn.Forte@Sun.COM  *      by the plugin.
2345*7836SJohn.Forte@Sun.COM  *
2346*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2347*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2348*7836SJohn.Forte@Sun.COM  *
2349*7836SJohn.Forte@Sun.COM  *******************************************************************************
2350*7836SJohn.Forte@Sun.COM  */
MP_SetLogicalUnitLoadBalanceType(MP_OID logicalUnitOid,MP_LOAD_BALANCE_TYPE loadBalance)2351*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetLogicalUnitLoadBalanceType(
2352*7836SJohn.Forte@Sun.COM     MP_OID logicalUnitOid,
2353*7836SJohn.Forte@Sun.COM     MP_LOAD_BALANCE_TYPE loadBalance)
2354*7836SJohn.Forte@Sun.COM {
2355*7836SJohn.Forte@Sun.COM     MP_SetLogicalUnitLoadBalanceTypeFn PassFunc;
2356*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2357*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2358*7836SJohn.Forte@Sun.COM 
2359*7836SJohn.Forte@Sun.COM     if ((status = validate_object(logicalUnitOid,
2360*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MULTIPATH_LU,
2361*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2362*7836SJohn.Forte@Sun.COM         return (status);
2363*7836SJohn.Forte@Sun.COM     }
2364*7836SJohn.Forte@Sun.COM 
2365*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2366*7836SJohn.Forte@Sun.COM 
2367*7836SJohn.Forte@Sun.COM     index = logicalUnitOid.ownerId - 1;
2368*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2369*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetLogicalUnitLoadBalanceTypeFn)
2370*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2371*7836SJohn.Forte@Sun.COM         "MP_SetLogicalUnitLoadBalanceType");
2372*7836SJohn.Forte@Sun.COM 
2373*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2374*7836SJohn.Forte@Sun.COM 	    status = PassFunc(logicalUnitOid, loadBalance);
2375*7836SJohn.Forte@Sun.COM         } else {
2376*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2377*7836SJohn.Forte@Sun.COM         }
2378*7836SJohn.Forte@Sun.COM     } else {
2379*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2380*7836SJohn.Forte@Sun.COM     }
2381*7836SJohn.Forte@Sun.COM 
2382*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2383*7836SJohn.Forte@Sun.COM     return (status);
2384*7836SJohn.Forte@Sun.COM }
2385*7836SJohn.Forte@Sun.COM 
2386*7836SJohn.Forte@Sun.COM /**
2387*7836SJohn.Forte@Sun.COM  *******************************************************************************
2388*7836SJohn.Forte@Sun.COM  *
2389*7836SJohn.Forte@Sun.COM  * Set the weight to be assigned to a particular path.
2390*7836SJohn.Forte@Sun.COM  *
2391*7836SJohn.Forte@Sun.COM  * @param  pathOid
2392*7836SJohn.Forte@Sun.COM  *      The object ID of the path logical unit.
2393*7836SJohn.Forte@Sun.COM  *
2394*7836SJohn.Forte@Sun.COM  * @param  weight
2395*7836SJohn.Forte@Sun.COM  *      weight that will be assigned to the path logical unit.
2396*7836SJohn.Forte@Sun.COM  *
2397*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2398*7836SJohn.Forte@Sun.COM  *         an error occurred.
2399*7836SJohn.Forte@Sun.COM  *
2400*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2401*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2402*7836SJohn.Forte@Sun.COM  *
2403*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2404*7836SJohn.Forte@Sun.COM  *      Returned when the MP Path specified by the PathOid could not be
2405*7836SJohn.Forte@Sun.COM  *      found.
2406*7836SJohn.Forte@Sun.COM  *
2407*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2408*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2409*7836SJohn.Forte@Sun.COM  *
2410*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2411*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2412*7836SJohn.Forte@Sun.COM  *
2413*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
2414*7836SJohn.Forte@Sun.COM  *          Returned when the operation failed.
2415*7836SJohn.Forte@Sun.COM  *
2416*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_PATH_NONOPERATIONAL
2417*7836SJohn.Forte@Sun.COM  *          Returned when the driver cannot communicate through selected path.
2418*7836SJohn.Forte@Sun.COM  *
2419*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_WEIGHT
2420*7836SJohn.Forte@Sun.COM  *          Returned when the weight parameter is greater than the plugin's
2421*7836SJohn.Forte@Sun.COM  *      maxWeight property.
2422*7836SJohn.Forte@Sun.COM  *
2423*7836SJohn.Forte@Sun.COM  *******************************************************************************
2424*7836SJohn.Forte@Sun.COM  */
MP_SetPathWeight(MP_OID pathOid,MP_UINT32 weight)2425*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetPathWeight(
2426*7836SJohn.Forte@Sun.COM     MP_OID pathOid,
2427*7836SJohn.Forte@Sun.COM     MP_UINT32 weight)
2428*7836SJohn.Forte@Sun.COM {
2429*7836SJohn.Forte@Sun.COM     MP_SetPathWeightFn PassFunc;
2430*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2431*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2432*7836SJohn.Forte@Sun.COM 
2433*7836SJohn.Forte@Sun.COM     if ((status = validate_object(pathOid, MP_OBJECT_TYPE_PATH_LU,
2434*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2435*7836SJohn.Forte@Sun.COM         return (status);
2436*7836SJohn.Forte@Sun.COM     }
2437*7836SJohn.Forte@Sun.COM 
2438*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2439*7836SJohn.Forte@Sun.COM 
2440*7836SJohn.Forte@Sun.COM     index = pathOid.ownerId - 1;
2441*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2442*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetPathWeightFn)
2443*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2444*7836SJohn.Forte@Sun.COM         "MP_SetPathWeight");
2445*7836SJohn.Forte@Sun.COM 
2446*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2447*7836SJohn.Forte@Sun.COM 	    status = PassFunc(pathOid, weight);
2448*7836SJohn.Forte@Sun.COM         } else {
2449*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2450*7836SJohn.Forte@Sun.COM         }
2451*7836SJohn.Forte@Sun.COM     } else {
2452*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2453*7836SJohn.Forte@Sun.COM     }
2454*7836SJohn.Forte@Sun.COM 
2455*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2456*7836SJohn.Forte@Sun.COM     return (status);
2457*7836SJohn.Forte@Sun.COM }
2458*7836SJohn.Forte@Sun.COM 
2459*7836SJohn.Forte@Sun.COM /**
2460*7836SJohn.Forte@Sun.COM  *******************************************************************************
2461*7836SJohn.Forte@Sun.COM  *
2462*7836SJohn.Forte@Sun.COM  * Set the default load balance policy for the plugin.
2463*7836SJohn.Forte@Sun.COM  *
2464*7836SJohn.Forte@Sun.COM  * @param  oid
2465*7836SJohn.Forte@Sun.COM  *      The object ID of the plugin
2466*7836SJohn.Forte@Sun.COM  *
2467*7836SJohn.Forte@Sun.COM  * @param  loadBalance
2468*7836SJohn.Forte@Sun.COM  *      The desired default load balance policy for the specified plugin.
2469*7836SJohn.Forte@Sun.COM  *
2470*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2471*7836SJohn.Forte@Sun.COM  *         an error occurred.
2472*7836SJohn.Forte@Sun.COM  *
2473*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2474*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2475*7836SJohn.Forte@Sun.COM  *
2476*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2477*7836SJohn.Forte@Sun.COM  *      Returned when the the plugin specified by @ref oid could not be
2478*7836SJohn.Forte@Sun.COM  *      found.
2479*7836SJohn.Forte@Sun.COM  *
2480*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2481*7836SJohn.Forte@Sun.COM  *      Returned if the oid of the object is not valid.
2482*7836SJohn.Forte@Sun.COM  *
2483*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2484*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2485*7836SJohn.Forte@Sun.COM  *
2486*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2487*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2488*7836SJohn.Forte@Sun.COM  *
2489*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
2490*7836SJohn.Forte@Sun.COM  *          Returned when the specified loadBalance type cannot be handled
2491*7836SJohn.Forte@Sun.COM  *      by the plugin.
2492*7836SJohn.Forte@Sun.COM  *
2493*7836SJohn.Forte@Sun.COM  *******************************************************************************
2494*7836SJohn.Forte@Sun.COM  */
MP_SetPluginLoadBalanceType(MP_OID oid,MP_LOAD_BALANCE_TYPE loadBalance)2495*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetPluginLoadBalanceType(
2496*7836SJohn.Forte@Sun.COM     MP_OID oid,
2497*7836SJohn.Forte@Sun.COM     MP_LOAD_BALANCE_TYPE loadBalance)
2498*7836SJohn.Forte@Sun.COM {
2499*7836SJohn.Forte@Sun.COM     MP_SetPluginLoadBalanceTypePluginFn PassFunc;
2500*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2501*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2502*7836SJohn.Forte@Sun.COM 
2503*7836SJohn.Forte@Sun.COM     if ((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2504*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2505*7836SJohn.Forte@Sun.COM         return (status);
2506*7836SJohn.Forte@Sun.COM     }
2507*7836SJohn.Forte@Sun.COM 
2508*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2509*7836SJohn.Forte@Sun.COM 
2510*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2511*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2512*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetPluginLoadBalanceTypePluginFn)
2513*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2514*7836SJohn.Forte@Sun.COM         "MP_SetPluginLoadBalanceTypePlugin");
2515*7836SJohn.Forte@Sun.COM 
2516*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2517*7836SJohn.Forte@Sun.COM 	    status = PassFunc(loadBalance);
2518*7836SJohn.Forte@Sun.COM         } else {
2519*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2520*7836SJohn.Forte@Sun.COM         }
2521*7836SJohn.Forte@Sun.COM     } else {
2522*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2523*7836SJohn.Forte@Sun.COM     }
2524*7836SJohn.Forte@Sun.COM 
2525*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2526*7836SJohn.Forte@Sun.COM     return (status);
2527*7836SJohn.Forte@Sun.COM }
2528*7836SJohn.Forte@Sun.COM 
2529*7836SJohn.Forte@Sun.COM /**
2530*7836SJohn.Forte@Sun.COM  *******************************************************************************
2531*7836SJohn.Forte@Sun.COM  *
2532*7836SJohn.Forte@Sun.COM  * Set the failback polling rates. Setting both rates to zero disables polling.
2533*7836SJohn.Forte@Sun.COM  *
2534*7836SJohn.Forte@Sun.COM  * @param  pluginOid
2535*7836SJohn.Forte@Sun.COM  *      The object ID of the plugin or multipath lu.
2536*7836SJohn.Forte@Sun.COM  *
2537*7836SJohn.Forte@Sun.COM  * @param  pollingRate
2538*7836SJohn.Forte@Sun.COM  *      The value to be set in MP_PLUGIN_PROPERTIES currentPollingRate.or
2539*7836SJohn.Forte@Sun.COM  *	MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES pollingRate.
2540*7836SJohn.Forte@Sun.COM  *
2541*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2542*7836SJohn.Forte@Sun.COM  *         an error occurred.
2543*7836SJohn.Forte@Sun.COM  *
2544*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2545*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2546*7836SJohn.Forte@Sun.COM  *
2547*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2548*7836SJohn.Forte@Sun.COM  *      Returned when the the plugin specified by @ref oid could not be
2549*7836SJohn.Forte@Sun.COM  *      found.
2550*7836SJohn.Forte@Sun.COM  *
2551*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2552*7836SJohn.Forte@Sun.COM  *      Returned if one of the polling values is outside the range
2553*7836SJohn.Forte@Sun.COM  *      supported by the driver.
2554*7836SJohn.Forte@Sun.COM  *
2555*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2556*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2557*7836SJohn.Forte@Sun.COM  *
2558*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2559*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2560*7836SJohn.Forte@Sun.COM  *
2561*7836SJohn.Forte@Sun.COM  *******************************************************************************
2562*7836SJohn.Forte@Sun.COM  */
MP_SetFailbackPollingRate(MP_OID oid,MP_UINT32 pollingRate)2563*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetFailbackPollingRate(
2564*7836SJohn.Forte@Sun.COM     MP_OID oid,
2565*7836SJohn.Forte@Sun.COM     MP_UINT32 pollingRate)
2566*7836SJohn.Forte@Sun.COM {
2567*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2568*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2569*7836SJohn.Forte@Sun.COM 
2570*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2571*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2572*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2573*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2574*7836SJohn.Forte@Sun.COM         return (status);
2575*7836SJohn.Forte@Sun.COM     }
2576*7836SJohn.Forte@Sun.COM 
2577*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2578*7836SJohn.Forte@Sun.COM 
2579*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2580*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2581*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
2582*7836SJohn.Forte@Sun.COM 	    MP_SetFailbackPollingRatePluginFn PassFunc;
2583*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_SetFailbackPollingRatePluginFn)
2584*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2585*7836SJohn.Forte@Sun.COM         	"MP_SetFailbackPollingRatePlugin");
2586*7836SJohn.Forte@Sun.COM 
2587*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2588*7836SJohn.Forte@Sun.COM 		status = PassFunc(pollingRate);
2589*7836SJohn.Forte@Sun.COM 	    } else {
2590*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2591*7836SJohn.Forte@Sun.COM 	    }
2592*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
2593*7836SJohn.Forte@Sun.COM 	    MP_SetFailbackPollingRateLuFn PassFunc;
2594*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_SetFailbackPollingRateLuFn)
2595*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2596*7836SJohn.Forte@Sun.COM         	"MP_SetFailbackPollingRateLu");
2597*7836SJohn.Forte@Sun.COM 
2598*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2599*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid, pollingRate);
2600*7836SJohn.Forte@Sun.COM 	    } else {
2601*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2602*7836SJohn.Forte@Sun.COM 	    }
2603*7836SJohn.Forte@Sun.COM 	} else {
2604*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
2605*7836SJohn.Forte@Sun.COM 	}
2606*7836SJohn.Forte@Sun.COM     }
2607*7836SJohn.Forte@Sun.COM 
2608*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2609*7836SJohn.Forte@Sun.COM     return (status);
2610*7836SJohn.Forte@Sun.COM }
2611*7836SJohn.Forte@Sun.COM 
2612*7836SJohn.Forte@Sun.COM /**
2613*7836SJohn.Forte@Sun.COM  *******************************************************************************
2614*7836SJohn.Forte@Sun.COM  *
2615*7836SJohn.Forte@Sun.COM  * Set the probing polling rates. Setting both rates to zero disables polling.
2616*7836SJohn.Forte@Sun.COM  *
2617*7836SJohn.Forte@Sun.COM  * @param  pluginOid
2618*7836SJohn.Forte@Sun.COM  *      The object ID of either the plugin or a multipath logical unit.
2619*7836SJohn.Forte@Sun.COM  *
2620*7836SJohn.Forte@Sun.COM  * @param  pollingRate
2621*7836SJohn.Forte@Sun.COM  *      The value to be set in MP_PLUGIN_PROPERTIES current pollingRate or
2622*7836SJohn.Forte@Sun.COM  *	MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES pollingRate.
2623*7836SJohn.Forte@Sun.COM  *
2624*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2625*7836SJohn.Forte@Sun.COM  *         an error occurred.
2626*7836SJohn.Forte@Sun.COM  *
2627*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2628*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2629*7836SJohn.Forte@Sun.COM  *
2630*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2631*7836SJohn.Forte@Sun.COM  *      Returned when the the plugin specified by @ref oid could not be
2632*7836SJohn.Forte@Sun.COM  *      found.
2633*7836SJohn.Forte@Sun.COM  *
2634*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2635*7836SJohn.Forte@Sun.COM  *      Returned if one of the polling values is outside the range
2636*7836SJohn.Forte@Sun.COM  *      supported by the driver.
2637*7836SJohn.Forte@Sun.COM  *
2638*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2639*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2640*7836SJohn.Forte@Sun.COM  *
2641*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2642*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2643*7836SJohn.Forte@Sun.COM  *
2644*7836SJohn.Forte@Sun.COM  *******************************************************************************
2645*7836SJohn.Forte@Sun.COM  */
MP_SetProbingPollingRate(MP_OID oid,MP_UINT32 pollingRate)2646*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetProbingPollingRate(
2647*7836SJohn.Forte@Sun.COM     MP_OID    oid,
2648*7836SJohn.Forte@Sun.COM     MP_UINT32 pollingRate)
2649*7836SJohn.Forte@Sun.COM {
2650*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2651*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2652*7836SJohn.Forte@Sun.COM 
2653*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2654*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2655*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2656*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2657*7836SJohn.Forte@Sun.COM         return (status);
2658*7836SJohn.Forte@Sun.COM     }
2659*7836SJohn.Forte@Sun.COM 
2660*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2661*7836SJohn.Forte@Sun.COM 
2662*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2663*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2664*7836SJohn.Forte@Sun.COM 	if (oid.objectType == MP_OBJECT_TYPE_PLUGIN) {
2665*7836SJohn.Forte@Sun.COM 	    MP_SetProbingPollingRatePluginFn PassFunc;
2666*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_SetProbingPollingRatePluginFn)
2667*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2668*7836SJohn.Forte@Sun.COM         	"MP_SetProbingPollingRatePlugin");
2669*7836SJohn.Forte@Sun.COM 
2670*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2671*7836SJohn.Forte@Sun.COM 		status = PassFunc(pollingRate);
2672*7836SJohn.Forte@Sun.COM 	    } else {
2673*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2674*7836SJohn.Forte@Sun.COM 	    }
2675*7836SJohn.Forte@Sun.COM 	} else if (oid.objectType == MP_OBJECT_TYPE_MULTIPATH_LU) {
2676*7836SJohn.Forte@Sun.COM 	    MP_SetProbingPollingRateLuFn PassFunc;
2677*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_SetProbingPollingRateLuFn)
2678*7836SJohn.Forte@Sun.COM 	    dlsym(plugintable[index].hdlPlugin,
2679*7836SJohn.Forte@Sun.COM         	"MP_SetProbingPollingRateLu");
2680*7836SJohn.Forte@Sun.COM 
2681*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2682*7836SJohn.Forte@Sun.COM 		status = PassFunc(oid, pollingRate);
2683*7836SJohn.Forte@Sun.COM 	    } else {
2684*7836SJohn.Forte@Sun.COM 		status = MP_STATUS_UNSUPPORTED;
2685*7836SJohn.Forte@Sun.COM 	    }
2686*7836SJohn.Forte@Sun.COM 	} else {
2687*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_INVALID_PARAMETER;
2688*7836SJohn.Forte@Sun.COM 	}
2689*7836SJohn.Forte@Sun.COM     }
2690*7836SJohn.Forte@Sun.COM 
2691*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2692*7836SJohn.Forte@Sun.COM     return (status);
2693*7836SJohn.Forte@Sun.COM }
2694*7836SJohn.Forte@Sun.COM 
2695*7836SJohn.Forte@Sun.COM /**
2696*7836SJohn.Forte@Sun.COM  *******************************************************************************
2697*7836SJohn.Forte@Sun.COM  *
2698*7836SJohn.Forte@Sun.COM  * Set proprietary properties in supported object instances.
2699*7836SJohn.Forte@Sun.COM  *
2700*7836SJohn.Forte@Sun.COM  * @param  pluginOid
2701*7836SJohn.Forte@Sun.COM  *      The object ID of MP_LOAD_BALANCE_PROPRIETARY_TYPE, MP_PLUGIN_PROPERTIES
2702*7836SJohn.Forte@Sun.COM  *	or MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES.
2703*7836SJohn.Forte@Sun.COM  *
2704*7836SJohn.Forte@Sun.COM  * @param  count
2705*7836SJohn.Forte@Sun.COM  *	   The number of valid items in pPropertyList.
2706*7836SJohn.Forte@Sun.COM  *
2707*7836SJohn.Forte@Sun.COM  * @param  pPropertyList
2708*7836SJohn.Forte@Sun.COM  *	   A pointer to an array of property name/value pairs. This array must
2709*7836SJohn.Forte@Sun.COM  *	   contain the same number of elements as count.
2710*7836SJohn.Forte@Sun.COM  *
2711*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2712*7836SJohn.Forte@Sun.COM  *         an error occurred.
2713*7836SJohn.Forte@Sun.COM  *
2714*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2715*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2716*7836SJohn.Forte@Sun.COM  *
2717*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2718*7836SJohn.Forte@Sun.COM  *      Returned when the the plugin specified by @ref oid could not be
2719*7836SJohn.Forte@Sun.COM  *      found.
2720*7836SJohn.Forte@Sun.COM  *
2721*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2722*7836SJohn.Forte@Sun.COM  *      Returned if one of the polling values is outside the range
2723*7836SJohn.Forte@Sun.COM  *      supported by the driver.
2724*7836SJohn.Forte@Sun.COM  *
2725*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2726*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2727*7836SJohn.Forte@Sun.COM  *
2728*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2729*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2730*7836SJohn.Forte@Sun.COM  *
2731*7836SJohn.Forte@Sun.COM  *******************************************************************************
2732*7836SJohn.Forte@Sun.COM  */
MP_SetProprietaryProperties(MP_OID oid,MP_UINT32 count,MP_PROPRIETARY_PROPERTY * pPropertyList)2733*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetProprietaryProperties(
2734*7836SJohn.Forte@Sun.COM     MP_OID    oid,
2735*7836SJohn.Forte@Sun.COM     MP_UINT32 count,
2736*7836SJohn.Forte@Sun.COM     MP_PROPRIETARY_PROPERTY *pPropertyList)
2737*7836SJohn.Forte@Sun.COM {
2738*7836SJohn.Forte@Sun.COM     MP_SetProprietaryPropertiesFn PassFunc;
2739*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2740*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2741*7836SJohn.Forte@Sun.COM 
2742*7836SJohn.Forte@Sun.COM     if (((status = validate_object(oid, MP_OBJECT_TYPE_PLUGIN,
2743*7836SJohn.Forte@Sun.COM 	MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2744*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_MULTIPATH_LU,
2745*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) &&
2746*7836SJohn.Forte@Sun.COM 	((status = validate_object(oid, MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE,
2747*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS)) {
2748*7836SJohn.Forte@Sun.COM         return (status);
2749*7836SJohn.Forte@Sun.COM     }
2750*7836SJohn.Forte@Sun.COM 
2751*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2752*7836SJohn.Forte@Sun.COM 
2753*7836SJohn.Forte@Sun.COM     index = oid.ownerId - 1;
2754*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2755*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetProprietaryPropertiesFn)
2756*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2757*7836SJohn.Forte@Sun.COM         "MP_SetProprietaryProperties");
2758*7836SJohn.Forte@Sun.COM 
2759*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2760*7836SJohn.Forte@Sun.COM 	    status = PassFunc(oid, count, pPropertyList);
2761*7836SJohn.Forte@Sun.COM         } else {
2762*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2763*7836SJohn.Forte@Sun.COM         }
2764*7836SJohn.Forte@Sun.COM     } else {
2765*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2766*7836SJohn.Forte@Sun.COM     }
2767*7836SJohn.Forte@Sun.COM 
2768*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2769*7836SJohn.Forte@Sun.COM     return (status);
2770*7836SJohn.Forte@Sun.COM }
2771*7836SJohn.Forte@Sun.COM 
2772*7836SJohn.Forte@Sun.COM /**
2773*7836SJohn.Forte@Sun.COM  *******************************************************************************
2774*7836SJohn.Forte@Sun.COM  *
2775*7836SJohn.Forte@Sun.COM  * Set the access state for a list of target port groups. This allows
2776*7836SJohn.Forte@Sun.COM  * a client to force a failover or failback to a desired set of target port
2777*7836SJohn.Forte@Sun.COM  * groups.
2778*7836SJohn.Forte@Sun.COM  *
2779*7836SJohn.Forte@Sun.COM  * @param  luOid
2780*7836SJohn.Forte@Sun.COM  *      The object ID of the logical unit where the command is sent.
2781*7836SJohn.Forte@Sun.COM  *
2782*7836SJohn.Forte@Sun.COM  * @param  count
2783*7836SJohn.Forte@Sun.COM  *      The number of valid items in the pTpgStateList.
2784*7836SJohn.Forte@Sun.COM  *
2785*7836SJohn.Forte@Sun.COM  * @param  pTpgStateList
2786*7836SJohn.Forte@Sun.COM  *      A pointer to an array of TPG/access-state values. This array must
2787*7836SJohn.Forte@Sun.COM  *      contain the same number of elements as @ref count.
2788*7836SJohn.Forte@Sun.COM  *
2789*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2790*7836SJohn.Forte@Sun.COM  *         an error occurred.
2791*7836SJohn.Forte@Sun.COM  *
2792*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2793*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2794*7836SJohn.Forte@Sun.COM  *
2795*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_OBJECT_NOT_FOUND
2796*7836SJohn.Forte@Sun.COM  *      Returned when the MP_MULTIPATH_LOGICAL_UNIT associated with @ref
2797*7836SJohn.Forte@Sun.COM  *      oid could not be found.
2798*7836SJohn.Forte@Sun.COM  *
2799*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2800*7836SJohn.Forte@Sun.COM  *      Returned if pTpgStateList is null or if one of the TPGs referenced
2801*7836SJohn.Forte@Sun.COM  *      in the list is not associated with the specified MP logical unit.
2802*7836SJohn.Forte@Sun.COM  *
2803*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNSUPPORTED
2804*7836SJohn.Forte@Sun.COM  *      Returned when the implementation does not support the API
2805*7836SJohn.Forte@Sun.COM  *
2806*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2807*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2808*7836SJohn.Forte@Sun.COM  *
2809*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_ACCESS_STATE_INVALID
2810*7836SJohn.Forte@Sun.COM  *         Returned if the target device returns a status indicating the caller
2811*7836SJohn.Forte@Sun.COM  *     is attempting to establish an illegal combination of access states.
2812*7836SJohn.Forte@Sun.COM  *
2813*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
2814*7836SJohn.Forte@Sun.COM  *          Returned if the underlying interface failed the commend for some
2815*7836SJohn.Forte@Sun.COM  *      reason other than MP_STATUS_ACCESS_STATE_INVALID
2816*7836SJohn.Forte@Sun.COM  *
2817*7836SJohn.Forte@Sun.COM  *******************************************************************************
2818*7836SJohn.Forte@Sun.COM  */
MP_SetTPGAccess(MP_OID luOid,MP_UINT32 count,MP_TPG_STATE_PAIR * pTpgStateList)2819*7836SJohn.Forte@Sun.COM MP_STATUS MP_SetTPGAccess(
2820*7836SJohn.Forte@Sun.COM     MP_OID luOid,
2821*7836SJohn.Forte@Sun.COM     MP_UINT32 count,
2822*7836SJohn.Forte@Sun.COM     MP_TPG_STATE_PAIR *pTpgStateList)
2823*7836SJohn.Forte@Sun.COM {
2824*7836SJohn.Forte@Sun.COM     MP_SetTPGAccessFn PassFunc;
2825*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2826*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2827*7836SJohn.Forte@Sun.COM 
2828*7836SJohn.Forte@Sun.COM     if ((status = validate_object(luOid, MP_OBJECT_TYPE_MULTIPATH_LU,
2829*7836SJohn.Forte@Sun.COM         MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2830*7836SJohn.Forte@Sun.COM         return (status);
2831*7836SJohn.Forte@Sun.COM     }
2832*7836SJohn.Forte@Sun.COM 
2833*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2834*7836SJohn.Forte@Sun.COM 
2835*7836SJohn.Forte@Sun.COM     index = luOid.ownerId - 1;
2836*7836SJohn.Forte@Sun.COM     if (plugintable[index].hdlPlugin != NULL) {
2837*7836SJohn.Forte@Sun.COM         PassFunc = (MP_SetTPGAccessFn)
2838*7836SJohn.Forte@Sun.COM         dlsym(plugintable[index].hdlPlugin,
2839*7836SJohn.Forte@Sun.COM         "MP_SetTPGAccess");
2840*7836SJohn.Forte@Sun.COM 
2841*7836SJohn.Forte@Sun.COM         if (PassFunc != NULL) {
2842*7836SJohn.Forte@Sun.COM 	    status = PassFunc(luOid, count, pTpgStateList);
2843*7836SJohn.Forte@Sun.COM         } else {
2844*7836SJohn.Forte@Sun.COM 	    status = MP_STATUS_UNSUPPORTED;
2845*7836SJohn.Forte@Sun.COM         }
2846*7836SJohn.Forte@Sun.COM     } else {
2847*7836SJohn.Forte@Sun.COM         status = MP_STATUS_FAILED;
2848*7836SJohn.Forte@Sun.COM     }
2849*7836SJohn.Forte@Sun.COM 
2850*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2851*7836SJohn.Forte@Sun.COM     return (status);
2852*7836SJohn.Forte@Sun.COM }
2853*7836SJohn.Forte@Sun.COM 
2854*7836SJohn.Forte@Sun.COM /**
2855*7836SJohn.Forte@Sun.COM  *******************************************************************************
2856*7836SJohn.Forte@Sun.COM  *
2857*7836SJohn.Forte@Sun.COM  * Registers a client function that is to be called
2858*7836SJohn.Forte@Sun.COM  * whenever the property of an an object changes.
2859*7836SJohn.Forte@Sun.COM  *
2860*7836SJohn.Forte@Sun.COM  * @param  pClientFn,
2861*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_OBJECT_PROPERTY_FN function defined by the
2862*7836SJohn.Forte@Sun.COM  *      client. On successful return this function will be called to
2863*7836SJohn.Forte@Sun.COM  *      inform the client of objects that have had one or more properties
2864*7836SJohn.Forte@Sun.COM  *      change.
2865*7836SJohn.Forte@Sun.COM  *
2866*7836SJohn.Forte@Sun.COM  * @param  objectType
2867*7836SJohn.Forte@Sun.COM  *      The type of object the client wishes to deregister for
2868*7836SJohn.Forte@Sun.COM  *      property change callbacks. If null, then all objects types are
2869*7836SJohn.Forte@Sun.COM  *      deregistered.
2870*7836SJohn.Forte@Sun.COM  *
2871*7836SJohn.Forte@Sun.COM  * @param  pCallerData
2872*7836SJohn.Forte@Sun.COM  *      A pointer that is passed to the callback routine with each event.
2873*7836SJohn.Forte@Sun.COM  *      This may be used by the caller to correlate the event to source of
2874*7836SJohn.Forte@Sun.COM  *      the registration.
2875*7836SJohn.Forte@Sun.COM  *
2876*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2877*7836SJohn.Forte@Sun.COM  *         an error occurred.
2878*7836SJohn.Forte@Sun.COM  *
2879*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2880*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2881*7836SJohn.Forte@Sun.COM  *
2882*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2883*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is NULL or specifies a memory area
2884*7836SJohn.Forte@Sun.COM  *      that is not executable.
2885*7836SJohn.Forte@Sun.COM  *
2886*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FN_REPLACED
2887*7836SJohn.Forte@Sun.COM  *      Returned when an existing client function is replaced with the one
2888*7836SJohn.Forte@Sun.COM  *      specified in pClientFn.
2889*7836SJohn.Forte@Sun.COM  *
2890*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2891*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2892*7836SJohn.Forte@Sun.COM  *
2893*7836SJohn.Forte@Sun.COM  *******************************************************************************
2894*7836SJohn.Forte@Sun.COM  */
MP_RegisterForObjectPropertyChanges(MP_OBJECT_PROPERTY_FN pClientFn,MP_OBJECT_TYPE objectType,void * pCallerData,MP_OID pluginOid)2895*7836SJohn.Forte@Sun.COM MP_STATUS MP_RegisterForObjectPropertyChanges(
2896*7836SJohn.Forte@Sun.COM     MP_OBJECT_PROPERTY_FN pClientFn,
2897*7836SJohn.Forte@Sun.COM     MP_OBJECT_TYPE objectType,
2898*7836SJohn.Forte@Sun.COM     void *pCallerData,
2899*7836SJohn.Forte@Sun.COM     MP_OID pluginOid)
2900*7836SJohn.Forte@Sun.COM {
2901*7836SJohn.Forte@Sun.COM     MP_RegisterForObjectPropertyChangesPluginFn PassFunc;
2902*7836SJohn.Forte@Sun.COM     MP_UINT32 i;
2903*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
2904*7836SJohn.Forte@Sun.COM     MP_STATUS status;
2905*7836SJohn.Forte@Sun.COM 
2906*7836SJohn.Forte@Sun.COM     if (pClientFn == NULL) {
2907*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
2908*7836SJohn.Forte@Sun.COM     }
2909*7836SJohn.Forte@Sun.COM 
2910*7836SJohn.Forte@Sun.COM     if (objectType > MP_OBJECT_TYPE_MAX) {
2911*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_OBJECT_TYPE);
2912*7836SJohn.Forte@Sun.COM     }
2913*7836SJohn.Forte@Sun.COM 
2914*7836SJohn.Forte@Sun.COM     if (!(is_zero_oid(pluginOid))) {
2915*7836SJohn.Forte@Sun.COM 	if ((status = validate_object(pluginOid, MP_OBJECT_TYPE_PLUGIN,
2916*7836SJohn.Forte@Sun.COM 	    MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
2917*7836SJohn.Forte@Sun.COM 	    return (status);
2918*7836SJohn.Forte@Sun.COM 	}
2919*7836SJohn.Forte@Sun.COM     }
2920*7836SJohn.Forte@Sun.COM 
2921*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
2922*7836SJohn.Forte@Sun.COM 
2923*7836SJohn.Forte@Sun.COM     if (is_zero_oid(pluginOid)) {
2924*7836SJohn.Forte@Sun.COM 	for (i = 0; i < number_of_plugins; i++) {
2925*7836SJohn.Forte@Sun.COM 	    if (plugintable[i].hdlPlugin != NULL) {
2926*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_RegisterForObjectPropertyChangesPluginFn)
2927*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[i].hdlPlugin,
2928*7836SJohn.Forte@Sun.COM 		"MP_RegisterForObjectPropertyChangesPlugin");
2929*7836SJohn.Forte@Sun.COM 	    }
2930*7836SJohn.Forte@Sun.COM 
2931*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
2932*7836SJohn.Forte@Sun.COM 		status =
2933*7836SJohn.Forte@Sun.COM 		     PassFunc(pClientFn, objectType, pCallerData);
2934*7836SJohn.Forte@Sun.COM 		/* ignore an error and continue */
2935*7836SJohn.Forte@Sun.COM 	    }
2936*7836SJohn.Forte@Sun.COM 	}
2937*7836SJohn.Forte@Sun.COM     } else {
2938*7836SJohn.Forte@Sun.COM 	index = pluginOid.ownerId - 1;
2939*7836SJohn.Forte@Sun.COM 	if (plugintable[index].hdlPlugin != NULL) {
2940*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_RegisterForObjectPropertyChangesPluginFn)
2941*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[index].hdlPlugin,
2942*7836SJohn.Forte@Sun.COM 		"MP_RegisterForObjectPropertyChangesPlugin");
2943*7836SJohn.Forte@Sun.COM 	}
2944*7836SJohn.Forte@Sun.COM 
2945*7836SJohn.Forte@Sun.COM 	if (PassFunc != NULL) {
2946*7836SJohn.Forte@Sun.COM 	    status = PassFunc(pClientFn, objectType, pCallerData);
2947*7836SJohn.Forte@Sun.COM 	}
2948*7836SJohn.Forte@Sun.COM     }
2949*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
2950*7836SJohn.Forte@Sun.COM     return (status);
2951*7836SJohn.Forte@Sun.COM }
2952*7836SJohn.Forte@Sun.COM 
2953*7836SJohn.Forte@Sun.COM /**
2954*7836SJohn.Forte@Sun.COM  *******************************************************************************
2955*7836SJohn.Forte@Sun.COM  *
2956*7836SJohn.Forte@Sun.COM  * Deregisters a previously registered client function that is to be invoked
2957*7836SJohn.Forte@Sun.COM  * whenever an object's property changes.
2958*7836SJohn.Forte@Sun.COM  *
2959*7836SJohn.Forte@Sun.COM  * @param  pClientFn,
2960*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_OBJECT_PROPERTY_FN function defined by the
2961*7836SJohn.Forte@Sun.COM  *      client that was previously registered using
2962*7836SJohn.Forte@Sun.COM  *      the MP_RegisterForObjectPropertyChanges API. On successful return
2963*7836SJohn.Forte@Sun.COM  *      this function will no longer be called to inform the client of
2964*7836SJohn.Forte@Sun.COM  *      object property changes.
2965*7836SJohn.Forte@Sun.COM  *
2966*7836SJohn.Forte@Sun.COM  * @param  objectType
2967*7836SJohn.Forte@Sun.COM  *      The type of object the client wishes to deregister for
2968*7836SJohn.Forte@Sun.COM  *      property change callbacks. If null, then all objects types are
2969*7836SJohn.Forte@Sun.COM  *      deregistered.
2970*7836SJohn.Forte@Sun.COM  *
2971*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
2972*7836SJohn.Forte@Sun.COM  *         an error occurred.
2973*7836SJohn.Forte@Sun.COM  *
2974*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
2975*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
2976*7836SJohn.Forte@Sun.COM  *
2977*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
2978*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is NULL or specifies a memory area
2979*7836SJohn.Forte@Sun.COM  *      that is not executable.
2980*7836SJohn.Forte@Sun.COM  *
2981*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNKNOWN_FN
2982*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is not the same as the previously registered
2983*7836SJohn.Forte@Sun.COM  *      function.
2984*7836SJohn.Forte@Sun.COM  *
2985*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
2986*7836SJohn.Forte@Sun.COM  *          Returned if oid does not specify any valid object type.
2987*7836SJohn.Forte@Sun.COM  *
2988*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
2989*7836SJohn.Forte@Sun.COM  *          Returned if pClientFn deregistration is not possible at this time.
2990*7836SJohn.Forte@Sun.COM  *
2991*7836SJohn.Forte@Sun.COM  *******************************************************************************
2992*7836SJohn.Forte@Sun.COM  */
MP_DeregisterForObjectPropertyChanges(MP_OBJECT_PROPERTY_FN pClientFn,MP_OBJECT_TYPE objectType,MP_OID pluginOid)2993*7836SJohn.Forte@Sun.COM MP_STATUS MP_DeregisterForObjectPropertyChanges(
2994*7836SJohn.Forte@Sun.COM     MP_OBJECT_PROPERTY_FN pClientFn,
2995*7836SJohn.Forte@Sun.COM     MP_OBJECT_TYPE objectType,
2996*7836SJohn.Forte@Sun.COM     MP_OID pluginOid)
2997*7836SJohn.Forte@Sun.COM {
2998*7836SJohn.Forte@Sun.COM     MP_DeregisterForObjectPropertyChangesPluginFn PassFunc;
2999*7836SJohn.Forte@Sun.COM     MP_UINT32 i;
3000*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
3001*7836SJohn.Forte@Sun.COM     MP_STATUS status;
3002*7836SJohn.Forte@Sun.COM 
3003*7836SJohn.Forte@Sun.COM     if (pClientFn == NULL) {
3004*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
3005*7836SJohn.Forte@Sun.COM     }
3006*7836SJohn.Forte@Sun.COM 
3007*7836SJohn.Forte@Sun.COM     if (objectType > MP_OBJECT_TYPE_MAX) {
3008*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_OBJECT_TYPE);
3009*7836SJohn.Forte@Sun.COM     }
3010*7836SJohn.Forte@Sun.COM 
3011*7836SJohn.Forte@Sun.COM     if (!(is_zero_oid(pluginOid))) {
3012*7836SJohn.Forte@Sun.COM 	if ((status = validate_object(pluginOid, MP_OBJECT_TYPE_PLUGIN,
3013*7836SJohn.Forte@Sun.COM 	    MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
3014*7836SJohn.Forte@Sun.COM 	    return (status);
3015*7836SJohn.Forte@Sun.COM 	}
3016*7836SJohn.Forte@Sun.COM     }
3017*7836SJohn.Forte@Sun.COM 
3018*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
3019*7836SJohn.Forte@Sun.COM 
3020*7836SJohn.Forte@Sun.COM     if (is_zero_oid(pluginOid)) {
3021*7836SJohn.Forte@Sun.COM 	for (i = 0; i < number_of_plugins; i++) {
3022*7836SJohn.Forte@Sun.COM 	    if (plugintable[i].hdlPlugin != NULL) {
3023*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_DeregisterForObjectPropertyChangesPluginFn)
3024*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[i].hdlPlugin,
3025*7836SJohn.Forte@Sun.COM 		"MP_DeregisterForObjectPropertyChangesPlugin");
3026*7836SJohn.Forte@Sun.COM 	    }
3027*7836SJohn.Forte@Sun.COM 
3028*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
3029*7836SJohn.Forte@Sun.COM 		status = PassFunc(pClientFn, objectType);
3030*7836SJohn.Forte@Sun.COM 	    }
3031*7836SJohn.Forte@Sun.COM 	}
3032*7836SJohn.Forte@Sun.COM     } else {
3033*7836SJohn.Forte@Sun.COM 	index = pluginOid.ownerId - 1;
3034*7836SJohn.Forte@Sun.COM 	if (plugintable[index].hdlPlugin != NULL) {
3035*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_DeregisterForObjectPropertyChangesPluginFn)
3036*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[index].hdlPlugin,
3037*7836SJohn.Forte@Sun.COM 		"MP_DeregisterForObjectPropertyChangesPlugin");
3038*7836SJohn.Forte@Sun.COM 	}
3039*7836SJohn.Forte@Sun.COM 
3040*7836SJohn.Forte@Sun.COM 	if (PassFunc != NULL) {
3041*7836SJohn.Forte@Sun.COM 	    status = PassFunc(pClientFn, objectType);
3042*7836SJohn.Forte@Sun.COM 	}
3043*7836SJohn.Forte@Sun.COM     }
3044*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
3045*7836SJohn.Forte@Sun.COM     return (status);
3046*7836SJohn.Forte@Sun.COM }
3047*7836SJohn.Forte@Sun.COM 
3048*7836SJohn.Forte@Sun.COM /**
3049*7836SJohn.Forte@Sun.COM  *******************************************************************************
3050*7836SJohn.Forte@Sun.COM  *
3051*7836SJohn.Forte@Sun.COM  * Registers a client function that is to be called
3052*7836SJohn.Forte@Sun.COM  * whenever a high level object appears or disappears.
3053*7836SJohn.Forte@Sun.COM  *
3054*7836SJohn.Forte@Sun.COM  * @param  pClientFn,
3055*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_OBJECT_VISIBILITY_FN function defined by the
3056*7836SJohn.Forte@Sun.COM  *      client. On successful return this function will be called to
3057*7836SJohn.Forte@Sun.COM  *      inform the client of objects whose visibility has changed.
3058*7836SJohn.Forte@Sun.COM  *
3059*7836SJohn.Forte@Sun.COM  * @param  objectType
3060*7836SJohn.Forte@Sun.COM  *      The type of object the client wishes to deregister for
3061*7836SJohn.Forte@Sun.COM  *      property change callbacks. If null, then all objects types are
3062*7836SJohn.Forte@Sun.COM  *      deregistered.
3063*7836SJohn.Forte@Sun.COM  *
3064*7836SJohn.Forte@Sun.COM  * @param  pCallerData
3065*7836SJohn.Forte@Sun.COM  *      A pointer that is passed to the callback routine with each event.
3066*7836SJohn.Forte@Sun.COM  *      This may be used by the caller to correlate the event to source of
3067*7836SJohn.Forte@Sun.COM  *      the registration.
3068*7836SJohn.Forte@Sun.COM  *
3069*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3070*7836SJohn.Forte@Sun.COM  *         an error occurred.
3071*7836SJohn.Forte@Sun.COM  *
3072*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3073*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
3074*7836SJohn.Forte@Sun.COM  *
3075*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
3076*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is NULL or specifies a memory area
3077*7836SJohn.Forte@Sun.COM  *      that is not executable.
3078*7836SJohn.Forte@Sun.COM  *
3079*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FN_REPLACED
3080*7836SJohn.Forte@Sun.COM  *      Returned when an existing client function is replaced with the one
3081*7836SJohn.Forte@Sun.COM  *      specified in pClientFn.
3082*7836SJohn.Forte@Sun.COM  *
3083*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
3084*7836SJohn.Forte@Sun.COM  *          Returned if objectType does not specify any valid object type.
3085*7836SJohn.Forte@Sun.COM  *
3086*7836SJohn.Forte@Sun.COM  *******************************************************************************
3087*7836SJohn.Forte@Sun.COM  */
MP_RegisterForObjectVisibilityChanges(MP_OBJECT_VISIBILITY_FN pClientFn,MP_OBJECT_TYPE objectType,void * pCallerData,MP_OID pluginOid)3088*7836SJohn.Forte@Sun.COM MP_STATUS MP_RegisterForObjectVisibilityChanges(
3089*7836SJohn.Forte@Sun.COM     MP_OBJECT_VISIBILITY_FN pClientFn,
3090*7836SJohn.Forte@Sun.COM     MP_OBJECT_TYPE objectType,
3091*7836SJohn.Forte@Sun.COM     void *pCallerData,
3092*7836SJohn.Forte@Sun.COM     MP_OID pluginOid)
3093*7836SJohn.Forte@Sun.COM {
3094*7836SJohn.Forte@Sun.COM     MP_RegisterForObjectVisibilityChangesPluginFn PassFunc;
3095*7836SJohn.Forte@Sun.COM     MP_UINT32 i;
3096*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
3097*7836SJohn.Forte@Sun.COM     MP_STATUS status;
3098*7836SJohn.Forte@Sun.COM 
3099*7836SJohn.Forte@Sun.COM     if (pClientFn == NULL) {
3100*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
3101*7836SJohn.Forte@Sun.COM     }
3102*7836SJohn.Forte@Sun.COM 
3103*7836SJohn.Forte@Sun.COM     if (objectType > MP_OBJECT_TYPE_MAX) {
3104*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_OBJECT_TYPE);
3105*7836SJohn.Forte@Sun.COM     }
3106*7836SJohn.Forte@Sun.COM 
3107*7836SJohn.Forte@Sun.COM     if (!(is_zero_oid(pluginOid))) {
3108*7836SJohn.Forte@Sun.COM 	if ((status = validate_object(pluginOid, MP_OBJECT_TYPE_PLUGIN,
3109*7836SJohn.Forte@Sun.COM 	    MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
3110*7836SJohn.Forte@Sun.COM 	    return (status);
3111*7836SJohn.Forte@Sun.COM 	}
3112*7836SJohn.Forte@Sun.COM     }
3113*7836SJohn.Forte@Sun.COM 
3114*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
3115*7836SJohn.Forte@Sun.COM 
3116*7836SJohn.Forte@Sun.COM     if (is_zero_oid(pluginOid)) {
3117*7836SJohn.Forte@Sun.COM 	for (i = 0; i < number_of_plugins; i++) {
3118*7836SJohn.Forte@Sun.COM 	    if (plugintable[i].hdlPlugin != NULL) {
3119*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_RegisterForObjectVisibilityChangesPluginFn)
3120*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[i].hdlPlugin,
3121*7836SJohn.Forte@Sun.COM 		"MP_RegisterForObjectVisibilityChangesPlugin");
3122*7836SJohn.Forte@Sun.COM 	    }
3123*7836SJohn.Forte@Sun.COM 
3124*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
3125*7836SJohn.Forte@Sun.COM 		status = PassFunc(pClientFn, objectType, pCallerData);
3126*7836SJohn.Forte@Sun.COM 		/* ignore an error and continue. */
3127*7836SJohn.Forte@Sun.COM 	    }
3128*7836SJohn.Forte@Sun.COM 	}
3129*7836SJohn.Forte@Sun.COM     } else {
3130*7836SJohn.Forte@Sun.COM 	    index = pluginOid.ownerId - 1;
3131*7836SJohn.Forte@Sun.COM 	    if (plugintable[index].hdlPlugin != NULL) {
3132*7836SJohn.Forte@Sun.COM 	    PassFunc = (MP_RegisterForObjectVisibilityChangesPluginFn)
3133*7836SJohn.Forte@Sun.COM 		dlsym(plugintable[index].hdlPlugin,
3134*7836SJohn.Forte@Sun.COM 		"MP_RegisterForObjectVisibilityChangesPlugin");
3135*7836SJohn.Forte@Sun.COM 	    }
3136*7836SJohn.Forte@Sun.COM 
3137*7836SJohn.Forte@Sun.COM 	    if (PassFunc != NULL) {
3138*7836SJohn.Forte@Sun.COM 		status = PassFunc(pClientFn, objectType, pCallerData);
3139*7836SJohn.Forte@Sun.COM 	    }
3140*7836SJohn.Forte@Sun.COM     }
3141*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
3142*7836SJohn.Forte@Sun.COM     return (status);
3143*7836SJohn.Forte@Sun.COM 
3144*7836SJohn.Forte@Sun.COM }
3145*7836SJohn.Forte@Sun.COM 
3146*7836SJohn.Forte@Sun.COM /**
3147*7836SJohn.Forte@Sun.COM  *******************************************************************************
3148*7836SJohn.Forte@Sun.COM  *
3149*7836SJohn.Forte@Sun.COM  * Deregisters a previously registered client function that is to be invoked
3150*7836SJohn.Forte@Sun.COM  * whenever a high level object appears or disappears.
3151*7836SJohn.Forte@Sun.COM  *
3152*7836SJohn.Forte@Sun.COM  * @param  pClientFn,
3153*7836SJohn.Forte@Sun.COM  *      A pointer to an MP_OBJECT_VISIBILITY_FN function defined by the
3154*7836SJohn.Forte@Sun.COM  *      client that was previously registered using
3155*7836SJohn.Forte@Sun.COM  *      the MP_RegisterForObjectVisibilityChanges API. On successful return
3156*7836SJohn.Forte@Sun.COM  *      this function will no longer be called to inform the client of
3157*7836SJohn.Forte@Sun.COM  *      object property changes.
3158*7836SJohn.Forte@Sun.COM  *
3159*7836SJohn.Forte@Sun.COM  * @param  objectType
3160*7836SJohn.Forte@Sun.COM  *      The type of object the client wishes to deregister for visibility
3161*7836SJohn.Forte@Sun.COM  *      change callbacks. If null, then all objects types are
3162*7836SJohn.Forte@Sun.COM  *      deregistered.
3163*7836SJohn.Forte@Sun.COM  *
3164*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3165*7836SJohn.Forte@Sun.COM  *         an error occurred.
3166*7836SJohn.Forte@Sun.COM  *
3167*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3168*7836SJohn.Forte@Sun.COM  *         Returned when the operation is successful.
3169*7836SJohn.Forte@Sun.COM  *
3170*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
3171*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is NULL or specifies a memory area
3172*7836SJohn.Forte@Sun.COM  *      that is not executable.
3173*7836SJohn.Forte@Sun.COM  *
3174*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_UNKNOWN_FN
3175*7836SJohn.Forte@Sun.COM  *      Returned if pClientFn is not the same as the previously registered
3176*7836SJohn.Forte@Sun.COM  *      function.
3177*7836SJohn.Forte@Sun.COM  *
3178*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_OBJECT_TYPE
3179*7836SJohn.Forte@Sun.COM  *          Returned if objectType does not specify any valid object type.
3180*7836SJohn.Forte@Sun.COM  *
3181*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
3182*7836SJohn.Forte@Sun.COM  *          Returned if pClientFn deregistration is not possible at this time.
3183*7836SJohn.Forte@Sun.COM  *
3184*7836SJohn.Forte@Sun.COM  *******************************************************************************
3185*7836SJohn.Forte@Sun.COM  */
MP_DeregisterForObjectVisibilityChanges(MP_OBJECT_VISIBILITY_FN pClientFn,MP_OBJECT_TYPE objectType,MP_OID pluginOid)3186*7836SJohn.Forte@Sun.COM MP_STATUS MP_DeregisterForObjectVisibilityChanges(
3187*7836SJohn.Forte@Sun.COM     MP_OBJECT_VISIBILITY_FN pClientFn,
3188*7836SJohn.Forte@Sun.COM     MP_OBJECT_TYPE objectType,
3189*7836SJohn.Forte@Sun.COM     MP_OID pluginOid)
3190*7836SJohn.Forte@Sun.COM {
3191*7836SJohn.Forte@Sun.COM     MP_DeregisterForObjectVisibilityChangesPluginFn PassFunc;
3192*7836SJohn.Forte@Sun.COM     MP_UINT32 i;
3193*7836SJohn.Forte@Sun.COM     MP_UINT32 index;
3194*7836SJohn.Forte@Sun.COM     MP_STATUS status;
3195*7836SJohn.Forte@Sun.COM 
3196*7836SJohn.Forte@Sun.COM     if (pClientFn == NULL) {
3197*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_PARAMETER);
3198*7836SJohn.Forte@Sun.COM     }
3199*7836SJohn.Forte@Sun.COM 
3200*7836SJohn.Forte@Sun.COM     if (objectType > MP_OBJECT_TYPE_MAX) {
3201*7836SJohn.Forte@Sun.COM         return (MP_STATUS_INVALID_OBJECT_TYPE);
3202*7836SJohn.Forte@Sun.COM     }
3203*7836SJohn.Forte@Sun.COM 
3204*7836SJohn.Forte@Sun.COM     if (!(is_zero_oid(pluginOid))) {
3205*7836SJohn.Forte@Sun.COM 	if ((status = validate_object(pluginOid, MP_OBJECT_TYPE_PLUGIN,
3206*7836SJohn.Forte@Sun.COM 	    MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
3207*7836SJohn.Forte@Sun.COM 	    return (status);
3208*7836SJohn.Forte@Sun.COM 	}
3209*7836SJohn.Forte@Sun.COM     }
3210*7836SJohn.Forte@Sun.COM 
3211*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_lock(&mp_lib_mutex);
3212*7836SJohn.Forte@Sun.COM 
3213*7836SJohn.Forte@Sun.COM     if (is_zero_oid(pluginOid)) {
3214*7836SJohn.Forte@Sun.COM 	for (i = 0; i < number_of_plugins; i++) {
3215*7836SJohn.Forte@Sun.COM 	    if (plugintable[i].hdlPlugin != NULL) {
3216*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_DeregisterForObjectVisibilityChangesPluginFn)
3217*7836SJohn.Forte@Sun.COM 		    dlsym(plugintable[i].hdlPlugin,
3218*7836SJohn.Forte@Sun.COM 		    "MP_DeregisterForObjectVisibilityChangesPlugin");
3219*7836SJohn.Forte@Sun.COM 		if (PassFunc != NULL) {
3220*7836SJohn.Forte@Sun.COM 		    status = PassFunc(pClientFn, objectType);
3221*7836SJohn.Forte@Sun.COM 		}
3222*7836SJohn.Forte@Sun.COM 	    }
3223*7836SJohn.Forte@Sun.COM 	}
3224*7836SJohn.Forte@Sun.COM     } else  {
3225*7836SJohn.Forte@Sun.COM 	    index = pluginOid.ownerId - 1;
3226*7836SJohn.Forte@Sun.COM 	    if (plugintable[index].hdlPlugin != NULL) {
3227*7836SJohn.Forte@Sun.COM 		PassFunc = (MP_DeregisterForObjectVisibilityChangesPluginFn)
3228*7836SJohn.Forte@Sun.COM 		    dlsym(plugintable[index].hdlPlugin,
3229*7836SJohn.Forte@Sun.COM 		    "MP_DeregisterForObjectVisibilityChangesPlugin");
3230*7836SJohn.Forte@Sun.COM 		if (PassFunc != NULL) {
3231*7836SJohn.Forte@Sun.COM 		    status = PassFunc(pClientFn, objectType);
3232*7836SJohn.Forte@Sun.COM 		}
3233*7836SJohn.Forte@Sun.COM 	    }
3234*7836SJohn.Forte@Sun.COM     }
3235*7836SJohn.Forte@Sun.COM 
3236*7836SJohn.Forte@Sun.COM     (void) pthread_mutex_unlock(&mp_lib_mutex);
3237*7836SJohn.Forte@Sun.COM     return (status);
3238*7836SJohn.Forte@Sun.COM }
3239*7836SJohn.Forte@Sun.COM 
3240*7836SJohn.Forte@Sun.COM /**
3241*7836SJohn.Forte@Sun.COM  *******************************************************************************
3242*7836SJohn.Forte@Sun.COM  *
3243*7836SJohn.Forte@Sun.COM  * Compare two Oids for equality to see whether they refer to the same object.
3244*7836SJohn.Forte@Sun.COM  *
3245*7836SJohn.Forte@Sun.COM  * @param  oid1
3246*7836SJohn.Forte@Sun.COM  *          Oid to compare.
3247*7836SJohn.Forte@Sun.COM  *
3248*7836SJohn.Forte@Sun.COM  * @param  oid2
3249*7836SJohn.Forte@Sun.COM  *          Oid to compare.
3250*7836SJohn.Forte@Sun.COM  *
3251*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3252*7836SJohn.Forte@Sun.COM  *         an error occurred.
3253*7836SJohn.Forte@Sun.COM  *
3254*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3255*7836SJohn.Forte@Sun.COM  *         Returned when the two Oids do refer to the same object.
3256*7836SJohn.Forte@Sun.COM  *
3257*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
3258*7836SJohn.Forte@Sun.COM  *      Returned if the Oids don't compare.
3259*7836SJohn.Forte@Sun.COM  *
3260*7836SJohn.Forte@Sun.COM  *******************************************************************************
3261*7836SJohn.Forte@Sun.COM  */
MP_CompareOIDs(MP_OID oid1,MP_OID oid2)3262*7836SJohn.Forte@Sun.COM MP_STATUS MP_CompareOIDs(
3263*7836SJohn.Forte@Sun.COM         MP_OID oid1,
3264*7836SJohn.Forte@Sun.COM     MP_OID oid2)
3265*7836SJohn.Forte@Sun.COM {
3266*7836SJohn.Forte@Sun.COM     if ((oid1.objectType == oid2.objectType) && (oid1.ownerId == oid2.ownerId)
3267*7836SJohn.Forte@Sun.COM     	&& (oid1.objectSequenceNumber == oid2.objectSequenceNumber)) {
3268*7836SJohn.Forte@Sun.COM     	return (MP_STATUS_SUCCESS);
3269*7836SJohn.Forte@Sun.COM     } else {
3270*7836SJohn.Forte@Sun.COM     	return (MP_STATUS_FAILED);
3271*7836SJohn.Forte@Sun.COM     }
3272*7836SJohn.Forte@Sun.COM }
3273*7836SJohn.Forte@Sun.COM 
3274*7836SJohn.Forte@Sun.COM /**
3275*7836SJohn.Forte@Sun.COM  *******************************************************************************
3276*7836SJohn.Forte@Sun.COM  *
3277*7836SJohn.Forte@Sun.COM  * Frees memory returned by an MP API.
3278*7836SJohn.Forte@Sun.COM  *
3279*7836SJohn.Forte@Sun.COM  * @param  pOidList
3280*7836SJohn.Forte@Sun.COM  *      A pointer to the memory returned by an MP API. On successful
3281*7836SJohn.Forte@Sun.COM         return, the allocated memory is freed.
3282*7836SJohn.Forte@Sun.COM  *
3283*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3284*7836SJohn.Forte@Sun.COM  *         an error occurred.
3285*7836SJohn.Forte@Sun.COM  *
3286*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3287*7836SJohn.Forte@Sun.COM  *         Returned when pPluginId is deregistered successfully.
3288*7836SJohn.Forte@Sun.COM  *
3289*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
3290*7836SJohn.Forte@Sun.COM  *      Returned if pMemory is NULL or specifies a memory area to which
3291*7836SJohn.Forte@Sun.COM  *      data cannot be written.
3292*7836SJohn.Forte@Sun.COM  *
3293*7836SJohn.Forte@Sun.COM  *******************************************************************************
3294*7836SJohn.Forte@Sun.COM  */
MP_FreeOidList(MP_OID_LIST * pOidList)3295*7836SJohn.Forte@Sun.COM MP_STATUS MP_FreeOidList(MP_OID_LIST *pOidList)
3296*7836SJohn.Forte@Sun.COM {
3297*7836SJohn.Forte@Sun.COM 	if (pOidList == NULL) {
3298*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3299*7836SJohn.Forte@Sun.COM 	}
3300*7836SJohn.Forte@Sun.COM 
3301*7836SJohn.Forte@Sun.COM 	free(pOidList);
3302*7836SJohn.Forte@Sun.COM 
3303*7836SJohn.Forte@Sun.COM 	return (MP_STATUS_SUCCESS);
3304*7836SJohn.Forte@Sun.COM }
3305*7836SJohn.Forte@Sun.COM 
3306*7836SJohn.Forte@Sun.COM static MP_CHAR *HDR =
3307*7836SJohn.Forte@Sun.COM "#\n"
3308*7836SJohn.Forte@Sun.COM "# This file contains names and references to MP API plugin libraries\n"
3309*7836SJohn.Forte@Sun.COM "#\n"
3310*7836SJohn.Forte@Sun.COM "#  Do NOT manually edit this file\n"
3311*7836SJohn.Forte@Sun.COM "#\n"
3312*7836SJohn.Forte@Sun.COM "# Format:\n"
3313*7836SJohn.Forte@Sun.COM "#\n"
3314*7836SJohn.Forte@Sun.COM "# <library ID>  <library pathname>\n"
3315*7836SJohn.Forte@Sun.COM "#\n";
3316*7836SJohn.Forte@Sun.COM 
3317*7836SJohn.Forte@Sun.COM #define CLEANUP_N_RET(fd, ret)  \
3318*7836SJohn.Forte@Sun.COM 	if (lock_register(fd, F_SETLK, F_UNLCK, 0, SEEK_SET, 0) < 0) { \
3319*7836SJohn.Forte@Sun.COM 		close(fd); \
3320*7836SJohn.Forte@Sun.COM 		return (MP_STATUS_FAILED); \
3321*7836SJohn.Forte@Sun.COM 	} \
3322*7836SJohn.Forte@Sun.COM 	close(fd); \
3323*7836SJohn.Forte@Sun.COM 	return (ret)
3324*7836SJohn.Forte@Sun.COM 
3325*7836SJohn.Forte@Sun.COM /*
3326*7836SJohn.Forte@Sun.COM  * This function sets an advisory lock on the file pointed to by the argument
3327*7836SJohn.Forte@Sun.COM  * fd, which is a file descriptor. The lock is set using fcntl() which uses
3328*7836SJohn.Forte@Sun.COM  * flock structure.
3329*7836SJohn.Forte@Sun.COM  */
3330*7836SJohn.Forte@Sun.COM static int
lock_register(int fd,int cmd,int type,off_t offset,int whence,off_t len)3331*7836SJohn.Forte@Sun.COM lock_register(int fd, int cmd, int type, off_t offset, int whence, off_t len)
3332*7836SJohn.Forte@Sun.COM {
3333*7836SJohn.Forte@Sun.COM     struct flock lock;
3334*7836SJohn.Forte@Sun.COM 
3335*7836SJohn.Forte@Sun.COM     lock.l_type = type;
3336*7836SJohn.Forte@Sun.COM     lock.l_start = offset;
3337*7836SJohn.Forte@Sun.COM     lock.l_whence = whence;
3338*7836SJohn.Forte@Sun.COM     lock.l_len = len;
3339*7836SJohn.Forte@Sun.COM 
3340*7836SJohn.Forte@Sun.COM     return (fcntl(fd, cmd, &lock));
3341*7836SJohn.Forte@Sun.COM }
3342*7836SJohn.Forte@Sun.COM 
3343*7836SJohn.Forte@Sun.COM /*
3344*7836SJohn.Forte@Sun.COM  * This function searches for "srch_str" (of length "slen") in "buf" (of length
3345*7836SJohn.Forte@Sun.COM  * "buflen"). If it is not found, "write_offset" has the offset in "buf" where
3346*7836SJohn.Forte@Sun.COM  * "srch_str" would have to be added in "buf". If "srch_str" is found in "buf",
3347*7836SJohn.Forte@Sun.COM  * "write_offset" has its offset in "buf"
3348*7836SJohn.Forte@Sun.COM  *
3349*7836SJohn.Forte@Sun.COM  * ARGUMENTS :
3350*7836SJohn.Forte@Sun.COM  * buf		- buffer to search in
3351*7836SJohn.Forte@Sun.COM  * buflen	- length of buffer
3352*7836SJohn.Forte@Sun.COM  * srch_id	- id to search
3353*7836SJohn.Forte@Sun.COM  * id_len	- length of srch_id
3354*7836SJohn.Forte@Sun.COM  * write_offset	- Set in function on exit
3355*7836SJohn.Forte@Sun.COM  *		- It is the offset in buf where srch_str is or should be
3356*7836SJohn.Forte@Sun.COM  * bytes_left	- Set in function on exit
3357*7836SJohn.Forte@Sun.COM  *		- It is the # of bytes left beyond write_offset in buf
3358*7836SJohn.Forte@Sun.COM  * RETURN VALUES :
3359*7836SJohn.Forte@Sun.COM  * Zero - "srch_id" found in "buf"... "write_offset" has offset in "buf"
3360*7836SJohn.Forte@Sun.COM  * != 0 - "srch_str" NOT found in "buf" ... "write_offset" points to the end of
3361*7836SJohn.Forte@Sun.COM  *	    "buf".
3362*7836SJohn.Forte@Sun.COM  */
3363*7836SJohn.Forte@Sun.COM static int
search_line(MP_CHAR * buf,size_t buflen,MP_CHAR * srch_id,size_t id_len,int * write_offset,int * bytes_left)3364*7836SJohn.Forte@Sun.COM search_line(MP_CHAR *buf, size_t buflen, MP_CHAR *srch_id, size_t id_len,
3365*7836SJohn.Forte@Sun.COM 		int *write_offset, int *bytes_left)
3366*7836SJohn.Forte@Sun.COM {
3367*7836SJohn.Forte@Sun.COM 	int	retval, sizeof_conf_hdr = strlen(HDR);
3368*7836SJohn.Forte@Sun.COM 	MP_CHAR	*sol;		/* Pointer to Start-Of-Line */
3369*7836SJohn.Forte@Sun.COM 	MP_CHAR	*cur_pos;	/* current position */
3370*7836SJohn.Forte@Sun.COM 
3371*7836SJohn.Forte@Sun.COM 	*bytes_left = buflen;
3372*7836SJohn.Forte@Sun.COM 	*write_offset = 0;
3373*7836SJohn.Forte@Sun.COM 
3374*7836SJohn.Forte@Sun.COM 	if (buf == NULL || buflen <= 0)
3375*7836SJohn.Forte@Sun.COM 		return (-1);
3376*7836SJohn.Forte@Sun.COM 
3377*7836SJohn.Forte@Sun.COM 	if (srch_id == NULL || id_len <= 0)
3378*7836SJohn.Forte@Sun.COM 		return (0);
3379*7836SJohn.Forte@Sun.COM 
3380*7836SJohn.Forte@Sun.COM 	sol = cur_pos = buf;
3381*7836SJohn.Forte@Sun.COM 
3382*7836SJohn.Forte@Sun.COM 	/*
3383*7836SJohn.Forte@Sun.COM 	 * mp conf file should not be edited but takes care of
3384*7836SJohn.Forte@Sun.COM 	 * any extra white space when parsing the line.
3385*7836SJohn.Forte@Sun.COM 	 *
3386*7836SJohn.Forte@Sun.COM 	 * The line should have id + delimiter + name + newline.
3387*7836SJohn.Forte@Sun.COM 	 */
3388*7836SJohn.Forte@Sun.COM 	while (*bytes_left >= (id_len + 3)) {
3389*7836SJohn.Forte@Sun.COM 	    /* skip leading blank or space. */
3390*7836SJohn.Forte@Sun.COM 	    while ((*cur_pos == ' ') || (*cur_pos == '\t')) {
3391*7836SJohn.Forte@Sun.COM 		cur_pos++;
3392*7836SJohn.Forte@Sun.COM 	    }
3393*7836SJohn.Forte@Sun.COM 
3394*7836SJohn.Forte@Sun.COM 	    if (strncmp(cur_pos, srch_id, id_len) == 0) {
3395*7836SJohn.Forte@Sun.COM 		/* id matched. */
3396*7836SJohn.Forte@Sun.COM 		cur_pos += id_len;
3397*7836SJohn.Forte@Sun.COM 
3398*7836SJohn.Forte@Sun.COM 		while (*cur_pos != '\n') {
3399*7836SJohn.Forte@Sun.COM 		    cur_pos++;
3400*7836SJohn.Forte@Sun.COM 		}
3401*7836SJohn.Forte@Sun.COM 		*write_offset = (sol - buf);
3402*7836SJohn.Forte@Sun.COM 		*bytes_left = buflen - ((cur_pos + 1) - buf);
3403*7836SJohn.Forte@Sun.COM 		return (0);
3404*7836SJohn.Forte@Sun.COM 	    } else {
3405*7836SJohn.Forte@Sun.COM 		/* move to the next line */
3406*7836SJohn.Forte@Sun.COM 		while (*cur_pos != '\n') {
3407*7836SJohn.Forte@Sun.COM 		    cur_pos++;
3408*7836SJohn.Forte@Sun.COM 		}
3409*7836SJohn.Forte@Sun.COM 		*bytes_left = buflen - ((cur_pos + 1) - buf);
3410*7836SJohn.Forte@Sun.COM 	    }
3411*7836SJohn.Forte@Sun.COM 	    sol = cur_pos = cur_pos + 1;
3412*7836SJohn.Forte@Sun.COM 	}
3413*7836SJohn.Forte@Sun.COM 
3414*7836SJohn.Forte@Sun.COM 	/* Given strings are not found. */
3415*7836SJohn.Forte@Sun.COM 	*write_offset = buflen;
3416*7836SJohn.Forte@Sun.COM 	return (-1);
3417*7836SJohn.Forte@Sun.COM }
3418*7836SJohn.Forte@Sun.COM 
3419*7836SJohn.Forte@Sun.COM /**
3420*7836SJohn.Forte@Sun.COM  *******************************************************************************
3421*7836SJohn.Forte@Sun.COM  *
3422*7836SJohn.Forte@Sun.COM  * Registers a plugin with common library.  The implementation of this routine
3423*7836SJohn.Forte@Sun.COM  * is based on configuration file /etc/mpapi.conf that contains a list of
3424*7836SJohn.Forte@Sun.COM  * plugin libraries.
3425*7836SJohn.Forte@Sun.COM  *
3426*7836SJohn.Forte@Sun.COM  * @param  pPluginId
3427*7836SJohn.Forte@Sun.COM  *	    A pointer to the key name shall be the reversed domain name of
3428*7836SJohn.Forte@Sun.COM  *	    the vendor followed by followed by the vendor specific name for
3429*7836SJohn.Forte@Sun.COM  *	    the plugin that uniquely identifies the plugin.  Should be NULL
3430*7836SJohn.Forte@Sun.COM  *	    terminated.
3431*7836SJohn.Forte@Sun.COM  *
3432*7836SJohn.Forte@Sun.COM  * @param  pFileName
3433*7836SJohn.Forte@Sun.COM  *	    The full path to the plugin library.
3434*7836SJohn.Forte@Sun.COM  *	    Should be NULL terminated.
3435*7836SJohn.Forte@Sun.COM  *
3436*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3437*7836SJohn.Forte@Sun.COM  *         an error occurred.
3438*7836SJohn.Forte@Sun.COM  *
3439*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3440*7836SJohn.Forte@Sun.COM  *         Returned when pPluginId is deregistered successfully.
3441*7836SJohn.Forte@Sun.COM  *
3442*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
3443*7836SJohn.Forte@Sun.COM  *      Returned if pPluginId is NULL or specifies a memory area that
3444*7836SJohn.Forte@Sun.COM  *      is not executable.
3445*7836SJohn.Forte@Sun.COM  *
3446*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
3447*7836SJohn.Forte@Sun.COM  *          Returned if pClientFn deregistration is not possible at this time.
3448*7836SJohn.Forte@Sun.COM  *
3449*7836SJohn.Forte@Sun.COM  *******************************************************************************
3450*7836SJohn.Forte@Sun.COM  */
MP_RegisterPlugin(MP_WCHAR * pPluginId,char * pFileName)3451*7836SJohn.Forte@Sun.COM MP_STATUS MP_RegisterPlugin(
3452*7836SJohn.Forte@Sun.COM 	MP_WCHAR *pPluginId,
3453*7836SJohn.Forte@Sun.COM 	char *pFileName)
3454*7836SJohn.Forte@Sun.COM {
3455*7836SJohn.Forte@Sun.COM 	int mpconf, bytes_left, write_offset;
3456*7836SJohn.Forte@Sun.COM 	MP_CHAR fullline[MAX_LINE_SIZE]; /* Full line to add to mpapi.conf */
3457*7836SJohn.Forte@Sun.COM 	MP_CHAR *mpconf_buf;
3458*7836SJohn.Forte@Sun.COM 	MP_CHAR pluginid[MAX_NAME_SIZE];
3459*7836SJohn.Forte@Sun.COM 	char systemPath[MAX_NAME_SIZE], mpConfFilePath[MAX_NAME_SIZE];
3460*7836SJohn.Forte@Sun.COM 	MP_UINT32   new_file_flag = 0;
3461*7836SJohn.Forte@Sun.COM 	MP_UINT32   sizeof_conf_hdr = strlen(HDR);
3462*7836SJohn.Forte@Sun.COM 	struct stat	stbuf;
3463*7836SJohn.Forte@Sun.COM 
3464*7836SJohn.Forte@Sun.COM 	if ((pPluginId == NULL) || (pFileName == NULL)) {
3465*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3466*7836SJohn.Forte@Sun.COM 	}
3467*7836SJohn.Forte@Sun.COM 
3468*7836SJohn.Forte@Sun.COM 	if (stat(pFileName, &stbuf) != 0) {
3469*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3470*7836SJohn.Forte@Sun.COM 	}
3471*7836SJohn.Forte@Sun.COM 
3472*7836SJohn.Forte@Sun.COM 	if (wcstombs(pluginid, pPluginId, MAX_NAME_SIZE) != wcslen(pPluginId)) {
3473*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3474*7836SJohn.Forte@Sun.COM 	}
3475*7836SJohn.Forte@Sun.COM 
3476*7836SJohn.Forte@Sun.COM 	*fullline = '\0';
3477*7836SJohn.Forte@Sun.COM 	strncpy(fullline, pluginid, MAX_NAME_SIZE);
3478*7836SJohn.Forte@Sun.COM 	/* add tab */
3479*7836SJohn.Forte@Sun.COM 	strncat(fullline, "\t", MAX_LINE_SIZE - strlen(pluginid));
3480*7836SJohn.Forte@Sun.COM 	strncat(fullline, pFileName, MAX_LINE_SIZE - strlen(pluginid) - 1);
3481*7836SJohn.Forte@Sun.COM 	/* add a new line. */
3482*7836SJohn.Forte@Sun.COM 	strncat(fullline, "\n",
3483*7836SJohn.Forte@Sun.COM 	    MAX_LINE_SIZE - strlen(pluginid) - strlen(pFileName) -1);
3484*7836SJohn.Forte@Sun.COM 
3485*7836SJohn.Forte@Sun.COM 	/* Open configuration file from known location */
3486*7836SJohn.Forte@Sun.COM 	strncpy(mpConfFilePath, "/etc/mpapi.conf", MAX_NAME_SIZE);
3487*7836SJohn.Forte@Sun.COM 
3488*7836SJohn.Forte@Sun.COM 	if ((chmod(mpConfFilePath, S_IRUSR|S_IRGRP|S_IROTH) == -1) &&
3489*7836SJohn.Forte@Sun.COM 		(errno == ENOENT))  {
3490*7836SJohn.Forte@Sun.COM 	    new_file_flag = 1;
3491*7836SJohn.Forte@Sun.COM 	}
3492*7836SJohn.Forte@Sun.COM 
3493*7836SJohn.Forte@Sun.COM 	if ((mpconf = open(mpConfFilePath, O_RDWR | O_CREAT)) == -1) {
3494*7836SJohn.Forte@Sun.COM 		return (MP_STATUS_FAILED);
3495*7836SJohn.Forte@Sun.COM 	}
3496*7836SJohn.Forte@Sun.COM 
3497*7836SJohn.Forte@Sun.COM 	if (fchmod(mpconf, S_IRUSR | S_IRGRP | S_IROTH) < 0) {
3498*7836SJohn.Forte@Sun.COM 	    close(mpconf);
3499*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_FAILED);
3500*7836SJohn.Forte@Sun.COM 	}
3501*7836SJohn.Forte@Sun.COM 
3502*7836SJohn.Forte@Sun.COM 	if (lock_register(mpconf, F_SETLKW, F_WRLCK, 0, SEEK_SET, 0) < 0) {
3503*7836SJohn.Forte@Sun.COM 	    close(mpconf);
3504*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_FAILED);
3505*7836SJohn.Forte@Sun.COM 	}
3506*7836SJohn.Forte@Sun.COM 
3507*7836SJohn.Forte@Sun.COM 	if (fstat(mpconf, &stbuf) == -1) {
3508*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3509*7836SJohn.Forte@Sun.COM 	}
3510*7836SJohn.Forte@Sun.COM 
3511*7836SJohn.Forte@Sun.COM 	if ((new_file_flag) || (stbuf.st_size == 0)) {
3512*7836SJohn.Forte@Sun.COM 	    if (write(mpconf, HDR, sizeof_conf_hdr) !=
3513*7836SJohn.Forte@Sun.COM 		sizeof_conf_hdr) {
3514*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3515*7836SJohn.Forte@Sun.COM 	    }
3516*7836SJohn.Forte@Sun.COM 
3517*7836SJohn.Forte@Sun.COM 	    if (pwrite(mpconf, fullline, strlen(fullline),
3518*7836SJohn.Forte@Sun.COM 		sizeof_conf_hdr) !=
3519*7836SJohn.Forte@Sun.COM 		strlen(fullline)) {
3520*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3521*7836SJohn.Forte@Sun.COM 	    }
3522*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_SUCCESS);
3523*7836SJohn.Forte@Sun.COM 	}
3524*7836SJohn.Forte@Sun.COM 
3525*7836SJohn.Forte@Sun.COM 	if ((mpconf_buf = (MP_CHAR *)mmap(0, stbuf.st_size,
3526*7836SJohn.Forte@Sun.COM 		PROT_READ | PROT_WRITE,
3527*7836SJohn.Forte@Sun.COM 		MAP_SHARED, mpconf, 0)) == MAP_FAILED) {
3528*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3529*7836SJohn.Forte@Sun.COM 	}
3530*7836SJohn.Forte@Sun.COM 
3531*7836SJohn.Forte@Sun.COM 	if (search_line(mpconf_buf, stbuf.st_size,
3532*7836SJohn.Forte@Sun.COM 	    pluginid, strlen(pluginid), &write_offset, &bytes_left) == 0) {
3533*7836SJohn.Forte@Sun.COM 	    /* found a match. */
3534*7836SJohn.Forte@Sun.COM 	    munmap((void *)mpconf_buf, stbuf.st_size);
3535*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_SUCCESS);
3536*7836SJohn.Forte@Sun.COM 	} else {
3537*7836SJohn.Forte@Sun.COM 	    munmap((void *)mpconf_buf, stbuf.st_size);
3538*7836SJohn.Forte@Sun.COM 	    /* append the fullline to the mpconf. */
3539*7836SJohn.Forte@Sun.COM 	    if (pwrite(mpconf, fullline, strlen(fullline),
3540*7836SJohn.Forte@Sun.COM 		write_offset) !=
3541*7836SJohn.Forte@Sun.COM 		strlen(fullline)) {
3542*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3543*7836SJohn.Forte@Sun.COM 	    } else {
3544*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_SUCCESS);
3545*7836SJohn.Forte@Sun.COM 	    }
3546*7836SJohn.Forte@Sun.COM 	}
3547*7836SJohn.Forte@Sun.COM }
3548*7836SJohn.Forte@Sun.COM 
3549*7836SJohn.Forte@Sun.COM /**
3550*7836SJohn.Forte@Sun.COM  *******************************************************************************
3551*7836SJohn.Forte@Sun.COM  *
3552*7836SJohn.Forte@Sun.COM  * Deregisters a plugin from the common library.  This routine is based on
3553*7836SJohn.Forte@Sun.COM  * configuration file /etc/mpapi.conf that contains a list of plugin libraries.
3554*7836SJohn.Forte@Sun.COM  *
3555*7836SJohn.Forte@Sun.COM  * @param  pPluginId
3556*7836SJohn.Forte@Sun.COM  *      A pointer to a Plugin ID previously registered using
3557*7836SJohn.Forte@Sun.COM  *      the MP_RegisterPlugin API..
3558*7836SJohn.Forte@Sun.COM  *
3559*7836SJohn.Forte@Sun.COM  * @return An MP_STATUS indicating if the operation was successful or if
3560*7836SJohn.Forte@Sun.COM  *         an error occurred.
3561*7836SJohn.Forte@Sun.COM  *
3562*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_SUCCESS
3563*7836SJohn.Forte@Sun.COM  *         Returned when pPluginId is deregistered successfully.
3564*7836SJohn.Forte@Sun.COM  *
3565*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_INVALID_PARAMETER
3566*7836SJohn.Forte@Sun.COM  *      Returned if pPluginId is NULL or specifies a memory area that
3567*7836SJohn.Forte@Sun.COM  *      is not executable.
3568*7836SJohn.Forte@Sun.COM  *
3569*7836SJohn.Forte@Sun.COM  * @retval MP_STATUS_FAILED
3570*7836SJohn.Forte@Sun.COM  *          Returned if pClientFn deregistration is not possible at this time.
3571*7836SJohn.Forte@Sun.COM  *
3572*7836SJohn.Forte@Sun.COM  *******************************************************************************
3573*7836SJohn.Forte@Sun.COM  */
MP_DeregisterPlugin(MP_WCHAR * pPluginId)3574*7836SJohn.Forte@Sun.COM MP_STATUS MP_DeregisterPlugin(
3575*7836SJohn.Forte@Sun.COM     MP_WCHAR *pPluginId)
3576*7836SJohn.Forte@Sun.COM {
3577*7836SJohn.Forte@Sun.COM 	int mpconf, tmp_mpconf, bytes_left, write_offset;
3578*7836SJohn.Forte@Sun.COM 	char systemPath[MAX_NAME_SIZE], mpConfFilePath[MAX_NAME_SIZE],
3579*7836SJohn.Forte@Sun.COM 	    tmp_mpConfFilePath[MAX_NAME_SIZE + sizeof(pid_t)];
3580*7836SJohn.Forte@Sun.COM 	MP_CHAR    pluginid[MAX_NAME_SIZE];
3581*7836SJohn.Forte@Sun.COM 	MP_CHAR    *mpconf_buf;
3582*7836SJohn.Forte@Sun.COM 	MP_UINT32   sizeof_conf_hdr = strlen(HDR);
3583*7836SJohn.Forte@Sun.COM 	struct stat	stbuf;
3584*7836SJohn.Forte@Sun.COM 
3585*7836SJohn.Forte@Sun.COM 	if (pPluginId == NULL) {
3586*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3587*7836SJohn.Forte@Sun.COM 	}
3588*7836SJohn.Forte@Sun.COM 
3589*7836SJohn.Forte@Sun.COM 	if (wcstombs(pluginid, pPluginId, MAX_NAME_SIZE) != wcslen(pPluginId)) {
3590*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_INVALID_PARAMETER);
3591*7836SJohn.Forte@Sun.COM 	}
3592*7836SJohn.Forte@Sun.COM 
3593*7836SJohn.Forte@Sun.COM 	/* Open configuration file from known location */
3594*7836SJohn.Forte@Sun.COM 	strncpy(mpConfFilePath, "/etc/mpapi.conf", MAX_NAME_SIZE);
3595*7836SJohn.Forte@Sun.COM 
3596*7836SJohn.Forte@Sun.COM 	if ((chmod(mpConfFilePath, S_IRUSR|S_IRGRP|S_IROTH) == -1) &&
3597*7836SJohn.Forte@Sun.COM 		(errno == ENOENT))  {
3598*7836SJohn.Forte@Sun.COM 	    /* no file found */
3599*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_UNKNOWN_FN);
3600*7836SJohn.Forte@Sun.COM 	}
3601*7836SJohn.Forte@Sun.COM 
3602*7836SJohn.Forte@Sun.COM 	if ((mpconf = open(mpConfFilePath, O_RDWR)) == -1) {
3603*7836SJohn.Forte@Sun.COM 		return (MP_STATUS_FAILED);
3604*7836SJohn.Forte@Sun.COM 	}
3605*7836SJohn.Forte@Sun.COM 
3606*7836SJohn.Forte@Sun.COM 	if (fchmod(mpconf, S_IRUSR | S_IRGRP | S_IROTH) < 0) {
3607*7836SJohn.Forte@Sun.COM 	    close(mpconf);
3608*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_FAILED);
3609*7836SJohn.Forte@Sun.COM 	}
3610*7836SJohn.Forte@Sun.COM 
3611*7836SJohn.Forte@Sun.COM 	if (lock_register(mpconf, F_SETLKW, F_WRLCK, 0, SEEK_SET, 0) < 0) {
3612*7836SJohn.Forte@Sun.COM 	    close(mpconf);
3613*7836SJohn.Forte@Sun.COM 	    return (MP_STATUS_FAILED);
3614*7836SJohn.Forte@Sun.COM 	}
3615*7836SJohn.Forte@Sun.COM 
3616*7836SJohn.Forte@Sun.COM 	if (fstat(mpconf, &stbuf) == -1) {
3617*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3618*7836SJohn.Forte@Sun.COM 	}
3619*7836SJohn.Forte@Sun.COM 
3620*7836SJohn.Forte@Sun.COM 	if (stbuf.st_size == 0) {
3621*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_SUCCESS);
3622*7836SJohn.Forte@Sun.COM 	}
3623*7836SJohn.Forte@Sun.COM 
3624*7836SJohn.Forte@Sun.COM 	if ((mpconf_buf = (MP_CHAR *)mmap(0, stbuf.st_size,
3625*7836SJohn.Forte@Sun.COM 		PROT_READ | PROT_WRITE,
3626*7836SJohn.Forte@Sun.COM 		MAP_SHARED, mpconf, 0)) == MAP_FAILED) {
3627*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3628*7836SJohn.Forte@Sun.COM 	}
3629*7836SJohn.Forte@Sun.COM 
3630*7836SJohn.Forte@Sun.COM 	if (search_line(mpconf_buf, stbuf.st_size, pluginid, strlen(pluginid),
3631*7836SJohn.Forte@Sun.COM 		&write_offset, &bytes_left) != 0) {
3632*7836SJohn.Forte@Sun.COM 	    munmap((void *)mpconf_buf, stbuf.st_size);
3633*7836SJohn.Forte@Sun.COM 	    CLEANUP_N_RET(mpconf, MP_STATUS_UNKNOWN_FN);
3634*7836SJohn.Forte@Sun.COM 	} else {
3635*7836SJohn.Forte@Sun.COM 	    /*
3636*7836SJohn.Forte@Sun.COM 	     * found a match.
3637*7836SJohn.Forte@Sun.COM 	     * construct temp file name using pid.
3638*7836SJohn.Forte@Sun.COM 	     */
3639*7836SJohn.Forte@Sun.COM 	    (void) snprintf(tmp_mpConfFilePath, MAX_NAME_SIZE,
3640*7836SJohn.Forte@Sun.COM 		"%s%ld", "/etc/mpapi.conf", getpid());
3641*7836SJohn.Forte@Sun.COM 
3642*7836SJohn.Forte@Sun.COM 	    if ((tmp_mpconf = open(tmp_mpConfFilePath,
3643*7836SJohn.Forte@Sun.COM 		O_RDWR|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
3644*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3645*7836SJohn.Forte@Sun.COM 	    }
3646*7836SJohn.Forte@Sun.COM 
3647*7836SJohn.Forte@Sun.COM 	    if (write(tmp_mpconf, mpconf_buf, write_offset) != write_offset) {
3648*7836SJohn.Forte@Sun.COM 		close(tmp_mpconf);
3649*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3650*7836SJohn.Forte@Sun.COM 	    }
3651*7836SJohn.Forte@Sun.COM 
3652*7836SJohn.Forte@Sun.COM 	    if (pwrite(tmp_mpconf, mpconf_buf + (stbuf.st_size - bytes_left),
3653*7836SJohn.Forte@Sun.COM 		bytes_left, write_offset) != bytes_left) {
3654*7836SJohn.Forte@Sun.COM 		close(tmp_mpconf);
3655*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3656*7836SJohn.Forte@Sun.COM 	    }
3657*7836SJohn.Forte@Sun.COM 
3658*7836SJohn.Forte@Sun.COM 	    close(tmp_mpconf);
3659*7836SJohn.Forte@Sun.COM 	    munmap((void *)mpconf_buf, stbuf.st_size);
3660*7836SJohn.Forte@Sun.COM 
3661*7836SJohn.Forte@Sun.COM 	    /* rename temp file to mpConfFile before unlock and close. */
3662*7836SJohn.Forte@Sun.COM 	    if (rename(tmp_mpConfFilePath, mpConfFilePath) != 0) {
3663*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_FAILED);
3664*7836SJohn.Forte@Sun.COM 	    } else {
3665*7836SJohn.Forte@Sun.COM 		CLEANUP_N_RET(mpconf, MP_STATUS_SUCCESS);
3666*7836SJohn.Forte@Sun.COM 	    }
3667*7836SJohn.Forte@Sun.COM 	}
3668*7836SJohn.Forte@Sun.COM }
3669