Print this page
    
1845 allow disable of UNMAP via stmfadm(1M).
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/stmfadm/stmfadm.c
          +++ new/usr/src/cmd/stmfadm/stmfadm.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 2010 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 <stmfadm.h>
  40   40  #include <libstmf.h>
  41   41  #include <signal.h>
  42   42  #include <pthread.h>
  43   43  #include <locale.h>
  44   44  
  45   45  static int addHostGroupMemberFunc(int, char **, cmdOptions_t *, void *);
  46   46  static int addTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *);
  47   47  static int addViewFunc(int, char **, cmdOptions_t *, void *);
  48   48  static int createHostGroupFunc(int, char **, cmdOptions_t *, void *);
  49   49  static int createLuFunc(int, char **, cmdOptions_t *, void *);
  50   50  static int modifyLuFunc(int, char **, cmdOptions_t *, void *);
  51   51  static int importLuFunc(int, char **, cmdOptions_t *, void *);
  52   52  static int deleteLuFunc(int, char **, cmdOptions_t *, void *);
  53   53  static int createTargetGroupFunc(int, char **, cmdOptions_t *, void *);
  54   54  static int deleteHostGroupFunc(int, char **, cmdOptions_t *, void *);
  55   55  static int deleteTargetGroupFunc(int, char **, cmdOptions_t *, void *);
  56   56  static int listLuFunc(int, char **, cmdOptions_t *, void *);
  57   57  static int listTargetFunc(int, char **, cmdOptions_t *, void *);
  58   58  static int listViewFunc(int, char **, cmdOptions_t *, void *);
  59   59  static int listHostGroupFunc(int, char **, cmdOptions_t *, void *);
  60   60  static int listStateFunc(int, char **, cmdOptions_t *, void *);
  61   61  static int listTargetGroupFunc(int, char **, cmdOptions_t *, void *);
  62   62  static int offlineTargetFunc(int, char **, cmdOptions_t *, void *);
  63   63  static int offlineLuFunc(int, char **, cmdOptions_t *, void *);
  64   64  static int onlineTargetFunc(int, char **, cmdOptions_t *, void *);
  65   65  static int onlineLuFunc(int, char **, cmdOptions_t *, void *);
  66   66  static int onlineOfflineTarget(char *, int);
  67   67  static int onlineOfflineLu(char *, int);
  68   68  static int removeHostGroupMemberFunc(int, char **, cmdOptions_t *, void *);
  69   69  static int removeTargetGroupMemberFunc(int, char **, cmdOptions_t *, void *);
  70   70  static int callModify(char *, stmfGuid *, uint32_t, const char *, const char *);
  71   71  static int removeViewFunc(int, char **, cmdOptions_t *, void *);
  72   72  static char *getExecBasename(char *);
  
    | 
      ↓ open down ↓ | 
    72 lines elided | 
    
      ↑ open up ↑ | 
  
  73   73  static int parseDevid(char *input, stmfDevid *devid);
  74   74  static void printGroupProps(stmfGroupProperties *groupProps);
  75   75  static int checkScsiNameString(wchar_t *, stmfDevid *);
  76   76  static int checkHexUpper(char *);
  77   77  static int checkIscsiName(wchar_t *);
  78   78  static void printLuProps(stmfLogicalUnitProperties *luProps);
  79   79  static int printExtLuProps(stmfGuid *guid);
  80   80  static void printGuid(stmfGuid *guid, FILE *printWhere);
  81   81  static void printTargetProps(stmfTargetProperties *);
  82   82  static void printSessionProps(stmfSessionList *);
  83      -static int setLuPropFromInput(luResource, char *);
       83 +static int setLuPropFromInput(luResource, char *, uint32_t *);
  84   84  static int convertCharToPropId(char *, uint32_t *);
  85   85  
  86   86  
  87   87  
  88   88  /*
  89   89   *  MAJOR - This should only change when there is an incompatible change made
  90   90   *  to the interfaces or the output.
  91   91   *
  92   92   *  MINOR - This should change whenever there is a new command or new feature
  93   93   *  with no incompatible change.
  94   94   */
  95   95  #define VERSION_STRING_MAJOR        "1"
  96   96  #define VERSION_STRING_MINOR        "0"
  97   97  #define MAX_DEVID_INPUT             256
  98   98  #define GUID_INPUT                  32
  99   99  #define MAX_LU_NBR                  16383
 100  100  #define ONLINE_LU                   0
 101  101  #define OFFLINE_LU                  1
 102  102  #define ONLINE_TARGET               2
 103  103  #define OFFLINE_TARGET              3
 104  104  #define PROPS_FORMAT                "    %-18s: "
 105  105  #define VIEW_FORMAT                 "    %-13s: "
 106  106  #define LVL3_FORMAT                 "        %s"
 107  107  #define LVL4_FORMAT                 "            %s"
 108  108  #define DELAYED_EXEC_WAIT_INTERVAL  300 * 1000 * 1000   /* in nano sec */
 109  109  #define DELAYED_EXEC_WAIT_MAX       30  /* Maximum number of interval times */
 110  110  
 111  111  /* SCSI Name String length definitions */
 112  112  #define SNS_EUI_16                  16
 113  113  #define SNS_EUI_24                  24
 114  114  #define SNS_EUI_32                  32
 115  115  #define SNS_NAA_16                  16
 116  116  #define SNS_NAA_32                  32
 117  117  #define SNS_WWN_16                  16
 118  118  #define SNS_IQN_223                 223
 119  119  
 120  120  /* LU Property strings */
 121  121  #define GUID                        "GUID"
 122  122  #define ALIAS                       "ALIAS"
  
    | 
      ↓ open down ↓ | 
    29 lines elided | 
    
      ↑ open up ↑ | 
  
 123  123  #define VID                         "VID"
 124  124  #define PID                         "PID"
 125  125  #define META_FILE                   "META"
 126  126  #define WRITE_PROTECT               "WP"
 127  127  #define WRITEBACK_CACHE_DISABLE     "WCD"
 128  128  #define COMPANY_ID                  "OUI"
 129  129  #define BLOCK_SIZE                  "BLK"
 130  130  #define SERIAL_NUMBER               "SERIAL"
 131  131  #define MGMT_URL                    "MGMT-URL"
 132  132  #define HOST_ID                     "HOST-ID"
      133 +#define UNMAP                       "UNMAP"
 133  134  
 134  135  #define STMFADM_SUCCESS             0
 135  136  #define STMFADM_FAILURE             1
 136  137  
 137  138  #define MODIFY_HELP "\n"\
 138  139  "Description: Modify properties of a logical unit. \n" \
 139  140  "Valid properties for -p, --lu-prop are: \n" \
 140  141  "     alias    - alias for logical unit (up to 255 chars)\n" \
 141  142  "     mgmt-url - Management URL address\n" \
      143 +"     unmap    - iSCSI UNMAP enabled (true, false)\n" \
 142  144  "     wcd      - write cache disabled (true, false)\n" \
 143  145  "     wp       - write protect (true, false)\n\n" \
 144  146  "-f alters the meaning of the operand to be a file name\n" \
 145  147  "rather than a LU name. This allows for modification\n" \
 146  148  "of a logical unit that is not yet imported into stmf\n"
 147  149  
 148  150  #define CREATE_HELP "\n"\
 149  151  "Description: Create a logical unit. \n" \
 150  152  "Valid properties for -p, --lu-prop are: \n" \
 151  153  "     alias    - alias for logical unit (up to 255 chars)\n" \
 152  154  "     blk      - block size in bytes in 2^n\n" \
 153  155  "     guid     - 32 ascii hex characters in NAA format \n" \
 154  156  "     host-id  - host identifier to be used for GUID generation \n" \
 155  157  "                8 ascii hex characters\n" \
 156  158  "     meta     - separate meta data file name\n" \
 157  159  "     mgmt-url - Management URL address\n" \
 158  160  "     oui      - organizational unique identifier\n" \
 159  161  "                6 ascii hex characters of valid format\n" \
 160  162  "     pid      - product identifier (up to 16 chars)\n" \
 161  163  "     serial   - serial number (up to 252 chars)\n" \
      164 +"     unmap    - iSCSI UNMAP enabled (true, false)\n" \
 162  165  "     vid      - vendor identifier (up to 8 chars)\n" \
 163  166  "     wcd      - write cache disabled (true, false)\n" \
 164  167  "     wp       - write protect (true, false)\n"
 165  168  #define ADD_VIEW_HELP "\n"\
 166  169  "Description: Add a view entry to a logical unit. \n" \
 167  170  "A view entry is comprised of three elements; the \n" \
 168  171  "logical unit number, the target group name and the\n" \
 169  172  "host group name. These three elements combine together\n" \
 170  173  "to form a view for a given COMSTAR logical unit.\n" \
 171  174  "This view is realized by a client, a SCSI initiator,\n" \
 172  175  "via a REPORT LUNS command. \n"
 173  176  
 174  177  
 175  178  
 176  179  /* tables set up based on cmdparse instructions */
 177  180  
 178  181  /* add new options here */
 179  182  optionTbl_t longOptions[] = {
 180  183          {"all", no_arg, 'a', NULL},
 181  184          {"group-name", required_arg, 'g', "group-name"},
 182  185          {"keep-views", no_arg, 'k', NULL},
 183  186          {"lu-name", required_arg, 'l', "LU-Name"},
 184  187          {"lun", required_arg, 'n', "logical-unit-number"},
 185  188          {"lu-prop", required_arg, 'p', "logical-unit-property=value"},
 186  189          {"file", no_arg, 'f', "filename"},
 187  190          {"size", required_arg, 's', "size K/M/G/T/P"},
 188  191          {"target-group", required_arg, 't', "group-name"},
 189  192          {"host-group", required_arg, 'h', "group-name"},
 190  193          {"verbose", no_arg, 'v', NULL},
 191  194          {NULL, 0, 0, 0}
 192  195  };
 193  196  
 194  197  /*
 195  198   * Add new subcommands here
 196  199   */
 197  200  subCommandProps_t subcommands[] = {
 198  201          {"add-hg-member", addHostGroupMemberFunc, "g", "g", NULL,
 199  202                  OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
 200  203          {"add-tg-member", addTargetGroupMemberFunc, "g", "g", NULL,
 201  204                  OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
 202  205          {"add-view", addViewFunc, "nth", NULL, NULL,
 203  206                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, ADD_VIEW_HELP},
 204  207          {"create-hg", createHostGroupFunc, NULL, NULL, NULL,
 205  208                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
 206  209          {"create-tg", createTargetGroupFunc, NULL, NULL, NULL,
 207  210                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
 208  211          {"create-lu", createLuFunc, "ps", NULL, NULL, OPERAND_MANDATORY_SINGLE,
 209  212                  "lu file", CREATE_HELP},
 210  213          {"delete-hg", deleteHostGroupFunc, NULL, NULL, NULL,
 211  214                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
 212  215          {"modify-lu", modifyLuFunc, "psf", NULL, NULL, OPERAND_MANDATORY_SINGLE,
 213  216                  OPERANDSTRING_LU, MODIFY_HELP},
 214  217          {"delete-lu", deleteLuFunc, "k", NULL, NULL,
 215  218                  OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_LU, NULL},
 216  219          {"delete-tg", deleteTargetGroupFunc, NULL, NULL, NULL,
 217  220                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_GROUP_NAME, NULL},
 218  221          {"import-lu", importLuFunc, NULL, NULL, NULL,
 219  222                  OPERAND_MANDATORY_SINGLE, "file name", NULL},
 220  223          {"list-hg", listHostGroupFunc, "v", NULL, NULL,
 221  224                  OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL},
 222  225          {"list-lu", listLuFunc, "v", NULL, NULL, OPERAND_OPTIONAL_MULTIPLE,
 223  226                  OPERANDSTRING_LU, NULL},
 224  227          {"list-state", listStateFunc, NULL, NULL, NULL, OPERAND_NONE, NULL},
 225  228          {"list-target", listTargetFunc, "v", NULL, NULL,
 226  229                  OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_TARGET, NULL},
 227  230          {"list-tg", listTargetGroupFunc, "v", NULL, NULL,
 228  231                  OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_GROUP_NAME, NULL},
 229  232          {"list-view", listViewFunc, "l", "l", NULL,
 230  233                  OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL},
 231  234          {"online-lu", onlineLuFunc, NULL, NULL, NULL,
 232  235                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
 233  236          {"offline-lu", offlineLuFunc, NULL, NULL, NULL,
 234  237                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_LU, NULL},
 235  238          {"online-target", onlineTargetFunc, NULL, NULL, NULL,
 236  239                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL},
 237  240          {"offline-target", offlineTargetFunc, NULL, NULL, NULL,
 238  241                  OPERAND_MANDATORY_SINGLE, OPERANDSTRING_TARGET, NULL},
 239  242          {"remove-hg-member", removeHostGroupMemberFunc, "g", "g", NULL,
 240  243                  OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
 241  244          {"remove-tg-member", removeTargetGroupMemberFunc, "g", "g", NULL,
 242  245                  OPERAND_MANDATORY_MULTIPLE, OPERANDSTRING_GROUP_MEMBER, NULL},
 243  246          {"remove-view", removeViewFunc, "la", "l", NULL,
 244  247                  OPERAND_OPTIONAL_MULTIPLE, OPERANDSTRING_VIEW_ENTRY, NULL},
 245  248          {NULL, 0, NULL, NULL, 0, NULL, 0, NULL, NULL}
 246  249  };
 247  250  
 248  251  /* globals */
 249  252  char *cmdName;
 250  253  
 251  254  /*
 252  255   * addHostGroupMemberFunc
 253  256   *
 254  257   * Add members to a host group
 255  258   *
 256  259   */
 257  260  /*ARGSUSED*/
 258  261  static int
 259  262  addHostGroupMemberFunc(int operandLen, char *operands[], cmdOptions_t *options,
 260  263      void *args)
 261  264  {
 262  265          int i;
 263  266          int ret = 0;
 264  267          int stmfRet;
 265  268          stmfGroupName groupName = {0};
 266  269          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
 267  270          stmfDevid devid;
 268  271  
 269  272          for (; options->optval; options++) {
 270  273                  switch (options->optval) {
 271  274                          /* host group name */
 272  275                          case 'g':
 273  276                                  (void) mbstowcs(groupNamePrint, options->optarg,
 274  277                                      sizeof (stmfGroupName) - 1);
 275  278                                  bcopy(options->optarg, groupName,
 276  279                                      strlen(options->optarg));
 277  280                                  break;
 278  281                          default:
 279  282                                  (void) fprintf(stderr, "%s: %c: %s\n",
 280  283                                      cmdName, options->optval,
 281  284                                      gettext("unknown option"));
 282  285                                  return (1);
 283  286                  }
 284  287          }
 285  288  
 286  289          for (i = 0; i < operandLen; i++) {
 287  290                  if (parseDevid(operands[i], &devid) != 0) {
 288  291                          (void) fprintf(stderr, "%s: %s: %s\n",
 289  292                              cmdName, operands[i],
 290  293                              gettext("unrecognized device id"));
 291  294                          ret++;
 292  295                          continue;
 293  296                  }
 294  297                  stmfRet = stmfAddToHostGroup(&groupName, &devid);
 295  298                  switch (stmfRet) {
 296  299                          case STMF_STATUS_SUCCESS:
 297  300                                  break;
 298  301                          case STMF_ERROR_EXISTS:
 299  302                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 300  303                                      operands[i], gettext("already exists"));
 301  304                                  ret++;
 302  305                                  break;
 303  306                          case STMF_ERROR_GROUP_NOT_FOUND:
 304  307                                  (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
 305  308                                      groupNamePrint, gettext("not found"));
 306  309                                  ret++;
 307  310                                  break;
 308  311                          case STMF_ERROR_PERM:
 309  312                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 310  313                                      gettext("permission denied"));
 311  314                                  ret++;
 312  315                                  break;
 313  316                          case STMF_ERROR_BUSY:
 314  317                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 315  318                                      operands[i], gettext("resource busy"));
 316  319                                  ret++;
 317  320                                  break;
 318  321                          case STMF_ERROR_SERVICE_NOT_FOUND:
 319  322                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 320  323                                      gettext("STMF service not found"));
 321  324                                  ret++;
 322  325                                  break;
 323  326                          case STMF_ERROR_SERVICE_DATA_VERSION:
 324  327                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 325  328                                      gettext("STMF service version incorrect"));
 326  329                                  ret++;
 327  330                                  break;
 328  331                          default:
 329  332                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 330  333                                      operands[i], gettext("unknown error"));
 331  334                                  ret++;
 332  335                                  break;
 333  336                  }
 334  337          }
 335  338  
 336  339          return (ret);
 337  340  }
 338  341  
 339  342  /*
 340  343   * addTargetGroupMemberFunc
 341  344   *
 342  345   * Add members to a target group
 343  346   *
 344  347   */
 345  348  /*ARGSUSED*/
 346  349  static int
 347  350  addTargetGroupMemberFunc(int operandLen, char *operands[],
 348  351      cmdOptions_t *options, void *args)
 349  352  {
 350  353          int i;
 351  354          int ret = 0;
 352  355          int stmfRet;
 353  356          stmfGroupName groupName = {0};
 354  357          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
 355  358          stmfDevid devid;
 356  359  
 357  360          for (; options->optval; options++) {
 358  361                  switch (options->optval) {
 359  362                          /* target group name */
 360  363                          case 'g':
 361  364                                  (void) mbstowcs(groupNamePrint, options->optarg,
 362  365                                      sizeof (stmfGroupName) - 1);
 363  366                                  bcopy(options->optarg, groupName,
 364  367                                      strlen(options->optarg));
 365  368                                  break;
 366  369                          default:
 367  370                                  (void) fprintf(stderr, "%s: %c: %s\n",
 368  371                                      cmdName, options->optval,
 369  372                                      gettext("unknown option"));
 370  373                                  return (1);
 371  374                  }
 372  375          }
 373  376  
 374  377          for (i = 0; i < operandLen; i++) {
 375  378                  if (parseDevid(operands[i], &devid) != 0) {
 376  379                          (void) fprintf(stderr, "%s: %s: %s\n",
 377  380                              cmdName, operands[i],
 378  381                              gettext("unrecognized device id"));
 379  382                          ret++;
 380  383                          continue;
 381  384                  }
 382  385                  stmfRet = stmfAddToTargetGroup(&groupName, &devid);
 383  386                  switch (stmfRet) {
 384  387                          case STMF_STATUS_SUCCESS:
 385  388                                  break;
 386  389                          case STMF_ERROR_EXISTS:
 387  390                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 388  391                                      operands[i], gettext("already exists"));
 389  392                                  ret++;
 390  393                                  break;
 391  394                          case STMF_ERROR_GROUP_NOT_FOUND:
 392  395                                  (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
 393  396                                      groupNamePrint, gettext("not found"));
 394  397                                  ret++;
 395  398                                  break;
 396  399                          case STMF_ERROR_PERM:
 397  400                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 398  401                                      gettext("permission denied"));
 399  402                                  ret++;
 400  403                                  break;
 401  404                          case STMF_ERROR_BUSY:
 402  405                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 403  406                                      operands[i], gettext("resource busy"));
 404  407                                  ret++;
 405  408                                  break;
 406  409                          case STMF_ERROR_SERVICE_NOT_FOUND:
 407  410                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 408  411                                      gettext("STMF service not found"));
 409  412                                  ret++;
 410  413                                  break;
 411  414                          case STMF_ERROR_SERVICE_ONLINE:
 412  415                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 413  416                                      gettext("STMF service must be offline"));
 414  417                                  ret++;
 415  418                                  break;
 416  419                          case STMF_ERROR_SERVICE_DATA_VERSION:
 417  420                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 418  421                                      gettext("STMF service version incorrect"));
 419  422                                  ret++;
 420  423                                  break;
 421  424                          case STMF_ERROR_TG_ONLINE:
 422  425                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
 423  426                                      gettext("STMF target must be offline"));
 424  427                                  ret++;
 425  428                                  break;
 426  429                          default:
 427  430                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 428  431                                      operands[i], gettext("unknown error"));
 429  432                                  ret++;
 430  433                                  break;
 431  434                  }
 432  435          }
 433  436  
 434  437          return (ret);
 435  438  }
 436  439  
 437  440  /*
 438  441   * parseDevid
 439  442   *
 440  443   * Converts char * input to a stmfDevid
 441  444   *
 442  445   * input - this should be in the following format with either a
 443  446   * wwn. iqn. or eui. representation.
 444  447   * A name string of the format:
 445  448   *      wwn.<WWN> (FC/SAS address)
 446  449   *      iqn.<iSCSI name> (iSCSI iqn)
 447  450   *      eui.<WWN> (iSCSI eui name)
 448  451   *
 449  452   * devid - pointer to stmfDevid structure allocated by the caller.
 450  453   *
 451  454   * Returns:
 452  455   *  0 on success
 453  456   *  non-zero on failure
 454  457   */
 455  458  static int
 456  459  parseDevid(char *input, stmfDevid *devid)
 457  460  {
 458  461          wchar_t inputWc[MAX_DEVID_INPUT + 1] = {0};
 459  462  
 460  463          /* convert to wcs */
 461  464          (void) mbstowcs(inputWc, input, MAX_DEVID_INPUT);
 462  465  
 463  466          /*
 464  467           * Check for known scsi name string formats
 465  468           * If one is found, we're done
 466  469           * If not, then it's a failure to parse
 467  470           */
 468  471          if (checkScsiNameString(inputWc, devid) == 0) {
 469  472                  return (0);
 470  473          }
 471  474  
 472  475          return (-1);
 473  476  }
 474  477  
 475  478  /*
 476  479   * checkScsiNameString
 477  480   *
 478  481   * Validates known SCSI name string formats and converts to stmfDevid
 479  482   * format
 480  483   *
 481  484   * input - input SCSI name string
 482  485   * devid - pointer to stmfDevid structure allocated by the caller
 483  486   *         on successful return, contains the devid based on input
 484  487   *
 485  488   * returns:
 486  489   *         0 on success
 487  490   *         -1 on failure
 488  491   */
 489  492  static int
 490  493  checkScsiNameString(wchar_t *input, stmfDevid *devid)
 491  494  {
 492  495          char *mbString = NULL;
 493  496          int mbStringLen;
 494  497          int len;
 495  498          int i;
 496  499  
 497  500          /*
 498  501           * Convert to multi-byte string
 499  502           *
 500  503           * This is used for either eui or naa formats
 501  504           */
 502  505          mbString = calloc(1, (mbStringLen = wcstombs(mbString, input, 0)) + 1);
 503  506          if (mbString == NULL) {
 504  507                  (void) fprintf(stderr, "%s: %s\n",
 505  508                      cmdName, "Insufficient memory\n");
 506  509                  return (-1);
 507  510          }
 508  511          if (wcstombs(mbString, input, mbStringLen) == (size_t)-1) {
 509  512                  return (-1);
 510  513          }
 511  514  
 512  515          /*
 513  516           * check for iqn format
 514  517           */
 515  518          if (strncmp(mbString, "iqn.", 4) == 0) {
 516  519                  if ((len = strlen(mbString)) > (SNS_IQN_223)) {
 517  520                          return (-1);
 518  521                  }
 519  522                  for (i = 0; i < len; i++) {
 520  523                          mbString[i] = tolower(mbString[i]);
 521  524                  }
 522  525                  if (checkIscsiName(input + 4) != 0) {
 523  526                          return (-1);
 524  527                  }
 525  528          } else if (strncmp(mbString, "wwn.", 4) == 0) {
 526  529                  if ((len = strlen(mbString + 4)) != SNS_WWN_16) {
 527  530                          return (-1);
 528  531                  } else if (checkHexUpper(mbString + 4) != 0) {
 529  532                          return (-1);
 530  533                  }
 531  534          } else if (strncmp(mbString, "eui.", 4) == 0) {
 532  535                  if ((len = strlen(mbString + 4)) != SNS_EUI_16) {
 533  536                          return (-1);
 534  537                  } else if (checkHexUpper(mbString + 4) != 0) {
 535  538                          return (-1);
 536  539                  }
 537  540          } else {
 538  541                  return (-1);
 539  542          }
 540  543  
 541  544          /*
 542  545           * We have a validated name string.
 543  546           * Go ahead and set the length and copy it.
 544  547           */
 545  548          devid->identLength = strlen(mbString);
 546  549          bzero(devid->ident, STMF_IDENT_LENGTH);
 547  550          bcopy(mbString, devid->ident, devid->identLength);
 548  551  
 549  552          return (0);
 550  553  }
 551  554  
 552  555  
 553  556  /*
 554  557   * Checks whether the entire string is in hex and converts to upper
 555  558   */
 556  559  static int
 557  560  checkHexUpper(char *input)
 558  561  {
 559  562          int i;
 560  563  
 561  564          for (i = 0; i < strlen(input); i++) {
 562  565                  if (isxdigit(input[i])) {
 563  566                          input[i] = toupper(input[i]);
 564  567                          continue;
 565  568                  }
 566  569                  return (-1);
 567  570          }
 568  571  
 569  572          return (0);
 570  573  }
 571  574  
 572  575  /*
 573  576   * checkIscsiName
 574  577   *
 575  578   * Purpose: Basic string checking on name
 576  579   */
 577  580  static int
 578  581  checkIscsiName(wchar_t *input)
 579  582  {
 580  583          int i;
 581  584  
 582  585          for (i = 0; input[i] != 0; i++) {
 583  586                  if (!iswalnum(input[i]) && input[i] != '-' &&
 584  587                      input[i] != '.' && input[i] != ':') {
 585  588                          return (-1);
 586  589                  }
 587  590          }
 588  591  
 589  592          return (0);
 590  593  }
 591  594  
 592  595  
 593  596  /*
 594  597   * addViewFunc
 595  598   *
 596  599   * Adds a view entry to a logical unit
 597  600   *
 598  601   */
 599  602  /*ARGSUSED*/
 600  603  static int
 601  604  addViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
 602  605      void *args)
 603  606  {
 604  607          stmfViewEntry viewEntry;
 605  608          stmfGuid inGuid;
 606  609          unsigned int guid[sizeof (stmfGuid)];
 607  610          uint16_t inputLuNbr;
 608  611          int ret = 0;
 609  612          int stmfRet;
 610  613          int i;
 611  614          char sGuid[GUID_INPUT + 1];
 612  615  
 613  616          bzero(&viewEntry, sizeof (viewEntry));
 614  617          /* init view entry structure */
 615  618          viewEntry.allHosts = B_TRUE;
 616  619          viewEntry.allTargets = B_TRUE;
 617  620          viewEntry.luNbrValid = B_FALSE;
 618  621  
 619  622          /* check input length */
 620  623          if (strlen(operands[0]) != GUID_INPUT) {
 621  624                  (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0],
 622  625                      gettext("must be "), GUID_INPUT,
 623  626                      gettext(" hexadecimal digits"));
 624  627                  return (1);
 625  628          }
 626  629  
 627  630          for (; options->optval; options++) {
 628  631                  switch (options->optval) {
 629  632                          /* logical unit number */
 630  633                          case 'n':
 631  634                                  viewEntry.luNbrValid = B_TRUE;
 632  635                                  inputLuNbr = atoi(options->optarg);
 633  636                                  if (inputLuNbr > MAX_LU_NBR) {
 634  637                                          (void) fprintf(stderr, "%s: %d: %s\n",
 635  638                                              cmdName, inputLuNbr,
 636  639                                              gettext("Logical unit number"
 637  640                                              " must be less than 16384"));
 638  641                                          return (1);
 639  642                                  }
 640  643                                  viewEntry.luNbr[0] = inputLuNbr >> 8;
 641  644                                  viewEntry.luNbr[1] = inputLuNbr & 0xff;
 642  645                                  break;
 643  646                          /* host group */
 644  647                          case 'h':
 645  648                                  viewEntry.allHosts = B_FALSE;
 646  649                                  bcopy(options->optarg, viewEntry.hostGroup,
 647  650                                      strlen(options->optarg));
 648  651                                  break;
 649  652                          /* target group */
 650  653                          case 't':
 651  654                                  viewEntry.allTargets = B_FALSE;
 652  655                                  bcopy(options->optarg, viewEntry.targetGroup,
 653  656                                      strlen(options->optarg));
 654  657                                  break;
 655  658                          default:
 656  659                                  (void) fprintf(stderr, "%s: %c: %s\n",
 657  660                                      cmdName, options->optval,
 658  661                                      gettext("unknown option"));
 659  662                                  return (1);
 660  663                  }
 661  664          }
 662  665  
 663  666          /* convert to lower case for scan */
 664  667          for (i = 0; i < 32; i++)
 665  668                  sGuid[i] = tolower(operands[0][i]);
 666  669          sGuid[i] = 0;
 667  670  
 668  671          (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
 669  672              &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
 670  673              &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
 671  674              &guid[12], &guid[13], &guid[14], &guid[15]);
 672  675  
 673  676          for (i = 0; i < sizeof (stmfGuid); i++) {
 674  677                  inGuid.guid[i] = guid[i];
 675  678          }
 676  679  
 677  680          /* add the view entry */
 678  681          stmfRet = stmfAddViewEntry(&inGuid, &viewEntry);
 679  682          switch (stmfRet) {
 680  683                  case STMF_STATUS_SUCCESS:
 681  684                          break;
 682  685                  case STMF_ERROR_EXISTS:
 683  686                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 684  687                              operands[0], gettext("already exists"));
 685  688                          ret++;
 686  689                          break;
 687  690                  case STMF_ERROR_BUSY:
 688  691                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 689  692                              operands[0], gettext("resource busy"));
 690  693                          ret++;
 691  694                          break;
 692  695                  case STMF_ERROR_SERVICE_NOT_FOUND:
 693  696                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 694  697                              gettext("STMF service not found"));
 695  698                          ret++;
 696  699                          break;
 697  700                  case STMF_ERROR_PERM:
 698  701                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 699  702                              gettext("permission denied"));
 700  703                          ret++;
 701  704                          break;
 702  705                  case STMF_ERROR_LUN_IN_USE:
 703  706                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 704  707                              gettext("LUN already in use"));
 705  708                          ret++;
 706  709                          break;
 707  710                  case STMF_ERROR_VE_CONFLICT:
 708  711                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 709  712                              gettext("view entry exists"));
 710  713                          ret++;
 711  714                          break;
 712  715                  case STMF_ERROR_CONFIG_NONE:
 713  716                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 714  717                              gettext("STMF service is not initialized"));
 715  718                          ret++;
 716  719                          break;
 717  720                  case STMF_ERROR_SERVICE_DATA_VERSION:
 718  721                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 719  722                              gettext("STMF service version incorrect"));
 720  723                          ret++;
 721  724                          break;
 722  725                  case STMF_ERROR_INVALID_HG:
 723  726                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 724  727                              gettext("invalid host group"));
 725  728                          ret++;
 726  729                          break;
 727  730                  case STMF_ERROR_INVALID_TG:
 728  731                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 729  732                              gettext("invalid target group"));
 730  733                          ret++;
 731  734                          break;
 732  735                  default:
 733  736                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 734  737                              operands[0], gettext("unknown error"));
 735  738                          ret++;
 736  739                          break;
 737  740          }
 738  741  
 739  742          return (ret);
 740  743  }
 741  744  
 742  745  /*
 743  746   * createHostGroupFunc
 744  747   *
 745  748   * Create a host group
 746  749   *
 747  750   */
 748  751  /*ARGSUSED*/
 749  752  static int
 750  753  createHostGroupFunc(int operandLen, char *operands[],
 751  754      cmdOptions_t *options, void *args)
 752  755  {
 753  756          int ret = 0;
 754  757          int stmfRet;
 755  758          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
 756  759          stmfGroupName groupName = {0};
 757  760  
 758  761          (void) strlcpy(groupName, operands[0], sizeof (groupName));
 759  762          (void) mbstowcs(groupNamePrint, (char *)groupName,
 760  763              sizeof (stmfGroupName) - 1);
 761  764          /* call create group */
 762  765          stmfRet = stmfCreateHostGroup(&groupName);
 763  766          switch (stmfRet) {
 764  767                  case STMF_STATUS_SUCCESS:
 765  768                          break;
 766  769                  case STMF_ERROR_EXISTS:
 767  770                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 768  771                              operands[0], gettext("already exists"));
 769  772                          ret++;
 770  773                          break;
 771  774                  case STMF_ERROR_BUSY:
 772  775                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
 773  776                              operands[0], gettext("resource busy"));
 774  777                          ret++;
 775  778                          break;
 776  779                  case STMF_ERROR_SERVICE_NOT_FOUND:
 777  780                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 778  781                              gettext("STMF service not found"));
 779  782                          ret++;
 780  783                          break;
 781  784                  case STMF_ERROR_PERM:
 782  785                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 783  786                              gettext("permission denied"));
 784  787                          ret++;
 785  788                          break;
 786  789                  case STMF_ERROR_SERVICE_DATA_VERSION:
 787  790                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 788  791                              gettext("STMF service version incorrect"));
 789  792                          ret++;
 790  793                          break;
 791  794                  default:
 792  795                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
 793  796                              operands[0], gettext("unknown error"));
 794  797                          ret++;
 795  798                          break;
 796  799          }
 797  800  
 798  801          return (ret);
 799  802  }
 800  803  
 801  804  /*
 802  805   * createLuFunc
 803  806   *
 804  807   * Create a logical unit
 805  808   *
 806  809   */
  
    | 
      ↓ open down ↓ | 
    635 lines elided | 
    
      ↑ open up ↑ | 
  
 807  810  /*ARGSUSED*/
 808  811  static int
 809  812  createLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
 810  813      void *args)
 811  814  {
 812  815          luResource hdl = NULL;
 813  816          int ret = 0;
 814  817          int stmfRet = 0;
 815  818          char guidAsciiBuf[33];
 816  819          stmfGuid createdGuid;
      820 +        uint32_t propid;
      821 +        boolean_t unmap_not_set = B_TRUE;
 817  822  
 818  823          stmfRet = stmfCreateLuResource(STMF_DISK, &hdl);
 819  824  
 820  825          if (stmfRet != STMF_STATUS_SUCCESS) {
 821  826                  (void) fprintf(stderr, "%s: %s\n",
 822  827                      cmdName, gettext("Failure to create lu resource\n"));
 823  828                  return (1);
 824  829          }
 825  830  
 826  831          for (; options->optval; options++) {
 827  832                  switch (options->optval) {
 828  833                          case 'p':
 829      -                                ret = setLuPropFromInput(hdl, options->optarg);
      834 +                                ret = setLuPropFromInput(hdl, options->optarg,
      835 +                                    &propid);
      836 +                                if (propid == STMF_LU_PROP_UNMAP)
      837 +                                        unmap_not_set = B_FALSE;
 830  838                                  if (ret != 0) {
 831  839                                          (void) stmfFreeLuResource(hdl);
 832  840                                          return (1);
 833  841                                  }
 834  842                                  break;
 835  843                          case 's':
 836  844                                  stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_SIZE,
 837  845                                      options->optarg);
 838  846                                  if (stmfRet != STMF_STATUS_SUCCESS) {
 839  847                                          (void) fprintf(stderr, "%s: %c: %s\n",
 840  848                                              cmdName, options->optval,
 841  849                                              gettext("size param invalid"));
 842  850                                          (void) stmfFreeLuResource(hdl);
 843  851                                          return (1);
  
    | 
      ↓ open down ↓ | 
    4 lines elided | 
    
      ↑ open up ↑ | 
  
 844  852                                  }
 845  853                                  break;
 846  854                          default:
 847  855                                  (void) fprintf(stderr, "%s: %c: %s\n",
 848  856                                      cmdName, options->optval,
 849  857                                      gettext("unknown option"));
 850  858                                  return (1);
 851  859                  }
 852  860          }
 853  861  
      862 +        if (unmap_not_set) {
      863 +                /*
      864 +                 * We "enable" unmap by default, but STMF is hostile toward
      865 +                 * enable-by-default, so we enable it here if it hasn't
      866 +                 * already been set.
      867 +                 */
      868 +                if (stmfSetLuProp(hdl, STMF_LU_PROP_UNMAP, "true") !=
      869 +                    STMF_STATUS_SUCCESS) {
      870 +                        fprintf(stderr, "%s: %s\n", cmdName,
      871 +                            gettext("Problems setting UNMAP default"));
      872 +                }
      873 +        }
      874 +
 854  875          stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]);
 855  876  
 856  877          if (stmfRet != STMF_STATUS_SUCCESS) {
 857  878                  (void) fprintf(stderr, "%s: %s\n",
 858  879                      cmdName, gettext("could not set filename"));
 859  880                  return (1);
 860  881          }
 861  882  
 862  883          stmfRet = stmfCreateLu(hdl, &createdGuid);
 863  884          switch (stmfRet) {
 864  885                  case STMF_STATUS_SUCCESS:
 865  886                          break;
 866  887                  case STMF_ERROR_BUSY:
 867  888                  case STMF_ERROR_LU_BUSY:
 868  889                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 869  890                              gettext("resource busy"));
 870  891                          ret++;
 871  892                          break;
 872  893                  case STMF_ERROR_PERM:
 873  894                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 874  895                              gettext("permission denied"));
 875  896                          ret++;
 876  897                          break;
 877  898                  case STMF_ERROR_FILE_IN_USE:
 878  899                          (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
 879  900                              operands[0], gettext("in use"));
 880  901                          ret++;
 881  902                          break;
 882  903                  case STMF_ERROR_INVALID_BLKSIZE:
 883  904                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 884  905                              gettext("invalid block size"));
 885  906                          ret++;
 886  907                          break;
 887  908                  case STMF_ERROR_GUID_IN_USE:
 888  909                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 889  910                              gettext("guid in use"));
 890  911                          ret++;
 891  912                          break;
 892  913                  case STMF_ERROR_META_FILE_NAME:
 893  914                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 894  915                              gettext("meta file error"));
 895  916                          ret++;
 896  917                          break;
 897  918                  case STMF_ERROR_DATA_FILE_NAME:
 898  919                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 899  920                              gettext("data file error"));
 900  921                          ret++;
 901  922                          break;
 902  923                  case STMF_ERROR_FILE_SIZE_INVALID:
 903  924                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 904  925                              gettext("file size invalid"));
 905  926                          ret++;
 906  927                          break;
 907  928                  case STMF_ERROR_SIZE_OUT_OF_RANGE:
 908  929                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 909  930                              gettext("invalid size"));
 910  931                          ret++;
 911  932                          break;
 912  933                  case STMF_ERROR_META_CREATION:
 913  934                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 914  935                              gettext("could not create meta file"));
 915  936                          ret++;
 916  937                          break;
 917  938                  case STMF_ERROR_WRITE_CACHE_SET:
 918  939                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 919  940                              gettext("could not set write cache"));
 920  941                          ret++;
 921  942                          break;
 922  943                  default:
 923  944                          (void) fprintf(stderr, "%s: %s\n", cmdName,
 924  945                              gettext("unknown error"));
 925  946                          ret++;
 926  947                          break;
 927  948          }
 928  949  
 929  950          if (ret != 0) {
 930  951                  goto done;
 931  952          }
 932  953  
 933  954          (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
 934  955              "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
 935  956              "%02X%02X%02X%02X%02X%02X",
 936  957              createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2],
 937  958              createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5],
 938  959              createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8],
 939  960              createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11],
 940  961              createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14],
 941  962              createdGuid.guid[15]);
 942  963          (void) printf("Logical unit created: %s\n", guidAsciiBuf);
 943  964  
 944  965  done:
 945  966          (void) stmfFreeLuResource(hdl);
 946  967          return (ret);
 947  968  }
 948  969  
 949  970  /*
 950  971   * createLuFunc
 951  972   *
 952  973   * Create a logical unit
 953  974   *
 954  975   */
 955  976  /*ARGSUSED*/
 956  977  static int
 957  978  modifyLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
 958  979      void *args)
 959  980  {
 960  981          stmfGuid inGuid;
 961  982          unsigned int guid[sizeof (stmfGuid)];
 962  983          int ret = 0;
 963  984          int i;
 964  985          char *fname = NULL;
 965  986          char *lasts = NULL;
 966  987          char sGuid[GUID_INPUT + 1];
 967  988          char *prop = NULL;
 968  989          char *propVal = NULL;
 969  990          boolean_t fnameUsed = B_FALSE;
 970  991          uint32_t propId;
 971  992          cmdOptions_t *optionStart = options;
 972  993  
 973  994  
 974  995          for (; options->optval; options++) {
 975  996                  switch (options->optval) {
 976  997                          case 'f':
 977  998                                  fnameUsed = B_TRUE;
 978  999                                  fname = operands[0];
 979 1000                                  break;
 980 1001                  }
 981 1002          }
 982 1003          options = optionStart;
 983 1004  
 984 1005          /* check input length */
 985 1006          if (!fnameUsed && strlen(operands[0]) != GUID_INPUT) {
 986 1007                  (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[0],
 987 1008                      gettext("must be "), GUID_INPUT,
 988 1009                      gettext(" hexadecimal digits"));
 989 1010                  return (1);
 990 1011          }
 991 1012  
 992 1013          if (!fnameUsed) {
 993 1014                  /* convert to lower case for scan */
 994 1015                  for (i = 0; i < 32; i++)
 995 1016                          sGuid[i] = tolower(operands[0][i]);
 996 1017                  sGuid[i] = 0;
 997 1018                  (void) sscanf(sGuid,
 998 1019                      "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
 999 1020                      &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
1000 1021                      &guid[6], &guid[7], &guid[8], &guid[9], &guid[10],
1001 1022                      &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]);
1002 1023  
1003 1024                  for (i = 0; i < sizeof (stmfGuid); i++) {
1004 1025                          inGuid.guid[i] = guid[i];
1005 1026                  }
1006 1027          }
1007 1028  
1008 1029          for (; options->optval; options++) {
1009 1030                  switch (options->optval) {
1010 1031                          case 'p':
1011 1032                                  prop = strtok_r(options->optarg, "=", &lasts);
1012 1033                                  propVal = strtok_r(NULL, "=", &lasts);
1013 1034                                  ret = convertCharToPropId(prop, &propId);
1014 1035                                  if (ret != 0) {
1015 1036                                          (void) fprintf(stderr, "%s: %s: %s\n",
1016 1037                                              cmdName,
1017 1038                                          gettext("invalid property specified"),
1018 1039                                              prop);
1019 1040                                          return (1);
1020 1041                                  }
1021 1042                                  if (propVal ==  NULL &&
1022 1043                                      propId != STMF_LU_PROP_MGMT_URL) {
1023 1044                                          (void) fprintf(stderr, "%s: %s: %s\n",
1024 1045                                              cmdName, options->optarg,
1025 1046                                              gettext("invalid property specifier"
1026 1047                                              "- prop=val\n"));
1027 1048                                          return (1);
1028 1049                                  }
1029 1050                                  if (propVal ==  NULL) {
1030 1051                                          ret = callModify(fname, &inGuid, propId,
1031 1052                                              "", prop);
1032 1053                                  } else {
1033 1054                                          ret = callModify(fname, &inGuid, propId,
1034 1055                                              propVal, prop);
1035 1056                                  }
1036 1057                                  if (ret != 0) {
1037 1058                                          return (1);
1038 1059                                  }
1039 1060                                  break;
1040 1061                          case 's':
1041 1062                                  if (callModify(fname, &inGuid,
1042 1063                                      STMF_LU_PROP_SIZE, options->optarg,
1043 1064                                      "size") != 0) {
1044 1065                                          return (1);
1045 1066                                  }
1046 1067                                  break;
1047 1068                          case 'f':
1048 1069                                  break;
1049 1070                          default:
1050 1071                                  (void) fprintf(stderr, "%s: %c: %s\n",
1051 1072                                      cmdName, options->optval,
1052 1073                                      gettext("unknown option"));
1053 1074                                  return (1);
1054 1075                  }
1055 1076          }
1056 1077          return (ret);
1057 1078  }
1058 1079  
1059 1080  static int
1060 1081  callModify(char *fname, stmfGuid *luGuid, uint32_t prop, const char *propVal,
1061 1082      const char *propString)
1062 1083  {
1063 1084          int ret = 0;
1064 1085          int stmfRet = 0;
1065 1086  
1066 1087          if (!fname) {
1067 1088                  stmfRet = stmfModifyLu(luGuid, prop, propVal);
1068 1089          } else {
1069 1090                  stmfRet = stmfModifyLuByFname(STMF_DISK, fname, prop,
1070 1091                      propVal);
1071 1092          }
1072 1093          switch (stmfRet) {
1073 1094                  case STMF_STATUS_SUCCESS:
1074 1095                          break;
1075 1096                  case STMF_ERROR_BUSY:
1076 1097                  case STMF_ERROR_LU_BUSY:
1077 1098                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1078 1099                              gettext("resource busy"));
1079 1100                          ret++;
1080 1101                          break;
1081 1102                  case STMF_ERROR_PERM:
1082 1103                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1083 1104                              gettext("permission denied"));
1084 1105                          ret++;
1085 1106                          break;
1086 1107                  case STMF_ERROR_INVALID_BLKSIZE:
1087 1108                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1088 1109                              gettext("invalid block size"));
1089 1110                          ret++;
1090 1111                          break;
1091 1112                  case STMF_ERROR_GUID_IN_USE:
1092 1113                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1093 1114                              gettext("guid in use"));
1094 1115                          ret++;
1095 1116                          break;
1096 1117                  case STMF_ERROR_META_FILE_NAME:
1097 1118                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1098 1119                              gettext("meta file error"));
1099 1120                          ret++;
1100 1121                          break;
1101 1122                  case STMF_ERROR_DATA_FILE_NAME:
1102 1123                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1103 1124                              gettext("data file error"));
1104 1125                          ret++;
1105 1126                          break;
1106 1127                  case STMF_ERROR_FILE_SIZE_INVALID:
1107 1128                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1108 1129                              gettext("file size invalid"));
1109 1130                          ret++;
1110 1131                          break;
1111 1132                  case STMF_ERROR_SIZE_OUT_OF_RANGE:
1112 1133                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1113 1134                              gettext("invalid size"));
1114 1135                          ret++;
1115 1136                          break;
1116 1137                  case STMF_ERROR_META_CREATION:
1117 1138                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1118 1139                              gettext("could not create meta file"));
1119 1140                          ret++;
1120 1141                          break;
1121 1142                  case STMF_ERROR_INVALID_PROP:
1122 1143                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1123 1144                              gettext("invalid property for modify"));
1124 1145                          ret++;
1125 1146                          break;
1126 1147                  case STMF_ERROR_WRITE_CACHE_SET:
1127 1148                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1128 1149                              gettext("could not set write cache"));
1129 1150                          ret++;
1130 1151                          break;
1131 1152                  case STMF_ERROR_ACCESS_STATE_SET:
1132 1153                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1133 1154                              gettext("cannot modify while in standby mode"));
1134 1155                          ret++;
1135 1156                          break;
1136 1157                  default:
1137 1158                          (void) fprintf(stderr, "%s: %s: %s: %d\n", cmdName,
1138 1159                              gettext("could not set property"), propString,
1139 1160                              stmfRet);
1140 1161                          ret++;
1141 1162                          break;
1142 1163          }
1143 1164  
1144 1165          return (ret);
1145 1166  }
1146 1167  
1147 1168  
1148 1169  /*
1149 1170   * importLuFunc
1150 1171   *
1151 1172   * Create a logical unit
1152 1173   *
1153 1174   */
1154 1175  /*ARGSUSED*/
1155 1176  static int
1156 1177  importLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
1157 1178      void *args)
1158 1179  {
1159 1180          int stmfRet = 0;
1160 1181          int ret = 0;
1161 1182          char guidAsciiBuf[33];
1162 1183          stmfGuid createdGuid;
1163 1184  
1164 1185          stmfRet = stmfImportLu(STMF_DISK, operands[0], &createdGuid);
1165 1186          switch (stmfRet) {
1166 1187                  case STMF_STATUS_SUCCESS:
1167 1188                          break;
1168 1189                  case STMF_ERROR_BUSY:
1169 1190                  case STMF_ERROR_LU_BUSY:
1170 1191                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1171 1192                              gettext("resource busy"));
1172 1193                          ret++;
1173 1194                          break;
1174 1195                  case STMF_ERROR_PERM:
1175 1196                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1176 1197                              gettext("permission denied"));
1177 1198                          ret++;
1178 1199                          break;
1179 1200                  case STMF_ERROR_FILE_IN_USE:
1180 1201                          (void) fprintf(stderr, "%s: filename %s: %s\n", cmdName,
1181 1202                              operands[0], gettext("in use"));
1182 1203                          ret++;
1183 1204                          break;
1184 1205                  case STMF_ERROR_GUID_IN_USE:
1185 1206                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1186 1207                              gettext("guid in use"));
1187 1208                          ret++;
1188 1209                          break;
1189 1210                  case STMF_ERROR_META_FILE_NAME:
1190 1211                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1191 1212                              gettext("meta file error"));
1192 1213                          ret++;
1193 1214                          break;
1194 1215                  case STMF_ERROR_DATA_FILE_NAME:
1195 1216                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1196 1217                              gettext("data file error"));
1197 1218                          ret++;
1198 1219                          break;
1199 1220                  case STMF_ERROR_META_CREATION:
1200 1221                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1201 1222                              gettext("could not create meta file"));
1202 1223                          ret++;
1203 1224                          break;
1204 1225                  case STMF_ERROR_WRITE_CACHE_SET:
1205 1226                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1206 1227                              gettext("could not set write cache"));
1207 1228                          ret++;
1208 1229                          break;
1209 1230                  default:
1210 1231                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1211 1232                              gettext("unknown error"));
1212 1233                          ret++;
1213 1234                          break;
1214 1235          }
1215 1236  
1216 1237          if (ret != STMF_STATUS_SUCCESS) {
1217 1238                  goto done;
1218 1239          }
1219 1240  
1220 1241          (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
1221 1242              "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
1222 1243              "%02X%02X%02X%02X%02X%02X",
1223 1244              createdGuid.guid[0], createdGuid.guid[1], createdGuid.guid[2],
1224 1245              createdGuid.guid[3], createdGuid.guid[4], createdGuid.guid[5],
1225 1246              createdGuid.guid[6], createdGuid.guid[7], createdGuid.guid[8],
  
    | 
      ↓ open down ↓ | 
    362 lines elided | 
    
      ↑ open up ↑ | 
  
1226 1247              createdGuid.guid[9], createdGuid.guid[10], createdGuid.guid[11],
1227 1248              createdGuid.guid[12], createdGuid.guid[13], createdGuid.guid[14],
1228 1249              createdGuid.guid[15]);
1229 1250          (void) printf("Logical unit imported: %s\n", guidAsciiBuf);
1230 1251  
1231 1252  done:
1232 1253          return (ret);
1233 1254  }
1234 1255  
1235 1256  static int
1236      -setLuPropFromInput(luResource hdl, char *optarg)
     1257 +setLuPropFromInput(luResource hdl, char *optarg, uint32_t *propId)
