xref: /onnv-gate/usr/src/lib/cfgadm_plugins/fp/common/cfga_rcm.c (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  */
25*7836SJohn.Forte@Sun.COM 
26*7836SJohn.Forte@Sun.COM 
27*7836SJohn.Forte@Sun.COM #include "cfga_fp.h"
28*7836SJohn.Forte@Sun.COM 
29*7836SJohn.Forte@Sun.COM static fpcfga_ret_t fp_rcm_init(char *, cfga_flags_t, char **, uint_t *,
30*7836SJohn.Forte@Sun.COM 	char **rsrc_fixed);
31*7836SJohn.Forte@Sun.COM static int fp_rcm_process_node(di_node_t, void *);
32*7836SJohn.Forte@Sun.COM static fpcfga_ret_t fp_rcm_info_table(rcm_info_t *, char **);
33*7836SJohn.Forte@Sun.COM static char *chop_minor(char *);
34*7836SJohn.Forte@Sun.COM 
35*7836SJohn.Forte@Sun.COM #define	MAX_FORMAT	80
36*7836SJohn.Forte@Sun.COM #define	DEVICES		"/devices"
37*7836SJohn.Forte@Sun.COM 
38*7836SJohn.Forte@Sun.COM typedef struct {
39*7836SJohn.Forte@Sun.COM 	char *bus_path;
40*7836SJohn.Forte@Sun.COM 	char *filter;
41*7836SJohn.Forte@Sun.COM 	char **errstring;
42*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret;
43*7836SJohn.Forte@Sun.COM 	cfga_flags_t flags;
44*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t (*func)(char *, char *, char **, cfga_flags_t);
45*7836SJohn.Forte@Sun.COM } walkargs_t;
46*7836SJohn.Forte@Sun.COM 
47*7836SJohn.Forte@Sun.COM static fpcfga_ret_t fp_rcm_info_table(rcm_info_t *, char **);
48*7836SJohn.Forte@Sun.COM static int fp_rcm_process_node(di_node_t, void *);
49*7836SJohn.Forte@Sun.COM static fpcfga_ret_t fp_rcm_init(char *, cfga_flags_t, char **, uint_t *,
50*7836SJohn.Forte@Sun.COM     char **);
51*7836SJohn.Forte@Sun.COM static char *chop_minor(char *);
52*7836SJohn.Forte@Sun.COM 
53*7836SJohn.Forte@Sun.COM static rcm_handle_t *rcm_handle = NULL;
54*7836SJohn.Forte@Sun.COM static mutex_t rcm_handle_lock;
55*7836SJohn.Forte@Sun.COM 
56*7836SJohn.Forte@Sun.COM /*
57*7836SJohn.Forte@Sun.COM  * fp_rcm_offline()
58*7836SJohn.Forte@Sun.COM  *
59*7836SJohn.Forte@Sun.COM  *	Offline FP resource consumers.
60*7836SJohn.Forte@Sun.COM  */
61*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_offline(char * rsrc,char ** errstring,cfga_flags_t flags)62*7836SJohn.Forte@Sun.COM fp_rcm_offline(char *rsrc, char **errstring, cfga_flags_t flags)
63*7836SJohn.Forte@Sun.COM {
64*7836SJohn.Forte@Sun.COM 	int rret;
65*7836SJohn.Forte@Sun.COM 	uint_t rflags = 0;
66*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
67*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
68*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
69*7836SJohn.Forte@Sun.COM 
70*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, flags, errstring, &rflags, &rsrc_fixed))
71*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
72*7836SJohn.Forte@Sun.COM 		return (ret);
73*7836SJohn.Forte@Sun.COM 
74*7836SJohn.Forte@Sun.COM 	if ((rret = rcm_request_offline(rcm_handle, rsrc_fixed, rflags, &rinfo))
75*7836SJohn.Forte@Sun.COM 	    != RCM_SUCCESS) {
76*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_RCM_OFFLINE, rsrc_fixed, 0);
77*7836SJohn.Forte@Sun.COM 		if (rinfo) {
78*7836SJohn.Forte@Sun.COM 			(void) fp_rcm_info_table(rinfo, errstring);
79*7836SJohn.Forte@Sun.COM 			rcm_free_info(rinfo);
80*7836SJohn.Forte@Sun.COM 		}
81*7836SJohn.Forte@Sun.COM 		if (rret == RCM_FAILURE)
82*7836SJohn.Forte@Sun.COM 			(void) fp_rcm_online(rsrc, errstring, flags);
83*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_BUSY;
84*7836SJohn.Forte@Sun.COM 	}
85*7836SJohn.Forte@Sun.COM 
86*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
87*7836SJohn.Forte@Sun.COM 
88*7836SJohn.Forte@Sun.COM 	return (ret);
89*7836SJohn.Forte@Sun.COM }
90*7836SJohn.Forte@Sun.COM 
91*7836SJohn.Forte@Sun.COM /*
92*7836SJohn.Forte@Sun.COM  * fp_rcm_online()
93*7836SJohn.Forte@Sun.COM  *
94*7836SJohn.Forte@Sun.COM  *	Online FP resource consumers that were previously offlined.
95*7836SJohn.Forte@Sun.COM  */
96*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_online(char * rsrc,char ** errstring,cfga_flags_t flags)97*7836SJohn.Forte@Sun.COM fp_rcm_online(char *rsrc, char **errstring, cfga_flags_t flags)
98*7836SJohn.Forte@Sun.COM {
99*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
100*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
101*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
102*7836SJohn.Forte@Sun.COM 
103*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, flags, errstring, NULL, &rsrc_fixed))
104*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
105*7836SJohn.Forte@Sun.COM 		return (ret);
106*7836SJohn.Forte@Sun.COM 
107*7836SJohn.Forte@Sun.COM 	if (rcm_notify_online(rcm_handle, rsrc_fixed, 0, &rinfo)
108*7836SJohn.Forte@Sun.COM 	    != RCM_SUCCESS && rinfo != NULL) {
109*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_RCM_ONLINE, rsrc_fixed, 0);
110*7836SJohn.Forte@Sun.COM 		(void) fp_rcm_info_table(rinfo, errstring);
111*7836SJohn.Forte@Sun.COM 		rcm_free_info(rinfo);
112*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_ERR;
113*7836SJohn.Forte@Sun.COM 	}
114*7836SJohn.Forte@Sun.COM 
115*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
116*7836SJohn.Forte@Sun.COM 
117*7836SJohn.Forte@Sun.COM 	return (ret);
118*7836SJohn.Forte@Sun.COM }
119*7836SJohn.Forte@Sun.COM 
120*7836SJohn.Forte@Sun.COM /*
121*7836SJohn.Forte@Sun.COM  * fp_rcm_remove()
122*7836SJohn.Forte@Sun.COM  *
123*7836SJohn.Forte@Sun.COM  *	Remove FP resource consumers after their kernel removal.
124*7836SJohn.Forte@Sun.COM  */
125*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_remove(char * rsrc,char ** errstring,cfga_flags_t flags)126*7836SJohn.Forte@Sun.COM fp_rcm_remove(char *rsrc, char **errstring, cfga_flags_t flags)
127*7836SJohn.Forte@Sun.COM {
128*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
129*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
130*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
131*7836SJohn.Forte@Sun.COM 
132*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, flags, errstring, NULL, &rsrc_fixed))
133*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
134*7836SJohn.Forte@Sun.COM 		return (ret);
135*7836SJohn.Forte@Sun.COM 
136*7836SJohn.Forte@Sun.COM 	if (rcm_notify_remove(rcm_handle, rsrc_fixed, 0, &rinfo)
137*7836SJohn.Forte@Sun.COM 	    != RCM_SUCCESS) {
138*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_RCM_REMOVE, rsrc_fixed, 0);
139*7836SJohn.Forte@Sun.COM 		if (rinfo) {
140*7836SJohn.Forte@Sun.COM 			(void) fp_rcm_info_table(rinfo, errstring);
141*7836SJohn.Forte@Sun.COM 			rcm_free_info(rinfo);
142*7836SJohn.Forte@Sun.COM 		}
143*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_ERR;
144*7836SJohn.Forte@Sun.COM 	}
145*7836SJohn.Forte@Sun.COM 
146*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
147*7836SJohn.Forte@Sun.COM 
148*7836SJohn.Forte@Sun.COM 	return (ret);
149*7836SJohn.Forte@Sun.COM }
150*7836SJohn.Forte@Sun.COM 
151*7836SJohn.Forte@Sun.COM /*
152*7836SJohn.Forte@Sun.COM  * fp_rcm_suspend()
153*7836SJohn.Forte@Sun.COM  *
154*7836SJohn.Forte@Sun.COM  *	Suspend FP resource consumers before a bus quiesce.
155*7836SJohn.Forte@Sun.COM  */
156*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_suspend(char * rsrc,char * filter,char ** errstring,cfga_flags_t flags)157*7836SJohn.Forte@Sun.COM fp_rcm_suspend(char *rsrc, char *filter, char **errstring, cfga_flags_t flags)
158*7836SJohn.Forte@Sun.COM {
159*7836SJohn.Forte@Sun.COM 	int rret;
160*7836SJohn.Forte@Sun.COM 	uint_t rflags = 0;
161*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
162*7836SJohn.Forte@Sun.COM 	char *filter_fixed;
163*7836SJohn.Forte@Sun.COM 	char *rsrc_devpath;
164*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
165*7836SJohn.Forte@Sun.COM 	di_node_t node;
166*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
167*7836SJohn.Forte@Sun.COM 	walkargs_t walkargs;
168*7836SJohn.Forte@Sun.COM 	timespec_t zerotime = { 0, 0 };
169*7836SJohn.Forte@Sun.COM 
170*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, flags, errstring, &rflags, &rsrc_fixed))
171*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
172*7836SJohn.Forte@Sun.COM 		return (ret);
173*7836SJohn.Forte@Sun.COM 
174*7836SJohn.Forte@Sun.COM 	/* If a filter is provided, ensure that it makes sense */
175*7836SJohn.Forte@Sun.COM 	if (filter != NULL && strstr(filter, rsrc) != filter) {
176*7836SJohn.Forte@Sun.COM 		S_FREE(rsrc_fixed);
177*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERR_APID_INVAL, 0);
178*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
179*7836SJohn.Forte@Sun.COM 	}
180*7836SJohn.Forte@Sun.COM 
181*7836SJohn.Forte@Sun.COM 	/*
182*7836SJohn.Forte@Sun.COM 	 * If no filter is specified: attempt a suspension on the resource,
183*7836SJohn.Forte@Sun.COM 	 * directly.
184*7836SJohn.Forte@Sun.COM 	 */
185*7836SJohn.Forte@Sun.COM 	if (filter == NULL) {
186*7836SJohn.Forte@Sun.COM 		if ((rret = rcm_request_suspend(rcm_handle, rsrc_fixed, rflags,
187*7836SJohn.Forte@Sun.COM 		    &zerotime, &rinfo)) != RCM_SUCCESS) {
188*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERRARG_RCM_SUSPEND, rsrc_fixed,
189*7836SJohn.Forte@Sun.COM 			    0);
190*7836SJohn.Forte@Sun.COM 			if (rinfo) {
191*7836SJohn.Forte@Sun.COM 				(void) fp_rcm_info_table(rinfo, errstring);
192*7836SJohn.Forte@Sun.COM 				rcm_free_info(rinfo);
193*7836SJohn.Forte@Sun.COM 			}
194*7836SJohn.Forte@Sun.COM 			if (rret == RCM_FAILURE)
195*7836SJohn.Forte@Sun.COM 				(void) fp_rcm_resume(rsrc, filter, errstring,
196*7836SJohn.Forte@Sun.COM 				    (flags & (~CFGA_FLAG_FORCE)));
197*7836SJohn.Forte@Sun.COM 			ret = FPCFGA_BUSY;
198*7836SJohn.Forte@Sun.COM 		}
199*7836SJohn.Forte@Sun.COM 		S_FREE(rsrc_fixed);
200*7836SJohn.Forte@Sun.COM 		return (ret);
201*7836SJohn.Forte@Sun.COM 	}
202*7836SJohn.Forte@Sun.COM 
203*7836SJohn.Forte@Sun.COM 	/*
204*7836SJohn.Forte@Sun.COM 	 * If a filter is specified: open the resource with libdevinfo, walk
205*7836SJohn.Forte@Sun.COM 	 * through its nodes, and attempt a suspension of each node that
206*7836SJohn.Forte@Sun.COM 	 * mismatches the filter.
207*7836SJohn.Forte@Sun.COM 	 */
208*7836SJohn.Forte@Sun.COM 
209*7836SJohn.Forte@Sun.COM 	/* Chop off the filter's minor name */
210*7836SJohn.Forte@Sun.COM 	if ((filter_fixed = chop_minor(filter)) == NULL)
211*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
212*7836SJohn.Forte@Sun.COM 
213*7836SJohn.Forte@Sun.COM 	/* get a libdevinfo snapshot of the resource's subtree */
214*7836SJohn.Forte@Sun.COM 	rsrc_devpath = rsrc_fixed;
215*7836SJohn.Forte@Sun.COM 	if (strstr(rsrc_fixed, DEVICES) != NULL)
216*7836SJohn.Forte@Sun.COM 		rsrc_devpath += strlen(DEVICES);
217*7836SJohn.Forte@Sun.COM 	node = di_init(rsrc_devpath, DINFOSUBTREE | DINFOMINOR);
218*7836SJohn.Forte@Sun.COM 	if (node == DI_NODE_NIL) {
219*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_DEVINFO, rsrc_fixed, 0);
220*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_ERR;
221*7836SJohn.Forte@Sun.COM 	}
222*7836SJohn.Forte@Sun.COM 
223*7836SJohn.Forte@Sun.COM 	/* apply the filter, and suspend all resources not filtered out */
224*7836SJohn.Forte@Sun.COM 	if (ret == FPCFGA_OK) {
225*7836SJohn.Forte@Sun.COM 
226*7836SJohn.Forte@Sun.COM 		walkargs.bus_path = rsrc_fixed;
227*7836SJohn.Forte@Sun.COM 		walkargs.filter = filter_fixed;
228*7836SJohn.Forte@Sun.COM 		walkargs.errstring = errstring;
229*7836SJohn.Forte@Sun.COM 		walkargs.ret = FPCFGA_OK;
230*7836SJohn.Forte@Sun.COM 		walkargs.flags = rflags;
231*7836SJohn.Forte@Sun.COM 		walkargs.func = fp_rcm_suspend;
232*7836SJohn.Forte@Sun.COM 
233*7836SJohn.Forte@Sun.COM 		if (di_walk_node(node, 0, &walkargs, fp_rcm_process_node) < 0)
234*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERRARG_DEVINFO, rsrc_fixed, 0);
235*7836SJohn.Forte@Sun.COM 
236*7836SJohn.Forte@Sun.COM 		ret = walkargs.ret;
237*7836SJohn.Forte@Sun.COM 	}
238*7836SJohn.Forte@Sun.COM 
239*7836SJohn.Forte@Sun.COM 	if (node != DI_NODE_NIL)
240*7836SJohn.Forte@Sun.COM 		di_fini(node);
241*7836SJohn.Forte@Sun.COM 
242*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
243*7836SJohn.Forte@Sun.COM 	S_FREE(filter_fixed);
244*7836SJohn.Forte@Sun.COM 
245*7836SJohn.Forte@Sun.COM 	if (ret != FPCFGA_OK)
246*7836SJohn.Forte@Sun.COM 		(void) fp_rcm_resume(rsrc, filter, errstring,
247*7836SJohn.Forte@Sun.COM 		    (flags & (~CFGA_FLAG_FORCE)));
248*7836SJohn.Forte@Sun.COM 
249*7836SJohn.Forte@Sun.COM 	return (ret);
250*7836SJohn.Forte@Sun.COM }
251*7836SJohn.Forte@Sun.COM 
252*7836SJohn.Forte@Sun.COM /*
253*7836SJohn.Forte@Sun.COM  * fp_rcm_resume()
254*7836SJohn.Forte@Sun.COM  *
255*7836SJohn.Forte@Sun.COM  *	Resume FP resource consumers after a bus has been unquiesced.
256*7836SJohn.Forte@Sun.COM  */
257*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_resume(char * rsrc,char * filter,char ** errstring,cfga_flags_t flags)258*7836SJohn.Forte@Sun.COM fp_rcm_resume(char *rsrc, char *filter, char **errstring, cfga_flags_t flags)
259*7836SJohn.Forte@Sun.COM {
260*7836SJohn.Forte@Sun.COM 	uint_t rflags = 0;
261*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
262*7836SJohn.Forte@Sun.COM 	char *filter_fixed;
263*7836SJohn.Forte@Sun.COM 	char *rsrc_devpath;
264*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
265*7836SJohn.Forte@Sun.COM 	di_node_t node;
266*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
267*7836SJohn.Forte@Sun.COM 	walkargs_t walkargs;
268*7836SJohn.Forte@Sun.COM 
269*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, flags, errstring, &rflags, &rsrc_fixed))
270*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
271*7836SJohn.Forte@Sun.COM 		return (ret);
272*7836SJohn.Forte@Sun.COM 
273*7836SJohn.Forte@Sun.COM 	/* If a filter is provided, ensure that it makes sense */
274*7836SJohn.Forte@Sun.COM 	if (filter != NULL && strstr(filter, rsrc) != filter) {
275*7836SJohn.Forte@Sun.COM 		S_FREE(rsrc_fixed);
276*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERR_APID_INVAL, 0);
277*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
278*7836SJohn.Forte@Sun.COM 	}
279*7836SJohn.Forte@Sun.COM 
280*7836SJohn.Forte@Sun.COM 	/*
281*7836SJohn.Forte@Sun.COM 	 * If no filter is specified: resume the resource directly.
282*7836SJohn.Forte@Sun.COM 	 */
283*7836SJohn.Forte@Sun.COM 	if (filter == NULL) {
284*7836SJohn.Forte@Sun.COM 		if (rcm_notify_resume(rcm_handle, rsrc_fixed, rflags, &rinfo)
285*7836SJohn.Forte@Sun.COM 		    != RCM_SUCCESS && rinfo != NULL) {
286*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERRARG_RCM_RESUME, rsrc_fixed,
287*7836SJohn.Forte@Sun.COM 			    0);
288*7836SJohn.Forte@Sun.COM 			(void) fp_rcm_info_table(rinfo, errstring);
289*7836SJohn.Forte@Sun.COM 			rcm_free_info(rinfo);
290*7836SJohn.Forte@Sun.COM 			ret = FPCFGA_BUSY;
291*7836SJohn.Forte@Sun.COM 		}
292*7836SJohn.Forte@Sun.COM 		S_FREE(rsrc_fixed);
293*7836SJohn.Forte@Sun.COM 		return (ret);
294*7836SJohn.Forte@Sun.COM 	}
295*7836SJohn.Forte@Sun.COM 
296*7836SJohn.Forte@Sun.COM 	/*
297*7836SJohn.Forte@Sun.COM 	 * If a filter is specified: open the resource with libdevinfo, walk
298*7836SJohn.Forte@Sun.COM 	 * through its nodes, and resume each of its nodes that mismatches
299*7836SJohn.Forte@Sun.COM 	 * the filter.
300*7836SJohn.Forte@Sun.COM 	 */
301*7836SJohn.Forte@Sun.COM 
302*7836SJohn.Forte@Sun.COM 	/* Chop off the filter's minor name */
303*7836SJohn.Forte@Sun.COM 	if ((filter_fixed = chop_minor(filter)) == NULL)
304*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
305*7836SJohn.Forte@Sun.COM 
306*7836SJohn.Forte@Sun.COM 	/* get a libdevinfo snapshot of the resource's subtree */
307*7836SJohn.Forte@Sun.COM 	rsrc_devpath = rsrc_fixed;
308*7836SJohn.Forte@Sun.COM 	if (strstr(rsrc_fixed, DEVICES) != NULL)
309*7836SJohn.Forte@Sun.COM 		rsrc_devpath += strlen(DEVICES);
310*7836SJohn.Forte@Sun.COM 	node = di_init(rsrc_devpath, DINFOSUBTREE | DINFOMINOR);
311*7836SJohn.Forte@Sun.COM 	if (node == DI_NODE_NIL) {
312*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_DEVINFO, rsrc_fixed, 0);
313*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_ERR;
314*7836SJohn.Forte@Sun.COM 	}
315*7836SJohn.Forte@Sun.COM 
316*7836SJohn.Forte@Sun.COM 	/* apply the filter, and resume all resources not filtered out */
317*7836SJohn.Forte@Sun.COM 	if (ret == FPCFGA_OK) {
318*7836SJohn.Forte@Sun.COM 
319*7836SJohn.Forte@Sun.COM 		walkargs.bus_path = rsrc_fixed;
320*7836SJohn.Forte@Sun.COM 		walkargs.filter = filter_fixed;
321*7836SJohn.Forte@Sun.COM 		walkargs.errstring = errstring;
322*7836SJohn.Forte@Sun.COM 		walkargs.ret = FPCFGA_OK;
323*7836SJohn.Forte@Sun.COM 		walkargs.flags = rflags;
324*7836SJohn.Forte@Sun.COM 		walkargs.func = fp_rcm_resume;
325*7836SJohn.Forte@Sun.COM 
326*7836SJohn.Forte@Sun.COM 		if (di_walk_node(node, 0, &walkargs, fp_rcm_process_node) < 0)
327*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERRARG_DEVINFO, rsrc_fixed, 0);
328*7836SJohn.Forte@Sun.COM 
329*7836SJohn.Forte@Sun.COM 		ret = walkargs.ret;
330*7836SJohn.Forte@Sun.COM 	}
331*7836SJohn.Forte@Sun.COM 
332*7836SJohn.Forte@Sun.COM 	if (node != DI_NODE_NIL)
333*7836SJohn.Forte@Sun.COM 		di_fini(node);
334*7836SJohn.Forte@Sun.COM 
335*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
336*7836SJohn.Forte@Sun.COM 	S_FREE(filter_fixed);
337*7836SJohn.Forte@Sun.COM 
338*7836SJohn.Forte@Sun.COM 	return (ret);
339*7836SJohn.Forte@Sun.COM }
340*7836SJohn.Forte@Sun.COM 
341*7836SJohn.Forte@Sun.COM /*
342*7836SJohn.Forte@Sun.COM  * fp_rcm_info
343*7836SJohn.Forte@Sun.COM  *
344*7836SJohn.Forte@Sun.COM  *	Queries RCM information for resources, and formats it into a table.
345*7836SJohn.Forte@Sun.COM  * The table is appended to the info argument.  If the info argument is a
346*7836SJohn.Forte@Sun.COM  * null pointer, then a new string is malloc'ed.  If the info argument is
347*7836SJohn.Forte@Sun.COM  * not a null pointer, then it is realloc'ed to the required size.
348*7836SJohn.Forte@Sun.COM  */
349*7836SJohn.Forte@Sun.COM fpcfga_ret_t
fp_rcm_info(char * rsrc,char ** errstring,char ** info)350*7836SJohn.Forte@Sun.COM fp_rcm_info(char *rsrc, char **errstring, char **info)
351*7836SJohn.Forte@Sun.COM {
352*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
353*7836SJohn.Forte@Sun.COM 	rcm_info_t *rinfo = NULL;
354*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
355*7836SJohn.Forte@Sun.COM 
356*7836SJohn.Forte@Sun.COM 	if ((ret = fp_rcm_init(rsrc, 0, errstring, NULL, &rsrc_fixed))
357*7836SJohn.Forte@Sun.COM 	    != FPCFGA_OK)
358*7836SJohn.Forte@Sun.COM 		return (ret);
359*7836SJohn.Forte@Sun.COM 
360*7836SJohn.Forte@Sun.COM 	if (info == NULL) {
361*7836SJohn.Forte@Sun.COM 		S_FREE(rsrc_fixed);
362*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
363*7836SJohn.Forte@Sun.COM 	}
364*7836SJohn.Forte@Sun.COM 
365*7836SJohn.Forte@Sun.COM 	if (rcm_get_info(rcm_handle, rsrc_fixed, 0, &rinfo)
366*7836SJohn.Forte@Sun.COM 	    != RCM_SUCCESS) {
367*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERRARG_RCM_INFO, rsrc_fixed, 0);
368*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_ERR;
369*7836SJohn.Forte@Sun.COM 	} else if (rinfo == NULL)
370*7836SJohn.Forte@Sun.COM 		ret = FPCFGA_OK;
371*7836SJohn.Forte@Sun.COM 
372*7836SJohn.Forte@Sun.COM 	if (rinfo) {
373*7836SJohn.Forte@Sun.COM 		if ((ret = fp_rcm_info_table(rinfo, info)) != FPCFGA_OK)
374*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERRARG_RCM_INFO, rsrc_fixed, 0);
375*7836SJohn.Forte@Sun.COM 		rcm_free_info(rinfo);
376*7836SJohn.Forte@Sun.COM 	}
377*7836SJohn.Forte@Sun.COM 
378*7836SJohn.Forte@Sun.COM 	S_FREE(rsrc_fixed);
379*7836SJohn.Forte@Sun.COM 
380*7836SJohn.Forte@Sun.COM 	return (ret);
381*7836SJohn.Forte@Sun.COM }
382*7836SJohn.Forte@Sun.COM 
383*7836SJohn.Forte@Sun.COM /*
384*7836SJohn.Forte@Sun.COM  * fp_rcm_init()
385*7836SJohn.Forte@Sun.COM  *
386*7836SJohn.Forte@Sun.COM  *	Contains common initialization code for entering a fp_rcm_xx()
387*7836SJohn.Forte@Sun.COM  * routine.
388*7836SJohn.Forte@Sun.COM  */
389*7836SJohn.Forte@Sun.COM static fpcfga_ret_t
fp_rcm_init(char * rsrc,cfga_flags_t flags,char ** errstring,uint_t * rflags,char ** rsrc_fixed)390*7836SJohn.Forte@Sun.COM fp_rcm_init(char *rsrc, cfga_flags_t flags, char **errstring, uint_t *rflags,
391*7836SJohn.Forte@Sun.COM 	char **rsrc_fixed)
392*7836SJohn.Forte@Sun.COM {
393*7836SJohn.Forte@Sun.COM 	/* Validate the rsrc argument */
394*7836SJohn.Forte@Sun.COM 	if (rsrc == NULL) {
395*7836SJohn.Forte@Sun.COM 		cfga_err(errstring, 0, ERR_APID_INVAL, 0);
396*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
397*7836SJohn.Forte@Sun.COM 	}
398*7836SJohn.Forte@Sun.COM 
399*7836SJohn.Forte@Sun.COM 	/* Translate the cfgadm flags to RCM flags */
400*7836SJohn.Forte@Sun.COM 	if (rflags && (flags & CFGA_FLAG_FORCE))
401*7836SJohn.Forte@Sun.COM 		*rflags |= RCM_FORCE;
402*7836SJohn.Forte@Sun.COM 
403*7836SJohn.Forte@Sun.COM 	/* Get a handle for the RCM operations */
404*7836SJohn.Forte@Sun.COM 	(void) mutex_lock(&rcm_handle_lock);
405*7836SJohn.Forte@Sun.COM 	if (rcm_handle == NULL) {
406*7836SJohn.Forte@Sun.COM 		if (rcm_alloc_handle(NULL, RCM_NOPID, NULL, &rcm_handle) !=
407*7836SJohn.Forte@Sun.COM 		    RCM_SUCCESS) {
408*7836SJohn.Forte@Sun.COM 			cfga_err(errstring, 0, ERR_RCM_HANDLE, 0);
409*7836SJohn.Forte@Sun.COM 			(void) mutex_unlock(&rcm_handle_lock);
410*7836SJohn.Forte@Sun.COM 			return (FPCFGA_LIB_ERR);
411*7836SJohn.Forte@Sun.COM 		}
412*7836SJohn.Forte@Sun.COM 	}
413*7836SJohn.Forte@Sun.COM 	(void) mutex_unlock(&rcm_handle_lock);
414*7836SJohn.Forte@Sun.COM 
415*7836SJohn.Forte@Sun.COM 	/* Chop off the rsrc's minor, if it has one */
416*7836SJohn.Forte@Sun.COM 	if ((*rsrc_fixed = chop_minor(rsrc)) == NULL)
417*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
418*7836SJohn.Forte@Sun.COM 
419*7836SJohn.Forte@Sun.COM 	return (FPCFGA_OK);
420*7836SJohn.Forte@Sun.COM }
421*7836SJohn.Forte@Sun.COM 
422*7836SJohn.Forte@Sun.COM /*
423*7836SJohn.Forte@Sun.COM  * fp_rcm_process_node
424*7836SJohn.Forte@Sun.COM  *
425*7836SJohn.Forte@Sun.COM  *	Helper routine for fp_rcm_{suspend,resume}.  This is a di_walk_node()
426*7836SJohn.Forte@Sun.COM  * callback that will apply a filter to every node it sees, and either suspend
427*7836SJohn.Forte@Sun.COM  * or resume it if it doesn't match the filter.
428*7836SJohn.Forte@Sun.COM  */
429*7836SJohn.Forte@Sun.COM static int
fp_rcm_process_node(di_node_t node,void * argp)430*7836SJohn.Forte@Sun.COM fp_rcm_process_node(di_node_t node, void *argp)
431*7836SJohn.Forte@Sun.COM {
432*7836SJohn.Forte@Sun.COM 	char *devfs_path;
433*7836SJohn.Forte@Sun.COM 	walkargs_t *walkargs;
434*7836SJohn.Forte@Sun.COM 	fpcfga_ret_t ret = FPCFGA_OK;
435*7836SJohn.Forte@Sun.COM 	char disk_path[MAXPATHLEN];
436*7836SJohn.Forte@Sun.COM 
437*7836SJohn.Forte@Sun.COM 	/* Guard against bad arguments */
438*7836SJohn.Forte@Sun.COM 	if ((walkargs = (walkargs_t *)argp) == NULL)
439*7836SJohn.Forte@Sun.COM 		return (DI_WALK_TERMINATE);
440*7836SJohn.Forte@Sun.COM 	if (walkargs->filter == NULL || walkargs->errstring == NULL) {
441*7836SJohn.Forte@Sun.COM 		walkargs->ret = FPCFGA_ERR;
442*7836SJohn.Forte@Sun.COM 		return (DI_WALK_TERMINATE);
443*7836SJohn.Forte@Sun.COM 	}
444*7836SJohn.Forte@Sun.COM 
445*7836SJohn.Forte@Sun.COM 	/* If the node has no minors, then skip it */
446*7836SJohn.Forte@Sun.COM 	if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL)
447*7836SJohn.Forte@Sun.COM 		return (DI_WALK_CONTINUE);
448*7836SJohn.Forte@Sun.COM 
449*7836SJohn.Forte@Sun.COM 	/* Construct the devices path */
450*7836SJohn.Forte@Sun.COM 	if ((devfs_path = di_devfs_path(node)) == NULL)
451*7836SJohn.Forte@Sun.COM 		return (DI_WALK_CONTINUE);
452*7836SJohn.Forte@Sun.COM 	(void) snprintf(disk_path, MAXPATHLEN, "%s%s", DEVICES, devfs_path);
453*7836SJohn.Forte@Sun.COM 	di_devfs_path_free(devfs_path);
454*7836SJohn.Forte@Sun.COM 
455*7836SJohn.Forte@Sun.COM 	/*
456*7836SJohn.Forte@Sun.COM 	 * If the node does not correspond to the targeted FP bus or the
457*7836SJohn.Forte@Sun.COM 	 * disk being filtered out, then use the appropriate suspend/resume
458*7836SJohn.Forte@Sun.COM 	 * function.
459*7836SJohn.Forte@Sun.COM 	 */
460*7836SJohn.Forte@Sun.COM 	if (strcmp(disk_path, walkargs->bus_path) != 0 &&
461*7836SJohn.Forte@Sun.COM 	    strcmp(disk_path, walkargs->filter) != 0)
462*7836SJohn.Forte@Sun.COM 		ret = (*walkargs->func)(disk_path, NULL, walkargs->errstring,
463*7836SJohn.Forte@Sun.COM 		    walkargs->flags);
464*7836SJohn.Forte@Sun.COM 
465*7836SJohn.Forte@Sun.COM 	/* Stop the walk early if the above operation failed */
466*7836SJohn.Forte@Sun.COM 	if (ret != FPCFGA_OK) {
467*7836SJohn.Forte@Sun.COM 		walkargs->ret = ret;
468*7836SJohn.Forte@Sun.COM 		return (DI_WALK_TERMINATE);
469*7836SJohn.Forte@Sun.COM 	}
470*7836SJohn.Forte@Sun.COM 
471*7836SJohn.Forte@Sun.COM 	return (DI_WALK_CONTINUE);
472*7836SJohn.Forte@Sun.COM }
473*7836SJohn.Forte@Sun.COM 
474*7836SJohn.Forte@Sun.COM /*
475*7836SJohn.Forte@Sun.COM  * fp_rcm_info_table
476*7836SJohn.Forte@Sun.COM  *
477*7836SJohn.Forte@Sun.COM  *	Takes an opaque rcm_info_t pointer and a character pointer, and appends
478*7836SJohn.Forte@Sun.COM  * the rcm_info_t data in the form of a table to the given character pointer.
479*7836SJohn.Forte@Sun.COM  */
480*7836SJohn.Forte@Sun.COM static fpcfga_ret_t
fp_rcm_info_table(rcm_info_t * rinfo,char ** table)481*7836SJohn.Forte@Sun.COM fp_rcm_info_table(rcm_info_t *rinfo, char **table)
482*7836SJohn.Forte@Sun.COM {
483*7836SJohn.Forte@Sun.COM 	int i;
484*7836SJohn.Forte@Sun.COM 	size_t w;
485*7836SJohn.Forte@Sun.COM 	size_t width = 0;
486*7836SJohn.Forte@Sun.COM 	size_t w_rsrc = 0;
487*7836SJohn.Forte@Sun.COM 	size_t w_info = 0;
488*7836SJohn.Forte@Sun.COM 	size_t table_size = 0;
489*7836SJohn.Forte@Sun.COM 	uint_t tuples = 0;
490*7836SJohn.Forte@Sun.COM 	rcm_info_tuple_t *tuple = NULL;
491*7836SJohn.Forte@Sun.COM 	char *rsrc;
492*7836SJohn.Forte@Sun.COM 	char *info;
493*7836SJohn.Forte@Sun.COM 	char *newtable;
494*7836SJohn.Forte@Sun.COM 	static char format[MAX_FORMAT];
495*7836SJohn.Forte@Sun.COM 	const char *info_info_str, *info_rsrc_str;
496*7836SJohn.Forte@Sun.COM 
497*7836SJohn.Forte@Sun.COM 	/* Protect against invalid arguments */
498*7836SJohn.Forte@Sun.COM 	if (rinfo == NULL || table == NULL)
499*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
500*7836SJohn.Forte@Sun.COM 
501*7836SJohn.Forte@Sun.COM 	/* Set localized table header strings */
502*7836SJohn.Forte@Sun.COM 	rsrc = gettext("Resource");
503*7836SJohn.Forte@Sun.COM 	info = gettext("Information");
504*7836SJohn.Forte@Sun.COM 
505*7836SJohn.Forte@Sun.COM 	/* A first pass, to size up the RCM information */
506*7836SJohn.Forte@Sun.COM 	while (tuple = rcm_info_next(rinfo, tuple)) {
507*7836SJohn.Forte@Sun.COM 		info_info_str = rcm_info_info(tuple);
508*7836SJohn.Forte@Sun.COM 		info_rsrc_str = rcm_info_rsrc(tuple);
509*7836SJohn.Forte@Sun.COM 		if ((info_info_str != NULL) && (info_rsrc_str != NULL)) {
510*7836SJohn.Forte@Sun.COM 			tuples++;
511*7836SJohn.Forte@Sun.COM 			if ((w = strlen(info_rsrc_str)) > w_rsrc)
512*7836SJohn.Forte@Sun.COM 				w_rsrc = w;
513*7836SJohn.Forte@Sun.COM 			if ((w = strlen(info_info_str)) > w_info)
514*7836SJohn.Forte@Sun.COM 				w_info = w;
515*7836SJohn.Forte@Sun.COM 		}
516*7836SJohn.Forte@Sun.COM 	}
517*7836SJohn.Forte@Sun.COM 
518*7836SJohn.Forte@Sun.COM 	/* If nothing was sized up above, stop early */
519*7836SJohn.Forte@Sun.COM 	if (tuples == 0)
520*7836SJohn.Forte@Sun.COM 		return (FPCFGA_OK);
521*7836SJohn.Forte@Sun.COM 
522*7836SJohn.Forte@Sun.COM 	/* Adjust column widths for column headings */
523*7836SJohn.Forte@Sun.COM 	if ((w = strlen(rsrc)) > w_rsrc)
524*7836SJohn.Forte@Sun.COM 		w_rsrc = w;
525*7836SJohn.Forte@Sun.COM 	else if ((w_rsrc - w) % 2)
526*7836SJohn.Forte@Sun.COM 		w_rsrc++;
527*7836SJohn.Forte@Sun.COM 	if ((w = strlen(info)) > w_info)
528*7836SJohn.Forte@Sun.COM 		w_info = w;
529*7836SJohn.Forte@Sun.COM 	else if ((w_info - w) % 2)
530*7836SJohn.Forte@Sun.COM 		w_info++;
531*7836SJohn.Forte@Sun.COM 
532*7836SJohn.Forte@Sun.COM 	/*
533*7836SJohn.Forte@Sun.COM 	 * Compute the total line width of each line,
534*7836SJohn.Forte@Sun.COM 	 * accounting for intercolumn spacing.
535*7836SJohn.Forte@Sun.COM 	 */
536*7836SJohn.Forte@Sun.COM 	width = w_info + w_rsrc + 4;
537*7836SJohn.Forte@Sun.COM 
538*7836SJohn.Forte@Sun.COM 	/* Allocate space for the table */
539*7836SJohn.Forte@Sun.COM 	table_size = (2 + tuples) * (width + 1) + 2;
540*7836SJohn.Forte@Sun.COM 	if (*table == NULL)
541*7836SJohn.Forte@Sun.COM 		*table = malloc(table_size);
542*7836SJohn.Forte@Sun.COM 	else {
543*7836SJohn.Forte@Sun.COM 		newtable = realloc(*table, strlen(*table) + table_size);
544*7836SJohn.Forte@Sun.COM 		if (newtable != NULL)
545*7836SJohn.Forte@Sun.COM 			*table = newtable;
546*7836SJohn.Forte@Sun.COM 	}
547*7836SJohn.Forte@Sun.COM 	if (*table == NULL)
548*7836SJohn.Forte@Sun.COM 		return (FPCFGA_ERR);
549*7836SJohn.Forte@Sun.COM 
550*7836SJohn.Forte@Sun.COM 	/* Place a table header into the string */
551*7836SJohn.Forte@Sun.COM 
552*7836SJohn.Forte@Sun.COM 	/* The resource header */
553*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, "\n");
554*7836SJohn.Forte@Sun.COM 	w = strlen(rsrc);
555*7836SJohn.Forte@Sun.COM 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
556*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, " ");
557*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, rsrc);
558*7836SJohn.Forte@Sun.COM 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
559*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, " ");
560*7836SJohn.Forte@Sun.COM 
561*7836SJohn.Forte@Sun.COM 	/* The information header */
562*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, "  ");
563*7836SJohn.Forte@Sun.COM 	w = strlen(info);
564*7836SJohn.Forte@Sun.COM 	for (i = 0; i < ((w_info - w) / 2); i++)
565*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, " ");
566*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, info);
567*7836SJohn.Forte@Sun.COM 	for (i = 0; i < ((w_info - w) / 2); i++)
568*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, " ");
569*7836SJohn.Forte@Sun.COM 
570*7836SJohn.Forte@Sun.COM 	/* Underline the headers */
571*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, "\n");
572*7836SJohn.Forte@Sun.COM 	for (i = 0; i < w_rsrc; i++)
573*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, "-");
574*7836SJohn.Forte@Sun.COM 	(void) strcat(*table, "  ");
575*7836SJohn.Forte@Sun.COM 	for (i = 0; i < w_info; i++)
576*7836SJohn.Forte@Sun.COM 		(void) strcat(*table, "-");
577*7836SJohn.Forte@Sun.COM 
578*7836SJohn.Forte@Sun.COM 	/* Construct the format string */
579*7836SJohn.Forte@Sun.COM 	(void) snprintf(format, MAX_FORMAT, "%%-%ds  %%-%ds", w_rsrc, w_info);
580*7836SJohn.Forte@Sun.COM 
581*7836SJohn.Forte@Sun.COM 	/* Add the tuples to the table string */
582*7836SJohn.Forte@Sun.COM 	tuple = NULL;
583*7836SJohn.Forte@Sun.COM 	while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
584*7836SJohn.Forte@Sun.COM 		info_info_str = rcm_info_info(tuple);
585*7836SJohn.Forte@Sun.COM 		info_rsrc_str = rcm_info_rsrc(tuple);
586*7836SJohn.Forte@Sun.COM 		if ((info_info_str != NULL) && (info_rsrc_str != NULL)) {
587*7836SJohn.Forte@Sun.COM 			(void) strcat(*table, "\n");
588*7836SJohn.Forte@Sun.COM 			(void) sprintf(&((*table)[strlen(*table)]),
589*7836SJohn.Forte@Sun.COM 			    format, info_rsrc_str, info_info_str);
590*7836SJohn.Forte@Sun.COM 		}
591*7836SJohn.Forte@Sun.COM 	}
592*7836SJohn.Forte@Sun.COM 
593*7836SJohn.Forte@Sun.COM 	return (FPCFGA_OK);
594*7836SJohn.Forte@Sun.COM }
595*7836SJohn.Forte@Sun.COM 
596*7836SJohn.Forte@Sun.COM /*
597*7836SJohn.Forte@Sun.COM  * chop_minor()
598*7836SJohn.Forte@Sun.COM  *
599*7836SJohn.Forte@Sun.COM  *	Chops off the minor name portion of a resource.  Allocates storage for
600*7836SJohn.Forte@Sun.COM  * the returned string.  Caller must free the storage if return is non-NULL.
601*7836SJohn.Forte@Sun.COM  */
602*7836SJohn.Forte@Sun.COM static char *
chop_minor(char * rsrc)603*7836SJohn.Forte@Sun.COM chop_minor(char *rsrc)
604*7836SJohn.Forte@Sun.COM {
605*7836SJohn.Forte@Sun.COM 	char *rsrc_fixed;
606*7836SJohn.Forte@Sun.COM 	char *cp;
607*7836SJohn.Forte@Sun.COM 
608*7836SJohn.Forte@Sun.COM 	if ((rsrc_fixed = strdup(rsrc)) == NULL)
609*7836SJohn.Forte@Sun.COM 		return (NULL);
610*7836SJohn.Forte@Sun.COM 	if ((cp = strrchr(rsrc_fixed, ':')) != NULL)
611*7836SJohn.Forte@Sun.COM 		*cp = '\0';
612*7836SJohn.Forte@Sun.COM 	return (rsrc_fixed);
613*7836SJohn.Forte@Sun.COM }
614