145039663SJohn Forte /*
245039663SJohn Forte * CDDL HEADER START
345039663SJohn Forte *
445039663SJohn Forte * The contents of this file are subject to the terms of the
545039663SJohn Forte * Common Development and Distribution License (the "License").
645039663SJohn Forte * You may not use this file except in compliance with the License.
745039663SJohn Forte *
845039663SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
945039663SJohn Forte * or http://www.opensolaris.org/os/licensing.
1045039663SJohn Forte * See the License for the specific language governing permissions
1145039663SJohn Forte * and limitations under the License.
1245039663SJohn Forte *
1345039663SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
1445039663SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1545039663SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
1645039663SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
1745039663SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
1845039663SJohn Forte *
1945039663SJohn Forte * CDDL HEADER END
2045039663SJohn Forte */
2145039663SJohn Forte /*
2245039663SJohn Forte * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2345039663SJohn Forte * Use is subject to license terms.
2445039663SJohn Forte */
2545039663SJohn Forte
2645039663SJohn Forte #include <stdlib.h>
2745039663SJohn Forte #include <stdio.h>
2845039663SJohn Forte #include <strings.h>
2945039663SJohn Forte #include <sys/types.h>
3045039663SJohn Forte #include <unistd.h>
3145039663SJohn Forte #include <wchar.h>
3245039663SJohn Forte #include <libintl.h>
3345039663SJohn Forte #include <errno.h>
3445039663SJohn Forte #include <time.h>
3545039663SJohn Forte #include <string.h>
3645039663SJohn Forte #include <assert.h>
3745039663SJohn Forte #include <getopt.h>
3845039663SJohn Forte #include <cmdparse.h>
3945039663SJohn Forte #include <libstmf.h>
4045039663SJohn Forte #include <signal.h>
4145039663SJohn Forte #include <pthread.h>
4245039663SJohn Forte #include <locale.h>
4345039663SJohn Forte
4445039663SJohn Forte static char *getExecBasename(char *);
4545039663SJohn Forte static int setLuStandbyFunc(int, char **, cmdOptions_t *, void *);
4645039663SJohn Forte static int disableAluaFunc(int, char **, cmdOptions_t *, void *);
4745039663SJohn Forte static int enableAluaFunc(int, char **, cmdOptions_t *, void *);
4845039663SJohn Forte
4945039663SJohn Forte #define OPERANDSTRING_LU "LU-name"
5045039663SJohn Forte #define OPERANDSTRING_NODE_ID "node ID (0 or 1)"
5145039663SJohn Forte
5245039663SJohn Forte #define VERSION_STRING_MAJOR "1"
5345039663SJohn Forte #define VERSION_STRING_MINOR "0"
5445039663SJohn Forte #define VERSION_STRING_MAX_LEN 10
5545039663SJohn Forte
5645039663SJohn Forte #define GUID_INPUT 32
5745039663SJohn Forte
5845039663SJohn Forte /* tables set up based on cmdparse instructions */
5945039663SJohn Forte
6045039663SJohn Forte /* add new options here */
6145039663SJohn Forte optionTbl_t longOptions[] = {
6245039663SJohn Forte {NULL, 0, 0, 0}
6345039663SJohn Forte };
6445039663SJohn Forte
6545039663SJohn Forte /*
6645039663SJohn Forte * Add new subcommands here
6745039663SJohn Forte */
6845039663SJohn Forte subCommandProps_t subcommands[] = {
6945039663SJohn Forte {"standby", setLuStandbyFunc, NULL, NULL, NULL,
7045039663SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
7145039663SJohn Forte {"disable", disableAluaFunc, NULL, NULL, NULL,
7245039663SJohn Forte OPERAND_NONE, NULL, NULL},
7345039663SJohn Forte {"enable", enableAluaFunc, NULL, NULL, NULL,
7445039663SJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_NODE_ID, NULL},
75*48fde5fbSToomas Soome {NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL}
7645039663SJohn Forte };
7745039663SJohn Forte
7845039663SJohn Forte /* globals */
7945039663SJohn Forte char *cmdName;
8045039663SJohn Forte
8145039663SJohn Forte /*
8245039663SJohn Forte * setLuStandbyFunc
8345039663SJohn Forte *
8445039663SJohn Forte * Purpose: set lu to standby
8545039663SJohn Forte *
8645039663SJohn Forte */
8745039663SJohn Forte /*ARGSUSED*/
8845039663SJohn Forte static int
setLuStandbyFunc(int operandLen,char * operands[],cmdOptions_t * options,void * args)8945039663SJohn Forte setLuStandbyFunc(int operandLen, char *operands[], cmdOptions_t *options,
9045039663SJohn Forte void *args)
9145039663SJohn Forte {
9245039663SJohn Forte char sGuid[GUID_INPUT + 1];
9345039663SJohn Forte stmfGuid inGuid;
9445039663SJohn Forte unsigned int guid[sizeof (stmfGuid)];
9545039663SJohn Forte int i;
9645039663SJohn Forte int ret = 0;
9745039663SJohn Forte
9845039663SJohn Forte if (strlen(operands[0]) != GUID_INPUT) {
9945039663SJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName,
10045039663SJohn Forte operands[0], gettext("must be"), GUID_INPUT,
10145039663SJohn Forte gettext("hexadecimal digits long"));
10245039663SJohn Forte return (1);
10345039663SJohn Forte }
10445039663SJohn Forte
10545039663SJohn Forte bcopy(operands[0], sGuid, GUID_INPUT);
10645039663SJohn Forte
10745039663SJohn Forte for (i = 0; i < GUID_INPUT; i++)
10845039663SJohn Forte sGuid[i] = tolower(sGuid[i]);
10945039663SJohn Forte sGuid[i] = 0;
11045039663SJohn Forte
11145039663SJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
11245039663SJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
11345039663SJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
11445039663SJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]);
11545039663SJohn Forte
11645039663SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) {
11745039663SJohn Forte inGuid.guid[i] = guid[i];
11845039663SJohn Forte }
11945039663SJohn Forte
12045039663SJohn Forte ret = stmfLuStandby(&inGuid);
12145039663SJohn Forte if (ret != STMF_STATUS_SUCCESS) {
12245039663SJohn Forte switch (ret) {
12345039663SJohn Forte case STMF_ERROR_PERM:
12445039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
12545039663SJohn Forte gettext("permission denied"));
12645039663SJohn Forte break;
12745039663SJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND:
12845039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
12945039663SJohn Forte gettext("STMF service not found"));
13045039663SJohn Forte break;
13145039663SJohn Forte case STMF_ERROR_NOT_FOUND:
13245039663SJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
13345039663SJohn Forte operands[0], gettext("not found"));
13445039663SJohn Forte break;
13545039663SJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION:
13645039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
13745039663SJohn Forte gettext("STMF service version incorrect"));
13845039663SJohn Forte break;
13945039663SJohn Forte default:
14045039663SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
14145039663SJohn Forte gettext("unknown error"));
14245039663SJohn Forte break;
14345039663SJohn Forte }
14445039663SJohn Forte }
14545039663SJohn Forte return (ret);
14645039663SJohn Forte }
14745039663SJohn Forte
14845039663SJohn Forte /*
14945039663SJohn Forte * disableAluaFunc
15045039663SJohn Forte *
15145039663SJohn Forte * Purpose: disable alua mode
15245039663SJohn Forte *
15345039663SJohn Forte */
15445039663SJohn Forte /*ARGSUSED*/
15545039663SJohn Forte static int
disableAluaFunc(int operandLen,char * operands[],cmdOptions_t * options,void * args)15645039663SJohn Forte disableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
15745039663SJohn Forte void *args)
15845039663SJohn Forte {
15945039663SJohn Forte return (stmfSetAluaState(B_FALSE, 0));
16045039663SJohn Forte }
16145039663SJohn Forte
16245039663SJohn Forte /*
16345039663SJohn Forte * enableAluaFunc
16445039663SJohn Forte *
16545039663SJohn Forte * Purpose: enable alua mode
16645039663SJohn Forte *
16745039663SJohn Forte */
16845039663SJohn Forte /*ARGSUSED*/
16945039663SJohn Forte static int
enableAluaFunc(int operandLen,char * operands[],cmdOptions_t * options,void * args)17045039663SJohn Forte enableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
17145039663SJohn Forte void *args)
17245039663SJohn Forte {
17345039663SJohn Forte uint8_t node_id = 0;
17429305893SPaul Griffiths-Todd if (operands[0][0] == '1') {
17545039663SJohn Forte node_id = 1;
17645039663SJohn Forte }
17745039663SJohn Forte return (stmfSetAluaState(B_TRUE, node_id));
17845039663SJohn Forte }
17945039663SJohn Forte
18045039663SJohn Forte
18145039663SJohn Forte /*
18245039663SJohn Forte * input:
18345039663SJohn Forte * execFullName - exec name of program (argv[0])
18445039663SJohn Forte *
18545039663SJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
18645039663SJohn Forte * (changed name to lowerCamelCase to keep consistent with this file)
18745039663SJohn Forte *
18845039663SJohn Forte * Returns:
18945039663SJohn Forte * command name portion of execFullName
19045039663SJohn Forte */
19145039663SJohn Forte static char *
getExecBasename(char * execFullname)19245039663SJohn Forte getExecBasename(char *execFullname)
19345039663SJohn Forte {
19445039663SJohn Forte char *lastSlash, *execBasename;
19545039663SJohn Forte
19645039663SJohn Forte /* guard against '/' at end of command invocation */
19745039663SJohn Forte for (;;) {
19845039663SJohn Forte lastSlash = strrchr(execFullname, '/');
19945039663SJohn Forte if (lastSlash == NULL) {
20045039663SJohn Forte execBasename = execFullname;
20145039663SJohn Forte break;
20245039663SJohn Forte } else {
20345039663SJohn Forte execBasename = lastSlash + 1;
20445039663SJohn Forte if (*execBasename == '\0') {
20545039663SJohn Forte *lastSlash = '\0';
20645039663SJohn Forte continue;
20745039663SJohn Forte }
20845039663SJohn Forte break;
20945039663SJohn Forte }
21045039663SJohn Forte }
21145039663SJohn Forte return (execBasename);
21245039663SJohn Forte }
21345039663SJohn Forte
21445039663SJohn Forte int
main(int argc,char * argv[])21545039663SJohn Forte main(int argc, char *argv[])
21645039663SJohn Forte {
21745039663SJohn Forte synTables_t synTables;
21845039663SJohn Forte char versionString[VERSION_STRING_MAX_LEN];
21945039663SJohn Forte int ret;
22045039663SJohn Forte int funcRet;
22145039663SJohn Forte void *subcommandArgs = NULL;
22245039663SJohn Forte
22345039663SJohn Forte (void) setlocale(LC_ALL, "");
22445039663SJohn Forte (void) textdomain(TEXT_DOMAIN);
22545039663SJohn Forte /* set global command name */
22645039663SJohn Forte cmdName = getExecBasename(argv[0]);
22745039663SJohn Forte
22845039663SJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
22945039663SJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
23045039663SJohn Forte synTables.versionString = versionString;
23145039663SJohn Forte synTables.longOptionTbl = &longOptions[0];
23245039663SJohn Forte synTables.subCommandPropsTbl = &subcommands[0];
23345039663SJohn Forte
23445039663SJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
23545039663SJohn Forte if (ret != 0) {
23645039663SJohn Forte return (ret);
23745039663SJohn Forte }
23845039663SJohn Forte
23945039663SJohn Forte return (funcRet);
24045039663SJohn Forte } /* end main */
241