xref: /illumos-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_RegForObjPropChangesPlugin.c (revision cd3e933325e68e23516a196a8fea7f49b1e497c3)
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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include "mp_utils.h"
26 
27 
28 /*
29  *	Called by the common layer to request the plugin to call
30  *	a client application's callback (pClientFn) when a property change
31  *	is detected for the given object type.
32  */
33 
34 MP_STATUS
35 MP_RegisterForObjectPropertyChangesPlugin(MP_OBJECT_PROPERTY_FN pClientFn,
36 		MP_OBJECT_TYPE objectType,
37 		void *pCallerData)
38 {
39 	MP_BOOL hasFunc = MP_FALSE;
40 
41 
42 	log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
43 	    " - enter");
44 
45 
46 	/* Validate the object type passes in within range */
47 	if (objectType > MP_OBJECT_TYPE_MAX) {
48 
49 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
50 		    " - objectType is invalid");
51 
52 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
53 		    " - error exit");
54 
55 		return (MP_STATUS_INVALID_PARAMETER);
56 	}
57 
58 	if (objectType < 1) {
59 
60 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
61 		    " - objectType is invalid");
62 
63 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
64 		    " - error exit");
65 
66 		return (MP_STATUS_INVALID_PARAMETER);
67 	}
68 
69 	/* Init sysevents if they have not been initialized yet */
70 	if (g_SysEventHandle == NULL) {
71 		if (init_sysevents() != MP_STATUS_SUCCESS)
72 			return (MP_STATUS_FAILED);
73 	}
74 
75 	/* Check to see if we are going to be replacing */
76 	(void) pthread_mutex_lock(&g_prop_mutex);
77 	if (g_Property_Callback_List[objectType].pClientFn != NULL) {
78 
79 		hasFunc = MP_TRUE;
80 	}
81 
82 	/* Add the registration */
83 	g_Property_Callback_List[objectType].pClientFn   = pClientFn;
84 	g_Property_Callback_List[objectType].pCallerData = pCallerData;
85 	(void) pthread_mutex_unlock(&g_prop_mutex);
86 
87 	if (hasFunc) {
88 
89 		log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
90 		    " - returning MP_STATUS_FN_REPLACED");
91 
92 		return (MP_STATUS_FN_REPLACED);
93 	}
94 
95 
96 	log(LOG_INFO, "MP_RegisterForObjectPropertyChangesPlugin()",
97 	    " - exit");
98 
99 	return (MP_STATUS_SUCCESS);
100 }
101