Print this page
3217 cfgadm should spell "adaptors" correctly
Reviewed by: Alexander Eremin <alexander.r.eremin@gmail.com>
Reviewed by: David Hoeppner <0xffea@gmail.com>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Eric Schrock <Eric.Schrock@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/cfgadm_plugins/fp/common/cfga_utils.c
          +++ new/usr/src/lib/cfgadm_plugins/fp/common/cfga_utils.c
↓ open down ↓ 129 lines elided ↑ open up ↑
 130  130                  "Configuration successful, but Repository update failed"},
 131  131  {ERR_UNCONF_OK_UPD_REP, 0, 1,
 132  132                  "Unconfiguration successful, but Repository update failed"},
 133  133  {ERR_PARTIAL_SUCCESS,   0, 1,
 134  134                          "Operation partially successful. Some failures seen"},
 135  135  {ERR_HBA_LOAD_LIBRARY,  0, 1,
 136  136                          "HBA load library failed"},
 137  137  {ERR_MATCHING_HBA_PORT, 0, 1,
 138  138                          "No match HBA port found"},
 139  139  {ERR_NO_ADAPTER_FOUND,  0, 1,
 140      -                        "No Fibre Channel adpaters found"},
      140 +                        "No Fibre Channel adapters found"},
 141  141  
 142  142  /* Errors with arguments */
 143  143  {ERRARG_OPT_INVAL,      1, 1,   "invalid option: "},
 144  144  {ERRARG_HWCMD_INVAL,    1, 1,   "invalid command: "},
 145  145  {ERRARG_DEVINFO,        1, 1,   "libdevinfo failed on path: "},
 146  146  {ERRARG_NOT_IN_DEVLIST, 1, 1,   "Device not found in fabric device list: "},
 147  147  {ERRARG_NOT_IN_DEVINFO, 1, 1,   "Could not find entry in devinfo tree: "},
 148  148  {ERRARG_DI_GET_PROP,    1, 1,   "Could not get libdevinfo property: "},
 149  149  {ERRARG_DC_DDEF_ALLOC,  1, 1,   "failed to alloc ddef space: "},
 150  150  {ERRARG_DC_BYTE_ARRAY,  1, 1,   "failed to add property: "},
↓ open down ↓ 284 lines elided ↑ open up ↑
 435  435                          goto err;
 436  436                  }
 437  437  
 438  438                  /* Remove the dynamic component from the base. */
 439  439                  *dyn = '\0';
 440  440          }
 441  441  
 442  442          /* Get the path of dynamic attachment point if already configured. */
 443  443          if (dyncomp != NULL) {
 444  444                  ret = dyn_apid_to_path(xport_phys, dyncomp,
 445      -                                &lunlistp, &l_errno);
      445 +                    &lunlistp, &l_errno);
 446  446                  if ((ret != FPCFGA_OK) && (ret != FPCFGA_APID_NOCONFIGURE)) {
 447  447                          cfga_err(errstring, l_errno, ERR_OP_FAILED, 0);
 448  448                          goto err;
 449  449                  }
 450  450          }
 451  451  
 452  452          assert(xport_phys != NULL);
 453  453  
 454  454          apidp->xport_phys = xport_phys;
 455  455          apidp->dyncomp = dyncomp;
