8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fcinfo / fcinfo.c
blob44e93541e39ab265fc2c055c09d8170df0ae383d
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 <fcinfo.h>
30 #define VERSION_STRING_MAX_LEN 10
32 * Version number:
33 * MAJOR - This should only change when there is an incompatible change made
34 * to the interfaces or the output.
36 * MINOR - This should change whenever there is a new command or new feature
37 * with no incompatible change.
39 #define VERSION_STRING_MAJOR "1"
40 #define VERSION_STRING_MINOR "0"
42 #define OPTIONSTRING1 "HBA Port WWN"
43 #define OPTIONSTRING2 "HBA Node WWN"
44 /* forward declarations */
45 static int listHbaPortFunc(int, char **, cmdOptions_t *, void *);
46 static int listRemotePortFunc(int, char **, cmdOptions_t *, void *);
47 static int listLogicalUnitFunc(int, char **, cmdOptions_t *, void *);
48 static int npivCreatePortFunc(int, char **, cmdOptions_t *, void *);
49 static int npivDeletePortFunc(int, char **, cmdOptions_t *, void *);
50 static int npivCreatePortListFunc(int, char **, cmdOptions_t *, void *);
51 static int npivListHbaPortFunc(int, char **, cmdOptions_t *, void *);
52 static int npivListRemotePortFunc(int, char **, cmdOptions_t *, void *);
53 static int fcoeAdmCreatePortFunc(int, char **, cmdOptions_t *, void *);
54 static int fcoeListPortsFunc(int, char **, cmdOptions_t *, void *);
55 static int fcoeAdmDeletePortFunc(int, char **, cmdOptions_t *, void *);
56 static int fcadmForceLipFunc(int, char **, cmdOptions_t *, void *);
57 static char *getExecBasename(char *);
60 * Add new options here
62 * Optional option-arguments are not allowed by CLIP
64 optionTbl_t fcinfolongOptions[] = {
65 {"port", required_argument, 'p', OPTIONSTRING1},
66 {"target", no_argument, 't', NULL},
67 {"initiator", no_argument, 'i', NULL},
68 {"linkstat", no_argument, 'l', NULL},
69 {"scsi-target", no_argument, 's', NULL},
70 {"fcoe", no_argument, 'e', NULL},
71 {"verbose", no_argument, 'v', NULL},
72 {NULL, 0, 0}
75 optionTbl_t fcadmlongOptions[] = {
76 {"port", required_argument, 'p', OPTIONSTRING1},
77 {"node", required_argument, 'n', OPTIONSTRING2},
78 {"linkstat", no_argument, 'l', NULL},
79 {"scsi-target", no_argument, 's', NULL},
80 {"fcoe-force-promisc", no_argument, 'f', NULL},
81 {"target", no_argument, 't', NULL},
82 {"initiator", no_argument, 'i', NULL},
83 {NULL, 0, 0}
87 * Add new subcommands here
89 subCommandProps_t fcinfosubcommands[] = {
90 {"hba-port", listHbaPortFunc, "itel", NULL, NULL,
91 OPERAND_OPTIONAL_MULTIPLE, "WWN"},
92 {"remote-port", listRemotePortFunc, "lsp", "p", NULL,
93 OPERAND_OPTIONAL_MULTIPLE, "WWN"},
94 {"logical-unit", listLogicalUnitFunc, "v", NULL, NULL,
95 OPERAND_OPTIONAL_MULTIPLE, "OS Device Path"},
96 {"lu", listLogicalUnitFunc, "v", NULL, NULL,
97 OPERAND_OPTIONAL_MULTIPLE, "OS Device Path"},
98 {NULL, 0, NULL, NULL, NULL, 0, NULL, NULL}
101 subCommandProps_t fcadmsubcommands[] = {
102 {"create-npiv-port",
103 npivCreatePortFunc, "pn", NULL, NULL,
104 OPERAND_MANDATORY_SINGLE, "WWN"},
105 {"delete-npiv-port",
106 npivDeletePortFunc, "p", "p", NULL,
107 OPERAND_MANDATORY_SINGLE, "WWN"},
108 {"hba-port",
109 npivListHbaPortFunc, "l", NULL, NULL,
110 OPERAND_OPTIONAL_MULTIPLE, "WWN"},
111 {"remote-port",
112 npivListRemotePortFunc, "psl", "p", NULL,
113 OPERAND_OPTIONAL_MULTIPLE, "WWN"},
114 {"create-port-list",
115 npivCreatePortListFunc, NULL, NULL, NULL,
116 OPERAND_NONE, NULL},
117 {"create-fcoe-port",
118 fcoeAdmCreatePortFunc, "itpnf", NULL, NULL,
119 OPERAND_MANDATORY_SINGLE, "Network Interface Name"},
120 {"delete-fcoe-port",
121 fcoeAdmDeletePortFunc, NULL, NULL, NULL,
122 OPERAND_MANDATORY_SINGLE, "Network Interface Name"},
123 {"list-fcoe-ports",
124 fcoeListPortsFunc, "it", NULL, NULL,
125 OPERAND_NONE, NULL},
126 {"force-lip",
127 fcadmForceLipFunc, NULL, NULL, NULL,
128 OPERAND_MANDATORY_SINGLE, "WWN"},
129 {NULL, 0, NULL, NULL, NULL, 0, NULL, NULL}
133 * Pass in options/arguments, rest of arguments
135 /*ARGSUSED*/
136 static int
137 listHbaPortFunc(int objects, char *argv[], cmdOptions_t *options, void *addArgs)
139 return (fc_util_list_hbaport(objects, argv, options));
143 * Pass in options/arguments, rest of arguments
145 /*ARGSUSED*/
146 static int
147 listRemotePortFunc(int objects, char *argv[], cmdOptions_t *options,
148 void *addArgs)
150 return (fc_util_list_remoteport(objects, argv, options));
154 * Pass in options/arguments, rest of arguments
156 /*ARGSUSED*/
157 static int
158 listLogicalUnitFunc(int objects, char *argv[], cmdOptions_t *options,
159 void *addArgs)
161 return (fc_util_list_logicalunit(objects, argv, options));
165 * Pass in options/arguments, rest of arguments
167 /*ARGSUSED*/
168 static int
169 npivCreatePortFunc(int objects, char *argv[],
170 cmdOptions_t *options, void *addArgs) {
171 return (fc_util_create_npivport(objects, argv, options));
174 static int
175 npivCreatePortListFunc(int objects, char *argv[],
176 cmdOptions_t *options, void *addArgs) {
177 if ((objects == 0) && addArgs && options && argv) {
178 objects = 1;
180 return (fc_util_create_portlist());
184 * Pass in options/arguments, rest of arguments
186 /*ARGSUSED*/
187 static int
188 npivDeletePortFunc(int objects, char *argv[],
189 cmdOptions_t *options, void *addArgs) {
190 return (fc_util_delete_npivport(objects, argv, options));
194 * Pass in options/arguments, rest of arguments
196 /*ARGSUSED*/
197 static int
198 npivListHbaPortFunc(int objects, char *argv[],
199 cmdOptions_t *options, void *addArgs) {
200 return (fc_util_list_hbaport(objects, argv, options));
204 * Pass in options/arguments, rest of arguments
206 /*ARGSUSED*/
207 static int
208 npivListRemotePortFunc(int objects, char *argv[],
209 cmdOptions_t *options, void *addArgs) {
210 return (fc_util_list_remoteport(objects, argv, options));
214 * Pass in options/arguments, rest of arguments
216 /*ARGSUSED*/
217 static int
218 fcoeAdmCreatePortFunc(int objects, char *argv[], cmdOptions_t *options,
219 void *addArgs)
221 return (fcoe_adm_create_port(objects, argv, options));
225 * Pass in options/arguments, rest of arguments
227 /*ARGSUSED*/
228 static int
229 fcoeAdmDeletePortFunc(int objects, char *argv[], cmdOptions_t *options,
230 void *addArgs)
232 return (fcoe_adm_delete_port(objects, argv));
236 * Pass in options/arguments, rest of arguments
238 /*ARGSUSED*/
239 static int
240 fcoeListPortsFunc(int objects, char *argv[], cmdOptions_t *options,
241 void *addArgs)
243 return (fcoe_adm_list_ports(options));
247 * Pass in options/arguments, rest of arguments
249 /*ARGSUSED*/
250 static int
251 fcadmForceLipFunc(int objects, char *argv[], cmdOptions_t *options,
252 void *addArgs)
254 return (fc_util_force_lip(objects, argv));
258 * input:
259 * execFullName - exec name of program (argv[0])
261 * Returns:
262 * command name portion of execFullName
264 static char *
265 getExecBasename(char *execFullname)
267 char *lastSlash, *execBasename;
269 /* guard against '/' at end of command invocation */
270 for (;;) {
271 lastSlash = strrchr(execFullname, '/');
272 if (lastSlash == NULL) {
273 execBasename = execFullname;
274 break;
275 } else {
276 execBasename = lastSlash + 1;
277 if (*execBasename == '\0') {
278 *lastSlash = '\0';
279 continue;
281 break;
284 return (execBasename);
288 * main calls a parser that checks syntax of the input command against
289 * various rules tables.
291 * The parser provides usage feedback based upon same tables by calling
292 * two usage functions, usage and subUsage, handling command and subcommand
293 * usage respectively.
295 * The parser handles all printing of usage syntactical errors
297 * When syntax is successfully validated, the parser calls the associated
298 * function using the subcommands table functions.
300 * Syntax is as follows:
301 * command subcommand [options] resource-type [<object>]
303 * The return value from the function is placed in funcRet
306 main(int argc, char *argv[])
308 synTables_t synTables;
309 char versionString[VERSION_STRING_MAX_LEN];
310 int ret;
311 int funcRet;
312 void *subcommandArgs = NULL;
314 (void) setlocale(LC_ALL, "");
315 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
316 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
317 #endif
318 (void) textdomain(TEXT_DOMAIN);
320 /* set global command name */
321 cmdName = getExecBasename(argv[0]);
323 sprintf(versionString, "%s.%s",
324 VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
325 synTables.versionString = versionString;
326 if (strcmp(cmdName, "fcadm") == 0) {
327 synTables.longOptionTbl = &fcadmlongOptions[0];
328 synTables.subCommandPropsTbl = &fcadmsubcommands[0];
329 } else {
330 synTables.longOptionTbl = &fcinfolongOptions[0];
331 synTables.subCommandPropsTbl = &fcinfosubcommands[0];
334 /* call the CLI parser */
335 ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
336 if (ret == 1) {
337 fprintf(stdout, "%s %s(1M)\n",
338 gettext("For more information, please see"), cmdName);
339 return (1);
340 } else if (ret == -1) {
341 perror(cmdName);
342 return (1);
345 if (funcRet != 0) {
346 return (1);
348 return (0);