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.
29 #include <sys/types.h>
44 static char *getExecBasename(char *);
45 static int setLuStandbyFunc(int, char **, cmdOptions_t
*, void *);
46 static int disableAluaFunc(int, char **, cmdOptions_t
*, void *);
47 static int enableAluaFunc(int, char **, cmdOptions_t
*, void *);
49 #define OPERANDSTRING_LU "LU-name"
50 #define OPERANDSTRING_NODE_ID "node ID (0 or 1)"
52 #define VERSION_STRING_MAJOR "1"
53 #define VERSION_STRING_MINOR "0"
54 #define VERSION_STRING_MAX_LEN 10
58 /* tables set up based on cmdparse instructions */
60 /* add new options here */
61 optionTbl_t longOptions
[] = {
66 * Add new subcommands here
68 subCommandProps_t subcommands
[] = {
69 {"standby", setLuStandbyFunc
, NULL
, NULL
, NULL
,
70 OPERAND_MANDATORY_SINGLE
, OPERANDSTRING_LU
, NULL
},
71 {"disable", disableAluaFunc
, NULL
, NULL
, NULL
,
72 OPERAND_NONE
, NULL
, NULL
},
73 {"enable", enableAluaFunc
, NULL
, NULL
, NULL
,
74 OPERAND_MANDATORY_SINGLE
, OPERANDSTRING_NODE_ID
, NULL
},
75 {NULL
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, NULL
}
85 * Purpose: set lu to standby
90 setLuStandbyFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
93 char sGuid
[GUID_INPUT
+ 1];
95 unsigned int guid
[sizeof (stmfGuid
)];
99 if (strlen(operands
[0]) != GUID_INPUT
) {
100 (void) fprintf(stderr
, "%s: %s: %s %d %s\n", cmdName
,
101 operands
[0], gettext("must be"), GUID_INPUT
,
102 gettext("hexadecimal digits long"));
106 bcopy(operands
[0], sGuid
, GUID_INPUT
);
108 for (i
= 0; i
< GUID_INPUT
; i
++)
109 sGuid
[i
] = tolower(sGuid
[i
]);
112 (void) sscanf(sGuid
, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
113 &guid
[0], &guid
[1], &guid
[2], &guid
[3], &guid
[4], &guid
[5],
114 &guid
[6], &guid
[7], &guid
[8], &guid
[9], &guid
[10], &guid
[11],
115 &guid
[12], &guid
[13], &guid
[14], &guid
[15]);
117 for (i
= 0; i
< sizeof (stmfGuid
); i
++) {
118 inGuid
.guid
[i
] = guid
[i
];
121 ret
= stmfLuStandby(&inGuid
);
122 if (ret
!= STMF_STATUS_SUCCESS
) {
124 case STMF_ERROR_PERM
:
125 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
126 gettext("permission denied"));
128 case STMF_ERROR_SERVICE_NOT_FOUND
:
129 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
130 gettext("STMF service not found"));
132 case STMF_ERROR_NOT_FOUND
:
133 (void) fprintf(stderr
, "%s: %s: %s\n", cmdName
,
134 operands
[0], gettext("not found"));
136 case STMF_ERROR_SERVICE_DATA_VERSION
:
137 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
138 gettext("STMF service version incorrect"));
141 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
142 gettext("unknown error"));
152 * Purpose: disable alua mode
157 disableAluaFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
160 return (stmfSetAluaState(B_FALSE
, 0));
166 * Purpose: enable alua mode
171 enableAluaFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
175 if (operands
[0][0] == '1') {
178 return (stmfSetAluaState(B_TRUE
, node_id
));
184 * execFullName - exec name of program (argv[0])
186 * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
187 * (changed name to lowerCamelCase to keep consistent with this file)
190 * command name portion of execFullName
193 getExecBasename(char *execFullname
)
195 char *lastSlash
, *execBasename
;
197 /* guard against '/' at end of command invocation */
199 lastSlash
= strrchr(execFullname
, '/');
200 if (lastSlash
== NULL
) {
201 execBasename
= execFullname
;
204 execBasename
= lastSlash
+ 1;
205 if (*execBasename
== '\0') {
212 return (execBasename
);
216 main(int argc
, char *argv
[])
218 synTables_t synTables
;
219 char versionString
[VERSION_STRING_MAX_LEN
];
222 void *subcommandArgs
= NULL
;
224 (void) setlocale(LC_ALL
, "");
225 (void) textdomain(TEXT_DOMAIN
);
226 /* set global command name */
227 cmdName
= getExecBasename(argv
[0]);
229 (void) snprintf(versionString
, VERSION_STRING_MAX_LEN
, "%s.%s",
230 VERSION_STRING_MAJOR
, VERSION_STRING_MINOR
);
231 synTables
.versionString
= versionString
;
232 synTables
.longOptionTbl
= &longOptions
[0];
233 synTables
.subCommandPropsTbl
= &subcommands
[0];
235 ret
= cmdParse(argc
, argv
, synTables
, subcommandArgs
, &funcRet
);