↓ open down ↓ 101 lines elided ↑ open up ↑
 557  557                  *l_errnop = errno;
 558  558                  ret = FPCFGA_LIB_ERR;
 559  559                  goto out;
 560  560          }
 561  561  
 562  562          fpnode = di_drv_first_node("fp", tree_root);
 563  563  
 564  564          while (fpnode) {
 565  565                  devfs_fp_path = di_devfs_path(fpnode);
 566  566                  if ((devfs_fp_path) && !(strncmp(devfs_fp_path,
 567      -                                root_path, strlen(root_path)))) {
      567 +                    root_path, strlen(root_path)))) {
 568  568                          found = 1;
 569  569                          di_devfs_path_free(devfs_fp_path);
 570  570                          break;
 571  571                  }
 572  572                  di_devfs_path_free(devfs_fp_path);
 573  573                  fpnode = di_drv_next_node(fpnode);
 574  574          }
 575  575          if (!(found)) {
 576  576                  ret = FPCFGA_LIB_ERR;
 577  577                  goto out;
↓ open down ↓ 2 lines elided ↑ open up ↑
 580  580          }
 581  581  
 582  582          /* Walk the tree */
 583  583          errno = 0;
 584  584          if (cmd == FPCFGA_WALK_NODE) {
 585  585                  rv = di_walk_node(root, up->walkmode.node_args.flags, arg,
 586  586                      up->walkmode.node_args.fcn);
 587  587          } else {
 588  588                  assert(cmd == FPCFGA_WALK_MINOR);
 589  589                  rv = di_walk_minor(root, up->walkmode.minor_args.nodetype, 0,
 590      -                        arg, up->walkmode.minor_args.fcn);
      590 +                    arg, up->walkmode.minor_args.fcn);
 591  591          }
 592  592  
 593  593          if (rv != 0) {
 594  594                  *l_errnop = errno;
 595  595                  ret = FPCFGA_LIB_ERR;
 596  596          } else {
 597  597                  if ((up->flags & FLAG_PATH_INFO_WALK) == FLAG_PATH_INFO_WALK) {
 598  598                          ret = stat_path_info_node(root, arg, l_errnop);
 599  599                  } else {
 600  600                          *l_errnop = 0;
↓ open down ↓ 63 lines elided ↑ open up ↑
 664  664                  *errstring = tmp_err_str;
 665  665                  return;
 666  666          }
 667  667  
 668  668          /*
 669  669           * *errstring != NULL
 670  670           * There was something in errstring prior to this call.
 671  671           * So, concatenate the old and new strings
 672  672           */
 673  673          if ((tmp_str = calloc(1,
 674      -                strlen(*errstring) + strlen(tmp_err_str) + 2)) == NULL) {
      674 +            strlen(*errstring) + strlen(tmp_err_str) + 2)) == NULL) {
 675  675                  /* In case of error, retain only the earlier message */
 676  676                  free(tmp_err_str);
 677  677                  return;
 678  678          }
 679  679  
 680  680          sprintf(tmp_str, "%s\n%s", *errstring, tmp_err_str);
 681  681          free(tmp_err_str);
 682  682          free(*errstring);
 683  683          *errstring = tmp_str;
 684  684  }
