8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / cfgadm_plugins / scsi / common / cfga_scsi.c
blobc11f48165fac4b0946199902ca9bc57e11c95e5f
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include "cfga_scsi.h"
29 * This file contains the entry points to the plug-in as defined in the
30 * config_admin(3X) man page.
34 * Set the version number
36 int cfga_version = CFGA_HSL_V2;
39 * For debugging - higher values increase verbosity
41 int _scfga_debug = 0;
43 #pragma init(_cfgadm_scsi_init)
45 static void
46 _cfgadm_scsi_init()
48 char *tstr;
50 if (tstr = getenv("SCFGA_DEBUG")) {
51 _scfga_debug = atoi(tstr);
55 /*ARGSUSED*/
56 cfga_err_t
57 cfga_change_state(
58 cfga_cmd_t state_change_cmd,
59 const char *ap_id,
60 const char *options,
61 struct cfga_confirm *confp,
62 struct cfga_msg *msgp,
63 char **errstring,
64 cfga_flags_t flags)
66 apid_t apidt = {NULL};
67 scfga_ret_t ret;
69 if (errstring != NULL) {
70 *errstring = NULL;
74 * All sub-commands which can change state of device require
75 * root privileges.
77 if (geteuid() != 0) {
78 return (CFGA_PRIV);
81 if (options != NULL && strcmp(options, OPT_DISABLE_RCM) != 0) {
82 cfga_err(errstring, 0, ERRARG_OPT_INVAL, options, 0);
83 return (CFGA_ERROR);
86 if ((ret = apidt_create(ap_id, &apidt, errstring)) != SCFGA_OK) {
87 return (err_cvt(ret));
90 if (options != NULL)
91 apidt.flags |= FLAG_DISABLE_RCM;
93 /* A dynamic component indicates a device, else it is the bus */
94 if (apidt.dyncomp != NULL) {
95 ret = dev_change_state(state_change_cmd, &apidt, flags,
96 errstring);
97 } else {
98 ret = bus_change_state(state_change_cmd, &apidt, confp, flags,
99 errstring);
102 apidt_free(&apidt);
103 return (err_cvt(ret));
106 /*ARGSUSED*/
107 cfga_err_t
108 cfga_private_func(
109 const char *func,
110 const char *ap_id,
111 const char *options,
112 struct cfga_confirm *confp,
113 struct cfga_msg *msgp,
114 char **errstring,
115 cfga_flags_t flags)
117 apid_t apidt = {NULL};
118 prompt_t args = {NULL};
119 scfga_ret_t ret;
121 if (errstring != NULL)
122 *errstring = NULL;
124 if (geteuid() != 0) {
125 return (CFGA_PRIV);
128 if (func == NULL) {
129 return (CFGA_ERROR);
132 if (options != NULL && strcmp(options, OPT_DISABLE_RCM) != 0) {
133 cfga_err(errstring, 0, ERRARG_OPT_INVAL, options, 0);
134 return (CFGA_ERROR);
137 if ((ret = apidt_create(ap_id, &apidt, errstring)) != SCFGA_OK) {
138 return (err_cvt(ret));
141 if (apidt.dyntype == PATH_APID) {
142 return (CFGA_OPNOTSUPP);
145 if (options != NULL)
146 apidt.flags |= FLAG_DISABLE_RCM;
148 args.confp = confp;
149 args.msgp = msgp;
152 * Process command
154 ret = invoke_cmd(func, &apidt, &args, flags, errstring);
156 apidt_free(&apidt);
157 return (err_cvt(ret));
160 /*ARGSUSED*/
161 cfga_err_t
162 cfga_test(
163 const char *ap_id,
164 const char *options,
165 struct cfga_msg *msgp,
166 char **errstring,
167 cfga_flags_t flags)
169 if (errstring != NULL) {
170 *errstring = NULL;
173 if (geteuid() != 0) {
174 return (CFGA_PRIV);
177 return (CFGA_OPNOTSUPP);
180 /*ARGSUSED*/
181 cfga_err_t
182 cfga_list_ext(
183 const char *ap_id,
184 cfga_list_data_t **ap_id_list,
185 int *nlistp,
186 const char *options,
187 const char *listopts,
188 char **errstring,
189 cfga_flags_t flags)
191 int hba, expand, nelem;
192 ldata_list_t *llp = NULL;
193 apid_t apidt = {NULL};
194 scfga_cmd_t cmd;
195 scfga_ret_t ret;
197 if (errstring != NULL) {
198 *errstring = NULL;
201 if (ap_id_list == NULL || nlistp == NULL) {
202 return (CFGA_ERROR);
205 *ap_id_list = NULL;
206 *nlistp = 0;
209 * There is no RCM involvement in "list" operations.
210 * The only supported option is OPT_USE_DIFORCE.
212 if (options != NULL && strcmp(options, OPT_USE_DIFORCE) != 0) {
213 cfga_err(errstring, 0, ERRARG_OPT_INVAL, options, 0);
214 return (CFGA_ERROR);
217 hba = 0;
218 if (GET_DYN(ap_id) == NULL) {
219 hba = 1;
222 expand = 0;
223 if ((flags & CFGA_FLAG_LIST_ALL) == CFGA_FLAG_LIST_ALL) {
224 expand = 1;
228 * We expand published attachment points but not
229 * dynamic attachment points
232 if (!hba) { /* Stat a single device - no expansion for devices */
233 cmd = SCFGA_STAT_DEV;
234 } else if (!expand) { /* Stat only the HBA */
235 cmd = SCFGA_STAT_BUS;
236 } else { /* Expand HBA attachment point */
237 cmd = SCFGA_STAT_ALL;
240 if ((ret = apidt_create(ap_id, &apidt, errstring)) != SCFGA_OK) {
241 return (err_cvt(ret));
245 * Currently only 1 option supported
247 if (options)
248 apidt.flags |= FLAG_USE_DIFORCE;
250 llp = NULL;
251 nelem = 0;
253 ret = do_list(&apidt, cmd, &llp, &nelem, errstring);
254 if (ret != SCFGA_OK) {
255 goto out;
258 assert(llp != NULL);
260 if (list_ext_postprocess(&llp, nelem, ap_id_list, nlistp,
261 errstring) != SCFGA_OK) {
262 assert(*ap_id_list == NULL && *nlistp == 0);
263 ret = SCFGA_LIB_ERR;
264 } else {
265 assert(*ap_id_list != NULL && *nlistp == nelem);
266 ret = SCFGA_OK;
269 /* FALLTHROUGH */
270 out:
271 list_free(&llp);
272 apidt_free(&apidt);
273 return (err_cvt(ret));
277 /*ARGSUSED*/
278 cfga_err_t
279 cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
281 cfga_msg(msgp, MSG_HELP_HDR, MSG_HELP_USAGE, 0);
283 return (CFGA_OK);
287 * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm