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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #define VERSION_STRING_MAX_LEN 10
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
},
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
},
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
[] = {
103 npivCreatePortFunc
, "pn", NULL
, NULL
,
104 OPERAND_MANDATORY_SINGLE
, "WWN"},
106 npivDeletePortFunc
, "p", "p", NULL
,
107 OPERAND_MANDATORY_SINGLE
, "WWN"},
109 npivListHbaPortFunc
, "l", NULL
, NULL
,
110 OPERAND_OPTIONAL_MULTIPLE
, "WWN"},
112 npivListRemotePortFunc
, "psl", "p", NULL
,
113 OPERAND_OPTIONAL_MULTIPLE
, "WWN"},
115 npivCreatePortListFunc
, NULL
, NULL
, NULL
,
118 fcoeAdmCreatePortFunc
, "itpnf", NULL
, NULL
,
119 OPERAND_MANDATORY_SINGLE
, "Network Interface Name"},
121 fcoeAdmDeletePortFunc
, NULL
, NULL
, NULL
,
122 OPERAND_MANDATORY_SINGLE
, "Network Interface Name"},
124 fcoeListPortsFunc
, "it", NULL
, NULL
,
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
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
147 listRemotePortFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
150 return (fc_util_list_remoteport(objects
, argv
, options
));
154 * Pass in options/arguments, rest of arguments
158 listLogicalUnitFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
161 return (fc_util_list_logicalunit(objects
, argv
, options
));
165 * Pass in options/arguments, rest of arguments
169 npivCreatePortFunc(int objects
, char *argv
[],
170 cmdOptions_t
*options
, void *addArgs
) {
171 return (fc_util_create_npivport(objects
, argv
, options
));
175 npivCreatePortListFunc(int objects
, char *argv
[],
176 cmdOptions_t
*options
, void *addArgs
) {
177 if ((objects
== 0) && addArgs
&& options
&& argv
) {
180 return (fc_util_create_portlist());
184 * Pass in options/arguments, rest of arguments
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
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
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
218 fcoeAdmCreatePortFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
221 return (fcoe_adm_create_port(objects
, argv
, options
));
225 * Pass in options/arguments, rest of arguments
229 fcoeAdmDeletePortFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
232 return (fcoe_adm_delete_port(objects
, argv
));
236 * Pass in options/arguments, rest of arguments
240 fcoeListPortsFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
243 return (fcoe_adm_list_ports(options
));
247 * Pass in options/arguments, rest of arguments
251 fcadmForceLipFunc(int objects
, char *argv
[], cmdOptions_t
*options
,
254 return (fc_util_force_lip(objects
, argv
));
259 * execFullName - exec name of program (argv[0])
262 * command name portion of execFullName
265 getExecBasename(char *execFullname
)
267 char *lastSlash
, *execBasename
;
269 /* guard against '/' at end of command invocation */
271 lastSlash
= strrchr(execFullname
, '/');
272 if (lastSlash
== NULL
) {
273 execBasename
= execFullname
;
276 execBasename
= lastSlash
+ 1;
277 if (*execBasename
== '\0') {
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
];
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 */
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];
330 synTables
.longOptionTbl
= &fcinfolongOptions
[0];
331 synTables
.subCommandPropsTbl
= &fcinfosubcommands
[0];
334 /* call the CLI parser */
335 ret
= cmdParse(argc
, argv
, synTables
, subcommandArgs
, &funcRet
);
337 fprintf(stdout
, "%s %s(1M)\n",
338 gettext("For more information, please see"), cmdName
);
340 } else if (ret
== -1) {