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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
32 #include "isns_server.h"
39 extern uint64_t esi_threshold
;
40 extern uint8_t mgmt_scn
;
41 extern ctrl_node_t
*control_nodes
;
42 extern pthread_mutex_t ctrl_node_mtx
;
43 extern char data_store
[MAXPATHLEN
];
45 #define DEFAULT_ESI_THRESHOLD 3
46 #define MAX_ESI_THRESHOLD 10
49 * load_config loads config data through SMF.
50 * arg DATA_STORE_UPDATE indicates whether the data store location
51 * can be updated or not.
54 load_config(boolean_t DATA_STORE_UPDATE
)
59 scf_handle_t
*handle
= NULL
;
60 scf_scope_t
*sc
= NULL
;
61 scf_service_t
*svc
= NULL
;
62 scf_propertygroup_t
*pg
= NULL
;
63 scf_property_t
*prop
= NULL
;
64 scf_value_t
*value
= NULL
;
65 scf_iter_t
*value_iter
= NULL
;
67 ctrl_node_t
*ctrl_node_p
;
68 char scf_name
[MAXNAMELEN
];
71 /* connect to the current SMF global repository */
72 handle
= scf_handle_create(SCF_VERSION
);
74 /* allocate scf resources */
75 sc
= scf_scope_create(handle
);
76 svc
= scf_service_create(handle
);
77 pg
= scf_pg_create(handle
);
78 prop
= scf_property_create(handle
);
79 value
= scf_value_create(handle
);
80 value_iter
= scf_iter_create(handle
);
82 /* if failed to allocate resources, exit */
83 if (handle
== NULL
|| sc
== NULL
|| svc
== NULL
|| pg
== NULL
||
84 prop
== NULL
|| value
== NULL
|| value_iter
== NULL
) {
85 isnslog(LOG_DEBUG
, "load_config",
86 "scf handles allocation failed.");
90 /* bind scf handle to the running svc.configd daemon */
91 if (scf_handle_bind(handle
) == -1) {
92 isnslog(LOG_DEBUG
, "load_config", "scf binding failed.");
96 /* get the scope of the localhost in the current repository */
97 if (scf_handle_get_scope(handle
, SCF_SCOPE_LOCAL
, sc
) == -1) {
98 isnslog(LOG_DEBUG
, "load_config", "Getting scf scope failed.");
102 /* get the service "network/isns_server" within the scope */
103 if (scf_scope_get_service(sc
, ISNS_SERVER_SVC_NAME
, svc
) == -1) {
104 isnslog(LOG_DEBUG
, "load_config", "Getting %s service failed.",
105 ISNS_SERVER_SVC_NAME
);
109 /* get the property group "config" within the given service */
110 if (scf_service_get_pg(svc
, ISNS_SERVER_CONFIG
, pg
) == -1) {
111 isnslog(LOG_DEBUG
, "load_config",
112 "Getting property group %s failed.",
118 * Now get the properties.
120 if (scf_pg_get_property(pg
, CONFIG_ESI_THRESHOLD
, prop
) == -1) {
121 isnslog(LOG_DEBUG
, "load_config", "Getting property %s failed",
122 CONFIG_ESI_THRESHOLD
);
126 if (scf_property_get_value(prop
, value
) == -1) {
127 isnslog(LOG_DEBUG
, "load_config",
128 "Getting property value for %s failed.",
129 CONFIG_ESI_THRESHOLD
);
133 if (scf_value_get_count(value
, &esi_threshold
) == -1) {
134 isnslog(LOG_DEBUG
, "load_config",
135 "Getting property integer value for %s failed.",
136 CONFIG_ESI_THRESHOLD
);
140 /* the range of ESI Threshold is [1, 10] */
141 if (esi_threshold
< 1) {
142 esi_threshold
= DEFAULT_ESI_THRESHOLD
; /* 3 */
143 } else if (esi_threshold
> MAX_ESI_THRESHOLD
) {
144 esi_threshold
= MAX_ESI_THRESHOLD
; /* 10 */
147 isnslog(LOG_DEBUG
, "load_config",
148 "%s set to %d", CONFIG_ESI_THRESHOLD
, esi_threshold
);
150 if (scf_pg_get_property(pg
, CONFIG_MGMT_SCN
, prop
) == -1) {
151 isnslog(LOG_DEBUG
, "load_config",
152 "Getting scf property %s failed.", CONFIG_MGMT_SCN
);
156 if (scf_property_get_value(prop
, value
) == -1) {
157 isnslog(LOG_DEBUG
, "load_config",
158 "Getting property value for %s failed.",
163 if (scf_value_get_boolean(value
, &mgmt_scn
) == -1) {
164 isnslog(LOG_DEBUG
, "load_config",
165 "Getting boolean value for property %s failed",
169 isnslog(LOG_DEBUG
, "load_config",
170 "%s set to %s", CONFIG_MGMT_SCN
,
171 mgmt_scn
? "true" : "false");
173 if (DATA_STORE_UPDATE
) {
174 if (scf_pg_get_property(pg
, CONFIG_DATA_STORE
, prop
) == -1) {
175 isnslog(LOG_DEBUG
, "load_config", "Getting property %s failed",
180 if (scf_property_get_value(prop
, value
) == -1) {
181 isnslog(LOG_DEBUG
, "load_config",
182 "Getting property value for %s failed",
188 if (scf_value_get_astring(value
, data_store
, MAXPATHLEN
) == -1) {
189 isnslog(LOG_DEBUG
, "load_config",
190 "Getting property string value for %s failed",
194 isnslog(LOG_DEBUG
, "load_config",
195 "%s set to %s", CONFIG_DATA_STORE
, data_store
);
198 if (scf_pg_get_property(pg
, CONFIG_CONTROL_NODES
, prop
) == -1) {
199 isnslog(LOG_DEBUG
, "load_config", "Getting property %s failed",
200 CONFIG_CONTROL_NODES
);
204 if (scf_iter_property_values(value_iter
, prop
) == -1) {
205 isnslog(LOG_DEBUG
, "load_config",
206 "Getting iteration property %s failed",
207 CONFIG_CONTROL_NODES
);
211 /* remove any old control node first. */
212 (void) pthread_mutex_lock(&ctrl_node_mtx
);
213 while (control_nodes
!= NULL
) {
214 ctrl_node_p
= control_nodes
->next
;
215 free(control_nodes
->name
);
217 control_nodes
= ctrl_node_p
;
220 while (scf_iter_next_value(value_iter
, value
) != 0) {
221 if (scf_value_get_ustring(value
, scf_name
, MAXNAMELEN
) == -1) {
222 isnslog(LOG_DEBUG
, "load_config",
223 "Getting property string value for %s failed",
224 CONFIG_CONTROL_NODES
);
225 (void) pthread_mutex_unlock(&ctrl_node_mtx
);
228 ctrl_node_p
= (ctrl_node_t
*)malloc(sizeof (ctrl_node_t
));
229 if (ctrl_node_p
== NULL
) {
230 isnslog(LOG_DEBUG
, "load_config", "malloc() failed.");
231 (void) pthread_mutex_unlock(&ctrl_node_mtx
);
234 if (strlen(scf_name
) != 0) {
235 name
= (char *)malloc(strlen(scf_name
) + 1);
238 isnslog(LOG_DEBUG
, "load_config", "malloc() failed.");
239 (void) pthread_mutex_unlock(&ctrl_node_mtx
);
242 (void) strcpy(name
, scf_name
);
243 ctrl_node_p
->name
= (uchar_t
*)name
;
244 ctrl_node_p
->next
= control_nodes
;
245 control_nodes
= ctrl_node_p
;
247 isnslog(LOG_DEBUG
, "load_config",
248 "%s set to %s", CONFIG_CONTROL_NODES
, scf_name
);
253 (void) pthread_mutex_unlock(&ctrl_node_mtx
);
255 isnslog(LOG_DEBUG
, "load_config", "loading server settings ok.");
260 /* destroy scf pointers */
262 scf_value_destroy(value
);
264 if (value_iter
!= NULL
) {
265 scf_iter_destroy(value_iter
);
268 scf_property_destroy(prop
);
274 scf_service_destroy(svc
);
277 scf_scope_destroy(sc
);
279 if (handle
!= NULL
) {
280 scf_handle_destroy(handle
);
287 * is_control_node checks the given name to see if it is a control node.
296 (void) pthread_mutex_lock(&ctrl_node_mtx
);
299 if (strcmp((char *)p
->name
, (char *)name
) == 0) {
300 (void) pthread_mutex_unlock(&ctrl_node_mtx
);
305 (void) pthread_mutex_unlock(&ctrl_node_mtx
);