fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusing namespace std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Standard definition for general topology lookup (See T11 FC-FS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst int HBAPort::RNID_GENERAL_TOPOLOGY_DATA_FORMAT = 0xDF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst uint8_t HBAPort::HBA_NPIV_PORT_MAX = UCHAR_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Construct a new deafult HBA Port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Compare two HBA ports for equality
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return TRUE if both ports are the same
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @return FALSE if the ports are different
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc Comparison is based on Node WWN, Port WWN and path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (this->getPortWWN() == comp.getPortWWN() &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Validate that the port is still present in the system
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @exception UnavailableException if the port is not present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc If the port is still present on the system, the routine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will return normally. If the port is not present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an exception will be thrown.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * structure for di_devlink_walk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo callback funtion for di_devlink_walk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition Find matching /dev link for the given path argument.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param devlink element and callback function argument.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc The input path is expected to not have "/devices".
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When path is specified, it doesn't have minor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * name. Therefore, the ../.. prefixes needs to be stripped.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // di_devlink_content contains /devices
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *content = (char *)di_devlink_content(devlink);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // make it sure the device path has minor name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(warg->linkpp) = strdup(di_devlink_path(devlink));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Convert /devices paths to /dev sym-link paths.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @postcondition The mapping buffer OSDeviceName paths will be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * converted to short names.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @param mappings The target mappings data to convert to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * short names
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc If no link
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is found, the long path is left as is.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Note: The NumberOfEntries field MUST not be greater than the size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the array passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid HBAPort::convertToShortNames(PHBA_FCPTARGETMAPPINGV2 mappings) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("di_devlink_init failed. Errno:%d", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // no need to check further, just return here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (int j = 0; j < mappings->NumberOfEntries; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strchr(mappings->entry[j].ScsiId.OSDeviceName, ':')) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // search link for minor node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = mappings->entry[j].ScsiId.OSDeviceName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = mappings->entry[j].ScsiId.OSDeviceName +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = mappings->entry[j].ScsiId.OSDeviceName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(mappings->entry[j].ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.len = strlen (mappings->entry[j].ScsiId.OSDeviceName) -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.path = mappings->entry[j].ScsiId.OSDeviceName +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.len = strlen(mappings->entry[j].ScsiId.OSDeviceName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.path = mappings->entry[j].ScsiId.OSDeviceName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) di_devlink_walk(hdl, NULL, minor_path, DI_PRIMARY_LINK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } // else leave OSDeviceName alone.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Finds controller path for a give device path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return vale: controller path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring HBAPort::lookupControllerPath(string path) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *dir_buf = new uchar_t[sizeof (struct dirent) + MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((readdir_r(dp, dirp, dirpp)) == 0 && dirp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError("Unable to find controller path");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // support hba with up to UCHAR_MAX number of ports.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivportsByIndex.size() + 1 > HBA_NPIV_PORT_MAX) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError("HBA NPIV Port count exceeds max number of ports");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivportsByIndex.insert(npivportsByIndex.end(), port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivportsByWWN.find(wwn) == npivportsByWWN.end()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= npivportsByIndex.size() || index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {