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
, 0, NULL
, NULL
, 0, NULL
, 0, NULL
, NULL
}
84 * Purpose: set lu to standby
89 setLuStandbyFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
92 char sGuid
[GUID_INPUT
+ 1];
94 unsigned int guid
[sizeof (stmfGuid
)];
98 if (strlen(operands
[0]) != GUID_INPUT
) {
99 (void) fprintf(stderr
, "%s: %s: %s %d %s\n", cmdName
,
100 operands
[0], gettext("must be"), GUID_INPUT
,
101 gettext("hexadecimal digits long"));
105 bcopy(operands
[0], sGuid
, GUID_INPUT
);
107 for (i
= 0; i
< GUID_INPUT
; i
++)
108 sGuid
[i
] = tolower(sGuid
[i
]);
111 (void) sscanf(sGuid
, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
112 &guid
[0], &guid
[1], &guid
[2], &guid
[3], &guid
[4], &guid
[5],
113 &guid
[6], &guid
[7], &guid
[8], &guid
[9], &guid
[10], &guid
[11],
114 &guid
[12], &guid
[13], &guid
[14], &guid
[15]);
116 for (i
= 0; i
< sizeof (stmfGuid
); i
++) {
117 inGuid
.guid
[i
] = guid
[i
];
120 ret
= stmfLuStandby(&inGuid
);
121 if (ret
!= STMF_STATUS_SUCCESS
) {
123 case STMF_ERROR_PERM
:
124 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
125 gettext("permission denied"));
127 case STMF_ERROR_SERVICE_NOT_FOUND
:
128 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
129 gettext("STMF service not found"));
131 case STMF_ERROR_NOT_FOUND
:
132 (void) fprintf(stderr
, "%s: %s: %s\n", cmdName
,
133 operands
[0], gettext("not found"));
135 case STMF_ERROR_SERVICE_DATA_VERSION
:
136 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
137 gettext("STMF service version incorrect"));
140 (void) fprintf(stderr
, "%s: %s\n", cmdName
,
141 gettext("unknown error"));
151 * Purpose: disable alua mode
156 disableAluaFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
159 return (stmfSetAluaState(B_FALSE
, 0));
165 * Purpose: enable alua mode
170 enableAluaFunc(int operandLen
, char *operands
[], cmdOptions_t
*options
,
174 if (operands
[0][0] == '1') {
177 return (stmfSetAluaState(B_TRUE
, node_id
));
183 * execFullName - exec name of program (argv[0])
185 * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
186 * (changed name to lowerCamelCase to keep consistent with this file)
189 * command name portion of execFullName
192 getExecBasename(char *execFullname
)
194 char *lastSlash
, *execBasename
;
196 /* guard against '/' at end of command invocation */
198 lastSlash
= strrchr(execFullname
, '/');
199 if (lastSlash
== NULL
) {
200 execBasename
= execFullname
;
203 execBasename
= lastSlash
+ 1;
204 if (*execBasename
== '\0') {
211 return (execBasename
);
215 main(int argc
, char *argv
[])
217 synTables_t synTables
;
218 char versionString
[VERSION_STRING_MAX_LEN
];
221 void *subcommandArgs
= NULL
;
223 (void) setlocale(LC_ALL
, "");
224 (void) textdomain(TEXT_DOMAIN
);
225 /* set global command name */
226 cmdName
= getExecBasename(argv
[0]);
228 (void) snprintf(versionString
, VERSION_STRING_MAX_LEN
, "%s.%s",
229 VERSION_STRING_MAJOR
, VERSION_STRING_MINOR
);
230 synTables
.versionString
= versionString
;
231 synTables
.longOptionTbl
= &longOptions
[0];
232 synTables
.subCommandPropsTbl
= &subcommands
[0];
234 ret
= cmdParse(argc
, argv
, synTables
, subcommandArgs
, &funcRet
);