↓ open down ↓ 236 lines elided ↑ open up ↑
 921  921          uint_t state;
 922  922  
 923  923          state = di_state(node);
 924  924  
 925  925          /*
 926  926           * CF1 without offline flag set is considered unknown state.
 927  927           * We are in a known state if either CF2 (driver attached) or
 928  928           * offline.
 929  929           */
 930  930          if ((state & DI_DEVICE_OFFLINE) == DI_DEVICE_OFFLINE ||
 931      -                (state & DI_DRIVER_DETACHED) != DI_DRIVER_DETACHED) {
      931 +            (state & DI_DRIVER_DETACHED) != DI_DRIVER_DETACHED) {
 932  932                  return (1);
 933  933          }
 934  934  
 935  935          return (0);
 936  936  }
 937  937  
 938  938  void
 939  939  list_free(ldata_list_t **llpp)
 940  940  {
 941  941          ldata_list_t *lp, *olp;
↓ open down ↓ 169 lines elided ↑ open up ↑
1111 1111   * Will handle retries if applicable.
1112 1112   */
1113 1113  int
1114 1114  getAdapterAttrs(HBA_HANDLE handle, HBA_ADAPTERATTRIBUTES *attrs)
1115 1115  {
1116 1116          int count = 0;
1117 1117          HBA_STATUS status = HBA_STATUS_ERROR_TRY_AGAIN; /* force first pass */
1118 1118  
1119 1119          /* Loop as long as we have a retryable error */
1120 1120          while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
1121      -                status == HBA_STATUS_ERROR_BUSY) &&
1122      -                count++ < HBA_MAX_RETRIES) {
     1121 +            status == HBA_STATUS_ERROR_BUSY) &&
     1122 +            count++ < HBA_MAX_RETRIES) {
1123 1123                  status = HBA_GetAdapterAttributes(handle, attrs);
1124 1124                  if (status == HBA_STATUS_OK) {
1125 1125                          break;
1126 1126                  }
1127 1127                  sleep(1);
1128 1128          }
1129 1129          return (status);
1130 1130  }
1131 1131  
1132 1132  /*
↓ open down ↓ 1 lines elided ↑ open up ↑
1134 1134   * Will handle retries if applicable.
1135 1135   */
1136 1136  int
1137 1137  getPortAttrsByWWN(HBA_HANDLE handle, HBA_WWN wwn, HBA_PORTATTRIBUTES *attrs)
1138 1138  {
1139 1139          int count = 0;
1140 1140          HBA_STATUS status = HBA_STATUS_ERROR_TRY_AGAIN; /* force first pass */
1141 1141  
1142 1142          /* Loop as long as we have a retryable error */
1143 1143          while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
1144      -                status == HBA_STATUS_ERROR_BUSY) &&
1145      -                count++ < HBA_MAX_RETRIES) {
     1144 +            status == HBA_STATUS_ERROR_BUSY) &&
     1145 +            count++ < HBA_MAX_RETRIES) {
1146 1146                  status = HBA_GetPortAttributesByWWN(handle, wwn, attrs);
1147 1147                  if (status == HBA_STATUS_OK) {
1148      -                    break;
     1148 +                        break;
1149 1149                  }
1150 1150  
1151 1151                  /* The odds of this occuring are very slim, but possible. */
1152 1152                  if (status == HBA_STATUS_ERROR_STALE_DATA) {
1153 1153                          /*
1154 1154                           * If we hit a stale data scenario,
1155 1155                           * we'll just tell the user to try again.
1156 1156                           */
1157 1157                          status = HBA_STATUS_ERROR_TRY_AGAIN;
1158 1158                          break;
↓ open down ↓ 9 lines elided ↑ open up ↑
1168 1168   */
1169 1169  int
1170 1170  getAdapterPortAttrs(HBA_HANDLE handle, int portIndex,
1171 1171              HBA_PORTATTRIBUTES *attrs)
1172 1172  {
1173 1173          int count = 0;
1174 1174          HBA_STATUS status = HBA_STATUS_ERROR_TRY_AGAIN; /* force first pass */
1175 1175  
1176 1176          /* Loop as long as we have a retryable error */
1177 1177          while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
1178      -                status == HBA_STATUS_ERROR_BUSY) &&
1179      -                count++ < HBA_MAX_RETRIES) {
     1178 +            status == HBA_STATUS_ERROR_BUSY) &&
     1179 +            count++ < HBA_MAX_RETRIES) {
1180 1180                  status = HBA_GetAdapterPortAttributes(handle, portIndex, attrs);
1181 1181                  if (status == HBA_STATUS_OK) {
1182 1182                          break;
1183 1183                  }
1184 1184  
1185 1185                  /* The odds of this occuring are very slim, but possible. */
1186 1186                  if (status == HBA_STATUS_ERROR_STALE_DATA) {
1187 1187                          /*
1188 1188                           * If we hit a stale data scenario,
1189 1189                           * we'll just tell the user to try again.
↓ open down ↓ 12 lines elided ↑ open up ↑
1202 1202   */
1203 1203  int
1204 1204  getDiscPortAttrs(HBA_HANDLE handle, int portIndex, int discIndex,
1205 1205              HBA_PORTATTRIBUTES *attrs)
1206 1206  {
1207 1207          int count = 0;
1208 1208          HBA_STATUS status = HBA_STATUS_ERROR_TRY_AGAIN; /* force first pass */
1209 1209  
1210 1210          /* Loop as long as we have a retryable error */
1211 1211          while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
1212      -                status == HBA_STATUS_ERROR_BUSY) &&
1213      -                count++ < HBA_MAX_RETRIES) {
     1212 +            status == HBA_STATUS_ERROR_BUSY) &&
     1213 +            count++ < HBA_MAX_RETRIES) {
1214 1214                  status = HBA_GetDiscoveredPortAttributes(handle, portIndex,
1215      -                                discIndex, attrs);
     1215 +                    discIndex, attrs);
