2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A
2N/A#include "HBANPIVPort.h"
2N/A#include "Exceptions.h"
2N/A#include "Trace.h"
2N/A#include <iostream>
2N/A#include <iomanip>
2N/A#include <cerrno>
2N/A#include <cstring>
2N/A#include <sys/types.h>
2N/A#include <sys/mkdev.h>
2N/A#include <sys/stat.h>
2N/A#include <fcntl.h>
2N/A#include <unistd.h>
2N/A#include <stropts.h>
2N/A#include <dirent.h>
2N/A#include <libdevinfo.h>
2N/A
2N/Ausing namespace std;
2N/A
2N/A
2N/A/**
2N/A * @memo Construct a new deafult HBA Port
2N/A * @version 1.7
2N/A */
2N/AHBANPIVPort::HBANPIVPort() {
2N/A}
2N/A
2N/A/**
2N/A * @memo Compare two HBA ports for equality
2N/A * @return TRUE if both ports are the same
2N/A * @return FALSE if the ports are different
2N/A * @version 1.7
2N/A *
2N/A * @doc Comparison is based on Node WWN, Port WWN and path
2N/A */
2N/Abool HBANPIVPort::operator==(HBANPIVPort &comp) {
2N/A return (this->getPortWWN() == comp.getPortWWN() &&
2N/A this->getNodeWWN() == comp.getNodeWWN());
2N/A}
2N/A
2N/A/*
2N/A * Finds controller path for a give device path.
2N/A *
2N/A * Return vale: controller path.
2N/A */
2N/Astring HBANPIVPort::lookupControllerPath(string path) {
2N/A Trace log("lookupControllerPath");
2N/A DIR *dp;
2N/A char buf[MAXPATHLEN];
2N/A char node[MAXPATHLEN];
2N/A struct dirent **dirpp, *dirp;
2N/A const char dir[] = "/dev/cfg";
2N/A ssize_t count;
2N/A uchar_t *dir_buf = new uchar_t[sizeof (struct dirent) + MAXPATHLEN];
2N/A
2N/A if ((dp = opendir(dir)) == NULL) {
2N/A string tmp = "Unable to open ";
2N/A tmp += dir;
2N/A tmp += "to find controller number.";
2N/A delete (dir_buf);
2N/A throw IOError(tmp);
2N/A }
2N/A
2N/A dirp = (struct dirent *) dir_buf;
2N/A dirpp = &dirp;
2N/A while ((readdir_r(dp, dirp, dirpp)) == 0 && dirp != NULL) {
2N/A if (strcmp(dirp->d_name, ".") == 0 ||
2N/A strcmp(dirp->d_name, "..") == 0) {
2N/A continue;
2N/A }
2N/A sprintf(node, "%s/%s", dir, dirp->d_name);
2N/A if ((count = readlink(node,buf,sizeof(buf)))) {
2N/A buf[count] = '\0';
2N/A if (strstr(buf, path.c_str())) {
2N/A string cfg_path = dir;
2N/A cfg_path += "/";
2N/A cfg_path += dirp->d_name;
2N/A closedir(dp);
2N/A delete (dir_buf);
2N/A return (cfg_path);
2N/A }
2N/A }
2N/A }
2N/A
2N/A closedir(dp);
2N/A delete (dir_buf);
2N/A throw InternalError("Unable to find controller path");
2N/A}
2N/A