sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / cmd / stmfproxy / aluaadm / aluaadm.c
blobe1173f485f0f2e1b3b7a0a4a24e032709eaffbd6
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 <stdlib.h>
27 #include <stdio.h>
28 #include <strings.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31 #include <wchar.h>
32 #include <libintl.h>
33 #include <errno.h>
34 #include <time.h>
35 #include <string.h>
36 #include <assert.h>
37 #include <getopt.h>
38 #include <cmdparse.h>
39 #include <libstmf.h>
40 #include <signal.h>
41 #include <pthread.h>
42 #include <locale.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
56 #define GUID_INPUT 32
58 /* tables set up based on cmdparse instructions */
60 /* add new options here */
61 optionTbl_t longOptions[] = {
62 {NULL, 0, 0, 0}
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}
79 /* globals */
80 char *cmdName;
83 * setLuStandbyFunc
85 * Purpose: set lu to standby
88 /*ARGSUSED*/
89 static int
90 setLuStandbyFunc(int operandLen, char *operands[], cmdOptions_t *options,
91 void *args)
93 char sGuid[GUID_INPUT + 1];
94 stmfGuid inGuid;
95 unsigned int guid[sizeof (stmfGuid)];
96 int i;
97 int ret = 0;
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"));
103 return (1);
106 bcopy(operands[0], sGuid, GUID_INPUT);
108 for (i = 0; i < GUID_INPUT; i++)
109 sGuid[i] = tolower(sGuid[i]);
110 sGuid[i] = 0;
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) {
123 switch (ret) {
124 case STMF_ERROR_PERM:
125 (void) fprintf(stderr, "%s: %s\n", cmdName,
126 gettext("permission denied"));
127 break;
128 case STMF_ERROR_SERVICE_NOT_FOUND:
129 (void) fprintf(stderr, "%s: %s\n", cmdName,
130 gettext("STMF service not found"));
131 break;
132 case STMF_ERROR_NOT_FOUND:
133 (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
134 operands[0], gettext("not found"));
135 break;
136 case STMF_ERROR_SERVICE_DATA_VERSION:
137 (void) fprintf(stderr, "%s: %s\n", cmdName,
138 gettext("STMF service version incorrect"));
139 break;
140 default:
141 (void) fprintf(stderr, "%s: %s\n", cmdName,
142 gettext("unknown error"));
143 break;
146 return (ret);
150 * disableAluaFunc
152 * Purpose: disable alua mode
155 /*ARGSUSED*/
156 static int
157 disableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
158 void *args)
160 return (stmfSetAluaState(B_FALSE, 0));
164 * enableAluaFunc
166 * Purpose: enable alua mode
169 /*ARGSUSED*/
170 static int
171 enableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
172 void *args)
174 uint8_t node_id = 0;
175 if (operands[0][0] == '1') {
176 node_id = 1;
178 return (stmfSetAluaState(B_TRUE, node_id));
183 * input:
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)
189 * Returns:
190 * command name portion of execFullName
192 static char *
193 getExecBasename(char *execFullname)
195 char *lastSlash, *execBasename;
197 /* guard against '/' at end of command invocation */
198 for (;;) {
199 lastSlash = strrchr(execFullname, '/');
200 if (lastSlash == NULL) {
201 execBasename = execFullname;
202 break;
203 } else {
204 execBasename = lastSlash + 1;
205 if (*execBasename == '\0') {
206 *lastSlash = '\0';
207 continue;
209 break;
212 return (execBasename);
216 main(int argc, char *argv[])
218 synTables_t synTables;
219 char versionString[VERSION_STRING_MAX_LEN];
220 int ret;
221 int funcRet;
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);
236 if (ret != 0) {
237 return (ret);
240 return (funcRet);
241 } /* end main */