xref: /illumos-gate/usr/src/lib/mpapi/libmpapi/common/mpapi-sun.c (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Description
28  * mpapi-sun.c - Implements the Sun Extension to the Multipath Management
29  * API Version 1.0
30  */
31 
32 #include <dlfcn.h>
33 #include <pthread.h>
34 #include "mpapi.h"
35 #include "mpapi-sun.h"
36 #include "mpapi-plugin.h"
37 
38 extern MPPLUGININFO_T plugintable[MP_MAX_NUM_PLUGINS];
39 
40 extern pthread_mutex_t mp_lib_mutex;
41 extern MP_STATUS validate_object(MP_OID obj, MP_OBJECT_TYPE objType,
42 		MP_UINT32 flag);
43 
44 MP_STATUS Sun_MP_SendScsiCmd(
45 	MP_OID pathOid, struct uscsi_cmd *cmd)
46 {
47 	Sun_MP_SendScsiCmdFn PassFunc;
48 	MP_UINT32 index;
49 	MP_STATUS status;
50 
51 	if ((status = validate_object(pathOid, MP_OBJECT_TYPE_PATH_LU,
52 	    MP_OBJECT_TYPE_MATCH)) != MP_STATUS_SUCCESS) {
53 	    return (status);
54 	}
55 
56 	(void) pthread_mutex_lock(&mp_lib_mutex);
57 
58 	index = pathOid.ownerId - 1;
59 	if (plugintable[index].hdlPlugin != NULL) {
60 	    PassFunc = (Sun_MP_SendScsiCmdFn)
61 	    dlsym(plugintable[index].hdlPlugin,
62 	    "Sun_MP_SendScsiCmd");
63 
64 	    if (PassFunc != NULL) {
65 		status = PassFunc(pathOid, cmd);
66 	    } else {
67 		status = MP_STATUS_UNSUPPORTED;
68 	    }
69 	} else {
70 	    status = MP_STATUS_FAILED;
71 	}
72 
73 	(void) pthread_mutex_unlock(&mp_lib_mutex);
74 	return (status);
75 }
76