1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21fcf3ce44SJohn Forte /*
224c06356bSdh * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fcf3ce44SJohn Forte * Use is subject to license terms.
2448bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
25fcf3ce44SJohn Forte */
26fcf3ce44SJohn Forte
27fcf3ce44SJohn Forte /*
28fcf3ce44SJohn Forte * mpathadm.c : MP API CLI program
29fcf3ce44SJohn Forte *
30fcf3ce44SJohn Forte */
31fcf3ce44SJohn Forte
32fcf3ce44SJohn Forte #include <libintl.h>
33fcf3ce44SJohn Forte
34fcf3ce44SJohn Forte #include <mpapi.h>
35fcf3ce44SJohn Forte #include "cmdparse.h"
36fcf3ce44SJohn Forte #include "mpathadm_text.h"
37fcf3ce44SJohn Forte #include "mpathadm.h"
38fcf3ce44SJohn Forte
39fcf3ce44SJohn Forte #include <sys/types.h>
40fcf3ce44SJohn Forte #include <sys/stat.h>
41fcf3ce44SJohn Forte #include <unistd.h>
42fcf3ce44SJohn Forte #include <stdlib.h>
43fcf3ce44SJohn Forte #include <devid.h>
44fcf3ce44SJohn Forte #include <fcntl.h>
45fcf3ce44SJohn Forte
46fcf3ce44SJohn Forte /* helper functions */
47fcf3ce44SJohn Forte static char *getExecBasename(char *);
48fcf3ce44SJohn Forte
49fcf3ce44SJohn Forte /* object functions per subcommand */
50fcf3ce44SJohn Forte static int listFunc(int, char **, int, cmdOptions_t *, void *);
51fcf3ce44SJohn Forte static int showFunc(int, char **, int, cmdOptions_t *, void *);
52fcf3ce44SJohn Forte static int modifyFunc(int, char **, int, cmdOptions_t *, void *);
53fcf3ce44SJohn Forte static int enableFunc(int, char **, int, cmdOptions_t *, void *);
54fcf3ce44SJohn Forte static int disableFunc(int, char **, int, cmdOptions_t *, void *);
55fcf3ce44SJohn Forte static int failoverFunc(int, char **, int, cmdOptions_t *, void *);
56fcf3ce44SJohn Forte static int overrideFunc(int, char **, int, cmdOptions_t *, void *);
57fcf3ce44SJohn Forte
58fcf3ce44SJohn Forte #define VERSION_STRING_MAX_LEN 10
59fcf3ce44SJohn Forte
60fcf3ce44SJohn Forte #define OPTIONSTRING_NAME "name"
61fcf3ce44SJohn Forte #define OPTIONSTRING_TPNAME "target-port name"
62fcf3ce44SJohn Forte #define OPTIONSTRING_ONOFF "on/off"
63fcf3ce44SJohn Forte #define OPTIONSTRING_LBTYPE "loadbalance type"
64fcf3ce44SJohn Forte #define OPTIONSTRING_IPORT "initiator-port name"
65fcf3ce44SJohn Forte #define OPTIONSTRING_LUNIT "logical-unit name"
66fcf3ce44SJohn Forte #define OPTIONSTRING_CANCEL "cancel"
67fcf3ce44SJohn Forte #define OPTIONSTRING_VALUE "value"
68fcf3ce44SJohn Forte
69fcf3ce44SJohn Forte /*
70fcf3ce44SJohn Forte * Version number: (copied from iscsiadm)
71fcf3ce44SJohn Forte * MAJOR - This should only change when there is an incompatible change made
72fcf3ce44SJohn Forte * to the interfaces or the output.
73fcf3ce44SJohn Forte *
74fcf3ce44SJohn Forte * MINOR - This should change whenever there is a new command or new feature
75fcf3ce44SJohn Forte * with no incompatible change.
76fcf3ce44SJohn Forte */
77fcf3ce44SJohn Forte #define VERSION_STRING_MAJOR "1"
78fcf3ce44SJohn Forte #define VERSION_STRING_MINOR "0"
79fcf3ce44SJohn Forte
80fcf3ce44SJohn Forte
81fcf3ce44SJohn Forte /* globals */
82fcf3ce44SJohn Forte static char *cmdName;
83fcf3ce44SJohn Forte
84fcf3ce44SJohn Forte
85fcf3ce44SJohn Forte /*
86fcf3ce44SJohn Forte * ****************************************************************************
87fcf3ce44SJohn Forte *
88fcf3ce44SJohn Forte * getExecBasename - copied from iscsiadm code
89fcf3ce44SJohn Forte *
90fcf3ce44SJohn Forte * input:
91fcf3ce44SJohn Forte * execFullName - exec name of program (argv[0])
92fcf3ce44SJohn Forte *
93fcf3ce44SJohn Forte * Returns:
94fcf3ce44SJohn Forte * command name portion of execFullName
95fcf3ce44SJohn Forte *
96fcf3ce44SJohn Forte * ****************************************************************************
97fcf3ce44SJohn Forte */
98fcf3ce44SJohn Forte static char *
getExecBasename(char * execFullname)99fcf3ce44SJohn Forte getExecBasename(char *execFullname)
100fcf3ce44SJohn Forte {
101*ce5e7d21SToomas Soome char *lastSlash, *execBasename;
102fcf3ce44SJohn Forte
103fcf3ce44SJohn Forte /* guard against '/' at end of command invocation */
104fcf3ce44SJohn Forte for (;;) {
105fcf3ce44SJohn Forte lastSlash = strrchr(execFullname, '/');
106fcf3ce44SJohn Forte if (lastSlash == NULL) {
107fcf3ce44SJohn Forte execBasename = execFullname;
108fcf3ce44SJohn Forte break;
109fcf3ce44SJohn Forte } else {
110fcf3ce44SJohn Forte execBasename = lastSlash + 1;
111fcf3ce44SJohn Forte if (*execBasename == '\0') {
112fcf3ce44SJohn Forte *lastSlash = '\0';
113fcf3ce44SJohn Forte continue;
114fcf3ce44SJohn Forte }
115fcf3ce44SJohn Forte break;
116fcf3ce44SJohn Forte }
117fcf3ce44SJohn Forte }
118fcf3ce44SJohn Forte return (execBasename);
119fcf3ce44SJohn Forte }
120fcf3ce44SJohn Forte
121fcf3ce44SJohn Forte
122fcf3ce44SJohn Forte /*
123fcf3ce44SJohn Forte * Add new options here
124fcf3ce44SJohn Forte */
125fcf3ce44SJohn Forte
126fcf3ce44SJohn Forte /* tables set up based on cmdparse instructions */
127fcf3ce44SJohn Forte optionTbl_t longOptions[] = {
128fcf3ce44SJohn Forte {"inqname", required_arg, 'n', OPTIONSTRING_NAME},
129fcf3ce44SJohn Forte {"target-port", required_arg, 't', OPTIONSTRING_TPNAME},
130fcf3ce44SJohn Forte {"autofailback", required_arg, 'a', OPTIONSTRING_ONOFF},
131fcf3ce44SJohn Forte {"autoprobe", required_arg, 'p', OPTIONSTRING_ONOFF},
132fcf3ce44SJohn Forte {"loadbalance", required_arg, 'b', OPTIONSTRING_LBTYPE},
133fcf3ce44SJohn Forte {"initiator-port", required_arg, 'i', OPTIONSTRING_IPORT},
134fcf3ce44SJohn Forte {"logical-unit", required_arg, 'l', OPTIONSTRING_LUNIT},
135fcf3ce44SJohn Forte {"cancel", no_arg, 'c', OPTIONSTRING_CANCEL},
136fcf3ce44SJohn Forte {"vendor-id", required_arg, 'd', OPTIONSTRING_VALUE},
137fcf3ce44SJohn Forte {NULL, 0, 0, 0}
138fcf3ce44SJohn Forte };
139fcf3ce44SJohn Forte
140fcf3ce44SJohn Forte
141fcf3ce44SJohn Forte /*
142fcf3ce44SJohn Forte * Add new subcommands here
143fcf3ce44SJohn Forte */
144fcf3ce44SJohn Forte subcommand_t subcommands[] = {
145fcf3ce44SJohn Forte {"list", LIST, listFunc},
146fcf3ce44SJohn Forte {"show", SHOW, showFunc},
147fcf3ce44SJohn Forte {"modify", MODIFY, modifyFunc},
148fcf3ce44SJohn Forte {"enable", ENABLE, enableFunc},
149fcf3ce44SJohn Forte {"disable", DISABLE, disableFunc},
150fcf3ce44SJohn Forte {"failover", FAILOVER, failoverFunc},
151fcf3ce44SJohn Forte {"override", OVERRIDE, overrideFunc},
152fcf3ce44SJohn Forte {NULL, 0, NULL}
153fcf3ce44SJohn Forte };
154fcf3ce44SJohn Forte
155fcf3ce44SJohn Forte /*
156fcf3ce44SJohn Forte * Add objects here
157fcf3ce44SJohn Forte */
158fcf3ce44SJohn Forte object_t objects[] = {
159fcf3ce44SJohn Forte {"mpath-support", MPATH_SUPPORT},
160fcf3ce44SJohn Forte {"logical-unit", LOGICAL_UNIT},
161fcf3ce44SJohn Forte {"LU", LOGICAL_UNIT},
162fcf3ce44SJohn Forte {"initiator-port", INITIATOR_PORT},
163fcf3ce44SJohn Forte {"path", PATH},
164fcf3ce44SJohn Forte {NULL, 0}
165fcf3ce44SJohn Forte };
166fcf3ce44SJohn Forte
167fcf3ce44SJohn Forte /*
168fcf3ce44SJohn Forte * Rules for subcommands and objects
169fcf3ce44SJohn Forte *
170fcf3ce44SJohn Forte * command
171fcf3ce44SJohn Forte *
172fcf3ce44SJohn Forte * reqOpCmd -> subcommands that must have an operand
173fcf3ce44SJohn Forte * optOpCmd -> subcommands that may have an operand
174fcf3ce44SJohn Forte * noOpCmd -> subcommands that will have no operand
175fcf3ce44SJohn Forte * invCmd -> subcommands that are invalid
176fcf3ce44SJohn Forte * multOpCmd -> subcommands that can accept multiple operands
177fcf3ce44SJohn Forte * operandDefinition -> Usage definition for the operand of this object
178fcf3ce44SJohn Forte */
179fcf3ce44SJohn Forte objectRules_t objectRules[] = {
180fcf3ce44SJohn Forte {MPATH_SUPPORT, SHOW|MODIFY|ADD, LIST|REMOVE, 0,
181fcf3ce44SJohn Forte ENABLE|DISABLE|FAILOVER|OVERRIDE, LIST|SHOW|MODIFY,
182fcf3ce44SJohn Forte "mpath-support name"},
183fcf3ce44SJohn Forte {INITIATOR_PORT, SHOW, LIST, 0,
184fcf3ce44SJohn Forte MODIFY|ENABLE|DISABLE|FAILOVER|OVERRIDE|ADD|REMOVE, LIST|SHOW,
185fcf3ce44SJohn Forte "initiator-port name"},
186fcf3ce44SJohn Forte {LOGICAL_UNIT, SHOW|MODIFY|FAILOVER, LIST, 0,
187fcf3ce44SJohn Forte ENABLE|DISABLE|OVERRIDE|ADD|REMOVE, LIST|SHOW|MODIFY,
188fcf3ce44SJohn Forte "logical-unit name"},
189fcf3ce44SJohn Forte {PATH, 0, 0, ENABLE|DISABLE|OVERRIDE,
190fcf3ce44SJohn Forte SHOW|LIST|MODIFY|FAILOVER|ADD|REMOVE, 0,
191fcf3ce44SJohn Forte "initiator-port name"},
192*ce5e7d21SToomas Soome {0, 0, 0, 0, 0, 0, NULL}
193fcf3ce44SJohn Forte };
194fcf3ce44SJohn Forte
195fcf3ce44SJohn Forte /*
196fcf3ce44SJohn Forte * list of objects, subcommands, valid short options, required flag and
197fcf3ce44SJohn Forte * exclusive option string
198fcf3ce44SJohn Forte *
199fcf3ce44SJohn Forte * If it's not here, there are no options for that object.
200fcf3ce44SJohn Forte */
201fcf3ce44SJohn Forte optionRules_t optionRules[] = {
202fcf3ce44SJohn Forte {LOGICAL_UNIT, LIST, "nt", B_FALSE, NULL},
203fcf3ce44SJohn Forte {LOGICAL_UNIT, MODIFY, "apb", B_TRUE, NULL},
204fcf3ce44SJohn Forte {MPATH_SUPPORT, MODIFY, "apb", B_TRUE, NULL},
205fcf3ce44SJohn Forte {MPATH_SUPPORT, ADD, "d", B_TRUE, NULL},
206fcf3ce44SJohn Forte {MPATH_SUPPORT, REMOVE, "d", B_TRUE, NULL},
207fcf3ce44SJohn Forte {PATH, ENABLE, "itl", B_TRUE, NULL},
208fcf3ce44SJohn Forte {PATH, DISABLE, "itl", B_TRUE, NULL},
209fcf3ce44SJohn Forte {PATH, OVERRIDE, "itlc", B_TRUE, NULL},
210*ce5e7d21SToomas Soome {0, 0, NULL, 0, NULL}
211fcf3ce44SJohn Forte };
212fcf3ce44SJohn Forte
213fcf3ce44SJohn Forte
214fcf3ce44SJohn Forte /*
215fcf3ce44SJohn Forte * ****************************************************************************
216fcf3ce44SJohn Forte *
217fcf3ce44SJohn Forte * listMpathSupport - mpathadm list mpath-support
218fcf3ce44SJohn Forte *
219fcf3ce44SJohn Forte * operandLen - number of operands user passed into the cli
220fcf3ce44SJohn Forte * operand - pointer to operand list from user
221fcf3ce44SJohn Forte *
222fcf3ce44SJohn Forte * ****************************************************************************
223fcf3ce44SJohn Forte */
224fcf3ce44SJohn Forte int
listMpathSupport(int operandLen,char * operand[])225fcf3ce44SJohn Forte listMpathSupport(int operandLen, char *operand[])
226fcf3ce44SJohn Forte {
227fcf3ce44SJohn Forte MP_STATUS mpstatus = MP_STATUS_SUCCESS;
228fcf3ce44SJohn Forte MP_PLUGIN_PROPERTIES pluginProps;
229fcf3ce44SJohn Forte MP_OID_LIST *pPluginOidList;
230fcf3ce44SJohn Forte boolean_t shown = B_FALSE;
231fcf3ce44SJohn Forte /* number of plugins listed */
2324c06356bSdh int i, op;
233fcf3ce44SJohn Forte
234fcf3ce44SJohn Forte if ((mpstatus = MP_GetPluginOidList(&pPluginOidList))
235fcf3ce44SJohn Forte != MP_STATUS_SUCCESS) {
236fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
237fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
238fcf3ce44SJohn Forte return (mpstatus);
239fcf3ce44SJohn Forte }
240fcf3ce44SJohn Forte if ((NULL == pPluginOidList) || (pPluginOidList->oidCount < 1)) {
241fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
242fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
243fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
244fcf3ce44SJohn Forte }
245fcf3ce44SJohn Forte
246fcf3ce44SJohn Forte
247fcf3ce44SJohn Forte /* loop through operands first */
248fcf3ce44SJohn Forte for (op = 0; (op < operandLen) |
249fcf3ce44SJohn Forte ((0 == operandLen) && (B_FALSE == shown)); op++) {
250fcf3ce44SJohn Forte shown = B_TRUE;
251fcf3ce44SJohn Forte for (i = 0; i < pPluginOidList->oidCount; i++) {
252fcf3ce44SJohn Forte
253fcf3ce44SJohn Forte (void) memset(&pluginProps, 0,
254fcf3ce44SJohn Forte sizeof (MP_PLUGIN_PROPERTIES));
255fcf3ce44SJohn Forte mpstatus =
256fcf3ce44SJohn Forte MP_GetPluginProperties(pPluginOidList->oids[i],
257fcf3ce44SJohn Forte &pluginProps);
258fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
259fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
260fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_PROPERTIES));
261fcf3ce44SJohn Forte } else {
262fcf3ce44SJohn Forte if (0 == operandLen) {
263fcf3ce44SJohn Forte /* if no operands, list them all */
264fcf3ce44SJohn Forte (void) printf("%s %s\n",
265fcf3ce44SJohn Forte getTextString(
266fcf3ce44SJohn Forte TEXT_LB_MPATH_SUPPORT),
267fcf3ce44SJohn Forte pluginProps.fileName);
268fcf3ce44SJohn Forte } else {
269fcf3ce44SJohn Forte /* if there is an operand... */
270fcf3ce44SJohn Forte /* ... compare and display if match */
271fcf3ce44SJohn Forte if (0 ==
272fcf3ce44SJohn Forte strcmp(operand[op],
273fcf3ce44SJohn Forte pluginProps.fileName)) {
274fcf3ce44SJohn Forte (void) printf("%s %s\n",
275fcf3ce44SJohn Forte getTextString(
276fcf3ce44SJohn Forte TEXT_LB_MPATH_SUPPORT),
277fcf3ce44SJohn Forte pluginProps.fileName);
278fcf3ce44SJohn Forte } else {
2794c06356bSdh /* begin back-up indentation */
2804c06356bSdh /* LINTED E_SEC_PRINTF_VAR_FMT */
2814c06356bSdh (void) fprintf(stderr, getTextString(
282fcf3ce44SJohn Forte ERR_CANT_FIND_MPATH_SUPPORT_WITH_NAME),
2834c06356bSdh operand[op]);
2844c06356bSdh /* end back-up indentation */
285fcf3ce44SJohn Forte (void) printf("\n");
286fcf3ce44SJohn Forte }
287fcf3ce44SJohn Forte }
288fcf3ce44SJohn Forte }
289fcf3ce44SJohn Forte }
290fcf3ce44SJohn Forte }
291fcf3ce44SJohn Forte
292fcf3ce44SJohn Forte return (mpstatus);
293fcf3ce44SJohn Forte }
294fcf3ce44SJohn Forte
295fcf3ce44SJohn Forte
296fcf3ce44SJohn Forte /*
297fcf3ce44SJohn Forte * ****************************************************************************
298fcf3ce44SJohn Forte *
299fcf3ce44SJohn Forte * showMpathSupport - mpathadm show mpath-support <mpath-support name>, ...
300fcf3ce44SJohn Forte *
301fcf3ce44SJohn Forte * operandLen - number of operands user passed into the cli
302fcf3ce44SJohn Forte * operand - pointer to operand list from user
303fcf3ce44SJohn Forte *
304fcf3ce44SJohn Forte * ****************************************************************************
305fcf3ce44SJohn Forte */
306fcf3ce44SJohn Forte int
showMpathSupport(int operandLen,char * operand[])307fcf3ce44SJohn Forte showMpathSupport(int operandLen, char *operand[])
308fcf3ce44SJohn Forte {
309fcf3ce44SJohn Forte MP_STATUS mpstatus = MP_STATUS_SUCCESS;
310fcf3ce44SJohn Forte MP_PLUGIN_PROPERTIES pluginProps;
311fcf3ce44SJohn Forte MP_OID_LIST *pPluginOidList;
312fcf3ce44SJohn Forte MP_OID_LIST *deviceOidListArray;
313fcf3ce44SJohn Forte MP_DEVICE_PRODUCT_PROPERTIES devProps;
314fcf3ce44SJohn Forte boolean_t bListIt = B_FALSE;
3154c06356bSdh int op, i, j;
316*ce5e7d21SToomas Soome MP_LOAD_BALANCE_TYPE lb;
317fcf3ce44SJohn Forte
318fcf3ce44SJohn Forte
319fcf3ce44SJohn Forte if ((mpstatus = MP_GetPluginOidList(&pPluginOidList)) !=
320fcf3ce44SJohn Forte MP_STATUS_SUCCESS) {
321fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
322fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_MPATH_SUPPORT_LIST));
323fcf3ce44SJohn Forte return (mpstatus);
324fcf3ce44SJohn Forte }
325fcf3ce44SJohn Forte if ((NULL == pPluginOidList) || (pPluginOidList->oidCount < 1)) {
326fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
327fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_MPATH_SUPPORT_LIST));
328fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
329fcf3ce44SJohn Forte }
330fcf3ce44SJohn Forte
331fcf3ce44SJohn Forte for (op = 0; op < operandLen; op++) {
3324c06356bSdh bListIt = B_FALSE;
333fcf3ce44SJohn Forte
334fcf3ce44SJohn Forte for (i = 0; i < pPluginOidList->oidCount; i++) {
335fcf3ce44SJohn Forte
336fcf3ce44SJohn Forte (void) memset(&pluginProps, 0,
337fcf3ce44SJohn Forte sizeof (MP_PLUGIN_PROPERTIES));
338fcf3ce44SJohn Forte mpstatus =
339fcf3ce44SJohn Forte MP_GetPluginProperties(pPluginOidList->oids[i],
340fcf3ce44SJohn Forte &pluginProps);
341fcf3ce44SJohn Forte if (MP_STATUS_SUCCESS != mpstatus) {
342fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
343fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_PROPERTIES));
344fcf3ce44SJohn Forte return (mpstatus);
345fcf3ce44SJohn Forte }
346fcf3ce44SJohn Forte
347fcf3ce44SJohn Forte if (0 == operandLen) {
348fcf3ce44SJohn Forte /* if no operand, list it */
349fcf3ce44SJohn Forte bListIt = B_TRUE;
350fcf3ce44SJohn Forte } else {
351fcf3ce44SJohn Forte /* ... compare and display if match */
352fcf3ce44SJohn Forte if (0 ==
353fcf3ce44SJohn Forte strcmp(operand[op],
354fcf3ce44SJohn Forte pluginProps.fileName)) {
355fcf3ce44SJohn Forte bListIt = B_TRUE;
356fcf3ce44SJohn Forte }
357fcf3ce44SJohn Forte }
358fcf3ce44SJohn Forte
359fcf3ce44SJohn Forte if (B_TRUE != bListIt) {
360fcf3ce44SJohn Forte break;
361fcf3ce44SJohn Forte }
362fcf3ce44SJohn Forte
363fcf3ce44SJohn Forte (void) printf("%s %s\n",
364fcf3ce44SJohn Forte getTextString(TEXT_LB_MPATH_SUPPORT),
365fcf3ce44SJohn Forte pluginProps.fileName);
366fcf3ce44SJohn Forte
367fcf3ce44SJohn Forte /* display the info for this plugin */
368fcf3ce44SJohn Forte (void) printf("\t%s ", getTextString(TEXT_LB_VENDOR));
369fcf3ce44SJohn Forte displayWideArray(pluginProps.vendor,
370fcf3ce44SJohn Forte sizeof (pluginProps.vendor));
371fcf3ce44SJohn Forte (void) printf("\n\t%s ",
372fcf3ce44SJohn Forte getTextString(TEXT_LB_DRIVER_NAME));
373fcf3ce44SJohn Forte displayArray(pluginProps.driverName,
374fcf3ce44SJohn Forte sizeof (pluginProps.driverName));
375fcf3ce44SJohn Forte (void) printf("\n\t%s ",
376fcf3ce44SJohn Forte getTextString(TEXT_LB_DEFAULT_LB));
377fcf3ce44SJohn Forte /* don't ignore load balance type none. */
378fcf3ce44SJohn Forte if (pluginProps.defaultloadBalanceType == 0) {
3794c06356bSdh (void) printf("%s",
3804c06356bSdh getTextString(TEXT_LBTYPE_NONE));
381fcf3ce44SJohn Forte } else {
3824c06356bSdh displayLoadBalanceString(
3834c06356bSdh pluginProps.defaultloadBalanceType);
384fcf3ce44SJohn Forte }
385fcf3ce44SJohn Forte (void) printf("\n");
386fcf3ce44SJohn Forte
387fcf3ce44SJohn Forte
388fcf3ce44SJohn Forte (void) printf("\t%s \n",
389fcf3ce44SJohn Forte getTextString(TEXT_LB_SUPPORTED_LB));
390fcf3ce44SJohn Forte /* check each bit, display string if found set */
391fcf3ce44SJohn Forte if (pluginProps.supportedLoadBalanceTypes == 0) {
392fcf3ce44SJohn Forte (void) printf("\t\t%s\n",
3934c06356bSdh getTextString(TEXT_LBTYPE_NONE));
394fcf3ce44SJohn Forte } else {
3954c06356bSdh lb = 1;
3964c06356bSdh do {
3974c06356bSdh if (0 != (lb & pluginProps.
3984c06356bSdh supportedLoadBalanceTypes)) {
3994c06356bSdh (void) printf("\t\t");
4004c06356bSdh displayLoadBalanceString(lb &
4014c06356bSdh pluginProps.
4024c06356bSdh supportedLoadBalanceTypes);
4034c06356bSdh (void) printf("\n");
4044c06356bSdh }
4054c06356bSdh lb = lb<<1;
4064c06356bSdh } while (lb < 0x80000000);
407fcf3ce44SJohn Forte }
408fcf3ce44SJohn Forte
409fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
410fcf3ce44SJohn Forte getTextString(TEXT_LB_ALLOWS_ACT_TPG),
411fcf3ce44SJohn Forte (MP_TRUE == pluginProps.canSetTPGAccess)?
412fcf3ce44SJohn Forte getTextString(TEXT_YES):getTextString(TEXT_NO));
413fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
414fcf3ce44SJohn Forte getTextString(TEXT_LB_ALLOWS_PATH_OV),
415fcf3ce44SJohn Forte (MP_TRUE == pluginProps.canOverridePaths)?
416fcf3ce44SJohn Forte getTextString(TEXT_YES):getTextString(TEXT_NO));
417fcf3ce44SJohn Forte (void) printf("\t%s %d\n",
418fcf3ce44SJohn Forte getTextString(TEXT_LB_SUPP_AUTO_FB),
419fcf3ce44SJohn Forte pluginProps.autoFailbackSupport);
420fcf3ce44SJohn Forte if ((MP_AUTOFAILBACK_SUPPORT_PLUGIN ==
421fcf3ce44SJohn Forte pluginProps.autoFailbackSupport) |
422fcf3ce44SJohn Forte (MP_AUTOFAILBACK_SUPPORT_PLUGINANDMPLU
423fcf3ce44SJohn Forte == pluginProps.autoFailbackSupport)) {
424fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
425fcf3ce44SJohn Forte getTextString(TEXT_LB_AUTO_FB),
426fcf3ce44SJohn Forte pluginProps.pluginAutoFailbackEnabled?\
427fcf3ce44SJohn Forte getTextString(TEXT_ON):
428fcf3ce44SJohn Forte getTextString(TEXT_OFF));
429fcf3ce44SJohn Forte (void) printf("\t%s %d/%d\n",
430fcf3ce44SJohn Forte getTextString(TEXT_LB_FB_POLLING_RATE),
431fcf3ce44SJohn Forte pluginProps.currentFailbackPollingRate,
432fcf3ce44SJohn Forte pluginProps.failbackPollingRateMax);
433fcf3ce44SJohn Forte } else {
434fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
435fcf3ce44SJohn Forte getTextString(TEXT_LB_AUTO_FB),
436fcf3ce44SJohn Forte getTextString(TEXT_NA));
437fcf3ce44SJohn Forte (void) printf("\t%s %s/%s\n",
438fcf3ce44SJohn Forte getTextString(TEXT_LB_FB_POLLING_RATE),
439fcf3ce44SJohn Forte getTextString(TEXT_NA),
440fcf3ce44SJohn Forte getTextString(TEXT_NA));
441fcf3ce44SJohn Forte }
442fcf3ce44SJohn Forte (void) printf("\t%s %d\n",
443fcf3ce44SJohn Forte getTextString(TEXT_LB_SUPP_AUTO_P),
444fcf3ce44SJohn Forte pluginProps.autoProbingSupport);
445fcf3ce44SJohn Forte if ((MP_AUTOPROBING_SUPPORT_PLUGIN ==
446fcf3ce44SJohn Forte pluginProps.autoProbingSupport) |
447fcf3ce44SJohn Forte (MP_AUTOPROBING_SUPPORT_PLUGIN ==
448fcf3ce44SJohn Forte pluginProps.autoProbingSupport)) {
449fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
450fcf3ce44SJohn Forte getTextString(TEXT_LB_AUTO_PROB),
451fcf3ce44SJohn Forte (MP_TRUE ==
452fcf3ce44SJohn Forte pluginProps.pluginAutoProbingEnabled)?\
453fcf3ce44SJohn Forte getTextString(TEXT_YES):
454fcf3ce44SJohn Forte getTextString(TEXT_NO));
455fcf3ce44SJohn Forte (void) printf("\t%s %d/%d\n",
456fcf3ce44SJohn Forte getTextString(TEXT_LB_PR_POLLING_RATE),
457fcf3ce44SJohn Forte pluginProps.currentProbingPollingRate,
458fcf3ce44SJohn Forte pluginProps.probingPollingRateMax);
459fcf3ce44SJohn Forte } else {
460fcf3ce44SJohn Forte (void) printf("\t%s %s\n",
461fcf3ce44SJohn Forte getTextString(TEXT_LB_AUTO_PROB),
462fcf3ce44SJohn Forte getTextString(TEXT_NA));
463fcf3ce44SJohn Forte (void) printf("\t%s %s/%s\n",
464fcf3ce44SJohn Forte getTextString(TEXT_LB_PR_POLLING_RATE),
465fcf3ce44SJohn Forte getTextString(TEXT_NA),
466fcf3ce44SJohn Forte getTextString(TEXT_NA));
467fcf3ce44SJohn Forte }
468fcf3ce44SJohn Forte
469fcf3ce44SJohn Forte
470fcf3ce44SJohn Forte (void) printf("\t%s\n",
471fcf3ce44SJohn Forte getTextString(TEXT_LB_SUPP_DEVICES));
472fcf3ce44SJohn Forte
473fcf3ce44SJohn Forte
474fcf3ce44SJohn Forte if (MP_TRUE !=
475fcf3ce44SJohn Forte pluginProps.onlySupportsSpecifiedProducts) {
476fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
477fcf3ce44SJohn Forte (void) printf(getTextString(TEXT_ANY_DEVICE));
478fcf3ce44SJohn Forte } else {
479fcf3ce44SJohn Forte /* if only supports specific products, */
480fcf3ce44SJohn Forte /* get device product properties supported */
481fcf3ce44SJohn Forte
482fcf3ce44SJohn Forte mpstatus = MP_GetDeviceProductOidList(\
483fcf3ce44SJohn Forte pPluginOidList->oids[i],
484fcf3ce44SJohn Forte &deviceOidListArray);
485fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
486fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
487fcf3ce44SJohn Forte cmdName, getTextString(
488fcf3ce44SJohn Forte ERR_NO_SUPP_DEVICE_INFO));
489fcf3ce44SJohn Forte /* can't get any more info, */
490fcf3ce44SJohn Forte /* so we're done with this one */
491fcf3ce44SJohn Forte break;
492fcf3ce44SJohn Forte }
493fcf3ce44SJohn Forte
494fcf3ce44SJohn Forte for (j = 0; j < deviceOidListArray->oidCount;
495fcf3ce44SJohn Forte j++) {
4964c06356bSdh /* begin backup indentation */
4974c06356bSdh (void) memset(&devProps, 0,
4984c06356bSdh sizeof (MP_DEVICE_PRODUCT_PROPERTIES));
4994c06356bSdh /* end backup indentation */
500fcf3ce44SJohn Forte if ((mpstatus =
501fcf3ce44SJohn Forte MP_GetDeviceProductProperties(\
502fcf3ce44SJohn Forte deviceOidListArray->oids[j],
503fcf3ce44SJohn Forte &devProps)) == MP_STATUS_SUCCESS) {
504fcf3ce44SJohn Forte
505fcf3ce44SJohn Forte (void) printf("\t\t%s ",
506fcf3ce44SJohn Forte getTextString(
507fcf3ce44SJohn Forte TEXT_LB_VENDOR));
508fcf3ce44SJohn Forte displayArray(devProps.vendor,
509fcf3ce44SJohn Forte sizeof (devProps.vendor));
510fcf3ce44SJohn Forte (void) printf("\n\t\t%s ",
511fcf3ce44SJohn Forte getTextString(
512fcf3ce44SJohn Forte TEXT_LB_PRODUCT));
513fcf3ce44SJohn Forte displayArray(devProps.product,
514fcf3ce44SJohn Forte sizeof (devProps.product));
515fcf3ce44SJohn Forte (void) printf("\n\t\t%s ",
516fcf3ce44SJohn Forte getTextString(
517fcf3ce44SJohn Forte TEXT_LB_REVISION));
518fcf3ce44SJohn Forte displayArray(devProps.revision,
519fcf3ce44SJohn Forte sizeof (devProps.revision));
520fcf3ce44SJohn Forte
521fcf3ce44SJohn Forte (void) printf("\n\t\t%s\n",
522fcf3ce44SJohn Forte getTextString(
523fcf3ce44SJohn Forte TEXT_LB_SUPPORTED_LB));
5244c06356bSdh /* begin back-up indentation */
5254c06356bSdh if (devProps.supportedLoadBalanceTypes == 0) {
5264c06356bSdh (void) printf("\t\t\t%s\n",
5274c06356bSdh getTextString(TEXT_LBTYPE_NONE));
5284c06356bSdh } else {
5294c06356bSdh lb = 1;
5304c06356bSdh do {
531fcf3ce44SJohn Forte if (0 != (lb &
532fcf3ce44SJohn Forte devProps.supportedLoadBalanceTypes)) {
533fcf3ce44SJohn Forte (void) printf("\t\t\t");
534fcf3ce44SJohn Forte displayLoadBalanceString(lb &
5354c06356bSdh devProps.supportedLoadBalanceTypes);
536fcf3ce44SJohn Forte (void) printf("\n");
537fcf3ce44SJohn Forte }
538fcf3ce44SJohn Forte lb = lb<<1;
5394c06356bSdh } while (lb < 0x80000000);
5404c06356bSdh }
5414c06356bSdh /* end back-up indentation */
542fcf3ce44SJohn Forte (void) printf("\n");
543fcf3ce44SJohn Forte
544fcf3ce44SJohn Forte } else {
545fcf3ce44SJohn Forte (void) fprintf(stderr,
546fcf3ce44SJohn Forte "%s: %s\n", cmdName,
547fcf3ce44SJohn Forte getTextString(
548fcf3ce44SJohn Forte ERR_NO_SUPP_DEVICE_INFO));
549fcf3ce44SJohn Forte }
550fcf3ce44SJohn Forte } /* for j */
551fcf3ce44SJohn Forte } /* if only supports specified devices */
552fcf3ce44SJohn Forte
553fcf3ce44SJohn Forte } /* for each plugin */
554fcf3ce44SJohn Forte
555fcf3ce44SJohn Forte if (B_FALSE == bListIt) {
556fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
557fcf3ce44SJohn Forte (void) fprintf(stderr, getTextString(
558fcf3ce44SJohn Forte ERR_CANT_FIND_MPATH_SUPPORT_WITH_NAME),
559fcf3ce44SJohn Forte operand[op]);
560fcf3ce44SJohn Forte (void) printf("\n");
561fcf3ce44SJohn Forte
562fcf3ce44SJohn Forte }
563fcf3ce44SJohn Forte
564fcf3ce44SJohn Forte } /* for each operand */
565fcf3ce44SJohn Forte
566fcf3ce44SJohn Forte
567fcf3ce44SJohn Forte return (mpstatus);
568fcf3ce44SJohn Forte }
569fcf3ce44SJohn Forte
570fcf3ce44SJohn Forte
571fcf3ce44SJohn Forte /*
572fcf3ce44SJohn Forte * ****************************************************************************
573fcf3ce44SJohn Forte *
574fcf3ce44SJohn Forte * modifyMpathSupport -
575*ce5e7d21SToomas Soome * mpathadm modify mpath-support [options] <mpath-support name>, ...
576fcf3ce44SJohn Forte *
577fcf3ce44SJohn Forte * operandLen - number of operands user passed into the cli
578fcf3ce44SJohn Forte * operand - pointer to operand list from user
579fcf3ce44SJohn Forte * options - pointer to option list from user
580fcf3ce44SJohn Forte *
581fcf3ce44SJohn Forte * ****************************************************************************
582fcf3ce44SJohn Forte */
583fcf3ce44SJohn Forte int
modifyMpathSupport(int operandLen,char * operand[],cmdOptions_t * options)584fcf3ce44SJohn Forte modifyMpathSupport(int operandLen, char *operand[], cmdOptions_t *options)
585fcf3ce44SJohn Forte {
5864c06356bSdh MP_STATUS mpstatus = MP_STATUS_SUCCESS;
5874c06356bSdh MP_PLUGIN_PROPERTIES pluginProps;
5884c06356bSdh MP_OID_LIST *pPluginOidList;
5894c06356bSdh boolean_t bFoundIt = B_FALSE;
5904c06356bSdh MP_OID pluginOid;
591*ce5e7d21SToomas Soome cmdOptions_t *optionList = options;
5924c06356bSdh char *cmdStr = getTextString(TEXT_UNKNOWN);
5934c06356bSdh int op, i, lbValue;
594fcf3ce44SJohn Forte
595fcf3ce44SJohn Forte if ((mpstatus = MP_GetPluginOidList(&pPluginOidList))
596fcf3ce44SJohn Forte != MP_STATUS_SUCCESS) {
597fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
598fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
599fcf3ce44SJohn Forte return (mpstatus);
600fcf3ce44SJohn Forte }
601fcf3ce44SJohn Forte if ((NULL == pPluginOidList) || (pPluginOidList->oidCount < 1)) {
602fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
603fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
604fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
605fcf3ce44SJohn Forte }
606fcf3ce44SJohn Forte
607fcf3ce44SJohn Forte for (op = 0; op < operandLen; op++) {
608fcf3ce44SJohn Forte bFoundIt = B_FALSE;
609fcf3ce44SJohn Forte for (i = 0;
610fcf3ce44SJohn Forte (i < pPluginOidList->oidCount) && (B_TRUE != bFoundIt);
611fcf3ce44SJohn Forte i++) {
612fcf3ce44SJohn Forte
613fcf3ce44SJohn Forte (void) memset(&pluginProps, 0,
614fcf3ce44SJohn Forte sizeof (MP_PLUGIN_PROPERTIES));
615fcf3ce44SJohn Forte if ((mpstatus =
616fcf3ce44SJohn Forte MP_GetPluginProperties(pPluginOidList->oids[i],
617fcf3ce44SJohn Forte &pluginProps)) == MP_STATUS_SUCCESS) {
618fcf3ce44SJohn Forte
619fcf3ce44SJohn Forte if (0 == strcmp(operand[op],
620fcf3ce44SJohn Forte pluginProps.fileName)) {
621fcf3ce44SJohn Forte bFoundIt = B_TRUE;
622fcf3ce44SJohn Forte pluginOid = pPluginOidList->oids[i];
623fcf3ce44SJohn Forte }
624fcf3ce44SJohn Forte } else {
625fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
626fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_PROPERTIES));
627fcf3ce44SJohn Forte }
628fcf3ce44SJohn Forte
629fcf3ce44SJohn Forte if (B_FALSE == bFoundIt) {
630fcf3ce44SJohn Forte break;
631fcf3ce44SJohn Forte }
632fcf3ce44SJohn Forte
633fcf3ce44SJohn Forte /* begin back-up indentation */
634fcf3ce44SJohn Forte /* we found the plugin oid */
635fcf3ce44SJohn Forte /* now change the options requested */
636fcf3ce44SJohn Forte switch (optionList->optval) {
637fcf3ce44SJohn Forte case 'a':
638fcf3ce44SJohn Forte /* modify autofailback */
639fcf3ce44SJohn Forte cmdStr = getTextString(TEXT_AUTO_FAILBACK);
640fcf3ce44SJohn Forte if (0 == strcasecmp(optionList->optarg,
641fcf3ce44SJohn Forte getTextString(TEXT_ON))) {
642fcf3ce44SJohn Forte mpstatus =
643fcf3ce44SJohn Forte MP_EnableAutoFailback(pluginOid);
644fcf3ce44SJohn Forte } else if (0 ==
6454c06356bSdh strcasecmp(optionList->optarg,
6464c06356bSdh getTextString(TEXT_OFF))) {
647fcf3ce44SJohn Forte mpstatus =
648fcf3ce44SJohn Forte MP_DisableAutoFailback(pluginOid);
649fcf3ce44SJohn Forte } else {
650fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
651fcf3ce44SJohn Forte (void) fprintf(stderr, getTextString(
652fcf3ce44SJohn Forte ERR_FAILED_TO_CHANGE_OPTION_WITH_REASON),
653fcf3ce44SJohn Forte cmdStr,
654fcf3ce44SJohn Forte getTextString(TEXT_ILLEGAL_ARGUMENT));
655fcf3ce44SJohn Forte (void) printf("\n");
656fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
657fcf3ce44SJohn Forte }
658fcf3ce44SJohn Forte break;
659fcf3ce44SJohn Forte case 'p':
660fcf3ce44SJohn Forte /* modify autoprobing */
661fcf3ce44SJohn Forte cmdStr = getTextString(TEXT_AUTO_PROBING);
662fcf3ce44SJohn Forte if (0 == strcasecmp(optionList->optarg,
663fcf3ce44SJohn Forte getTextString(TEXT_ON))) {
664fcf3ce44SJohn Forte mpstatus =
665fcf3ce44SJohn Forte MP_EnableAutoProbing(pluginOid);
666fcf3ce44SJohn Forte } else if (0 ==
6674c06356bSdh strcasecmp(optionList->optarg,
6684c06356bSdh getTextString(TEXT_OFF))) {
669fcf3ce44SJohn Forte mpstatus =
670fcf3ce44SJohn Forte MP_DisableAutoProbing(pluginOid);
671fcf3ce44SJohn Forte } else {
672fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
673fcf3ce44SJohn Forte (void) fprintf(stderr, getTextString(
674fcf3ce44SJohn Forte ERR_FAILED_TO_CHANGE_OPTION_WITH_REASON),
675fcf3ce44SJohn Forte cmdStr,
676fcf3ce44SJohn Forte getTextString(TEXT_ILLEGAL_ARGUMENT));
677fcf3ce44SJohn Forte (void) printf("\n");
678fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
679fcf3ce44SJohn Forte }
680fcf3ce44SJohn Forte break;
681fcf3ce44SJohn Forte case 'b':
682fcf3ce44SJohn Forte /* modify loadbalance type */
683fcf3ce44SJohn Forte cmdStr = getTextString(TEXT_LOAD_BALANCE);
684fcf3ce44SJohn Forte /* user of the cli sends text string, we need the int */
685fcf3ce44SJohn Forte /* value to pass to the mpapi */
686fcf3ce44SJohn Forte lbValue = getLbValueFromString(optionList->optarg);
687fcf3ce44SJohn Forte mpstatus =
688fcf3ce44SJohn Forte MP_SetPluginLoadBalanceType(pluginOid,
689fcf3ce44SJohn Forte lbValue);
690fcf3ce44SJohn Forte break;
691fcf3ce44SJohn Forte
692fcf3ce44SJohn Forte } /* switch */
693fcf3ce44SJohn Forte if (MP_STATUS_SUCCESS != mpstatus) {
694fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
695fcf3ce44SJohn Forte (void) fprintf(stderr,
696fcf3ce44SJohn Forte getTextString(
697fcf3ce44SJohn Forte ERR_FAILED_TO_CHANGE_OPTION_WITH_REASON),
698fcf3ce44SJohn Forte cmdStr, getMpStatusStr(mpstatus));
699fcf3ce44SJohn Forte (void) printf("\n");
700fcf3ce44SJohn Forte return (mpstatus);
701fcf3ce44SJohn Forte }
702fcf3ce44SJohn Forte /* end back-up indentation */
703fcf3ce44SJohn Forte
704fcf3ce44SJohn Forte } /* for each plugin */
705fcf3ce44SJohn Forte
706fcf3ce44SJohn Forte if (B_FALSE == bFoundIt) {
707fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
708fcf3ce44SJohn Forte (void) fprintf(stderr,
709fcf3ce44SJohn Forte getTextString(
710fcf3ce44SJohn Forte ERR_FAILED_TO_CHANGE_OPTION_WITH_REASON),
711fcf3ce44SJohn Forte cmdStr,
712fcf3ce44SJohn Forte getTextString(TEXT_MPATH_SUPPORT_NOT_FOUND));
713fcf3ce44SJohn Forte (void) printf("\n");
714fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
715fcf3ce44SJohn Forte }
716fcf3ce44SJohn Forte
717fcf3ce44SJohn Forte } /* for each operand */
718fcf3ce44SJohn Forte
719fcf3ce44SJohn Forte return (mpstatus);
720fcf3ce44SJohn Forte }
721fcf3ce44SJohn Forte
722fcf3ce44SJohn Forte
723fcf3ce44SJohn Forte /*
724fcf3ce44SJohn Forte * ****************************************************************************
725fcf3ce44SJohn Forte *
726fcf3ce44SJohn Forte * listLogicalUnit -
727*ce5e7d21SToomas Soome * mpathadm list {logical-unit | LU} [options] [<logical-unit name>, ...]
728fcf3ce44SJohn Forte *
729fcf3ce44SJohn Forte * operandLen - number of operands user passed into the cli
730fcf3ce44SJohn Forte * operand - pointer to operand list from user
731fcf3ce44SJohn Forte * options - pointer to option list from user
732fcf3ce44SJohn Forte *
733fcf3ce44SJohn Forte * ****************************************************************************
734fcf3ce44SJohn Forte */
735fcf3ce44SJohn Forte int
listLogicalUnit(int operandLen,char * operand[],cmdOptions_t * options)736fcf3ce44SJohn Forte listLogicalUnit(int operandLen, char *operand[], cmdOptions_t *options)
737fcf3ce44SJohn Forte {
7384c06356bSdh MP_STATUS mpstatus = MP_STATUS_SUCCESS;
7394c06356bSdh MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES luProps;
7404c06356bSdh MP_PLUGIN_PROPERTIES pluginProps;
7414c06356bSdh MP_TARGET_PORT_PROPERTIES tportProps;
7424c06356bSdh MP_OID_LIST *pPluginOidList, *pLogicalUnitOidList,
7434c06356bSdh *pTpgOidListArray, *pTportOidListArray;
7444c06356bSdh boolean_t bListIt = B_FALSE, bFoundOperand = B_FALSE,
7454c06356bSdh *bFoundOption, bContinue = B_FALSE;
7464c06356bSdh MP_OID luOid;
7474c06356bSdh cmdOptions_t *optionList = options;
7484c06356bSdh int opListCount = 0, i = 0, lu = 0, tpg = 0, opoffset = 0, j = 0,
7494c06356bSdh opStart = 0, opEnd = 0, opIndex;
750fcf3ce44SJohn Forte
751fcf3ce44SJohn Forte /* count number of options */
752fcf3ce44SJohn Forte for (; optionList->optval; optionList++) {
753fcf3ce44SJohn Forte opListCount++;
754fcf3ce44SJohn Forte }
755fcf3ce44SJohn Forte
756fcf3ce44SJohn Forte bFoundOption = malloc((sizeof (boolean_t)) * opListCount);
757fcf3ce44SJohn Forte if (NULL == bFoundOption) {
758fcf3ce44SJohn Forte (void) fprintf(stdout, "%s\n",
759fcf3ce44SJohn Forte getTextString(ERR_MEMORY_ALLOCATION));
760fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
761fcf3ce44SJohn Forte }
762fcf3ce44SJohn Forte
763fcf3ce44SJohn Forte /* list to keep track of multiple options */
764fcf3ce44SJohn Forte optionList = options;
765fcf3ce44SJohn Forte for (opIndex = 0; opIndex < opListCount; opIndex++) {
766fcf3ce44SJohn Forte bFoundOption[opIndex] = B_FALSE;
767fcf3ce44SJohn Forte }
768fcf3ce44SJohn Forte
769fcf3ce44SJohn Forte optionList = options;
770fcf3ce44SJohn Forte
771fcf3ce44SJohn Forte /* if no operands or options, list everything we find */
772fcf3ce44SJohn Forte if ((0 == operandLen) && (0 == opListCount)) {
773fcf3ce44SJohn Forte if ((mpstatus = MP_GetPluginOidList(&pPluginOidList))
774fcf3ce44SJohn Forte != MP_STATUS_SUCCESS) {
775fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
776fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
777fcf3ce44SJohn Forte return (mpstatus);
778fcf3ce44SJohn Forte }
779fcf3ce44SJohn Forte if ((NULL == pPluginOidList) ||
780fcf3ce44SJohn Forte (pPluginOidList->oidCount < 1)) {
781fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
782fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
783fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
784fcf3ce44SJohn Forte }
785fcf3ce44SJohn Forte
786fcf3ce44SJohn Forte for (i = 0; i < pPluginOidList->oidCount; i++) {
787fcf3ce44SJohn Forte /* get properties so we can list the name */
788fcf3ce44SJohn Forte (void) memset(&pluginProps, 0,
789fcf3ce44SJohn Forte sizeof (MP_PLUGIN_PROPERTIES));
790fcf3ce44SJohn Forte if ((mpstatus =
791fcf3ce44SJohn Forte MP_GetPluginProperties(pPluginOidList->oids[i],
792fcf3ce44SJohn Forte &pluginProps)) != MP_STATUS_SUCCESS) {
793fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
794fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_PROPERTIES));
795fcf3ce44SJohn Forte return (mpstatus);
796fcf3ce44SJohn Forte }
797fcf3ce44SJohn Forte
798fcf3ce44SJohn Forte /* attempt to find this logical unit */
799fcf3ce44SJohn Forte mpstatus = MP_GetMultipathLus(pPluginOidList->oids[i],
800fcf3ce44SJohn Forte &pLogicalUnitOidList);
801fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
802fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
803fcf3ce44SJohn Forte cmdName, getTextString(ERR_NO_LU_LIST));
804fcf3ce44SJohn Forte return (mpstatus);
805fcf3ce44SJohn Forte }
806fcf3ce44SJohn Forte
807fcf3ce44SJohn Forte for (lu = 0; lu < pLogicalUnitOidList->oidCount; lu++) {
8084c06356bSdh /* begin backup indentation */
8094c06356bSdh /* get lu properties so we can check the name */
8104c06356bSdh (void) memset(&luProps, 0,
8114c06356bSdh sizeof (MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES));
8124c06356bSdh /* end backup indentation */
813fcf3ce44SJohn Forte mpstatus =
814fcf3ce44SJohn Forte MP_GetMPLogicalUnitProperties(
815fcf3ce44SJohn Forte pLogicalUnitOidList->oids[lu],
816fcf3ce44SJohn Forte &luProps);
817fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
818fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
819fcf3ce44SJohn Forte cmdName,
820fcf3ce44SJohn Forte getTextString(ERR_NO_PROPERTIES));
821fcf3ce44SJohn Forte return (mpstatus);
822fcf3ce44SJohn Forte }
823fcf3ce44SJohn Forte
824fcf3ce44SJohn Forte luOid = pLogicalUnitOidList->oids[lu];
825fcf3ce44SJohn Forte if (listIndividualLogicalUnit(luOid, luProps)
826fcf3ce44SJohn Forte != 0) {
827fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
828fcf3ce44SJohn Forte }
829fcf3ce44SJohn Forte } /* for each LU */
830fcf3ce44SJohn Forte } /* for each plugin */
831fcf3ce44SJohn Forte } else { /* we have operands and/or options */
832fcf3ce44SJohn Forte
833fcf3ce44SJohn Forte /* check if we have operands */
834fcf3ce44SJohn Forte if (0 == operandLen) {
835fcf3ce44SJohn Forte /* no operands */
836fcf3ce44SJohn Forte opStart = -1;
837fcf3ce44SJohn Forte opEnd = 0;
838fcf3ce44SJohn Forte } else {
839fcf3ce44SJohn Forte /* operands */
840fcf3ce44SJohn Forte opStart = 0;
841fcf3ce44SJohn Forte opEnd = operandLen;
842fcf3ce44SJohn Forte }
843fcf3ce44SJohn Forte
844fcf3ce44SJohn Forte if ((mpstatus = MP_GetPluginOidList(&pPluginOidList))
845fcf3ce44SJohn Forte != MP_STATUS_SUCCESS) {
846fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
847fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
848fcf3ce44SJohn Forte return (mpstatus);
849fcf3ce44SJohn Forte }
850fcf3ce44SJohn Forte if ((NULL == pPluginOidList) ||
851fcf3ce44SJohn Forte (pPluginOidList->oidCount < 1)) {
852fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
853fcf3ce44SJohn Forte getTextString(ERR_NO_MPATH_SUPPORT_LIST));
854fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
855fcf3ce44SJohn Forte }
856fcf3ce44SJohn Forte
857fcf3ce44SJohn Forte for (opoffset = opStart; opoffset < opEnd; opoffset++) {
858fcf3ce44SJohn Forte /* loop through operands */
859fcf3ce44SJohn Forte bFoundOperand = B_FALSE;
860fcf3ce44SJohn Forte
861fcf3ce44SJohn Forte for (i = 0; i < pPluginOidList->oidCount; i++) {
862fcf3ce44SJohn Forte
863fcf3ce44SJohn Forte /*
864fcf3ce44SJohn Forte * loop through plugin, and get properties
865fcf3ce44SJohn Forte * so we can list the name
866fcf3ce44SJohn Forte */
867fcf3ce44SJohn Forte (void) memset(&pluginProps, 0,
868fcf3ce44SJohn Forte sizeof (MP_PLUGIN_PROPERTIES));
869fcf3ce44SJohn Forte if ((mpstatus =
870fcf3ce44SJohn Forte MP_GetPluginProperties(
871fcf3ce44SJohn Forte pPluginOidList->oids[i], &pluginProps))
872fcf3ce44SJohn Forte != MP_STATUS_SUCCESS) {
873fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
874fcf3ce44SJohn Forte cmdName,
875fcf3ce44SJohn Forte getTextString(ERR_NO_PROPERTIES));
876fcf3ce44SJohn Forte return (mpstatus);
877fcf3ce44SJohn Forte }
878fcf3ce44SJohn Forte
879fcf3ce44SJohn Forte /* attempt to find this logical unit */
880fcf3ce44SJohn Forte mpstatus =
881fcf3ce44SJohn Forte MP_GetMultipathLus(pPluginOidList->oids[i],
882fcf3ce44SJohn Forte &pLogicalUnitOidList);
883fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
884fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
885fcf3ce44SJohn Forte cmdName,
886fcf3ce44SJohn Forte getTextString(ERR_NO_LU_LIST));
887fcf3ce44SJohn Forte return (mpstatus);
888fcf3ce44SJohn Forte }
889fcf3ce44SJohn Forte
890fcf3ce44SJohn Forte for (lu = 0;
891fcf3ce44SJohn Forte (lu < pLogicalUnitOidList->oidCount);
892fcf3ce44SJohn Forte lu++) {
893fcf3ce44SJohn Forte bListIt = B_FALSE;
8944c06356bSdh /* begin backup indentation */
8954c06356bSdh /* get lu props & check the name */
8964c06356bSdh (void) memset(&luProps, 0,
8974c06356bSdh sizeof (MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES));
8984c06356bSdh /* end backup indentation */
899fcf3ce44SJohn Forte mpstatus =
900fcf3ce44SJohn Forte MP_GetMPLogicalUnitProperties(
901fcf3ce44SJohn Forte pLogicalUnitOidList->oids[lu],
902fcf3ce44SJohn Forte &luProps);
903fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
904fcf3ce44SJohn Forte (void) fprintf(stderr,
905fcf3ce44SJohn Forte "%s: %s\n", cmdName,
906fcf3ce44SJohn Forte getTextString(
907fcf3ce44SJohn Forte ERR_NO_PROPERTIES));
908fcf3ce44SJohn Forte return (mpstatus);
909fcf3ce44SJohn Forte }
910fcf3ce44SJohn Forte
911fcf3ce44SJohn Forte /*
912fcf3ce44SJohn Forte * compare operand - is it a match?
913fcf3ce44SJohn Forte * If so, continue
914fcf3ce44SJohn Forte */
915fcf3ce44SJohn Forte
916fcf3ce44SJohn Forte bContinue = B_TRUE;
917fcf3ce44SJohn Forte if (operandLen > 0) {
918fcf3ce44SJohn Forte bContinue =
919fcf3ce44SJohn Forte compareLUName(
920fcf3ce44SJohn Forte operand[opoffset],
921fcf3ce44SJohn Forte luProps.deviceFileName);
922fcf3ce44SJohn Forte }
923fcf3ce44SJohn Forte
924fcf3ce44SJohn Forte if (B_TRUE == bContinue) {
925fcf3ce44SJohn Forte
926fcf3ce44SJohn Forte if (0 != opListCount) {
927fcf3ce44SJohn Forte /* check options */
928fcf3ce44SJohn Forte
929fcf3ce44SJohn Forte
930fcf3ce44SJohn Forte /* begin backup indentation */
931fcf3ce44SJohn Forte optionList = options;
932fcf3ce44SJohn Forte
933fcf3ce44SJohn Forte for (opIndex = 0; optionList->optval; optionList++, opIndex++) {
934fcf3ce44SJohn Forte switch (optionList->optval) {
935fcf3ce44SJohn Forte case 'n':
936fcf3ce44SJohn Forte if (B_TRUE ==
937fcf3ce44SJohn Forte compareLUName(optionList->optarg, luProps.name)) {
938fcf3ce44SJohn Forte bListIt = B_TRUE;
939fcf3ce44SJohn Forte bFoundOperand = B_TRUE;
940fcf3ce44SJohn Forte bFoundOption[opIndex] = B_TRUE;
941fcf3ce44SJohn Forte }
942fcf3ce44SJohn Forte break;
943fcf3ce44SJohn Forte case 't':
944fcf3ce44SJohn Forte /* get TPG list */
945fcf3ce44SJohn Forte mpstatus =
946fcf3ce44SJohn Forte MP_GetAssociatedTPGOidList(pLogicalUnitOidList->oids[lu],
947fcf3ce44SJohn Forte &pTpgOidListArray);
948fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
949fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n", cmdName,
950fcf3ce44SJohn Forte getTextString(ERR_NO_ASSOC_TPGS));
951fcf3ce44SJohn Forte return (mpstatus);
952fcf3ce44SJohn Forte }
953fcf3ce44SJohn Forte
954fcf3ce44SJohn Forte /* get target ports */
955fcf3ce44SJohn Forte for (tpg = 0;
956fcf3ce44SJohn Forte (NULL != pTpgOidListArray) &&
957fcf3ce44SJohn Forte (tpg < pTpgOidListArray->oidCount) &&
958fcf3ce44SJohn Forte (B_FALSE == bListIt); tpg++) {
959fcf3ce44SJohn Forte mpstatus =
960fcf3ce44SJohn Forte MP_GetTargetPortOidList(pTpgOidListArray->oids[tpg],
9614c06356bSdh &pTportOidListArray);
962fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
963fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
964fcf3ce44SJohn Forte cmdName,
965fcf3ce44SJohn Forte getTextString(ERR_NO_ASSOC_TPORTS));
966fcf3ce44SJohn Forte return (mpstatus);
967fcf3ce44SJohn Forte }
968fcf3ce44SJohn Forte
969fcf3ce44SJohn Forte /* get target port properties for the name */
970fcf3ce44SJohn Forte for (j = 0; (NULL != pTportOidListArray) &&
971fcf3ce44SJohn Forte (j < pTportOidListArray->oidCount) &&
972fcf3ce44SJohn Forte (B_FALSE == bListIt); j++) {
973fcf3ce44SJohn Forte (void) memset(&tportProps, 0,
974fcf3ce44SJohn Forte sizeof (MP_TARGET_PORT_PROPERTIES));
975fcf3ce44SJohn Forte mpstatus =
976fcf3ce44SJohn Forte MP_GetTargetPortProperties(
977fcf3ce44SJohn Forte pTportOidListArray->oids[j], &tportProps);
978fcf3ce44SJohn Forte if (mpstatus != MP_STATUS_SUCCESS) {
979fcf3ce44SJohn Forte (void) fprintf(stderr, "%s: %s\n",
980fcf3ce44SJohn Forte cmdName,
981fcf3ce44SJohn Forte getTextString(ERR_NO_PROPERTIES));
982fcf3ce44SJohn Forte return (mpstatus);
983fcf3ce44SJohn Forte }
984fcf3ce44SJohn Forte
985fcf3ce44SJohn Forte
986fcf3ce44SJohn Forte /* check the name */
987fcf3ce44SJohn Forte if (0 == strcmp(optionList->optarg,
988fcf3ce44SJohn Forte tportProps.portID)) {
989fcf3ce44SJohn Forte bListIt = B_TRUE;
990fcf3ce44SJohn Forte bFoundOperand = B_TRUE;
991fcf3ce44SJohn Forte bFoundOption[opIndex] = B_TRUE;
992fcf3ce44SJohn Forte }
993fcf3ce44SJohn Forte } /* for each target port */
994fcf3ce44SJohn Forte } /* for each tpg */
995fcf3ce44SJohn Forte } /* end switch */
996fcf3ce44SJohn Forte } /* loop through options */
997fcf3ce44SJohn Forte /* end back-up indentation */
998fcf3ce44SJohn Forte
999fcf3ce44SJohn Forte } else {
1000fcf3ce44SJohn Forte /*
1001fcf3ce44SJohn Forte * if no options,
1002fcf3ce44SJohn Forte * listit
1003fcf3ce44SJohn Forte */
1004fcf3ce44SJohn Forte bListIt = B_TRUE;
1005fcf3ce44SJohn Forte bFoundOperand = B_TRUE;
1006fcf3ce44SJohn Forte }
1007fcf3ce44SJohn Forte } /* end bContinue check */
1008fcf3ce44SJohn Forte
1009fcf3ce44SJohn Forte if (bListIt) {
1010fcf3ce44SJohn Forte (void) printf("%s %s\n",
1011fcf3ce44SJohn Forte getTextString(TEXT_LB_MPATH_SUPPORT),
1012fcf3ce44SJohn Forte pluginProps.fileName);
1013fcf3ce44SJohn Forte luOid = pLogicalUnitOidList->oids[lu];
1014fcf3ce44SJohn Forte if (listIndividualLogicalUnit(luOid, luProps)
1015fcf3ce44SJohn Forte != 0) {
1016fcf3ce44SJohn Forte return (ERROR_CLI_FAILED);
1017fcf3ce44SJohn Forte }
1018fcf3ce44SJohn Forte
1019fcf3ce44SJohn Forte }
1020fcf3ce44SJohn Forte
1021fcf3ce44SJohn Forte } /* end LU loop */
1022fcf3ce44SJohn Forte } /* end plugin loop */
1023fcf3ce44SJohn Forte if ((0 == opListCount) && (0 != operandLen)) {
1024fcf3ce44SJohn Forte if (B_FALSE == bFoundOperand) {
1025fcf3ce44SJohn Forte /* option/operand combo not found */
1026fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
1027fcf3ce44SJohn Forte (void) fprintf(stderr,
1028fcf3ce44SJohn Forte getTextString(
1029fcf3ce44SJohn Forte ERR_LU_NOT_FOUND_WITH_MISSING_LU_STR),
1030fcf3ce44SJohn Forte operand[opoffset]);
1031fcf3ce44SJohn Forte (void) fprintf(stderr, "\n");
1032fcf3ce44SJohn Forte }
1033fcf3ce44SJohn Forte }
1034fcf3ce44SJohn Forte
1035fcf3ce44SJohn Forte optionList = options;
1036fcf3ce44SJohn Forte for (opIndex = 0; optionList->optval; optionList++,
1037fcf3ce44SJohn Forte opIndex++) {
1038fcf3ce44SJohn Forte if (B_FALSE == bFoundOption[opIndex]) {
1039fcf3ce44SJohn Forte /* LINTED E_SEC_PRINTF_VAR_FMT */
1040fcf3ce44SJohn Forte (void) fprintf(stderr,
1041fcf3ce44SJohn Forte getTextString(
1042fcf3ce44SJohn Forte ERR_LU_NOT_FOUND_WITH_MISSING_LU_STR),
1043fcf3ce44SJohn Forte optionList->optarg);
1044fcf3ce44SJohn Forte (void) fprintf(stderr, "\n");
1045fcf3ce44SJohn Forte }
1046fcf3ce44SJohn Forte }
1047fcf3ce44SJohn Forte
1048fcf3ce44SJohn Forte
1049fcf3ce44SJohn Forte
1050fcf3ce44SJohn Forte } /* end loop through operands */
1051fcf3ce44SJohn Forte } /* we have operands and/or options */
1052fcf3ce44SJohn Forte
1053fcf3ce44SJohn Forte
1054fcf3ce44SJohn Forte return (mpstatus);
1055fcf3ce44SJohn Forte }
1056fcf3ce44SJohn Forte
1057fcf3ce44SJohn Forte
1058fcf3ce44SJohn Forte /*
1059fcf3ce44SJohn Forte * ****************************************************************************
1060fcf3ce44SJohn Forte *
1061fcf3ce44SJohn Forte * compareLUName -
1062*ce5e7d21SToomas Soome * compare names directly and via devid if no match directly
1063fcf3ce44SJohn Forte *
1064fcf3ce44SJohn Forte * cmpString - first string to compare
1065fcf3ce44SJohn Forte * deviceProperty - string from properties
1066fcf3ce44SJohn Forte * sizeToCompare - size of deviceProperty
1067fcf3ce44SJohn Forte *
1068*ce5e7d21SToomas Soome * returns B_TRUE if the strings match either directly or via devid
1069fcf3ce44SJohn Forte * B_FALSE otherwise
1070fcf3ce44SJohn Forte *
1071fcf3ce44SJohn Forte * ****************************************************************************
1072fcf3ce44SJohn Forte */
1073fcf3ce44SJohn Forte boolean_t
compareLUName(MP_CHAR * cmpString,MP_CHAR * deviceProperty)1074fcf3ce44SJohn Forte compareLUName(MP_CHAR *cmpString, MP_CHAR *deviceProperty)
1075fcf3ce44SJohn Forte {
1076fcf3ce44SJohn Forte
1077fcf3ce44SJohn Forte boolean_t isSame = B_FALSE;
1078*ce5e7d21SToomas Soome int fd1, fd2;
1079fcf3ce44SJohn Forte ddi_devid_t devid1 = NULL, devid2 = NULL;
1080fcf3ce44SJohn Forte
1081fcf3ce44SJohn Forte if (0 == strcmp(cmpString, deviceProperty)) {
1082fcf3ce44SJohn Forte isSame = B_TRUE;
1083fcf3ce44SJohn Forte } else {
1084fcf3ce44SJohn Forte /* user input didn't match, try via devid */
1085