1216 1216                  if (status == HBA_STATUS_OK) {
1217 1217                          break;
1218 1218                  }
1219 1219  
1220 1220                  /* The odds of this occuring are very slim, but possible. */
1221 1221                  if (status == HBA_STATUS_ERROR_STALE_DATA) {
1222 1222                          /*
1223 1223                           * If we hit a stale data scenario, we'll just tell the
1224 1224                           * user to try again.
1225 1225                           */
↓ open down ↓ 20 lines elided ↑ open up ↑
1246 1246          HBA_PORTATTRIBUTES      portAttrs;
1247 1247          HBA_STATUS status = HBA_STATUS_OK;
1248 1248          int count, retry = 0, l_errno = 0;
1249 1249          int adapterIndex, portIndex;
1250 1250          char                    adapterName[256];
1251 1251          char                    *cfg_ptr, *tmpPtr;
1252 1252          char                    *logical_apid = NULL;
1253 1253  
1254 1254          status = HBA_LoadLibrary();
1255 1255          if (status != HBA_STATUS_OK) {
1256      -            cfga_err(errstring, 0, ERR_HBA_LOAD_LIBRARY, 0);
1257      -            return (FPCFGA_LIB_ERR);
     1256 +                cfga_err(errstring, 0, ERR_HBA_LOAD_LIBRARY, 0);
     1257 +                return (FPCFGA_LIB_ERR);
1258 1258          }
1259 1259          count = HBA_GetNumberOfAdapters();
1260 1260          if (count == 0) {
1261      -            cfga_err(errstring, 0, ERR_NO_ADAPTER_FOUND, 0);
1262      -            HBA_FreeLibrary();
1263      -            return (FPCFGA_LIB_ERR);
     1261 +                cfga_err(errstring, 0, ERR_NO_ADAPTER_FOUND, 0);
     1262 +                HBA_FreeLibrary();
     1263 +                return (FPCFGA_LIB_ERR);
1264 1264          }
1265 1265  
1266 1266          /* Loop over all HBAs */
1267 1267          for (adapterIndex = 0; adapterIndex < count; adapterIndex ++) {
1268      -            status = HBA_GetAdapterName(adapterIndex, (char *)&adapterName);
1269      -            if (status != HBA_STATUS_OK) {
1270      -                /* May have been DR'd */
1271      -                continue;
1272      -            }
1273      -            handle = HBA_OpenAdapter(adapterName);
1274      -            if (handle == 0) {
1275      -                /* May have been DR'd */
1276      -                continue;
1277      -            }
1278      -
1279      -            do {
1280      -                if (getAdapterAttrs(handle, &hbaAttrs)) {
1281      -                /* Should never happen */
1282      -                    HBA_CloseAdapter(handle);
1283      -                    continue;
     1268 +                status = HBA_GetAdapterName(adapterIndex, (char *)&adapterName);
     1269 +                if (status != HBA_STATUS_OK) {
     1270 +                        /* May have been DR'd */
     1271 +                        continue;
1284 1272                  }
     1273 +                handle = HBA_OpenAdapter(adapterName);
     1274 +                if (handle == 0) {
     1275 +                        /* May have been DR'd */
     1276 +                        continue;
     1277 +                }
1285 1278  
1286      -                /* Loop over all HBA Ports */
1287      -                for (portIndex = 0;
1288      -                    portIndex < hbaAttrs.NumberOfPorts; portIndex++) {
1289      -                    if ((status = getAdapterPortAttrs(handle, portIndex,
1290      -                        &portAttrs)) != HBA_STATUS_OK) {
1291      -                        /* Need to refresh adapter */
1292      -                        if (status == HBA_STATUS_ERROR_STALE_DATA) {
1293      -                            HBA_RefreshInformation(handle);
1294      -                            break;
1295      -                        } else {
1296      -                            continue;
     1279 +                do {
     1280 +                        if (getAdapterAttrs(handle, &hbaAttrs)) {
     1281 +                                /* Should never happen */
     1282 +                                HBA_CloseAdapter(handle);
     1283 +                                continue;
1297 1284                          }
1298      -                    }
1299 1285  
1300      -                        /*
1301      -                         * check to see if OSDeviceName is a /dev/cfg link
1302      -                         * or the physical path
1303      -                         */
1304      -                    if (strncmp(portAttrs.OSDeviceName, CFGA_DEV_DIR,
1305      -                        strlen(CFGA_DEV_DIR)) != 0) {
1306      -                        tmpPtr = strstr(portAttrs.OSDeviceName, MINOR_SEP);
1307      -                        if (tmpPtr != NULL) {
1308      -                                if (strncmp(portPath,
     1286 +                        /* Loop over all HBA Ports */
     1287 +                        for (portIndex = 0;
     1288 +                            portIndex < hbaAttrs.NumberOfPorts; portIndex++) {
     1289 +                                if ((status = getAdapterPortAttrs(handle,
     1290 +                                    portIndex,
     1291 +                                    &portAttrs)) != HBA_STATUS_OK) {
     1292 +                                        /* Need to refresh adapter */
     1293 +                                        if (status ==
     1294 +                                            HBA_STATUS_ERROR_STALE_DATA) {
     1295 +                                                HBA_RefreshInformation(handle);
     1296 +                                                break;
     1297 +                                        } else {
     1298 +                                                continue;
     1299 +                                        }
     1300 +                                }
     1301 +
     1302 +                                /*
     1303 +                                 * check to see if OSDeviceName is a /dev/cfg
     1304 +                                 * link or the physical path
     1305 +                                 */
     1306 +                                if (strncmp(portAttrs.OSDeviceName,
     1307 +                                    CFGA_DEV_DIR,
     1308 +                                    strlen(CFGA_DEV_DIR)) != 0) {
     1309 +                                        tmpPtr = strstr(portAttrs.OSDeviceName,
     1310 +                                            MINOR_SEP);
     1311 +                                        if ((tmpPtr != NULL) &&
     1312 +                                            strncmp(portPath,
1309 1313                                              portAttrs.OSDeviceName,
1310 1314                                              strlen(portAttrs.OSDeviceName) -
1311 1315                                              strlen(tmpPtr)) == 0) {
1312      -                                        if (matchingHandle)
1313      -                                                *matchingHandle = handle;
1314      -                                        if (matchingPortIndex)
1315      -                                                *matchingPortIndex = portIndex;
1316      -                                        if (matchingPortAttrs)
1317      -                                                *matchingPortAttrs = portAttrs;
1318      -                                        return (FPCFGA_OK);
     1316 +                                                if (matchingHandle)
     1317 +                                                        *matchingHandle =
     1318 +                                                            handle;
     1319 +                                                if (matchingPortIndex)
     1320 +                                                        *matchingPortIndex =
     1321 +                                                            portIndex;
     1322 +                                                if (matchingPortAttrs)
     1323 +                                                        *matchingPortAttrs =
     1324 +                                                            portAttrs;
     1325 +                                                return (FPCFGA_OK);
     1326 +                                        }
     1327 +                                } else {
     1328 +                                        /*
     1329 +                                         * strip off the /dev/cfg/ portion of
     1330 +                                         * the OSDeviceName make sure that the
     1331 +                                         * OSDeviceName is at least
     1332 +                                         * strlen("/dev/cfg") + 1 + 1 long.
     1333 +                                         * first 1 is for the / after /dev/cfg
     1334 +                                         * second 1 is to make sure there is
     1335 +                                         * somthing after
     1336 +                                         */
     1337 +                                        if (strlen(portAttrs.OSDeviceName) <
     1338 +                                            (strlen(CFGA_DEV_DIR) + 1 + 1))
     1339 +                                                continue;
     1340 +                                        cfg_ptr = portAttrs.OSDeviceName +
     1341 +                                            strlen(CFGA_DEV_DIR) + 1;
     1342 +                                        if (logical_apid == NULL) {
     1343 +                                                /*
     1344 +                                                 * get the /dev/cfg link from
     1345 +                                                 * the portPath
     1346 +                                                 */
     1347 +                                                if (make_xport_logid(portPath,
     1348 +                                                    &logical_apid,
     1349 +                                                    &l_errno) != FPCFGA_OK) {
     1350 +                                                        cfga_err(errstring,
     1351 +                                                            l_errno,
     1352 +                                                            ERR_LIST, 0);
     1353 +                                                        HBA_FreeLibrary();
     1354 +                                                        return
     1355 +                                                            (FPCFGA_LIB_ERR);
     1356 +                                                }
     1357 +                                        }
     1358 +                                        /* compare logical ap_id */
     1359 +                                        if (strcmp(logical_apid,
     1360 +                                            cfg_ptr) == 0) {
     1361 +                                                if (matchingHandle)
     1362 +                                                        *matchingHandle =
     1363 +                                                            handle;
     1364 +                                                if (matchingPortIndex)
     1365 +                                                        *matchingPortIndex =
     1366 +                                                            portIndex;
     1367 +                                                if (matchingPortAttrs)
     1368 +                                                        *matchingPortAttrs =
     1369 +                                                            portAttrs;
     1370 +                                                S_FREE(logical_apid);
     1371 +                                                return (FPCFGA_OK);
     1372 +                                        }
1319 1373                                  }
1320 1374                          }
1321      -                    } else {
1322      -                        /*
1323      -                         * strip off the /dev/cfg/ portion of the
1324      -                         * OSDeviceName
1325      -                         * make sure that the OSDeviceName is at least
1326      -                         * strlen("/dev/cfg") + 1 + 1 long.
1327      -                         *      first 1 is for the / after /dev/cfg
1328      -                         *      second 1 is to make sure there is somthing
1329      -                         *      after
1330      -                         */
1331      -                        if (strlen(portAttrs.OSDeviceName) <
1332      -                            (strlen(CFGA_DEV_DIR) + 1 + 1))
1333      -                                continue;
1334      -                        cfg_ptr = portAttrs.OSDeviceName +
1335      -                            strlen(CFGA_DEV_DIR) + 1;
1336      -                        if (logical_apid == NULL) {
1337      -                                /* get the /dev/cfg link from the portPath */
1338      -                                if (make_xport_logid(portPath, &logical_apid,
1339      -                                            &l_errno) != FPCFGA_OK) {
1340      -                                        cfga_err(errstring, l_errno,
1341      -                                            ERR_LIST, 0);
1342      -                                        HBA_FreeLibrary();
1343      -                                        return (FPCFGA_LIB_ERR);
1344      -                                }
1345      -                        }
1346      -                        /* compare logical ap_id */
1347      -                        if (strcmp(logical_apid, cfg_ptr) == 0) {
1348      -                                if (matchingHandle)
1349      -                                        *matchingHandle = handle;
1350      -                                if (matchingPortIndex)
1351      -                                        *matchingPortIndex = portIndex;
1352      -                                if (matchingPortAttrs)
1353      -                                        *matchingPortAttrs = portAttrs;
     1375 +                        if (logical_apid != NULL)
1354 1376                                  S_FREE(logical_apid);
1355      -                                return (FPCFGA_OK);
1356      -                        }
1357      -                    }
1358      -                }
1359      -                if (logical_apid != NULL)
1360      -                        S_FREE(logical_apid);
1361      -            } while ((status == HBA_STATUS_ERROR_STALE_DATA) &&
1362      -                (retry++ < HBA_MAX_RETRIES));
     1377 +                } while ((status == HBA_STATUS_ERROR_STALE_DATA) &&
     1378 +                    (retry++ < HBA_MAX_RETRIES));
1363 1379  
1364      -            HBA_CloseAdapter(handle);
     1380 +                HBA_CloseAdapter(handle);
1365 1381          }
1366 1382          free(logical_apid);
1367 1383  
1368      -        /* Got here. No mathcing adatper port found. */
     1384 +        /* Got here. No matching adapter port found. */
1369 1385          cfga_err(errstring, 0, ERR_MATCHING_HBA_PORT, 0);
1370 1386          HBA_FreeLibrary();
1371 1387          return (FPCFGA_LIB_ERR);
1372 1388  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX