xref: /titanic_41/usr/src/lib/mpapi/libmpscsi_vhci/common/Initialize.c (revision 5fbb41393be5d63f75952b1d72d4df2642d22557)
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 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 
31 #include "mp_utils.h"
32 
33 
34 /*
35  *	Global Variables
36  */
37 
38 MP_UINT32	g_pluginOwnerID = 0;
39 int		g_scsi_vhci_fd  = -1;
40 
41 PROPERTY_CALLBACK_NODE   g_Property_Callback_List[MP_OBJECT_TYPE_MAX + 1];
42 VISIBILITY_CALLBACK_NODE g_Visibility_Callback_List[MP_OBJECT_TYPE_MAX + 1];
43 
44 sysevent_handle_t *g_SysEventHandle = NULL;
45 
46 pthread_mutex_t g_visa_mutex = PTHREAD_MUTEX_INITIALIZER;
47 pthread_mutex_t g_prop_mutex = PTHREAD_MUTEX_INITIALIZER;
48 
49 /*
50  *	Called by the common layer to request the plugin to initialize
51  *	itself.
52  */
53 
54 MP_STATUS
55 Initialize(MP_UINT32 pluginOwnerID)
56 {
57 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
58 
59 
60 	log(LOG_INFO, "Initialize()", " - enter");
61 
62 
63 	(void) memset(&g_Property_Callback_List, 0,
64 		sizeof (PROPERTY_CALLBACK_NODE) * (MP_OBJECT_TYPE_MAX + 1));
65 
66 	(void) memset(&g_Visibility_Callback_List, 0,
67 		sizeof (VISIBILITY_CALLBACK_NODE) * (MP_OBJECT_TYPE_MAX + 1));
68 
69 	/* Attempt to open the driver that this plugin will make request of. */
70 	g_scsi_vhci_fd = open("/devices/scsi_vhci:devctl",
71 	    O_NDELAY | O_RDONLY);
72 
73 	if (g_scsi_vhci_fd < 0) {
74 		log(LOG_INFO, "Initialize()",
75 		    " - failed to open driver.  error is : %s",
76 		    strerror(errno));
77 		log(LOG_INFO, "Initialize()", " - error exit");
78 	    return (MP_STATUS_FAILED);
79 	}
80 
81 	g_pluginOwnerID = pluginOwnerID;
82 
83 	/* Register to listen for visibility and property change events */
84 	mpStatus = init_sysevents();
85 
86 	log(LOG_INFO, "Initialize()",
87 	    " - init_sysevents() returned %d",
88 	    mpStatus);
89 
90 
91 	log(LOG_INFO, "Initialize()", " - exit");
92 
93 	return (mpStatus);
94 }
95