Print this page
3751 ALUA mode: "/usr/demo/comstar/bin/aluaadm enable 1" sets "ALUA Node" = 0
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/stmfproxy/aluaadm/aluaadm.c
+++ new/usr/src/cmd/stmfproxy/aluaadm/aluaadm.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <stdlib.h>
27 27 #include <stdio.h>
28 28 #include <strings.h>
29 29 #include <sys/types.h>
30 30 #include <unistd.h>
31 31 #include <wchar.h>
32 32 #include <libintl.h>
33 33 #include <errno.h>
34 34 #include <time.h>
35 35 #include <string.h>
36 36 #include <assert.h>
37 37 #include <getopt.h>
38 38 #include <cmdparse.h>
39 39 #include <libstmf.h>
40 40 #include <signal.h>
41 41 #include <pthread.h>
42 42 #include <locale.h>
43 43
44 44 static char *getExecBasename(char *);
45 45 static int setLuStandbyFunc(int, char **, cmdOptions_t *, void *);
46 46 static int disableAluaFunc(int, char **, cmdOptions_t *, void *);
47 47 static int enableAluaFunc(int, char **, cmdOptions_t *, void *);
48 48
49 49 #define OPERANDSTRING_LU "LU-name"
50 50 #define OPERANDSTRING_NODE_ID "node ID (0 or 1)"
51 51
52 52 #define VERSION_STRING_MAJOR "1"
53 53 #define VERSION_STRING_MINOR "0"
54 54 #define VERSION_STRING_MAX_LEN 10
55 55
56 56 #define GUID_INPUT 32
57 57
58 58 /* tables set up based on cmdparse instructions */
59 59
60 60 /* add new options here */
61 61 optionTbl_t longOptions[] = {
62 62 {NULL, 0, 0, 0}
63 63 };
64 64
65 65 /*
66 66 * Add new subcommands here
67 67 */
68 68 subCommandProps_t subcommands[] = {
69 69 {"standby", setLuStandbyFunc, NULL, NULL, NULL,
70 70 OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
71 71 {"disable", disableAluaFunc, NULL, NULL, NULL,
72 72 OPERAND_NONE, NULL, NULL},
73 73 {"enable", enableAluaFunc, NULL, NULL, NULL,
74 74 OPERAND_MANDATORY_SINGLE, OPERANDSTRING_NODE_ID, NULL},
75 75 {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL}
76 76 };
77 77
78 78 /* globals */
79 79 char *cmdName;
80 80
81 81 /*
82 82 * setLuStandbyFunc
83 83 *
84 84 * Purpose: set lu to standby
85 85 *
86 86 */
87 87 /*ARGSUSED*/
88 88 static int
89 89 setLuStandbyFunc(int operandLen, char *operands[], cmdOptions_t *options,
90 90 void *args)
91 91 {
92 92 char sGuid[GUID_INPUT + 1];
93 93 stmfGuid inGuid;
94 94 unsigned int guid[sizeof (stmfGuid)];
95 95 int i;
96 96 int ret = 0;
97 97
98 98 if (strlen(operands[0]) != GUID_INPUT) {
99 99 (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName,
100 100 operands[0], gettext("must be"), GUID_INPUT,
101 101 gettext("hexadecimal digits long"));
102 102 return (1);
103 103 }
104 104
105 105 bcopy(operands[0], sGuid, GUID_INPUT);
106 106
107 107 for (i = 0; i < GUID_INPUT; i++)
108 108 sGuid[i] = tolower(sGuid[i]);
109 109 sGuid[i] = 0;
110 110
111 111 (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
112 112 &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
113 113 &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
114 114 &guid[12], &guid[13], &guid[14], &guid[15]);
115 115
116 116 for (i = 0; i < sizeof (stmfGuid); i++) {
117 117 inGuid.guid[i] = guid[i];
118 118 }
119 119
120 120 ret = stmfLuStandby(&inGuid);
121 121 if (ret != STMF_STATUS_SUCCESS) {
122 122 switch (ret) {
123 123 case STMF_ERROR_PERM:
124 124 (void) fprintf(stderr, "%s: %s\n", cmdName,
125 125 gettext("permission denied"));
126 126 break;
127 127 case STMF_ERROR_SERVICE_NOT_FOUND:
128 128 (void) fprintf(stderr, "%s: %s\n", cmdName,
129 129 gettext("STMF service not found"));
130 130 break;
131 131 case STMF_ERROR_NOT_FOUND:
132 132 (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
133 133 operands[0], gettext("not found"));
134 134 break;
135 135 case STMF_ERROR_SERVICE_DATA_VERSION:
136 136 (void) fprintf(stderr, "%s: %s\n", cmdName,
137 137 gettext("STMF service version incorrect"));
138 138 break;
139 139 default:
140 140 (void) fprintf(stderr, "%s: %s\n", cmdName,
141 141 gettext("unknown error"));
142 142 break;
143 143 }
144 144 }
145 145 return (ret);
146 146 }
147 147
148 148 /*
149 149 * disableAluaFunc
150 150 *
151 151 * Purpose: disable alua mode
152 152 *
153 153 */
154 154 /*ARGSUSED*/
155 155 static int
156 156 disableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
157 157 void *args)
158 158 {
159 159 return (stmfSetAluaState(B_FALSE, 0));
160 160 }
161 161
162 162 /*
163 163 * enableAluaFunc
↓ open down ↓ |
163 lines elided |
↑ open up ↑ |
164 164 *
165 165 * Purpose: enable alua mode
166 166 *
167 167 */
168 168 /*ARGSUSED*/
169 169 static int
170 170 enableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
171 171 void *args)
172 172 {
173 173 uint8_t node_id = 0;
174 - if (operands[0][1] == '1') {
174 + if (operands[0][0] == '1') {
175 175 node_id = 1;
176 176 }
177 177 return (stmfSetAluaState(B_TRUE, node_id));
178 178 }
179 179
180 180
181 181 /*
182 182 * input:
183 183 * execFullName - exec name of program (argv[0])
184 184 *
185 185 * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
186 186 * (changed name to lowerCamelCase to keep consistent with this file)
187 187 *
188 188 * Returns:
189 189 * command name portion of execFullName
190 190 */
191 191 static char *
192 192 getExecBasename(char *execFullname)
193 193 {
194 194 char *lastSlash, *execBasename;
195 195
196 196 /* guard against '/' at end of command invocation */
197 197 for (;;) {
198 198 lastSlash = strrchr(execFullname, '/');
199 199 if (lastSlash == NULL) {
200 200 execBasename = execFullname;
201 201 break;
202 202 } else {
203 203 execBasename = lastSlash + 1;
204 204 if (*execBasename == '\0') {
205 205 *lastSlash = '\0';
206 206 continue;
207 207 }
208 208 break;
209 209 }
210 210 }
211 211 return (execBasename);
212 212 }
213 213
214 214 int
215 215 main(int argc, char *argv[])
216 216 {
217 217 synTables_t synTables;
218 218 char versionString[VERSION_STRING_MAX_LEN];
219 219 int ret;
220 220 int funcRet;
221 221 void *subcommandArgs = NULL;
222 222
223 223 (void) setlocale(LC_ALL, "");
224 224 (void) textdomain(TEXT_DOMAIN);
225 225 /* set global command name */
226 226 cmdName = getExecBasename(argv[0]);
227 227
228 228 (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
229 229 VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
230 230 synTables.versionString = versionString;
231 231 synTables.longOptionTbl = &longOptions[0];
232 232 synTables.subCommandPropsTbl = &subcommands[0];
233 233
234 234 ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
235 235 if (ret != 0) {
236 236 return (ret);
237 237 }
238 238
239 239 return (funcRet);
240 240 } /* end main */
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX