450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER START
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * The contents of this file are subject to the terms of the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Common Development and Distribution License (the "License").
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You may not use this file except in compliance with the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * or http://www.opensolaris.org/os/licensing.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * See the License for the specific language governing permissions
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * and limitations under the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If applicable, add the following below this CDDL HEADER, with the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER END
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Use is subject to license terms.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <stdlib.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <stdio.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <strings.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/types.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <unistd.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <wchar.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libintl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <errno.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <time.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <string.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <assert.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <getopt.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <cmdparse.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libstmf.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <signal.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <pthread.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <locale.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic char *getExecBasename(char *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int setLuStandbyFunc(int, char **, cmdOptions_t *, void *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int disableAluaFunc(int, char **, cmdOptions_t *, void *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int enableAluaFunc(int, char **, cmdOptions_t *, void *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define OPERANDSTRING_LU "LU-name"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define OPERANDSTRING_NODE_ID "node ID (0 or 1)"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define VERSION_STRING_MAJOR "1"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define VERSION_STRING_MINOR "0"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define VERSION_STRING_MAX_LEN 10
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define GUID_INPUT 32
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* tables set up based on cmdparse instructions */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* add new options here */
450396635f70344c58b6b1e4db38cf17ff34445cJohn ForteoptionTbl_t longOptions[] = {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {NULL, 0, 0, 0}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Add new subcommands here
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortesubCommandProps_t subcommands[] = {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {"standby", setLuStandbyFunc, NULL, NULL, NULL,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {"disable", disableAluaFunc, NULL, NULL, NULL,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte OPERAND_NONE, NULL, NULL},
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {"enable", enableAluaFunc, NULL, NULL, NULL,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte OPERAND_MANDATORY_SINGLE, OPERANDSTRING_NODE_ID, NULL},
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* globals */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortechar *cmdName;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * setLuStandbyFunc
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: set lu to standby
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortesetLuStandbyFunc(int operandLen, char *operands[], cmdOptions_t *options,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte void *args)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char sGuid[GUID_INPUT + 1];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfGuid inGuid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte unsigned int guid[sizeof (stmfGuid)];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int i;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (strlen(operands[0]) != GUID_INPUT) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte operands[0], gettext("must be"), GUID_INPUT,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte gettext("hexadecimal digits long"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(operands[0], sGuid, GUID_INPUT);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (i = 0; i < GUID_INPUT; i++)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sGuid[i] = tolower(sGuid[i]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sGuid[i] = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &guid[12], &guid[13], &guid[14], &guid[15]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte inGuid.guid[i] = guid[i];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = stmfLuStandby(&inGuid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ret != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (ret) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ERROR_PERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte gettext("permission denied"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ERROR_SERVICE_NOT_FOUND:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte gettext("STMF service not found"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ERROR_NOT_FOUND:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte operands[0], gettext("not found"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_ERROR_SERVICE_DATA_VERSION:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte gettext("STMF service version incorrect"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte gettext("unknown error"));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * disableAluaFunc
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: disable alua mode
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortedisableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte void *args)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (stmfSetAluaState(B_FALSE, 0));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * enableAluaFunc
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: enable alua mode
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn ForteenableAluaFunc(int operandLen, char *operands[], cmdOptions_t *options,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte void *args)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint8_t node_id = 0;
293058931b0d2be50da82ce72d3249df01389444Paul Griffiths-Todd if (operands[0][0] == '1') {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte node_id = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (stmfSetAluaState(B_TRUE, node_id));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * input:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * execFullName - exec name of program (argv[0])
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * (changed name to lowerCamelCase to keep consistent with this file)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Returns:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * command name portion of execFullName
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic char *
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortegetExecBasename(char *execFullname)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char *lastSlash, *execBasename;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* guard against '/' at end of command invocation */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (;;) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte lastSlash = strrchr(execFullname, '/');
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (lastSlash == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte execBasename = execFullname;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte execBasename = lastSlash + 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (*execBasename == '\0') {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *lastSlash = '\0';
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (execBasename);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortemain(int argc, char *argv[])
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte synTables_t synTables;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char versionString[VERSION_STRING_MAX_LEN];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int funcRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte void *subcommandArgs = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) setlocale(LC_ALL, "");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) textdomain(TEXT_DOMAIN);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* set global command name */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cmdName = getExecBasename(argv[0]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte synTables.versionString = versionString;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte synTables.longOptionTbl = &longOptions[0];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte synTables.subCommandPropsTbl = &subcommands[0];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ret != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (funcRet);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte} /* end main */