4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #define MAX_FORMAT 80 /* for info table */
35 cfga_ib_ret_t
ib_rcm_offline(const char *, char **, char *,
37 cfga_ib_ret_t
ib_rcm_online(const char *, char **, char *,
39 cfga_ib_ret_t
ib_rcm_remove(const char *, char **, char *,
41 static cfga_ib_ret_t
ib_rcm_info_table(rcm_info_t
*, char **);
42 static cfga_ib_ret_t
ib_rcm_init(const char *, cfga_flags_t
, char **,
46 static rcm_handle_t
*rcm_handle
= NULL
;
47 static mutex_t rcm_handle_lock
= DEFAULTMUTEX
;
54 * rsrc - Resource name (typically an ap_id)
55 * errstring - Error message filled in case of a failure
56 * rsrc_fixed - Pointer to fixed path
57 * flags - flags to RCM
61 * CFGA_IB_OK on success or an appropriate error
63 * Offline IB resource consumers.
66 ib_rcm_offline(const char *rsrc
, char **errstring
, char *rsrc_fixed
,
71 rcm_info_t
*rinfo
= NULL
;
72 cfga_ib_ret_t ret
= CFGA_IB_OK
;
74 DPRINTF("ib_rcm_offline:\n");
76 if ((ret
= ib_rcm_init(rsrc
, flags
, errstring
, &rflags
)) !=
81 DPRINTF("ib_rcm_offline: rsrc_fixed: %s\n", rsrc_fixed
);
83 if ((rret
= rcm_request_offline(rcm_handle
, rsrc_fixed
, rflags
, &rinfo
))
85 DPRINTF("ib_rcm_offline: rcm_request_offline failed\n");
88 (void) ib_rcm_info_table(rinfo
, errstring
);
93 DPRINTF("ib_rcm_offline: table = %s\n", *errstring
);
95 if (rret
== RCM_FAILURE
) {
96 (void) ib_rcm_online(rsrc
, errstring
,
99 ret
= CFGA_IB_RCM_OFFLINE_ERR
;
110 * rsrc - Resource name (typically an ap_id)
111 * errstring - Error message filled in case of a failure
112 * rsrc_fixed - Pointer to fixed path
113 * flags - flags to RCM
117 * CFGA_IB_OK on success or an appropriate error
119 * Online IB resource consumers that were previously offlined.
122 ib_rcm_online(const char *rsrc
, char **errstring
, char *rsrc_fixed
,
125 rcm_info_t
*rinfo
= NULL
;
126 cfga_ib_ret_t ret
= CFGA_IB_OK
;
128 DPRINTF("ib_rcm_online:\n");
130 if ((ret
= ib_rcm_init(rsrc
, flags
, errstring
, NULL
)) != CFGA_IB_OK
) {
134 if (rcm_notify_online(rcm_handle
, rsrc_fixed
, 0, &rinfo
) !=
135 RCM_SUCCESS
&& (rinfo
!= NULL
)) {
136 DPRINTF("ib_rcm_online: rcm_notify_online failed\n");
138 (void) ib_rcm_info_table(rinfo
, errstring
);
139 rcm_free_info(rinfo
);
141 ret
= CFGA_IB_RCM_ONLINE_ERR
;
152 * rsrc - Resource name (typically an ap_id)
153 * errstring - Error message filled in case of a failure
154 * rsrc_fixed - Pointer to fixed path
155 * flags - flags to RCM
159 * CFGA_IB_OK on success or an appropriate error
161 * Remove IB resource consumers after their kernel removal.
164 ib_rcm_remove(const char *rsrc
, char **errstring
, char *rsrc_fixed
,
167 rcm_info_t
*rinfo
= NULL
;
168 cfga_ib_ret_t ret
= CFGA_IB_OK
;
170 DPRINTF("ib_rcm_remove:\n");
172 if ((ret
= ib_rcm_init(rsrc
, flags
, errstring
, NULL
)) != CFGA_IB_OK
) {
176 if (rcm_notify_remove(rcm_handle
, rsrc_fixed
, 0, &rinfo
) !=
177 RCM_SUCCESS
&& (rinfo
!= NULL
)) {
178 DPRINTF("ib_rcm_remove: rcm_notify_remove failed\n");
180 (void) ib_rcm_info_table(rinfo
, errstring
);
181 rcm_free_info(rinfo
);
183 ret
= CFGA_IB_RCM_ONLINE_ERR
;
194 * rsrc - Resource name (typically an ap_id)
195 * flags - flags to RCM
196 * errstring - Error message filled in case of a failure
197 * rflags - Flags filled up in case of a failure
201 * CFGA_IB_OK on success or an appropriate error
203 * Contains common initialization code for entering a ib_rcm_xx() routine.
207 ib_rcm_init(const char *rsrc
, cfga_flags_t flags
, char **errstring
,
210 DPRINTF("ib_rcm_init:\n");
212 /* Validate the rsrc argument */
214 DPRINTF("ib_rcm_init: rsrc is NULL\n");
215 return (CFGA_IB_INTERNAL_ERR
);
218 /* Translate the cfgadm flags to RCM flags */
219 if (rflags
&& (flags
& CFGA_FLAG_FORCE
)) {
220 *rflags
|= RCM_FORCE
;
223 /* Get a handle for the RCM operations */
224 (void) mutex_lock(&rcm_handle_lock
);
225 if (rcm_handle
== NULL
) {
226 if (rcm_alloc_handle(NULL
, RCM_NOPID
, NULL
, &rcm_handle
) !=
228 DPRINTF("ib_rcm_init: alloc_handle failed\n");
229 (void) mutex_unlock(&rcm_handle_lock
);
230 return (CFGA_IB_RCM_HANDLE_ERR
);
233 (void) mutex_unlock(&rcm_handle_lock
);
242 * rinfo - Resource information
243 * table - table to be printed
247 * CFGA_IB_OK on success or an appropriate error
249 * Takes an opaque rcm_info_t pointer and a character pointer,
250 * and appends the rcm_info_t data in the form of a table to the
251 * given character pointer.
254 ib_rcm_info_table(rcm_info_t
*rinfo
, char **table
)
261 size_t table_size
= 0;
263 rcm_info_tuple_t
*tuple
= NULL
;
267 static char format
[MAX_FORMAT
];
270 DPRINTF("ib_rcm_info_table:\n");
272 /* Protect against invalid arguments */
273 if (rinfo
== NULL
|| table
== NULL
) {
274 return (CFGA_IB_INTERNAL_ERR
);
277 /* Set localized table header strings */
278 rsrc
= dgettext(TEXT_DOMAIN
, "Resource");
279 info
= dgettext(TEXT_DOMAIN
, "Information");
281 /* A first pass, to size up the RCM information */
282 while (tuple
= rcm_info_next(rinfo
, tuple
)) {
283 if ((infostr
= rcm_info_info(tuple
)) != NULL
) {
285 if ((w
= strlen(rcm_info_rsrc(tuple
))) > w_rsrc
)
287 if ((w
= strlen(infostr
)) > w_info
)
292 /* If nothing was sized up above, stop early */
294 DPRINTF("ib_rcm_info_table: no tuples\n");
298 /* Adjust column widths for column headings */
299 if ((w
= strlen(rsrc
)) > w_rsrc
) {
301 } else if ((w_rsrc
- w
) % 2) {
305 if ((w
= strlen(info
)) > w_info
) {
307 } else if ((w_info
- w
) % 2) {
312 * Compute the total line width of each line,
313 * accounting for intercolumn spacing.
315 width
= w_info
+ w_rsrc
+ 4;
317 /* Allocate space for the table */
318 table_size
= (2 + tuples
) * (width
+ 1) + 2;
319 if (*table
== NULL
) {
320 *table
= malloc(table_size
);
322 newtable
= realloc(*table
, strlen(*table
) + table_size
);
323 if (newtable
!= NULL
)
328 return (CFGA_IB_ALLOC_FAIL
);
332 if (*table
== NULL
) {
333 DPRINTF("ib_rcm_info_table: no table\n");
334 return (CFGA_IB_ALLOC_FAIL
);
337 /* Place a table header into the string */
339 /* The resource header */
340 (void) strlcat(*table
, "\n", sizeof (*table
));
343 for (i
= 0; i
< ((w_rsrc
- w
) / 2); i
++) {
344 (void) strcat(*table
, " ");
346 (void) strlcat(*table
, rsrc
, sizeof (*table
));
348 for (i
= 0; i
< ((w_rsrc
- w
) / 2); i
++) {
349 (void) strcat(*table
, " ");
352 /* The information header */
353 (void) strcat(*table
, " ");
355 for (i
= 0; i
< ((w_info
- w
) / 2); i
++) {
356 (void) strcat(*table
, " ");
358 (void) strlcat(*table
, info
, sizeof (*table
));
360 for (i
= 0; i
< ((w_info
- w
) / 2); i
++) {
361 (void) strcat(*table
, " ");
364 (void) strcat(*table
, "\n");
366 /* Underline the headers */
367 for (i
= 0; i
< w_rsrc
; i
++) {
368 (void) strcat(*table
, "-");
371 (void) strcat(*table
, " ");
372 for (i
= 0; i
< w_info
; i
++) {
373 (void) strcat(*table
, "-");
376 (void) strcat(*table
, "\n");
378 /* Construct the format string */
379 (void) snprintf(format
, MAX_FORMAT
, "%%-%ds %%-%ds",
380 (int)w_rsrc
, (int)w_info
);
382 /* Add the tuples to the table string */
384 while ((tuple
= rcm_info_next(rinfo
, tuple
)) != NULL
) {
385 if ((infostr
= rcm_info_info(tuple
)) != NULL
) {
386 (void) sprintf(&((*table
)[strlen(*table
)]),
387 format
, rcm_info_rsrc(tuple
), infostr
);
388 (void) strcat(*table
, "\n");