1237 1258  {
1238 1259          char *prop = NULL;
1239 1260          char *propVal = NULL;
1240 1261          char *lasts = NULL;
1241      -        uint32_t propId;
1242 1262          int ret = 0;
1243 1263  
1244 1264          prop = strtok_r(optarg, "=", &lasts);
1245 1265          if ((propVal = strtok_r(NULL, "=", &lasts)) == NULL) {
1246 1266                  (void) fprintf(stderr, "%s: %s: %s\n",
1247 1267                      cmdName, optarg,
1248 1268                      gettext("invalid property specifier - prop=val\n"));
1249 1269                  return (1);
1250 1270          }
1251 1271  
1252      -        ret = convertCharToPropId(prop, &propId);
     1272 +        ret = convertCharToPropId(prop, propId);
1253 1273          if (ret != 0) {
1254 1274                  (void) fprintf(stderr, "%s: %s: %s\n",
1255 1275                      cmdName, gettext("invalid property specified"), prop);
1256 1276                  return (1);
1257 1277          }
1258 1278  
1259      -        ret = stmfSetLuProp(hdl, propId, propVal);
     1279 +        ret = stmfSetLuProp(hdl, *propId, propVal);
1260 1280          if (ret != STMF_STATUS_SUCCESS) {
1261 1281                  (void) fprintf(stderr, "%s: %s %s: ",
1262 1282                      cmdName, gettext("unable to set"), prop);
1263 1283                  switch (ret) {
1264 1284                          case STMF_ERROR_INVALID_PROPSIZE:
1265 1285                                  (void) fprintf(stderr, "invalid length\n");
1266 1286                                  break;
1267 1287                          case STMF_ERROR_INVALID_ARG:
1268 1288                                  (void) fprintf(stderr, "bad format\n");
1269 1289                                  break;
1270 1290                          default:
1271 1291                                  (void) fprintf(stderr, "\n");
1272 1292                                  break;
1273 1293                  }
1274 1294                  return (1);
1275 1295          }
1276 1296  
1277 1297          return (0);
1278 1298  }
1279 1299  
1280 1300  static int
1281 1301  convertCharToPropId(char *prop, uint32_t *propId)
1282 1302  {
1283 1303          if (strcasecmp(prop, GUID) == 0) {
1284 1304                  *propId = STMF_LU_PROP_GUID;
1285 1305          } else if (strcasecmp(prop, ALIAS) == 0) {
1286 1306                  *propId = STMF_LU_PROP_ALIAS;
1287 1307          } else if (strcasecmp(prop, VID) == 0) {
1288 1308                  *propId = STMF_LU_PROP_VID;
1289 1309          } else if (strcasecmp(prop, PID) == 0) {
1290 1310                  *propId = STMF_LU_PROP_PID;
1291 1311          } else if (strcasecmp(prop, WRITE_PROTECT) == 0) {
1292 1312                  *propId = STMF_LU_PROP_WRITE_PROTECT;
1293 1313          } else if (strcasecmp(prop, WRITEBACK_CACHE_DISABLE) == 0) {
1294 1314                  *propId = STMF_LU_PROP_WRITE_CACHE_DISABLE;
1295 1315          } else if (strcasecmp(prop, BLOCK_SIZE) == 0) {
1296 1316                  *propId = STMF_LU_PROP_BLOCK_SIZE;
  
    | 
      ↓ open down ↓ | 
    27 lines elided | 
    
      ↑ open up ↑ | 
  
1297 1317          } else if (strcasecmp(prop, SERIAL_NUMBER) == 0) {
1298 1318                  *propId = STMF_LU_PROP_SERIAL_NUM;
1299 1319          } else if (strcasecmp(prop, COMPANY_ID) == 0) {
1300 1320                  *propId = STMF_LU_PROP_COMPANY_ID;
1301 1321          } else if (strcasecmp(prop, META_FILE) == 0) {
1302 1322                  *propId = STMF_LU_PROP_META_FILENAME;
1303 1323          } else if (strcasecmp(prop, MGMT_URL) == 0) {
1304 1324                  *propId = STMF_LU_PROP_MGMT_URL;
1305 1325          } else if (strcasecmp(prop, HOST_ID) == 0) {
1306 1326                  *propId = STMF_LU_PROP_HOST_ID;
     1327 +        } else if (strcasecmp(prop, UNMAP) == 0) {
     1328 +                *propId = STMF_LU_PROP_UNMAP;
1307 1329          } else {
1308 1330                  return (1);
1309 1331          }
1310 1332          return (0);
1311 1333  }
1312 1334  
1313 1335  /*
1314 1336   * deleteLuFunc
1315 1337   *
1316 1338   * Delete a logical unit
1317 1339   *
1318 1340   */
1319 1341  /*ARGSUSED*/
1320 1342  static int
1321 1343  deleteLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
1322 1344      void *args)
1323 1345  {
1324 1346          int i, j;
1325 1347          int ret = 0;
1326 1348          int stmfRet;
1327 1349          unsigned int inGuid[sizeof (stmfGuid)];
1328 1350          stmfGuid delGuid;
1329 1351          boolean_t keepViews = B_FALSE;
1330 1352          boolean_t viewEntriesRemoved = B_FALSE;
1331 1353          boolean_t noLunFound = B_FALSE;
1332 1354          boolean_t views = B_FALSE;
1333 1355          boolean_t notValidHexNumber = B_FALSE;
1334 1356          char sGuid[GUID_INPUT + 1];
1335 1357          stmfViewEntryList *viewEntryList = NULL;
1336 1358  
1337 1359          for (; options->optval; options++) {
1338 1360                  switch (options->optval) {
1339 1361                          /* Keep views for logical unit */
1340 1362                          case 'k':
1341 1363                                  keepViews = B_TRUE;
1342 1364                                  break;
1343 1365                          default:
1344 1366                                  (void) fprintf(stderr, "%s: %c: %s\n",
1345 1367                                      cmdName, options->optval,
1346 1368                                      gettext("unknown option"));
1347 1369                                  return (1);
1348 1370                  }
1349 1371          }
1350 1372  
1351 1373  
1352 1374          for (i = 0; i < operandLen; i++) {
1353 1375                  for (j = 0; j < GUID_INPUT; j++) {
1354 1376                          if (!isxdigit(operands[i][j])) {
1355 1377                                  notValidHexNumber = B_TRUE;
1356 1378                                  break;
1357 1379                          }
1358 1380                          sGuid[j] = tolower(operands[i][j]);
1359 1381                  }
1360 1382                  if ((notValidHexNumber == B_TRUE) ||
1361 1383                      (strlen(operands[i]) != GUID_INPUT)) {
1362 1384                          (void) fprintf(stderr, "%s: %s: %s%d%s\n",
1363 1385                              cmdName, operands[i], gettext("must be "),
1364 1386                              GUID_INPUT,
1365 1387                              gettext(" hexadecimal digits long"));
1366 1388                          notValidHexNumber = B_FALSE;
1367 1389                          ret++;
1368 1390                          continue;
1369 1391                  }
1370 1392  
1371 1393                  sGuid[j] = 0;
1372 1394  
1373 1395                  (void) sscanf(sGuid,
1374 1396                      "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
1375 1397                      &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3],
1376 1398                      &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7],
1377 1399                      &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11],
1378 1400                      &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]);
1379 1401  
1380 1402                  for (j = 0; j < sizeof (stmfGuid); j++) {
1381 1403                          delGuid.guid[j] = inGuid[j];
1382 1404                  }
1383 1405  
1384 1406                  stmfRet = stmfDeleteLu(&delGuid);
1385 1407                  switch (stmfRet) {
1386 1408                          case STMF_STATUS_SUCCESS:
1387 1409                                  break;
1388 1410                          case STMF_ERROR_NOT_FOUND:
1389 1411                                  noLunFound = B_TRUE;
1390 1412                                  break;
1391 1413                          case STMF_ERROR_BUSY:
1392 1414                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1393 1415                                      gettext("resource busy"));
1394 1416                                  ret++;
1395 1417                                  break;
1396 1418                          case STMF_ERROR_PERM:
1397 1419                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1398 1420                                      gettext("permission denied"));
1399 1421                                  ret++;
1400 1422                                  break;
1401 1423                          default:
1402 1424                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1403 1425                                      gettext("unknown error"));
1404 1426                                  ret++;
1405 1427                                  break;
1406 1428                  }
1407 1429  
1408 1430                  if (!keepViews) {
1409 1431                          stmfRet = stmfGetViewEntryList(&delGuid,
1410 1432                              &viewEntryList);
1411 1433                          if (stmfRet == STMF_STATUS_SUCCESS) {
1412 1434                                  for (j = 0; j < viewEntryList->cnt; j++) {
1413 1435                                          (void) stmfRemoveViewEntry(&delGuid,
1414 1436                                              viewEntryList->ve[j].veIndex);
1415 1437                                  }
1416 1438                                  /* check if viewEntryList is empty */
1417 1439                                  if (viewEntryList->cnt != 0)
1418 1440                                          viewEntriesRemoved = B_TRUE;
1419 1441                                  stmfFreeMemory(viewEntryList);
1420 1442                          } else {
1421 1443                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1422 1444                                      gettext("unable to remove view entries\n"));
1423 1445                                  ret++;
1424 1446                          }
1425 1447  
1426 1448                  }
1427 1449                  if (keepViews) {
1428 1450                          stmfRet = stmfGetViewEntryList(&delGuid,
1429 1451                              &viewEntryList);
1430 1452                          if (stmfRet == STMF_STATUS_SUCCESS) {
1431 1453                                  views = B_TRUE;
1432 1454                                  stmfFreeMemory(viewEntryList);
1433 1455                          }
1434 1456                  }
1435 1457  
1436 1458                  if ((!viewEntriesRemoved && noLunFound && !views) ||
1437 1459                      (!views && keepViews && noLunFound)) {
1438 1460                          (void) fprintf(stderr, "%s: %s: %s\n",
1439 1461                              cmdName, sGuid,
1440 1462                              gettext("not found"));
1441 1463                          ret++;
1442 1464                  }
1443 1465                  noLunFound = viewEntriesRemoved = views = B_FALSE;
1444 1466          }
1445 1467          return (ret);
1446 1468  }
1447 1469  
1448 1470  
1449 1471  /*
1450 1472   * createTargetGroupFunc
1451 1473   *
1452 1474   * Create a target group
1453 1475   *
1454 1476   */
1455 1477  /*ARGSUSED*/
1456 1478  static int
1457 1479  createTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1458 1480      void *args)
1459 1481  {
1460 1482          int ret = 0;
1461 1483          int stmfRet;
1462 1484          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
1463 1485          stmfGroupName groupName = {0};
1464 1486  
1465 1487          (void) strlcpy(groupName, operands[0], sizeof (groupName));
1466 1488          (void) mbstowcs(groupNamePrint, (char *)groupName,
1467 1489              sizeof (stmfGroupName) - 1);
1468 1490          /* call create group */
1469 1491          stmfRet = stmfCreateTargetGroup(&groupName);
1470 1492          switch (stmfRet) {
1471 1493                  case STMF_STATUS_SUCCESS:
1472 1494                          break;
1473 1495                  case STMF_ERROR_EXISTS:
1474 1496                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1475 1497                              groupNamePrint, gettext("already exists"));
1476 1498                          ret++;
1477 1499                          break;
1478 1500                  case STMF_ERROR_BUSY:
1479 1501                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1480 1502                              groupNamePrint, gettext("resource busy"));
1481 1503                          ret++;
1482 1504                          break;
1483 1505                  case STMF_ERROR_PERM:
1484 1506                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1485 1507                              gettext("permission denied"));
1486 1508                          ret++;
1487 1509                          break;
1488 1510                  case STMF_ERROR_SERVICE_NOT_FOUND:
1489 1511                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1490 1512                              gettext("STMF service not found"));
1491 1513                          ret++;
1492 1514                          break;
1493 1515                  case STMF_ERROR_SERVICE_DATA_VERSION:
1494 1516                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1495 1517                              gettext("STMF service version incorrect"));
1496 1518                          ret++;
1497 1519                          break;
1498 1520                  default:
1499 1521                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1500 1522                              groupNamePrint, gettext("unknown error"));
1501 1523                          ret++;
1502 1524                          break;
1503 1525          }
1504 1526  
1505 1527          return (ret);
1506 1528  }
1507 1529  
1508 1530  /*
1509 1531   * deleteHostGroupFunc
1510 1532   *
1511 1533   * Delete a host group
1512 1534   *
1513 1535   */
1514 1536  /*ARGSUSED*/
1515 1537  static int
1516 1538  deleteHostGroupFunc(int operandLen, char *operands[],
1517 1539      cmdOptions_t *options, void *args)
1518 1540  {
1519 1541          int ret = 0;
1520 1542          int stmfRet;
1521 1543          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
1522 1544          stmfGroupName groupName = {0};
1523 1545  
1524 1546          (void) strlcpy(groupName, operands[0], sizeof (groupName));
1525 1547          (void) mbstowcs(groupNamePrint, (char *)groupName,
1526 1548              sizeof (stmfGroupName) - 1);
1527 1549          /* call delete group */
1528 1550          stmfRet = stmfDeleteHostGroup(&groupName);
1529 1551          switch (stmfRet) {
1530 1552                  case STMF_STATUS_SUCCESS:
1531 1553                          break;
1532 1554                  case STMF_ERROR_NOT_FOUND:
1533 1555                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1534 1556                              groupNamePrint, gettext("not found"));
1535 1557                          ret++;
1536 1558                          break;
1537 1559                  case STMF_ERROR_BUSY:
1538 1560                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1539 1561                              groupNamePrint, gettext("resource busy"));
1540 1562                          ret++;
1541 1563                          break;
1542 1564                  case STMF_ERROR_SERVICE_NOT_FOUND:
1543 1565                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1544 1566                              gettext("STMF service not found"));
1545 1567                          ret++;
1546 1568                          break;
1547 1569                  case STMF_ERROR_PERM:
1548 1570                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1549 1571                              gettext("permission denied"));
1550 1572                          ret++;
1551 1573                          break;
1552 1574                  case STMF_ERROR_GROUP_IN_USE:
1553 1575                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1554 1576                              groupNamePrint,
1555 1577                              gettext("group is in use by existing view entry"));
1556 1578                          ret++;
1557 1579                          break;
1558 1580                  case STMF_ERROR_SERVICE_DATA_VERSION:
1559 1581                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1560 1582                              gettext("STMF service version incorrect"));
1561 1583                          ret++;
1562 1584                          break;
1563 1585                  default:
1564 1586                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1565 1587                              groupNamePrint, gettext("unknown error"));
1566 1588                          ret++;
1567 1589                          break;
1568 1590          }
1569 1591  
1570 1592          return (ret);
1571 1593  }
1572 1594  
1573 1595  /*
1574 1596   * deleteTargetGroupFunc
1575 1597   *
1576 1598   * Delete a target group
1577 1599   *
1578 1600   */
1579 1601  /*ARGSUSED*/
1580 1602  static int
1581 1603  deleteTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1582 1604      void *args)
1583 1605  {
1584 1606          int ret = 0;
1585 1607          int stmfRet;
1586 1608          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
1587 1609          stmfGroupName groupName = {0};
1588 1610  
1589 1611          (void) strlcpy(groupName, operands[0], sizeof (groupName));
1590 1612          (void) mbstowcs(groupNamePrint, (char *)groupName,
1591 1613              sizeof (stmfGroupName) - 1);
1592 1614          /* call delete group */
1593 1615          stmfRet = stmfDeleteTargetGroup(&groupName);
1594 1616          switch (stmfRet) {
1595 1617                  case STMF_STATUS_SUCCESS:
1596 1618                          break;
1597 1619                  case STMF_ERROR_NOT_FOUND:
1598 1620                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1599 1621                              groupNamePrint, gettext("not found"));
1600 1622                          ret++;
1601 1623                          break;
1602 1624                  case STMF_ERROR_BUSY:
1603 1625                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1604 1626                              groupNamePrint, gettext("resource busy"));
1605 1627                          ret++;
1606 1628                          break;
1607 1629                  case STMF_ERROR_SERVICE_NOT_FOUND:
1608 1630                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1609 1631                              gettext("STMF service not found"));
1610 1632                          ret++;
1611 1633                          break;
1612 1634                  case STMF_ERROR_PERM:
1613 1635                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1614 1636                              gettext("permission denied"));
1615 1637                          ret++;
1616 1638                          break;
1617 1639                  case STMF_ERROR_GROUP_IN_USE:
1618 1640                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1619 1641                              groupNamePrint,
1620 1642                              gettext("group is in use by existing view entry"));
1621 1643                          ret++;
1622 1644                          break;
1623 1645                  case STMF_ERROR_SERVICE_DATA_VERSION:
1624 1646                          (void) fprintf(stderr, "%s: %s\n", cmdName,
1625 1647                              gettext("STMF service version incorrect"));
1626 1648                          ret++;
1627 1649                          break;
1628 1650                  default:
1629 1651                          (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
1630 1652                              groupNamePrint, gettext("unknown error"));
1631 1653                          ret++;
1632 1654                          break;
1633 1655          }
1634 1656  
1635 1657          return (ret);
1636 1658  }
1637 1659  
1638 1660  /*
1639 1661   * listHostGroupFunc
1640 1662   *
1641 1663   * Lists the specified host groups or all if none are specified
1642 1664   *
1643 1665   */
1644 1666  /*ARGSUSED*/
1645 1667  static int
1646 1668  listHostGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1647 1669      void *args)
1648 1670  {
1649 1671          int ret = 0;
1650 1672          int stmfRet;
1651 1673          int i, j, outerLoop;
1652 1674          boolean_t verbose = B_FALSE;
1653 1675          boolean_t found = B_TRUE;
1654 1676          boolean_t operandEntered;
1655 1677          stmfGroupList *groupList;
1656 1678          stmfGroupProperties *groupProps;
1657 1679          wchar_t operandName[sizeof (stmfGroupName)];
1658 1680          wchar_t groupNamePrint[sizeof (stmfGroupName)];
1659 1681  
1660 1682          for (; options->optval; options++) {
1661 1683                  switch (options->optval) {
1662 1684                          case 'v':
1663 1685                                  verbose = B_TRUE;
1664 1686                                  break;
1665 1687                          default:
1666 1688                                  (void) fprintf(stderr, "%s: %c: %s\n",
1667 1689                                      cmdName, options->optval,
1668 1690                                      gettext("unknown option"));
1669 1691                                  return (1);
1670 1692                  }
1671 1693          }
1672 1694  
1673 1695          if (operandLen > 0) {
1674 1696                  outerLoop = operandLen;
1675 1697                  operandEntered = B_TRUE;
1676 1698          } else {
1677 1699                  outerLoop = 1;
1678 1700                  operandEntered = B_FALSE;
1679 1701          }
1680 1702  
1681 1703          stmfRet = stmfGetHostGroupList(&groupList);
1682 1704          if (stmfRet != STMF_STATUS_SUCCESS) {
1683 1705                  switch (stmfRet) {
1684 1706                          case STMF_ERROR_BUSY:
1685 1707                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1686 1708                                      gettext("resource busy"));
1687 1709                                  break;
1688 1710                          case STMF_ERROR_SERVICE_NOT_FOUND:
1689 1711                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1690 1712                                      gettext("STMF service not found"));
1691 1713                                  break;
1692 1714                          case STMF_ERROR_PERM:
1693 1715                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1694 1716                                      gettext("permission denied"));
1695 1717                                  break;
1696 1718                          case STMF_ERROR_SERVICE_DATA_VERSION:
1697 1719                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1698 1720                                      gettext("STMF service version incorrect"));
1699 1721                                  break;
1700 1722                          default:
1701 1723                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1702 1724                                      gettext("unknown error"));
1703 1725                                  break;
1704 1726                  }
1705 1727                  return (1);
1706 1728          }
1707 1729  
1708 1730          for (i = 0; i < outerLoop; i++) {
1709 1731                  for (found = B_FALSE, j = 0; j < groupList->cnt; j++) {
1710 1732                          (void) mbstowcs(groupNamePrint,
1711 1733                              (char *)groupList->name[j],
1712 1734                              sizeof (stmfGroupName) - 1);
1713 1735                          groupNamePrint[sizeof (stmfGroupName) - 1] = 0;
1714 1736                          if (operandEntered) {
1715 1737                                  (void) mbstowcs(operandName, operands[i],
1716 1738                                      sizeof (stmfGroupName) - 1);
1717 1739                                  operandName[sizeof (stmfGroupName) - 1] = 0;
1718 1740                                  if (wcscmp(operandName, groupNamePrint)
1719 1741                                      == 0) {
1720 1742                                          found = B_TRUE;
1721 1743                                  }
1722 1744                          }
1723 1745                          if ((found && operandEntered) || !operandEntered) {
1724 1746                                  (void) printf("Host Group: %ws\n",
1725 1747                                      groupNamePrint);
1726 1748                                  if (verbose) {
1727 1749                                          stmfRet = stmfGetHostGroupMembers(
1728 1750                                              &(groupList->name[j]), &groupProps);
1729 1751                                          if (stmfRet != STMF_STATUS_SUCCESS) {
1730 1752                                                  return (1);
1731 1753                                          }
1732 1754                                          printGroupProps(groupProps);
1733 1755                                  }
1734 1756                                  if (found && operandEntered) {
1735 1757                                          break;
1736 1758                                  }
1737 1759                          }
1738 1760  
1739 1761                  }
1740 1762                  if (operandEntered && !found) {
1741 1763                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1742 1764                              operands[i], gettext("not found"));
1743 1765                          ret = 1;
1744 1766                  }
1745 1767          }
1746 1768          return (ret);
1747 1769  }
1748 1770  
1749 1771  /*
1750 1772   * printGroupProps
1751 1773   *
1752 1774   * Prints group members for target or host groups
1753 1775   *
1754 1776   */
1755 1777  static void
1756 1778  printGroupProps(stmfGroupProperties *groupProps)
1757 1779  {
1758 1780          int i;
1759 1781          wchar_t memberIdent[sizeof (groupProps->name[0].ident) + 1] = {0};
1760 1782  
1761 1783  
1762 1784          for (i = 0; i < groupProps->cnt; i++) {
1763 1785                  (void) mbstowcs(memberIdent, (char *)groupProps->name[i].ident,
1764 1786                      sizeof (groupProps->name[0].ident));
1765 1787                  (void) printf("\tMember: %ws\n", memberIdent);
1766 1788          }
1767 1789  }
1768 1790  
1769 1791  /*
1770 1792   * listTargetGroupFunc
1771 1793   *
1772 1794   * Lists the specified target groups or all if none are specified
1773 1795   *
1774 1796   */
1775 1797  /*ARGSUSED*/
1776 1798  static int
1777 1799  listTargetGroupFunc(int operandLen, char *operands[], cmdOptions_t *options,
1778 1800      void *args)
1779 1801  {
1780 1802          int ret = 0;
1781 1803          int stmfRet;
1782 1804          int i, j, outerLoop;
1783 1805          boolean_t verbose = B_FALSE;
1784 1806          boolean_t found = B_TRUE;
1785 1807          boolean_t operandEntered;
1786 1808          stmfGroupList *groupList;
1787 1809          stmfGroupProperties *groupProps;
1788 1810          wchar_t operandName[sizeof (stmfGroupName)];
1789 1811          wchar_t groupNamePrint[sizeof (stmfGroupName)];
1790 1812  
1791 1813          for (; options->optval; options++) {
1792 1814                  switch (options->optval) {
1793 1815                          case 'v':
1794 1816                                  verbose = B_TRUE;
1795 1817                                  break;
1796 1818                          default:
1797 1819                                  (void) fprintf(stderr, "%s: %c: %s\n",
1798 1820                                      cmdName, options->optval,
1799 1821                                      gettext("unknown option"));
1800 1822                                  return (1);
1801 1823                  }
1802 1824          }
1803 1825  
1804 1826          if (operandLen > 0) {
1805 1827                  outerLoop = operandLen;
1806 1828                  operandEntered = B_TRUE;
1807 1829          } else {
1808 1830                  outerLoop = 1;
1809 1831                  operandEntered = B_FALSE;
1810 1832          }
1811 1833  
1812 1834          stmfRet = stmfGetTargetGroupList(&groupList);
1813 1835          if (stmfRet != STMF_STATUS_SUCCESS) {
1814 1836                  switch (stmfRet) {
1815 1837                          case STMF_ERROR_BUSY:
1816 1838                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1817 1839                                      gettext("resource busy"));
1818 1840                                  break;
1819 1841                          case STMF_ERROR_SERVICE_NOT_FOUND:
1820 1842                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1821 1843                                      gettext("STMF service not found"));
1822 1844                                  break;
1823 1845                          case STMF_ERROR_SERVICE_DATA_VERSION:
1824 1846                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1825 1847                                      gettext("STMF service version incorrect"));
1826 1848                                  break;
1827 1849                          case STMF_ERROR_PERM:
1828 1850                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1829 1851                                      gettext("permission denied"));
1830 1852                                  break;
1831 1853                          default:
1832 1854                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1833 1855                                      gettext("unknown error"));
1834 1856                                  break;
1835 1857                  }
1836 1858                  return (1);
1837 1859          }
1838 1860  
1839 1861          for (i = 0; i < outerLoop; i++) {
1840 1862                  for (found = B_FALSE, j = 0; j < groupList->cnt; j++) {
1841 1863                          (void) mbstowcs(groupNamePrint,
1842 1864                              (char *)groupList->name[j],
1843 1865                              sizeof (stmfGroupName) - 1);
1844 1866                          groupNamePrint[sizeof (stmfGroupName) - 1] = 0;
1845 1867                          if (operandEntered) {
1846 1868                                  (void) mbstowcs(operandName, operands[i],
1847 1869                                      sizeof (stmfGroupName) - 1);
1848 1870                                  operandName[sizeof (stmfGroupName) - 1] = 0;
1849 1871                                  if (wcscmp(operandName, groupNamePrint)
1850 1872                                      == 0) {
1851 1873                                          found = B_TRUE;
1852 1874                                  }
1853 1875                          }
1854 1876                          if ((found && operandEntered) || !operandEntered) {
1855 1877                                  (void) printf("Target Group: %ws\n",
1856 1878                                      groupNamePrint);
1857 1879                                  if (verbose) {
1858 1880                                          stmfRet = stmfGetTargetGroupMembers(
1859 1881                                              &(groupList->name[j]), &groupProps);
1860 1882                                          if (stmfRet != STMF_STATUS_SUCCESS) {
1861 1883                                                  return (1);
1862 1884                                          }
1863 1885                                          printGroupProps(groupProps);
1864 1886                                  }
1865 1887                                  if (found && operandEntered) {
1866 1888                                          break;
1867 1889                                  }
1868 1890                          }
1869 1891  
1870 1892                  }
1871 1893                  if (operandEntered && !found) {
1872 1894                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
1873 1895                              operands[i], gettext("not found"));
1874 1896                          ret = 1;
1875 1897                  }
1876 1898          }
1877 1899          return (ret);
1878 1900  }
1879 1901  
1880 1902  /*
1881 1903   * listLuFunc
1882 1904   *
1883 1905   * List the logical units and optionally the properties
1884 1906   *
1885 1907   */
1886 1908  /*ARGSUSED*/
1887 1909  static int
1888 1910  listLuFunc(int operandLen, char *operands[], cmdOptions_t *options, void *args)
1889 1911  {
1890 1912          cmdOptions_t *optionList = options;
1891 1913          boolean_t operandEntered;
1892 1914          int i, j;
1893 1915          int ret = 0;
1894 1916          int stmfRet;
1895 1917          int outerLoop;
1896 1918          unsigned int inGuid[sizeof (stmfGuid)];
1897 1919          stmfGuid cmpGuid;
1898 1920          boolean_t verbose = B_FALSE;
1899 1921          boolean_t found;
1900 1922          char sGuid[GUID_INPUT + 1];
1901 1923          stmfGuidList *luList;
1902 1924          stmfLogicalUnitProperties luProps;
1903 1925          boolean_t invalidInput = B_FALSE;
1904 1926          stmfViewEntryList *viewEntryList;
1905 1927  
1906 1928          for (; optionList->optval; optionList++) {
1907 1929                  switch (optionList->optval) {
1908 1930                          case 'v':
1909 1931                                  verbose = B_TRUE;
1910 1932                                  break;
1911 1933                  }
1912 1934          }
1913 1935  
1914 1936          if ((stmfRet = stmfGetLogicalUnitList(&luList))
1915 1937              != STMF_STATUS_SUCCESS) {
1916 1938                  switch (stmfRet) {
1917 1939                          case STMF_ERROR_SERVICE_NOT_FOUND:
1918 1940                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1919 1941                                      gettext("STMF service not found"));
1920 1942                                  break;
1921 1943                          case STMF_ERROR_BUSY:
1922 1944                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1923 1945                                      gettext("resource busy"));
1924 1946                                  break;
1925 1947                          case STMF_ERROR_PERM:
1926 1948                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1927 1949                                      gettext("permission denied"));
1928 1950                                  break;
1929 1951                          case STMF_ERROR_SERVICE_DATA_VERSION:
1930 1952                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1931 1953                                      gettext("STMF service version incorrect"));
1932 1954                                  break;
1933 1955                          default:
1934 1956                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
1935 1957                                      gettext("list failed"));
1936 1958                                  break;
1937 1959                  }
1938 1960                  return (1);
1939 1961          }
1940 1962  
1941 1963          if (operandLen > 0) {
1942 1964                  operandEntered = B_TRUE;
1943 1965                  outerLoop = operandLen;
1944 1966          } else {
1945 1967                  operandEntered = B_FALSE;
1946 1968                  outerLoop = 1;
1947 1969          }
1948 1970  
1949 1971  
1950 1972          for (invalidInput = B_FALSE, i = 0; i < outerLoop; i++) {
1951 1973                  if (operandEntered) {
1952 1974                          if (strlen(operands[i]) != GUID_INPUT) {
1953 1975                                  invalidInput = B_TRUE;
1954 1976                          } else {
1955 1977                                  for (j = 0; j < GUID_INPUT; j++) {
1956 1978                                          if (!isxdigit(operands[i][j])) {
1957 1979                                                  invalidInput = B_TRUE;
1958 1980                                                  break;
1959 1981                                          }
1960 1982                                  }
1961 1983                          }
1962 1984                          if (invalidInput) {
1963 1985                                  (void) fprintf(stderr, "%s: %s: %s%d%s\n",
1964 1986                                      cmdName, operands[i], gettext("must be "),
1965 1987                                      GUID_INPUT,
1966 1988                                      gettext(" hexadecimal digits long"));
1967 1989                                  invalidInput = B_FALSE;
1968 1990                                  continue;
1969 1991                          }
1970 1992  
1971 1993                          for (j = 0; j < GUID_INPUT; j++) {
1972 1994                                  sGuid[j] = tolower(operands[i][j]);
1973 1995                          }
1974 1996                          sGuid[j] = 0;
1975 1997  
1976 1998                          (void) sscanf(sGuid,
1977 1999                              "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
1978 2000                              &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3],
1979 2001                              &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7],
1980 2002                              &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11],
1981 2003                              &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]);
1982 2004  
1983 2005                          for (j = 0; j < sizeof (stmfGuid); j++) {
1984 2006                                  cmpGuid.guid[j] = inGuid[j];
1985 2007                          }
1986 2008                  }
1987 2009  
1988 2010                  for (found = B_FALSE, j = 0; j < luList->cnt; j++) {
1989 2011                          if (operandEntered) {
1990 2012                                  if (bcmp(luList->guid[j].guid, cmpGuid.guid,
1991 2013                                      sizeof (stmfGuid)) == 0) {
1992 2014                                          found = B_TRUE;
1993 2015                                  }
1994 2016                          }
1995 2017                          if ((found && operandEntered) || !operandEntered) {
1996 2018                                  (void) printf("LU Name: ");
1997 2019                                  printGuid(&luList->guid[j], stdout);
1998 2020                                  (void) printf("\n");
1999 2021  
2000 2022                                  if (verbose) {
2001 2023                                          stmfRet = stmfGetLogicalUnitProperties(
2002 2024                                              &(luList->guid[j]), &luProps);
2003 2025                                          if (stmfRet == STMF_STATUS_SUCCESS) {
2004 2026                                                  printLuProps(&luProps);
2005 2027                                          } else {
2006 2028                                                  (void) fprintf(stderr, "%s:",
2007 2029                                                      cmdName);
2008 2030                                                  printGuid(&luList->guid[j],
2009 2031                                                      stderr);
2010 2032                                                  (void) fprintf(stderr, "%s\n",
2011 2033                                                      gettext(" get properties "
2012 2034                                                      "failed"));
2013 2035                                          }
2014 2036                                          stmfRet = stmfGetViewEntryList(
2015 2037                                              &(luList->guid[j]),
2016 2038                                              &viewEntryList);
2017 2039                                          (void) printf(PROPS_FORMAT,
2018 2040                                              "View Entry Count");
2019 2041                                          if (stmfRet == STMF_STATUS_SUCCESS) {
2020 2042                                                  (void) printf("%d",
2021 2043                                                      viewEntryList->cnt);
2022 2044                                          } else {
2023 2045                                                  (void) printf("unknown");
2024 2046                                          }
2025 2047                                          (void) printf("\n");
2026 2048                                          ret = printExtLuProps(
2027 2049                                              &(luList->guid[j]));
2028 2050                                  }
2029 2051                                  if (found && operandEntered) {
2030 2052                                          break;
2031 2053                                  }
2032 2054                          }
2033 2055  
2034 2056                  }
2035 2057                  if (operandEntered && !found) {
2036 2058                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2037 2059                              operands[i], gettext("not found"));
2038 2060                          ret = 1;
2039 2061                  }
2040 2062          }
2041 2063  
2042 2064          return (ret);
2043 2065  }
2044 2066  
2045 2067  static void
2046 2068  printGuid(stmfGuid *guid, FILE *stream)
2047 2069  {
2048 2070          int i;
2049 2071          for (i = 0; i < 16; i++) {
2050 2072                  (void) fprintf(stream, "%02X", guid->guid[i]);
2051 2073          }
2052 2074  }
2053 2075  
2054 2076  static int
2055 2077  printExtLuProps(stmfGuid *guid)
2056 2078  {
2057 2079          int stmfRet;
2058 2080          luResource hdl = NULL;
2059 2081          int ret = 0;
2060 2082          char propVal[MAXNAMELEN];
2061 2083          size_t propValSize = sizeof (propVal);
2062 2084  
2063 2085          if ((stmfRet = stmfGetLuResource(guid, &hdl))
2064 2086              != STMF_STATUS_SUCCESS) {
2065 2087                  switch (stmfRet) {
2066 2088                          case STMF_ERROR_BUSY:
2067 2089                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2068 2090                                      gettext("resource busy"));
2069 2091                                  break;
2070 2092                          case STMF_ERROR_PERM:
2071 2093                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2072 2094                                      gettext("permission denied"));
2073 2095                                  break;
2074 2096                          case STMF_ERROR_NOT_FOUND:
2075 2097                                  /* No error here */
2076 2098                                  return (0);
2077 2099                                  break;
2078 2100                          default:
2079 2101                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2080 2102                                      gettext("get extended properties failed"));
2081 2103                                  break;
2082 2104                  }
2083 2105                  return (1);
2084 2106          }
2085 2107  
2086 2108          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_FILENAME, propVal,
2087 2109              &propValSize);
2088 2110          (void) printf(PROPS_FORMAT, "Data File");
2089 2111          if (stmfRet == STMF_STATUS_SUCCESS) {
2090 2112                  (void) printf("%s\n", propVal);
2091 2113          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2092 2114                  (void) printf("not set\n");
2093 2115          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2094 2116                  (void) printf("prop unavailable in standby\n");
2095 2117          } else {
2096 2118                  (void) printf("<error retrieving property>\n");
2097 2119                  ret++;
2098 2120          }
2099 2121  
2100 2122          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_META_FILENAME, propVal,
2101 2123              &propValSize);
2102 2124          (void) printf(PROPS_FORMAT, "Meta File");
2103 2125          if (stmfRet == STMF_STATUS_SUCCESS) {
2104 2126                  (void) printf("%s\n", propVal);
2105 2127          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2106 2128                  (void) printf("not set\n");
2107 2129          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2108 2130                  (void) printf("prop unavailable in standby\n");
2109 2131          } else {
2110 2132                  (void) printf("<error retrieving property>\n");
2111 2133                  ret++;
2112 2134          }
2113 2135  
2114 2136          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SIZE, propVal,
2115 2137              &propValSize);
2116 2138          (void) printf(PROPS_FORMAT, "Size");
2117 2139          if (stmfRet == STMF_STATUS_SUCCESS) {
2118 2140                  (void) printf("%s\n", propVal);
2119 2141          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2120 2142                  (void) printf("not set\n");
2121 2143          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2122 2144                  (void) printf("prop unavailable in standby\n");
2123 2145          } else {
2124 2146                  (void) printf("<error retrieving property>\n");
2125 2147                  ret++;
2126 2148          }
2127 2149  
2128 2150          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_BLOCK_SIZE, propVal,
2129 2151              &propValSize);
2130 2152          (void) printf(PROPS_FORMAT, "Block Size");
2131 2153          if (stmfRet == STMF_STATUS_SUCCESS) {
2132 2154                  (void) printf("%s\n", propVal);
2133 2155          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2134 2156                  (void) printf("not set\n");
2135 2157          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2136 2158                  (void) printf("prop unavailable in standby\n");
2137 2159          } else {
2138 2160                  (void) printf("<error retrieving property>\n");
2139 2161                  ret++;
2140 2162          }
2141 2163  
2142 2164          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_MGMT_URL, propVal,
2143 2165              &propValSize);
2144 2166          (void) printf(PROPS_FORMAT, "Management URL");
2145 2167          if (stmfRet == STMF_STATUS_SUCCESS) {
2146 2168                  (void) printf("%s\n", propVal);
2147 2169          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2148 2170                  (void) printf("not set\n");
2149 2171          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2150 2172                  (void) printf("prop unavailable in standby\n");
2151 2173          } else {
2152 2174                  (void) printf("<error retrieving property>\n");
2153 2175                  ret++;
2154 2176          }
2155 2177  
2156 2178          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_VID, propVal,
2157 2179              &propValSize);
2158 2180          (void) printf(PROPS_FORMAT, "Vendor ID");
2159 2181          if (stmfRet == STMF_STATUS_SUCCESS) {
2160 2182                  (void) printf("%s\n", propVal);
2161 2183          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2162 2184                  (void) printf("not set\n");
2163 2185          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2164 2186                  (void) printf("prop unavailable in standby\n");
2165 2187          } else {
2166 2188                  (void) printf("<error retrieving property>\n");
2167 2189                  ret++;
2168 2190          }
2169 2191  
2170 2192          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_PID, propVal,
2171 2193              &propValSize);
2172 2194          (void) printf(PROPS_FORMAT, "Product ID");
2173 2195          if (stmfRet == STMF_STATUS_SUCCESS) {
2174 2196                  (void) printf("%s\n", propVal);
2175 2197          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2176 2198                  (void) printf("not set\n");
2177 2199          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2178 2200                  (void) printf("prop unavailable in standby\n");
2179 2201          } else {
2180 2202                  (void) printf("<error retrieving property>\n");
2181 2203                  ret++;
2182 2204          }
2183 2205  
2184 2206          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_SERIAL_NUM, propVal,
2185 2207              &propValSize);
2186 2208          (void) printf(PROPS_FORMAT, "Serial Num");
2187 2209          if (stmfRet == STMF_STATUS_SUCCESS) {
2188 2210                  (void) printf("%s\n", propVal);
2189 2211          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2190 2212                  (void) printf("not set\n");
2191 2213          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2192 2214                  (void) printf("prop unavailable in standby\n");
2193 2215          } else {
2194 2216                  (void) printf("<error retrieving property>\n");
2195 2217                  ret++;
2196 2218          }
2197 2219  
2198 2220          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_PROTECT, propVal,
2199 2221              &propValSize);
2200 2222          (void) printf(PROPS_FORMAT, "Write Protect");
2201 2223          if (stmfRet == STMF_STATUS_SUCCESS) {
2202 2224                  (void) printf("%s\n",
2203 2225                      strcasecmp(propVal, "true") ? "Disabled" : "Enabled");
2204 2226          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2205 2227                  (void) printf("not set\n");
2206 2228          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2207 2229                  (void) printf("prop unavailable in standby\n");
2208 2230          } else {
2209 2231                  (void) printf("<error retrieving property>\n");
2210 2232                  ret++;
  
    | 
      ↓ open down ↓ | 
    894 lines elided | 
    
      ↑ open up ↑ | 
  
2211 2233          }
2212 2234  
2213 2235          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_WRITE_CACHE_DISABLE, propVal,
2214 2236              &propValSize);
2215 2237          (void) printf(PROPS_FORMAT, "Writeback Cache");
2216 2238          if (stmfRet == STMF_STATUS_SUCCESS) {
2217 2239                  (void) printf("%s\n",
2218 2240                      strcasecmp(propVal, "true") ? "Enabled" : "Disabled");
2219 2241          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2220 2242                  (void) printf("not set\n");
     2243 +        } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
     2244 +                (void) printf("prop unavailable in standby\n");
     2245 +        } else {
     2246 +                (void) printf("<error retrieving property>\n");
     2247 +                ret++;
     2248 +        }
     2249 +
     2250 +        stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_UNMAP, propVal,
     2251 +            &propValSize);
     2252 +        (void) printf(PROPS_FORMAT, "UNMAP support");
     2253 +        if (stmfRet == STMF_STATUS_SUCCESS) {
     2254 +                (void) printf("%s\n", (strcasecmp(propVal, "true") == 0) ?
     2255 +                    "Enabled" : "Disabled");
     2256 +        } else if (stmfRet == STMF_ERROR_NO_PROP) {
     2257 +                (void) printf("not set\n");
2221 2258          } else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
2222 2259                  (void) printf("prop unavailable in standby\n");
2223 2260          } else {
2224 2261                  (void) printf("<error retrieving property>\n");
2225 2262                  ret++;
2226 2263          }
2227 2264  
2228 2265          stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_ACCESS_STATE, propVal,
2229 2266              &propValSize);
2230 2267          (void) printf(PROPS_FORMAT, "Access State");
2231 2268          if (stmfRet == STMF_STATUS_SUCCESS) {
2232 2269                  if (strcmp(propVal, STMF_ACCESS_ACTIVE) == 0) {
2233 2270                          (void) printf("%s\n", "Active");
2234 2271                  } else if (strcmp(propVal,
2235 2272                      STMF_ACCESS_ACTIVE_TO_STANDBY) == 0) {
2236 2273                          (void) printf("%s\n", "Active->Standby");
2237 2274                  } else if (strcmp(propVal, STMF_ACCESS_STANDBY) == 0) {
2238 2275                          (void) printf("%s\n", "Standby");
2239 2276                  } else if (strcmp(propVal,
2240 2277                      STMF_ACCESS_STANDBY_TO_ACTIVE) == 0) {
2241 2278                          (void) printf("%s\n", "Standby->Active");
2242 2279                  } else {
2243 2280                          (void) printf("%s\n", "Unknown");
2244 2281                  }
2245 2282          } else if (stmfRet == STMF_ERROR_NO_PROP) {
2246 2283                  (void) printf("not set\n");
2247 2284          } else {
2248 2285                  (void) printf("<error retrieving property>\n");
2249 2286                  ret++;
2250 2287          }
2251 2288  
2252 2289  done:
2253 2290          (void) stmfFreeLuResource(hdl);
2254 2291          return (ret);
2255 2292  
2256 2293  }
2257 2294  
2258 2295  
2259 2296  /*
2260 2297   * printLuProps
2261 2298   *
2262 2299   * Prints the properties for a logical unit
2263 2300   *
2264 2301   */
2265 2302  static void
2266 2303  printLuProps(stmfLogicalUnitProperties *luProps)
2267 2304  {
2268 2305          (void) printf(PROPS_FORMAT, "Operational Status");
2269 2306          switch (luProps->status) {
2270 2307                  case STMF_LOGICAL_UNIT_ONLINE:
2271 2308                          (void) printf("Online");
2272 2309                          break;
2273 2310                  case STMF_LOGICAL_UNIT_OFFLINE:
2274 2311                          (void) printf("Offline");
2275 2312                          break;
2276 2313                  case STMF_LOGICAL_UNIT_ONLINING:
2277 2314                          (void) printf("Onlining");
2278 2315                          break;
2279 2316                  case STMF_LOGICAL_UNIT_OFFLINING:
2280 2317                          (void) printf("Offlining");
2281 2318                          break;
2282 2319                  case STMF_LOGICAL_UNIT_UNREGISTERED:
2283 2320                          (void) printf("unregistered");
2284 2321                          (void) strncpy(luProps->providerName, "unregistered",
2285 2322                              sizeof (luProps->providerName));
2286 2323                          break;
2287 2324                  default:
2288 2325                          (void) printf("unknown");
2289 2326                          break;
2290 2327          }
2291 2328          (void) printf("\n");
2292 2329          (void) printf(PROPS_FORMAT, "Provider Name");
2293 2330          if (luProps->providerName[0] != 0) {
2294 2331                  (void) printf("%s", luProps->providerName);
2295 2332          } else {
2296 2333                  (void) printf("unknown");
2297 2334          }
2298 2335          (void) printf("\n");
2299 2336          (void) printf(PROPS_FORMAT, "Alias");
2300 2337          if (luProps->alias[0] != 0) {
2301 2338                  (void) printf("%s", luProps->alias);
2302 2339          } else {
2303 2340                  (void) printf("-");
2304 2341          }
2305 2342          (void) printf("\n");
2306 2343  }
2307 2344  
2308 2345  /*
2309 2346   * printTargetProps
2310 2347   *
2311 2348   * Prints the properties for a target
2312 2349   *
2313 2350   */
2314 2351  static void
2315 2352  printTargetProps(stmfTargetProperties *targetProps)
2316 2353  {
2317 2354          (void) printf(PROPS_FORMAT, "Operational Status");
2318 2355          switch (targetProps->status) {
2319 2356                  case STMF_TARGET_PORT_ONLINE:
2320 2357                          (void) printf("Online");
2321 2358                          break;
2322 2359                  case STMF_TARGET_PORT_OFFLINE:
2323 2360                          (void) printf("Offline");
2324 2361                          break;
2325 2362                  case STMF_TARGET_PORT_ONLINING:
2326 2363                          (void) printf("Onlining");
2327 2364                          break;
2328 2365                  case STMF_TARGET_PORT_OFFLINING:
2329 2366                          (void) printf("Offlining");
2330 2367                          break;
2331 2368                  default:
2332 2369                          (void) printf("unknown");
2333 2370                          break;
2334 2371          }
2335 2372          (void) printf("\n");
2336 2373          (void) printf(PROPS_FORMAT, "Provider Name");
2337 2374          if (targetProps->providerName[0] != 0) {
2338 2375                  (void) printf("%s", targetProps->providerName);
2339 2376          }
2340 2377          (void) printf("\n");
2341 2378          (void) printf(PROPS_FORMAT, "Alias");
2342 2379          if (targetProps->alias[0] != 0) {
2343 2380                  (void) printf("%s", targetProps->alias);
2344 2381          } else {
2345 2382                  (void) printf("-");
2346 2383          }
2347 2384          (void) printf("\n");
2348 2385          (void) printf(PROPS_FORMAT, "Protocol");
2349 2386          switch (targetProps->protocol) {
2350 2387                  case STMF_PROTOCOL_FIBRE_CHANNEL:
2351 2388                          (void) printf("%s", "Fibre Channel");
2352 2389                          break;
2353 2390                  case STMF_PROTOCOL_ISCSI:
2354 2391                          (void) printf("%s", "iSCSI");
2355 2392                          break;
2356 2393                  case STMF_PROTOCOL_SRP:
2357 2394                          (void) printf("%s", "SRP");
2358 2395                          break;
2359 2396                  case STMF_PROTOCOL_SAS:
2360 2397                          (void) printf("%s", "SAS");
2361 2398                          break;
2362 2399                  default:
2363 2400                          (void) printf("%s", "unknown");
2364 2401                          break;
2365 2402          }
2366 2403  
2367 2404          (void) printf("\n");
2368 2405  }
2369 2406  
2370 2407  /*
2371 2408   * printSessionProps
2372 2409   *
2373 2410   * Prints the session data
2374 2411   *
2375 2412   */
2376 2413  static void
2377 2414  printSessionProps(stmfSessionList *sessionList)
2378 2415  {
2379 2416          int i;
2380 2417          char *cTime;
2381 2418          wchar_t initiator[STMF_IDENT_LENGTH + 1];
2382 2419  
2383 2420          (void) printf(PROPS_FORMAT, "Sessions");
2384 2421          (void) printf("%d\n", sessionList->cnt);
2385 2422          for (i = 0; i < sessionList->cnt; i++) {
2386 2423                  (void) mbstowcs(initiator,
2387 2424                      (char *)sessionList->session[i].initiator.ident,
2388 2425                      STMF_IDENT_LENGTH);
2389 2426                  initiator[STMF_IDENT_LENGTH] = 0;
2390 2427                  (void) printf(LVL3_FORMAT, "Initiator: ");
2391 2428                  (void) printf("%ws\n", initiator);
2392 2429                  (void) printf(LVL4_FORMAT, "Alias: ");
2393 2430                  if (sessionList->session[i].alias[0] != 0) {
2394 2431                          (void) printf("%s", sessionList->session[i].alias);
2395 2432                  } else {
2396 2433                          (void) printf("-");
2397 2434                  }
2398 2435                  (void) printf("\n");
2399 2436                  (void) printf(LVL4_FORMAT, "Logged in since: ");
2400 2437                  cTime = ctime(&(sessionList->session[i].creationTime));
2401 2438                  if (cTime != NULL) {
2402 2439                          (void) printf("%s", cTime);
2403 2440                  } else {
2404 2441                          (void) printf("unknown\n");
2405 2442                  }
2406 2443          }
2407 2444  }
2408 2445  
2409 2446  static int
2410 2447  getStmfState(stmfState *state)
2411 2448  {
2412 2449          int ret;
2413 2450  
2414 2451          ret = stmfGetState(state);
2415 2452          switch (ret) {
2416 2453                  case STMF_STATUS_SUCCESS:
2417 2454                          break;
2418 2455                  case STMF_ERROR_PERM:
2419 2456                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2420 2457                              gettext("permission denied"));
2421 2458                          break;
2422 2459                  case STMF_ERROR_SERVICE_NOT_FOUND:
2423 2460                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2424 2461                              gettext("STMF service not found"));
2425 2462                          break;
2426 2463                  case STMF_ERROR_BUSY:
2427 2464                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2428 2465                              gettext("resource busy"));
2429 2466                          break;
2430 2467                  case STMF_ERROR_SERVICE_DATA_VERSION:
2431 2468                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2432 2469                              gettext("STMF service version incorrect"));
2433 2470                          break;
2434 2471                  default:
2435 2472                          (void) fprintf(stderr, "%s: %s: %d\n", cmdName,
2436 2473                              gettext("unknown error"), ret);
2437 2474                          break;
2438 2475          }
2439 2476          return (ret);
2440 2477  }
2441 2478  
2442 2479  /*
2443 2480   * listStateFunc
2444 2481   *
2445 2482   * List the operational and config state of the stmf service
2446 2483   *
2447 2484   */
2448 2485  /*ARGSUSED*/
2449 2486  static int
2450 2487  listStateFunc(int operandLen, char *operands[], cmdOptions_t *options,
2451 2488      void *args)
2452 2489  {
2453 2490          int ret;
2454 2491          stmfState state;
2455 2492          boolean_t aluaEnabled;
2456 2493          uint32_t node;
2457 2494  
2458 2495          if ((ret = getStmfState(&state)) != STMF_STATUS_SUCCESS)
2459 2496                  return (ret);
2460 2497  
2461 2498          (void) printf("%-18s: ", "Operational Status");
2462 2499          switch (state.operationalState) {
2463 2500                  case STMF_SERVICE_STATE_ONLINE:
2464 2501                          (void) printf("online");
2465 2502                          break;
2466 2503                  case STMF_SERVICE_STATE_OFFLINE:
2467 2504                          (void) printf("offline");
2468 2505                          break;
2469 2506                  case STMF_SERVICE_STATE_ONLINING:
2470 2507                          (void) printf("onlining");
2471 2508                          break;
2472 2509                  case STMF_SERVICE_STATE_OFFLINING:
2473 2510                          (void) printf("offlining");
2474 2511                          break;
2475 2512                  default:
2476 2513                          (void) printf("unknown");
2477 2514                          break;
2478 2515          }
2479 2516          (void) printf("\n");
2480 2517          (void) printf("%-18s: ", "Config Status");
2481 2518          switch (state.configState) {
2482 2519                  case STMF_CONFIG_STATE_NONE:
2483 2520                          (void) printf("uninitialized");
2484 2521                          break;
2485 2522                  case STMF_CONFIG_STATE_INIT:
2486 2523                          (void) printf("initializing");
2487 2524                          break;
2488 2525                  case STMF_CONFIG_STATE_INIT_DONE:
2489 2526                          (void) printf("initialized");
2490 2527                          break;
2491 2528                  default:
2492 2529                          (void) printf("unknown");
2493 2530                          break;
2494 2531          }
2495 2532          (void) printf("\n");
2496 2533          ret = stmfGetAluaState(&aluaEnabled, &node);
2497 2534          switch (ret) {
2498 2535                  case STMF_STATUS_SUCCESS:
2499 2536                          break;
2500 2537                  case STMF_ERROR_PERM:
2501 2538                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2502 2539                              gettext("permission denied"));
2503 2540                          break;
2504 2541                  case STMF_ERROR_BUSY:
2505 2542                          (void) fprintf(stderr, "%s: %s\n", cmdName,
2506 2543                              gettext("resource busy"));
2507 2544                          break;
2508 2545                  default:
2509 2546                          (void) fprintf(stderr, "%s: %s: %d\n", cmdName,
2510 2547                              gettext("unknown error"), ret);
2511 2548                          break;
2512 2549          }
2513 2550          (void) printf("%-18s: ", "ALUA Status");
2514 2551          if (ret == STMF_STATUS_SUCCESS) {
2515 2552                  if (aluaEnabled == B_TRUE) {
2516 2553                          (void) printf("enabled");
2517 2554                  } else {
2518 2555                          (void) printf("disabled");
2519 2556                  }
2520 2557          } else {
2521 2558                  (void) printf("unknown");
2522 2559          }
2523 2560  
2524 2561          (void) printf("\n");
2525 2562          (void) printf("%-18s: ", "ALUA Node");
2526 2563          if (ret == STMF_STATUS_SUCCESS) {
2527 2564                  (void) printf("%d", node);
2528 2565          } else {
2529 2566                  (void) printf("unknown");
2530 2567          }
2531 2568          (void) printf("\n");
2532 2569          return (ret);
2533 2570  }
2534 2571  
2535 2572  /*
2536 2573   * listTargetFunc
2537 2574   *
2538 2575   * list the targets and optionally their properties
2539 2576   *
2540 2577   */
2541 2578  /*ARGSUSED*/
2542 2579  static int
2543 2580  listTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
2544 2581      void *args)
2545 2582  {
2546 2583          cmdOptions_t *optionList = options;
2547 2584          int ret = 0;
2548 2585          int stmfRet;
2549 2586          int i, j;
2550 2587          int outerLoop;
2551 2588          stmfSessionList *sessionList;
2552 2589          stmfDevid devid;
2553 2590          boolean_t operandEntered, found, verbose = B_FALSE;
2554 2591          stmfDevidList *targetList;
2555 2592          wchar_t targetIdent[STMF_IDENT_LENGTH + 1];
2556 2593          stmfTargetProperties targetProps;
2557 2594  
2558 2595          if ((stmfRet = stmfGetTargetList(&targetList)) != STMF_STATUS_SUCCESS) {
2559 2596                  switch (stmfRet) {
2560 2597                          case STMF_ERROR_NOT_FOUND:
2561 2598                                  ret = 0;
2562 2599                                  break;
2563 2600                          case STMF_ERROR_SERVICE_OFFLINE:
2564 2601                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2565 2602                                      gettext("STMF service offline"));
2566 2603                                  break;
2567 2604                          case STMF_ERROR_BUSY:
2568 2605                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2569 2606                                      gettext("resource busy"));
2570 2607                                  break;
2571 2608                          case STMF_ERROR_SERVICE_DATA_VERSION:
2572 2609                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2573 2610                                      gettext("STMF service version incorrect"));
2574 2611                                  break;
2575 2612                          case STMF_ERROR_PERM:
2576 2613                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2577 2614                                      gettext("permission denied"));
2578 2615                                  break;
2579 2616                          default:
2580 2617                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2581 2618                                      gettext("unknown error"));
2582 2619                                  break;
2583 2620                  }
2584 2621                  return (1);
2585 2622          }
2586 2623  
2587 2624          for (; optionList->optval; optionList++) {
2588 2625                  switch (optionList->optval) {
2589 2626                          case 'v':
2590 2627                                  verbose = B_TRUE;
2591 2628                                  break;
2592 2629                  }
2593 2630          }
2594 2631  
2595 2632          if (operandLen > 0) {
2596 2633                  outerLoop = operandLen;
2597 2634                  operandEntered = B_TRUE;
2598 2635          } else {
2599 2636                  outerLoop = 1;
2600 2637                  operandEntered = B_FALSE;
2601 2638          }
2602 2639  
2603 2640          for (i = 0; i < outerLoop; i++) {
2604 2641                  if (operandEntered) {
2605 2642                          bzero(&devid, sizeof (devid));
2606 2643                          (void) parseDevid(operands[i], &devid);
2607 2644                  }
2608 2645                  for (found = B_FALSE, j = 0; j < targetList->cnt; j++) {
2609 2646                          if (operandEntered) {
2610 2647                                  if (bcmp(&devid, &(targetList->devid[j]),
2611 2648                                      sizeof (devid)) == 0) {
2612 2649                                          found = B_TRUE;
2613 2650                                  }
2614 2651                          }
2615 2652                          if ((found && operandEntered) || !operandEntered) {
2616 2653                                  (void) mbstowcs(targetIdent,
2617 2654                                      (char *)targetList->devid[j].ident,
2618 2655                                      STMF_IDENT_LENGTH);
2619 2656                                  targetIdent[STMF_IDENT_LENGTH] = 0;
2620 2657                                  (void) printf("Target: %ws\n", targetIdent);
2621 2658                                  if (verbose) {
2622 2659                                          stmfRet = stmfGetTargetProperties(
2623 2660                                              &(targetList->devid[j]),
2624 2661                                              &targetProps);
2625 2662                                          if (stmfRet == STMF_STATUS_SUCCESS) {
2626 2663                                                  printTargetProps(&targetProps);
2627 2664                                          } else {
2628 2665                                                  (void) fprintf(stderr, "%s:",
2629 2666                                                      cmdName);
2630 2667                                                  (void) fprintf(stderr, "%s\n",
2631 2668                                                      gettext(" get properties"
2632 2669                                                      " failed"));
2633 2670                                          }
2634 2671                                          stmfRet = stmfGetSessionList(
2635 2672                                              &(targetList->devid[j]),
2636 2673                                              &sessionList);
2637 2674                                          if (stmfRet == STMF_STATUS_SUCCESS) {
2638 2675                                                  printSessionProps(sessionList);
2639 2676                                          } else {
2640 2677                                                  (void) fprintf(stderr, "%s:",
2641 2678                                                      cmdName);
2642 2679                                                  (void) fprintf(stderr, "%s\n",
2643 2680                                                      gettext(" get session info"
2644 2681                                                      " failed"));
2645 2682                                          }
2646 2683                                  }
2647 2684                                  if (found && operandEntered) {
2648 2685                                          break;
2649 2686                                  }
2650 2687                          }
2651 2688  
2652 2689                  }
2653 2690                  if (operandEntered && !found) {
2654 2691                          (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2655 2692                              operands[i], "not found");
2656 2693                          ret = 1;
2657 2694                  }
2658 2695          }
2659 2696          return (ret);
2660 2697  }
2661 2698  
2662 2699  /*
2663 2700   * listViewFunc
2664 2701   *
2665 2702   * list the view entries for the specified logical unit
2666 2703   *
2667 2704   */
2668 2705  /*ARGSUSED*/
2669 2706  static int
2670 2707  listViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
2671 2708      void *args)
2672 2709  {
2673 2710          stmfViewEntryList *viewEntryList;
2674 2711          stmfGuid inGuid;
2675 2712          unsigned int guid[sizeof (stmfGuid)];
2676 2713          int ret = 0;
2677 2714          int stmfRet;
2678 2715          int i, j, outerLoop;
2679 2716          boolean_t found = B_TRUE;
2680 2717          boolean_t operandEntered;
2681 2718          uint16_t outputLuNbr;
2682 2719          wchar_t groupName[sizeof (stmfGroupName)];
2683 2720          char sGuid[GUID_INPUT + 1];
2684 2721  
2685 2722  
2686 2723          for (; options->optval; options++) {
2687 2724                  switch (options->optval) {
2688 2725                          case 'l':
2689 2726                                  if (strlen(options->optarg) != GUID_INPUT) {
2690 2727                                          (void) fprintf(stderr,
2691 2728                                              "%s: %s: %s%d%s\n",
2692 2729                                              cmdName, options->optarg,
2693 2730                                              gettext("must be "), GUID_INPUT,
2694 2731                                              gettext(" hexadecimal digits"
2695 2732                                              " long"));
2696 2733                                          return (1);
2697 2734                                  }
2698 2735                                  bcopy(options->optarg, sGuid, GUID_INPUT);
2699 2736                                  break;
2700 2737                          default:
2701 2738                                  (void) fprintf(stderr, "%s: %c: %s\n",
2702 2739                                      cmdName, options->optval,
2703 2740                                      gettext("unknown option"));
2704 2741                                  return (1);
2705 2742                  }
2706 2743          }
2707 2744  
2708 2745          if (operandLen > 0) {
2709 2746                  outerLoop = operandLen;
2710 2747                  operandEntered = B_TRUE;
2711 2748          } else {
2712 2749                  outerLoop = 1;
2713 2750                  operandEntered = B_FALSE;
2714 2751          }
2715 2752  
2716 2753          for (i = 0; i < 32; i++)
2717 2754                  sGuid[i] = tolower(sGuid[i]);
2718 2755          sGuid[i] = 0;
2719 2756  
2720 2757          (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
2721 2758              &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
2722 2759              &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
2723 2760              &guid[12], &guid[13], &guid[14], &guid[15]);
2724 2761  
2725 2762          for (i = 0; i < sizeof (stmfGuid); i++) {
2726 2763                  inGuid.guid[i] = guid[i];
2727 2764          }
2728 2765  
2729 2766          if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList))
2730 2767              != STMF_STATUS_SUCCESS) {
2731 2768  
2732 2769                  switch (stmfRet) {
2733 2770                          case STMF_ERROR_BUSY:
2734 2771                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2735 2772                                      sGuid, gettext("resource busy"));
2736 2773                                  break;
2737 2774                          case STMF_ERROR_SERVICE_NOT_FOUND:
2738 2775                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2739 2776                                      gettext("STMF service not found"));
2740 2777                                  break;
2741 2778                          case STMF_ERROR_SERVICE_DATA_VERSION:
2742 2779                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2743 2780                                      gettext("STMF service version incorrect"));
2744 2781                                  break;
2745 2782                          case STMF_ERROR_PERM:
2746 2783                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2747 2784                                      gettext("permission denied"));
2748 2785                                  break;
2749 2786                          default:
2750 2787                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2751 2788                                      sGuid, gettext("unknown error"));
2752 2789                                  break;
2753 2790                  }
2754 2791                  return (1);
2755 2792          }
2756 2793  
2757 2794          if (viewEntryList->cnt == 0) {
2758 2795                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2759 2796                      sGuid, gettext("no views found"));
2760 2797                  return (1);
2761 2798          }
2762 2799  
2763 2800          for (i = 0; i < outerLoop; i++) {
2764 2801                  for (found = B_FALSE, j = 0; j < viewEntryList->cnt; j++) {
2765 2802                          if (operandEntered) {
2766 2803                                  if (atoi(operands[i]) ==
2767 2804                                      viewEntryList->ve[j].veIndex) {
2768 2805                                          found = B_TRUE;
2769 2806                                  }
2770 2807                          }
2771 2808                          if ((found && operandEntered) || !operandEntered) {
2772 2809                                  (void) printf("View Entry: %d\n",
2773 2810                                      viewEntryList->ve[j].veIndex);
2774 2811                                  (void) printf(VIEW_FORMAT, "Host group");
2775 2812                                  if (viewEntryList->ve[j].allHosts) {
2776 2813                                          (void) printf("All\n");
2777 2814                                  } else {
2778 2815                                          (void) mbstowcs(groupName,
2779 2816                                              viewEntryList->ve[j].hostGroup,
2780 2817                                              sizeof (stmfGroupName) - 1);
2781 2818                                          groupName[sizeof (stmfGroupName) - 1]
2782 2819                                              = 0;
2783 2820                                          (void) printf("%ws\n", groupName);
2784 2821                                  }
2785 2822                                  (void) printf(VIEW_FORMAT, "Target group");
2786 2823                                  if (viewEntryList->ve[j].allTargets) {
2787 2824                                          (void) printf("All\n");
2788 2825                                  } else {
2789 2826                                          (void) mbstowcs(groupName,
2790 2827                                              viewEntryList->ve[j].targetGroup,
2791 2828                                              sizeof (stmfGroupName) - 1);
2792 2829                                          groupName[sizeof (stmfGroupName) - 1]
2793 2830                                              = 0;
2794 2831                                          (void) printf("%ws\n", groupName);
2795 2832                                  }
2796 2833                                  outputLuNbr = ((viewEntryList->ve[j].luNbr[0] &
2797 2834                                      0x3F) << 8) | viewEntryList->ve[j].luNbr[1];
2798 2835                                  (void) printf(VIEW_FORMAT, "LUN");
2799 2836                                  (void) printf("%d\n", outputLuNbr);
2800 2837                                  if (found && operandEntered) {
2801 2838                                          break;
2802 2839                                  }
2803 2840                          }
2804 2841                  }
2805 2842                  if (operandEntered && !found) {
2806 2843                          (void) fprintf(stderr, "%s: %s, %s: %s\n", cmdName,
2807 2844                              sGuid, operands[i], gettext("not found"));
2808 2845                          ret = 1;
2809 2846                  }
2810 2847          }
2811 2848  
2812 2849          return (ret);
2813 2850  }
2814 2851  
2815 2852  
2816 2853  /*
2817 2854   * onlineOfflineLu
2818 2855   *
2819 2856   * Purpose: Online or offline a logical unit
2820 2857   *
2821 2858   * lu - logical unit to online or offline
2822 2859   *
2823 2860   * state - ONLINE_LU
2824 2861   *         OFFLINE_LU
2825 2862   */
2826 2863  static int
2827 2864  onlineOfflineLu(char *lu, int state)
2828 2865  {
2829 2866          char sGuid[GUID_INPUT + 1];
2830 2867          stmfGuid inGuid;
2831 2868          unsigned int guid[sizeof (stmfGuid)];
2832 2869          int i;
2833 2870          int ret = 0, stmfRet;
2834 2871          stmfLogicalUnitProperties luProps;
2835 2872  
2836 2873          if (strlen(lu) != GUID_INPUT) {
2837 2874                  (void) fprintf(stderr, "%s: %s: %s %d %s\n", cmdName, lu,
2838 2875                      gettext("must be"), GUID_INPUT,
2839 2876                      gettext("hexadecimal digits long"));
2840 2877                  return (1);
2841 2878          }
2842 2879  
2843 2880          bcopy(lu, sGuid, GUID_INPUT);
2844 2881  
2845 2882          for (i = 0; i < 32; i++)
2846 2883                  sGuid[i] = tolower(sGuid[i]);
2847 2884          sGuid[i] = 0;
2848 2885  
2849 2886          (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
2850 2887              &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
2851 2888              &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
2852 2889              &guid[12], &guid[13], &guid[14], &guid[15]);
2853 2890  
2854 2891          for (i = 0; i < sizeof (stmfGuid); i++) {
2855 2892                  inGuid.guid[i] = guid[i];
2856 2893          }
2857 2894  
2858 2895          if (state == ONLINE_LU) {
2859 2896                  ret = stmfOnlineLogicalUnit(&inGuid);
2860 2897          } else if (state == OFFLINE_LU) {
2861 2898                  ret = stmfOfflineLogicalUnit(&inGuid);
2862 2899          } else {
2863 2900                  return (STMFADM_FAILURE);
2864 2901          }
2865 2902          if (ret != STMF_STATUS_SUCCESS) {
2866 2903                  switch (ret) {
2867 2904                          case STMF_ERROR_PERM:
2868 2905                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2869 2906                                      gettext("permission denied"));
2870 2907                                  break;
2871 2908                          case STMF_ERROR_SERVICE_NOT_FOUND:
2872 2909                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2873 2910                                      gettext("STMF service not found"));
2874 2911                                  break;
2875 2912                          case STMF_ERROR_BUSY:
2876 2913                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2877 2914                                      gettext("resource busy"));
2878 2915                                  break;
2879 2916                          case STMF_ERROR_NOT_FOUND:
2880 2917                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
2881 2918                                      lu, gettext("not found"));
2882 2919                                  break;
2883 2920                          case STMF_ERROR_SERVICE_DATA_VERSION:
2884 2921                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2885 2922                                      gettext("STMF service version incorrect"));
2886 2923                                  break;
2887 2924                          default:
2888 2925                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2889 2926                                      gettext("unknown error"));
2890 2927                                  break;
2891 2928                  }
2892 2929          } else {
2893 2930                  struct timespec ts = {0};
2894 2931                  unsigned int    count = 0;
2895 2932                  uint32_t        ret_state;
2896 2933  
2897 2934                  ret_state = (state == ONLINE_LU) ?
2898 2935                      STMF_LOGICAL_UNIT_ONLINING : STMF_LOGICAL_UNIT_OFFLINING;
2899 2936                  ts.tv_nsec = DELAYED_EXEC_WAIT_INTERVAL;
2900 2937  
2901 2938                  /* CONSTCOND */
2902 2939                  while (1) {
2903 2940                          stmfRet = stmfGetLogicalUnitProperties(&inGuid,
2904 2941                              &luProps);
2905 2942                          if (stmfRet == STMF_STATUS_SUCCESS)
2906 2943                                  ret_state = luProps.status;
2907 2944  
2908 2945                          if ((state == ONLINE_LU &&
2909 2946                              ret_state == STMF_LOGICAL_UNIT_ONLINE) ||
2910 2947                              (state == OFFLINE_LU &&
2911 2948                              ret_state == STMF_LOGICAL_UNIT_OFFLINE))
2912 2949                                  return (STMFADM_SUCCESS);
2913 2950  
2914 2951                          if ((state == ONLINE_LU &&
2915 2952                              ret_state == STMF_LOGICAL_UNIT_OFFLINE) ||
2916 2953                              (state == OFFLINE_LU &&
2917 2954                              ret_state == STMF_LOGICAL_UNIT_ONLINE))
2918 2955                                  return (STMFADM_FAILURE);
2919 2956  
2920 2957                          if (++count ==  DELAYED_EXEC_WAIT_MAX) {
2921 2958                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2922 2959                                      gettext("Logical Unit state change request "
2923 2960                                      "submitted. Waiting for completion "
2924 2961                                      "timed out"));
2925 2962                                  return (STMFADM_FAILURE);
2926 2963                          }
2927 2964                          (void) nanosleep(&ts, NULL);
2928 2965                  }
2929 2966          }
2930 2967          return (STMFADM_FAILURE);
2931 2968  }
2932 2969  
2933 2970  /*
2934 2971   * onlineLuFunc
2935 2972   *
2936 2973   * Purpose: Online a logical unit
2937 2974   *
2938 2975   */
2939 2976  /*ARGSUSED*/
2940 2977  static int
2941 2978  onlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
2942 2979      void *args)
2943 2980  {
2944 2981          int ret;
2945 2982          stmfState state;
2946 2983  
2947 2984          ret = getStmfState(&state);
2948 2985          if (ret != STMF_STATUS_SUCCESS)
2949 2986                  return (ret);
2950 2987          if (state.operationalState == STMF_SERVICE_STATE_OFFLINE ||
2951 2988              state.operationalState == STMF_SERVICE_STATE_OFFLINING) {
2952 2989                  (void) fprintf(stderr, "%s: %s\n", cmdName,
2953 2990                      gettext("STMF service is offline"));
2954 2991                  return (1);
2955 2992          }
2956 2993          return (onlineOfflineLu(operands[0], ONLINE_LU));
2957 2994  }
2958 2995  
2959 2996  /*
2960 2997   * offlineLuFunc
2961 2998   *
2962 2999   * Purpose: Offline a logical unit
2963 3000   *
2964 3001   */
2965 3002  /*ARGSUSED*/
2966 3003  static int
2967 3004  offlineLuFunc(int operandLen, char *operands[], cmdOptions_t *options,
2968 3005      void *args)
2969 3006  {
2970 3007          return (onlineOfflineLu(operands[0], OFFLINE_LU));
2971 3008  }
2972 3009  
2973 3010  /*
2974 3011   * onlineOfflineTarget
2975 3012   *
2976 3013   * Purpose: Online or offline a target
2977 3014   *
2978 3015   * target - target to online or offline
2979 3016   *
2980 3017   * state - ONLINE_TARGET
2981 3018   *         OFFLINE_TARGET
2982 3019   */
2983 3020  static int
2984 3021  onlineOfflineTarget(char *target, int state)
2985 3022  {
2986 3023          int ret = 0, stmfRet = 0;
2987 3024          stmfDevid devid;
2988 3025          stmfTargetProperties targetProps;
2989 3026  
2990 3027          if (parseDevid(target, &devid) != 0) {
2991 3028                  (void) fprintf(stderr, "%s: %s: %s\n",
2992 3029                      cmdName, target, gettext("unrecognized device id"));
2993 3030                  return (1);
2994 3031          }
2995 3032          if (state == ONLINE_TARGET) {
2996 3033                  ret = stmfOnlineTarget(&devid);
2997 3034          } else if (state == OFFLINE_TARGET) {
2998 3035                  ret = stmfOfflineTarget(&devid);
2999 3036          } else {
3000 3037                  return (STMFADM_FAILURE);
3001 3038          }
3002 3039          if (ret != STMF_STATUS_SUCCESS) {
3003 3040                  switch (ret) {
3004 3041                          case STMF_ERROR_PERM:
3005 3042                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3006 3043                                      gettext("permission denied"));
3007 3044                                  break;
3008 3045                          case STMF_ERROR_SERVICE_NOT_FOUND:
3009 3046                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3010 3047                                      gettext("STMF service not found"));
3011 3048                                  break;
3012 3049                          case STMF_ERROR_BUSY:
3013 3050                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3014 3051                                      gettext("resource busy"));
3015 3052                                  break;
3016 3053                          case STMF_ERROR_NOT_FOUND:
3017 3054                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3018 3055                                      target, gettext("not found"));
3019 3056                                  break;
3020 3057                          case STMF_ERROR_SERVICE_DATA_VERSION:
3021 3058                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3022 3059                                      gettext("STMF service version incorrect"));
3023 3060                                  break;
3024 3061                          default:
3025 3062                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3026 3063                                      gettext("unknown error"));
3027 3064                                  break;
3028 3065                  }
3029 3066          } else {
3030 3067                  struct timespec  ts = {0};
3031 3068                  unsigned int count = 0;
3032 3069                  uint32_t        ret_state;
3033 3070  
3034 3071                  ret_state = (state == ONLINE_TARGET) ?
3035 3072                      STMF_TARGET_PORT_ONLINING : STMF_TARGET_PORT_OFFLINING;
3036 3073                  ts.tv_nsec = DELAYED_EXEC_WAIT_INTERVAL;
3037 3074  
3038 3075                  /* CONSTCOND */
3039 3076                  while (1) {
3040 3077                          stmfRet = stmfGetTargetProperties(&devid, &targetProps);
3041 3078                          if (stmfRet == STMF_STATUS_SUCCESS)
3042 3079                                  ret_state = targetProps.status;
3043 3080  
3044 3081                          if ((state == ONLINE_TARGET &&
3045 3082                              ret_state == STMF_TARGET_PORT_ONLINE) ||
3046 3083                              (state == OFFLINE_TARGET &&
3047 3084                              ret_state == STMF_TARGET_PORT_OFFLINE)) {
3048 3085                                  return (STMFADM_SUCCESS);
3049 3086                          }
3050 3087  
3051 3088                          if ((state == ONLINE_TARGET &&
3052 3089                              ret_state == STMF_TARGET_PORT_OFFLINE) ||
3053 3090                              (state == OFFLINE_TARGET &&
3054 3091                              ret_state == STMF_TARGET_PORT_ONLINE)) {
3055 3092                                  return (STMFADM_FAILURE);
3056 3093                          }
3057 3094  
3058 3095                          if (++count ==  DELAYED_EXEC_WAIT_MAX) {
3059 3096                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3060 3097                                      gettext("Target state change request "
3061 3098                                      "submitted. Waiting for completion "
3062 3099                                      "timed out."));
3063 3100                                  return (STMFADM_FAILURE);
3064 3101                          }
3065 3102                          (void) nanosleep(&ts, NULL);
3066 3103                  }
3067 3104          }
3068 3105          return (STMFADM_FAILURE);
3069 3106  }
3070 3107  
3071 3108  /*
3072 3109   * onlineTargetFunc
3073 3110   *
3074 3111   * Purpose: Online a target
3075 3112   *
3076 3113   */
3077 3114  /*ARGSUSED*/
3078 3115  static int
3079 3116  onlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
3080 3117      void *args)
3081 3118  {
3082 3119          int ret;
3083 3120          stmfState state;
3084 3121  
3085 3122          ret = getStmfState(&state);
3086 3123          if (ret != STMF_STATUS_SUCCESS)
3087 3124                  return (ret);
3088 3125          if (state.operationalState == STMF_SERVICE_STATE_OFFLINE ||
3089 3126              state.operationalState == STMF_SERVICE_STATE_OFFLINING) {
3090 3127                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3091 3128                      gettext("STMF service is offline"));
3092 3129                  return (1);
3093 3130          }
3094 3131          return (onlineOfflineTarget(operands[0], ONLINE_TARGET));
3095 3132  }
3096 3133  
3097 3134  /*
3098 3135   * offlineTargetFunc
3099 3136   *
3100 3137   * Purpose: Offline a target
3101 3138   *
3102 3139   */
3103 3140  /*ARGSUSED*/
3104 3141  static int
3105 3142  offlineTargetFunc(int operandLen, char *operands[], cmdOptions_t *options,
3106 3143      void *args)
3107 3144  {
3108 3145          return (onlineOfflineTarget(operands[0], OFFLINE_TARGET));
3109 3146  }
3110 3147  
3111 3148  
3112 3149  /*ARGSUSED*/
3113 3150  static int
3114 3151  removeHostGroupMemberFunc(int operandLen, char *operands[],
3115 3152      cmdOptions_t *options, void *args)
3116 3153  {
3117 3154          int i;
3118 3155          int ret = 0;
3119 3156          int stmfRet;
3120 3157          stmfGroupName groupName = {0};
3121 3158          stmfDevid devid;
3122 3159          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
3123 3160  
3124 3161          for (; options->optval; options++) {
3125 3162                  switch (options->optval) {
3126 3163                          case 'g':
3127 3164                                  (void) mbstowcs(groupNamePrint, options->optarg,
3128 3165                                      sizeof (stmfGroupName) - 1);
3129 3166                                  bcopy(options->optarg, groupName,
3130 3167                                      strlen(options->optarg));
3131 3168                                  break;
3132 3169                          default:
3133 3170                                  (void) fprintf(stderr, "%s: %c: %s\n",
3134 3171                                      cmdName, options->optval,
3135 3172                                      gettext("unknown option"));
3136 3173                                  return (1);
3137 3174                  }
3138 3175          }
3139 3176  
3140 3177          for (i = 0; i < operandLen; i++) {
3141 3178                  if (parseDevid(operands[i], &devid) != 0) {
3142 3179                          (void) fprintf(stderr, "%s: %s: %s\n",
3143 3180                              cmdName, operands[i],
3144 3181                              gettext("unrecognized device id"));
3145 3182                          ret++;
3146 3183                          continue;
3147 3184                  }
3148 3185                  stmfRet = stmfRemoveFromHostGroup(&groupName, &devid);
3149 3186                  switch (stmfRet) {
3150 3187                          case STMF_STATUS_SUCCESS:
3151 3188                                  break;
3152 3189                          case STMF_ERROR_MEMBER_NOT_FOUND:
3153 3190                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3154 3191                                      operands[i], gettext("not found"));
3155 3192                                  ret++;
3156 3193                                  break;
3157 3194                          case STMF_ERROR_GROUP_NOT_FOUND:
3158 3195                                  (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
3159 3196                                      groupNamePrint, gettext("not found"));
3160 3197                                  ret++;
3161 3198                                  break;
3162 3199                          case STMF_ERROR_BUSY:
3163 3200                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3164 3201                                      operands[i], "resource busy");
3165 3202                                  ret++;
3166 3203                                  break;
3167 3204                          case STMF_ERROR_SERVICE_NOT_FOUND:
3168 3205                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3169 3206                                      gettext("STMF service not found"));
3170 3207                                  ret++;
3171 3208                                  break;
3172 3209                          case STMF_ERROR_SERVICE_DATA_VERSION:
3173 3210                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3174 3211                                      gettext("STMF service version incorrect"));
3175 3212                                  ret++;
3176 3213                                  break;
3177 3214                          case STMF_ERROR_PERM:
3178 3215                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3179 3216                                      gettext("permission denied"));
3180 3217                                  ret++;
3181 3218                                  break;
3182 3219                          default:
3183 3220                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3184 3221                                      operands[i], gettext("unknown error"));
3185 3222                                  ret++;
3186 3223                                  break;
3187 3224                  }
3188 3225          }
3189 3226  
3190 3227          return (ret);
3191 3228  }
3192 3229  
3193 3230  /*
3194 3231   * removeTargetGroupMemberFunc
3195 3232   *
3196 3233   * Removes one or more members from a target group
3197 3234   *
3198 3235   */
3199 3236  /*ARGSUSED*/
3200 3237  static int
3201 3238  removeTargetGroupMemberFunc(int operandLen, char *operands[],
3202 3239      cmdOptions_t *options, void *args)
3203 3240  {
3204 3241          int i;
3205 3242          int ret = 0;
3206 3243          int stmfRet;
3207 3244          stmfGroupName groupName = {0};
3208 3245          stmfDevid devid;
3209 3246          wchar_t groupNamePrint[sizeof (stmfGroupName)] = {0};
3210 3247  
3211 3248          for (; options->optval; options++) {
3212 3249                  switch (options->optval) {
3213 3250                          case 'g':
3214 3251                                  (void) mbstowcs(groupNamePrint, options->optarg,
3215 3252                                      sizeof (stmfGroupName) - 1);
3216 3253                                  bcopy(options->optarg, groupName,
3217 3254                                      strlen(options->optarg));
3218 3255                                  break;
3219 3256                          default:
3220 3257                                  (void) fprintf(stderr, "%s: %c: %s\n",
3221 3258                                      cmdName, options->optval,
3222 3259                                      gettext("unknown option"));
3223 3260                                  return (1);
3224 3261                  }
3225 3262          }
3226 3263  
3227 3264          for (i = 0; i < operandLen; i++) {
3228 3265                  if (parseDevid(operands[i], &devid) != 0) {
3229 3266                          (void) fprintf(stderr, "%s: %s: %s\n",
3230 3267                              cmdName, operands[i],
3231 3268                              gettext("unrecognized device id"));
3232 3269                          ret++;
3233 3270                          continue;
3234 3271                  }
3235 3272                  stmfRet = stmfRemoveFromTargetGroup(&groupName, &devid);
3236 3273                  switch (stmfRet) {
3237 3274                          case STMF_STATUS_SUCCESS:
3238 3275                                  break;
3239 3276                          case STMF_ERROR_MEMBER_NOT_FOUND:
3240 3277                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3241 3278                                      operands[i], gettext("not found"));
3242 3279                                  ret++;
3243 3280                                  break;
3244 3281                          case STMF_ERROR_GROUP_NOT_FOUND:
3245 3282                                  (void) fprintf(stderr, "%s: %ws: %s\n", cmdName,
3246 3283                                      groupNamePrint, gettext("not found"));
3247 3284                                  ret++;
3248 3285                                  break;
3249 3286                          case STMF_ERROR_BUSY:
3250 3287                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3251 3288                                      operands[i], gettext("resource busy"));
3252 3289                                  ret++;
3253 3290                                  break;
3254 3291                          case STMF_ERROR_SERVICE_NOT_FOUND:
3255 3292                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3256 3293                                      gettext("STMF service not found"));
3257 3294                                  ret++;
3258 3295                                  break;
3259 3296                          case STMF_ERROR_PERM:
3260 3297                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3261 3298                                      gettext("permission denied"));
3262 3299                                  ret++;
3263 3300                                  break;
3264 3301                          case STMF_ERROR_SERVICE_DATA_VERSION:
3265 3302                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3266 3303                                      gettext("STMF service version incorrect"));
3267 3304                                  ret++;
3268 3305                                  break;
3269 3306                          case STMF_ERROR_TG_ONLINE:
3270 3307                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3271 3308                                      gettext("STMF target must be offline"));
3272 3309                                  ret++;
3273 3310                                  break;
3274 3311                          default:
3275 3312                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3276 3313                                      operands[i], gettext("unknown error"));
3277 3314                                  ret++;
3278 3315                                  break;
3279 3316                  }
3280 3317          }
3281 3318  
3282 3319          return (ret);
3283 3320  }
3284 3321  
3285 3322  /*
3286 3323   * removeViewFunc
3287 3324   *
3288 3325   * Removes one or more view entries from a logical unit
3289 3326   *
3290 3327   */
3291 3328  /*ARGSUSED*/
3292 3329  static int
3293 3330  removeViewFunc(int operandLen, char *operands[], cmdOptions_t *options,
3294 3331      void *args)
3295 3332  {
3296 3333          char sGuid[GUID_INPUT + 1];
3297 3334          stmfViewEntryList *viewEntryList;
3298 3335          stmfGuid inGuid;
3299 3336          uint32_t count;
3300 3337          unsigned int guid[sizeof (stmfGuid)];
3301 3338          char *endPtr;
3302 3339          uint32_t veNbr;
3303 3340          int i;
3304 3341          boolean_t all = B_FALSE;
3305 3342          boolean_t luInput = B_FALSE;
3306 3343          int ret = 0;
3307 3344          int stmfRet;
3308 3345  
3309 3346          /* Note: 'l' is required */
3310 3347          for (; options->optval; options++) {
3311 3348                  switch (options->optval) {
3312 3349                          case 'l':
3313 3350                                  if (strlen(options->optarg) != GUID_INPUT) {
3314 3351                                          (void) fprintf(stderr,
3315 3352                                              "%s: %s: %s %d %s\n",
3316 3353                                              cmdName, options->optarg,
3317 3354                                              gettext("must be"), GUID_INPUT,
3318 3355                                              gettext("hexadecimal digits long"));
3319 3356                                          return (1);
3320 3357                                  }
3321 3358                                  bcopy(options->optarg, sGuid, GUID_INPUT);
3322 3359                                  luInput = B_TRUE;
3323 3360                                  break;
3324 3361                          case 'a':
3325 3362                                  /* removing all view entries for this GUID */
3326 3363                                  all = B_TRUE;
3327 3364                                  break;
3328 3365                          default:
3329 3366                                  (void) fprintf(stderr, "%s: %c: %s\n",
3330 3367                                      cmdName, options->optval,
3331 3368                                      "unknown option");
3332 3369                                  return (1);
3333 3370                  }
3334 3371          }
3335 3372  
3336 3373          if (!all && operandLen == 0) {
3337 3374                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3338 3375                      gettext("no view entries specified"));
3339 3376                  return (1);
3340 3377          }
3341 3378  
3342 3379          if (!luInput) {
3343 3380                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3344 3381                      gettext("logical unit (-l) not specified"));
3345 3382                  return (1);
3346 3383          }
3347 3384  
3348 3385          for (i = 0; i < 32; i++)
3349 3386                  sGuid[i] = tolower(sGuid[i]);
3350 3387          sGuid[i] = 0;
3351 3388  
3352 3389          (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
3353 3390              &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], &guid[5],
3354 3391              &guid[6], &guid[7], &guid[8], &guid[9], &guid[10], &guid[11],
3355 3392              &guid[12], &guid[13], &guid[14], &guid[15]);
3356 3393  
3357 3394          for (i = 0; i < sizeof (stmfGuid); i++) {
3358 3395                  inGuid.guid[i] = guid[i];
3359 3396          }
3360 3397  
3361 3398          if ((stmfRet = stmfGetViewEntryList(&inGuid, &viewEntryList))
3362 3399              != STMF_STATUS_SUCCESS) {
3363 3400  
3364 3401                  switch (stmfRet) {
3365 3402                          case STMF_ERROR_BUSY:
3366 3403                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3367 3404                                      sGuid, gettext("resource busy"));
3368 3405                                  break;
3369 3406                          case STMF_ERROR_SERVICE_NOT_FOUND:
3370 3407                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3371 3408                                      gettext("STMF service not found"));
3372 3409                                  break;
3373 3410                          case STMF_ERROR_SERVICE_DATA_VERSION:
3374 3411                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3375 3412                                      gettext("STMF service version incorrect"));
3376 3413                                  break;
3377 3414                          case STMF_ERROR_PERM:
3378 3415                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3379 3416                                      gettext("permission denied"));
3380 3417                                  break;
3381 3418                          default:
3382 3419                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3383 3420                                      sGuid, gettext("unknown error"));
3384 3421                                  break;
3385 3422                  }
3386 3423                  return (1);
3387 3424          }
3388 3425  
3389 3426          if (viewEntryList->cnt == 0) {
3390 3427                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3391 3428                      sGuid, gettext("no views found"));
3392 3429                  return (1);
3393 3430          }
3394 3431  
3395 3432          if (all) {
3396 3433                  count = viewEntryList->cnt;
3397 3434          } else {
3398 3435                  count = operandLen;
3399 3436          }
3400 3437  
3401 3438          for (i = 0; i < count; i++) {
3402 3439                  if (all) {
3403 3440                          veNbr = viewEntryList->ve[i].veIndex;
3404 3441                  } else {
3405 3442                          endPtr = NULL;
3406 3443                          veNbr = strtol(operands[i], &endPtr, 10);
3407 3444                          if (endPtr && *endPtr != 0) {
3408 3445                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3409 3446                                      operands[i], gettext("invalid input"));
3410 3447                                  continue;
3411 3448                          }
3412 3449                  }
3413 3450                  stmfRet = stmfRemoveViewEntry(&inGuid, veNbr);
3414 3451                  switch (stmfRet) {
3415 3452                          case STMF_STATUS_SUCCESS:
3416 3453                                  break;
3417 3454                          case STMF_ERROR_NOT_FOUND:
3418 3455                                  (void) fprintf(stderr, "%s: %s: %d: %s\n",
3419 3456                                      cmdName, sGuid, veNbr,
3420 3457                                      gettext("not found"));
3421 3458                                  ret++;
3422 3459                                  break;
3423 3460                          case STMF_ERROR_BUSY:
3424 3461                                  (void) fprintf(stderr, "%s: %s: %s\n", cmdName,
3425 3462                                      sGuid, gettext("resource busy"));
3426 3463                                  ret++;
3427 3464                                  break;
3428 3465                          case STMF_ERROR_SERVICE_NOT_FOUND:
3429 3466                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3430 3467                                      gettext("STMF service not found"));
3431 3468                                  ret++;
3432 3469                                  break;
3433 3470                          case STMF_ERROR_CONFIG_NONE:
3434 3471                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3435 3472                                      gettext("STMF service is not initialized"));
3436 3473                                  ret++;
3437 3474                                  break;
3438 3475                          case STMF_ERROR_SERVICE_DATA_VERSION:
3439 3476                                  (void) fprintf(stderr, "%s: %s\n", cmdName,
3440 3477                                      gettext("STMF service version incorrect"));
3441 3478                                  ret++;
3442 3479                                  break;
3443 3480                          default:
3444 3481                                  (void) fprintf(stderr, "%s: %s, %d: %s",
3445 3482                                      cmdName, sGuid, veNbr,
3446 3483                                      gettext("unknown error"));
3447 3484                                  ret++;
3448 3485                                  break;
3449 3486                  }
3450 3487          }
3451 3488  
3452 3489          return (ret);
3453 3490  }
3454 3491  
3455 3492  /*
3456 3493   * input:
3457 3494   *  execFullName - exec name of program (argv[0])
3458 3495   *
3459 3496   *  copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
3460 3497   *  (changed name to lowerCamelCase to keep consistent with this file)
3461 3498   *
3462 3499   * Returns:
3463 3500   *  command name portion of execFullName
3464 3501   */
3465 3502  static char *
3466 3503  getExecBasename(char *execFullname)
3467 3504  {
3468 3505          char *lastSlash, *execBasename;
3469 3506  
3470 3507          /* guard against '/' at end of command invocation */
3471 3508          for (;;) {
3472 3509                  lastSlash = strrchr(execFullname, '/');
3473 3510                  if (lastSlash == NULL) {
3474 3511                          execBasename = execFullname;
3475 3512                          break;
3476 3513                  } else {
3477 3514                          execBasename = lastSlash + 1;
3478 3515                          if (*execBasename == '\0') {
3479 3516                                  *lastSlash = '\0';
3480 3517                                  continue;
3481 3518                          }
3482 3519                          break;
3483 3520                  }
3484 3521          }
3485 3522          return (execBasename);
3486 3523  }
3487 3524  
3488 3525  int
3489 3526  main(int argc, char *argv[])
3490 3527  {
3491 3528          synTables_t synTables;
3492 3529          char versionString[VERSION_STRING_MAX_LEN];
3493 3530          int ret;
3494 3531          int funcRet;
3495 3532          void *subcommandArgs = NULL;
3496 3533  
3497 3534          (void) setlocale(LC_ALL, "");
3498 3535          (void) textdomain(TEXT_DOMAIN);
3499 3536          /* set global command name */
3500 3537          cmdName = getExecBasename(argv[0]);
3501 3538  
3502 3539          (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
3503 3540              VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
3504 3541          synTables.versionString = versionString;
3505 3542          synTables.longOptionTbl = &longOptions[0];
3506 3543          synTables.subCommandPropsTbl = &subcommands[0];
3507 3544  
3508 3545          ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
3509 3546          if (ret != 0) {
3510 3547                  return (ret);
3511 3548          }
3512 3549  
3513 3550          return (funcRet);
3514 3551  } /* end main */
  
    | 
      ↓ open down ↓ | 
    1284 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX