fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "HBAPort.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Exceptions.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "Trace.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <iostream>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <iomanip>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <cerrno>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <cstring>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stropts.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <dirent.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libdevinfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusing namespace std;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Standard definition for general topology lookup (See T11 FC-FS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst int HBAPort::RNID_GENERAL_TOPOLOGY_DATA_FORMAT = 0xDF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconst uint8_t HBAPort::HBA_NPIV_PORT_MAX = UCHAR_MAX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @memo Construct a new deafult HBA Port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBAPort::HBAPort() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc Comparison is based on Node WWN, Port WWN and path
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebool HBAPort::operator==(HBAPort &comp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (this->getPortWWN() == comp.getPortWWN() &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->getNodeWWN() == comp.getNodeWWN() &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this->getPath() == comp.getPath());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
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 *
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid HBAPort::validatePresent() {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("HBAPort::validatePresent");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string path = getPath();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(path.c_str(), &sbuf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno == ENOENT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw UnavailableException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.debug("Unable to stat %s: %s", path.c_str(),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * structure for di_devlink_walk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct walk_devlink {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **linkpp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} walk_devlink_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * @doc The input path is expected to not have "/devices".
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_devlink(di_devlink_t devlink, void *arg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("get_devlink");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte walk_devlink_t *warg = (walk_devlink_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When path is specified, it doesn't have minor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * name. Therefore, the ../.. prefixes needs to be stripped.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (warg->path) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // di_devlink_content contains /devices
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *content = (char *)di_devlink_content(devlink);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *start = strstr(content, "/devices");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(start, warg->path, warg->len) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // make it sure the device path has minor name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start[warg->len] != ':')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DI_WALK_CONTINUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(warg->linkpp) = strdup(di_devlink_path(devlink));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (DI_WALK_TERMINATE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/**
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 *
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 Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid HBAPort::convertToShortNames(PHBA_FCPTARGETMAPPINGV2 mappings) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("HBAPort::convertToShortNames");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devlink_handle_t hdl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte walk_devlink_t warg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *minor_path, *devlinkp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hdl = di_devlink_init(NULL, 0)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log.internalError("di_devlink_init failed. Errno:%d", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // no need to check further, just return here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 if (strstr(minor_path, "/devices") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = mappings->entry[j].ScsiId.OSDeviceName +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen("/devices");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = mappings->entry[j].ScsiId.OSDeviceName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.path = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor_path = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(mappings->entry[j].ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "/devices") != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.len = strlen (mappings->entry[j].ScsiId.OSDeviceName) -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen ("/devices");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.path = mappings->entry[j].ScsiId.OSDeviceName +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen ("/devices");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.len = strlen(mappings->entry[j].ScsiId.OSDeviceName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.path = mappings->entry[j].ScsiId.OSDeviceName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devlinkp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warg.linkpp = &devlinkp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) di_devlink_walk(hdl, NULL, minor_path, DI_PRIMARY_LINK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)&warg, get_devlink);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devlinkp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte snprintf(mappings->entry[j].ScsiId.OSDeviceName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (mappings->entry[j].ScsiId.OSDeviceName),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s", devlinkp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(devlinkp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } // else leave OSDeviceName alone.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte di_devlink_fini(&hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Finds controller path for a give device path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return vale: controller path.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring HBAPort::lookupControllerPath(string path) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("lookupControllerPath");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DIR *dp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char node[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct dirent **dirpp, *dirp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char dir[] = "/dev/cfg";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssize_t count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *dir_buf = new uchar_t[sizeof (struct dirent) + MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dp = opendir(dir)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string tmp = "Unable to open ";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp += dir;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp += "to find controller number.";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (dir_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IOError(tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirp = (struct dirent *) dir_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dirpp = &dirp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((readdir_r(dp, dirp, dirpp)) == 0 && dirp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(dirp->d_name, ".") == 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(dirp->d_name, "..") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(node, "%s/%s", dir, dirp->d_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((count = readlink(node,buf,sizeof(buf)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[count] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strstr(buf, path.c_str())) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte string cfg_path = dir;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_path += "/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_path += dirp->d_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte closedir(dp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (dir_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cfg_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte closedir(dp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delete (dir_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError("Unable to find controller path");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid HBAPort::addPort(HBANPIVPort *port) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("HBAPort::addPort");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // support hba with up to UCHAR_MAX number of ports.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivportsByIndex.size() + 1 > HBA_NPIV_PORT_MAX) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw InternalError("HBA NPIV Port count exceeds max number of ports");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivportsByWWN[port->getPortWWN()] = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivportsByIndex.insert(npivportsByIndex.end(), port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBANPIVPort* HBAPort::getPort(uint64_t wwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("HBAPort::getPort");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBANPIVPort *port = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivportsByWWN.find(wwn) == npivportsByWWN.end()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IllegalWWNException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port = npivportsByWWN[wwn];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteHBANPIVPort* HBAPort::getPortByIndex(int index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Trace log("HBAPort::getPortByIndex");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= npivportsByIndex.size() || index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw IllegalIndexException();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBANPIVPort *tmp = npivportsByIndex[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } catch (...) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte throw;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte