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/*
a79493184c9332129c9c91500069322f6f3fafddReed * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libscf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <syslog.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcinfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FCADM_RETRY_TIMES 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FCADM_SLEEP_TIME 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteWWN2str(char *buf, HBA_WWN *wwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *pc = (unsigned char *)&(wwn->wwn[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < 16; j += 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(&buf[j], "%02X", (int)*pc++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteisValidWWN(char *wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(wwn) != 16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < 16; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isxdigit(wwn[index])) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize scf stmf service access
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - returned handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * service - returned service handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortecfgInit(scf_handle_t **handle, scf_service_t **service)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_scope_t *scope = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*handle = scf_handle_create(SCF_VERSION)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_handle_bind(*handle) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*service = scf_service_create(*handle)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((scope = scf_scope_create(*handle)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_handle_get_scope(*handle, SCF_SCOPE_LOCAL, scope) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_scope_get_service(scope, NPIV_SERVICE, *service) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_scope_destroy(scope);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NPIV_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteerr:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*handle != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_handle_destroy(*handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*service != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_service_destroy(*service);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *service = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scope != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_scope_destroy(scope);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortenpivAddRemoveNPIVEntry(char *ppwwn, char *vnwwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *vpwwn, int vindex, int addRemoveFlag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_handle_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_service_t *svc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_propertygroup_t *pg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_t *tran = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_entry_t *entry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_property_t *prop = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_t *valueLookup = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_iter_t *valueIter = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_t **valueSet = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = NPIV_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t createProp = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lastAlloc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[NPIV_PORT_LIST_LENGTH] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char memberName[NPIV_PORT_LIST_LENGTH] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t found = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int valueArraySize = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int commitRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vnwwn) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(memberName, "%s:%s:%s:%d", ppwwn, vpwwn, vnwwn, vindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(memberName, "%s:%s", ppwwn, vpwwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = cfgInit(&handle, &svc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != NPIV_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((pg = scf_pg_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tran = scf_transaction_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((entry = scf_entry_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((prop = scf_property_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((valueIter = scf_iter_create(handle)) == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get property group or create it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_service_get_pg(svc, NPIV_PG_NAME, pg) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((scf_error() == SCF_ERROR_NOT_FOUND) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (addRemoveFlag == NPIV_ADD)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_service_add_pg(svc, NPIV_PG_NAME,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SCF_GROUP_APPLICATION, 0, pg) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "add pg failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte createProp = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (scf_error() == SCF_ERROR_NOT_FOUND) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "get pg failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != NPIV_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Begin the transaction */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_transaction_start(tran, pg) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "start transaction failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueSet = (scf_value_t **)calloc(1, sizeof (*valueSet)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (lastAlloc = PORT_LIST_ALLOC));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueSet == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (createProp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_transaction_property_new(tran, entry, NPIV_PORT_LIST,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SCF_TYPE_USTRING) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_error() == SCF_ERROR_EXISTS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "transaction property new failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_transaction_property_change(tran, entry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NPIV_PORT_LIST, SCF_TYPE_USTRING) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "transaction property change failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_pg_get_property(pg, NPIV_PORT_LIST, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "get property failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueLookup = scf_value_create(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueLookup == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "scf value alloc failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "iter value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_get_ustring(valueLookup,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf, MAXNAMELEN) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "iter value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strlen(buf) >= strlen(memberName)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(buf, memberName, strlen(memberName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addRemoveFlag == NPIV_ADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueSet[i] = scf_value_create(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueSet[i] == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "scf value alloc failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_set_ustring(valueSet[i], buf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "set value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "add value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= lastAlloc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lastAlloc += PORT_LIST_ALLOC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueSet = realloc(valueSet,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (*valueSet) * lastAlloc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueSet == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueArraySize = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found && (addRemoveFlag == NPIV_REMOVE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_MEMBER_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != NPIV_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addRemoveFlag == NPIV_ADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now create the new entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueSet[i] = scf_value_create(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueSet[i] == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "scf value alloc failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueArraySize++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set the new member name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_set_ustring(valueSet[i], memberName) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "set value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add the new member
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "add value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "transaction commit failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (commitRet == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = NPIV_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_handle_destroy(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svc != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_service_destroy(svc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_pg_destroy(pg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tran != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_destroy(tran);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_entry_destroy(entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_property_destroy(prop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueIter != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_iter_destroy(valueIter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueLookup != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_destroy(valueLookup);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free valueSet scf resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueArraySize > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < valueArraySize; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_destroy(valueSet[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now free the pointer array to the resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueSet != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(valueSet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteretrieveNPIVAttrs(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES *npivattrs, HBA_UINT32 *portIndex) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_ADAPTERATTRIBUTES attrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTATTRIBUTES portattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portCtr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs == NULL || portIndex == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (HBA_ADAPTERATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < 130) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&portattrs, 0, sizeof (HBA_PORTATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portCtr = 0; portCtr < attrs.NumberOfPorts; portCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portCtr, &portattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterPortAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portCtr, &portattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(portWWN.wwn, portattrs.PortWWN.wwn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (portattrs.PortWWN.wwn)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portCtr >= attrs.NumberOfPorts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *portIndex = portCtr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(handle, portCtr, npivattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte portCtr, npivattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_delete_npivport(int wwnCount, char **wwn_argv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t physicalportWWN, virtualportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN portWWN, vportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES npivattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 portIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char pwwn[17];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnCount != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Parameter\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; options->optval; options++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (options->optval) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'p':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isValidWWN(options->optarg)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Port WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isValidWWN(wwn_argv[0])) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Physical Port WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[0], "%016llx", &physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte physicalportWWN = htonll(physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte virtualportWWN = htonll(virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, portWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveNPIVAttrs(handle, portWWN, &npivattrs, &portIndex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs.MaxNumberOfNPIVPorts == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: NPIV not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delete a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_DeleteNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_DeleteNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to delete a npiv port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to get port NPIV attributes\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWN2str(pwwn, &vportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivAddRemoveNPIVEntry(wwn_argv[0],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, pwwn, 0, NPIV_REMOVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_create_npivport(int wwnCount,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **wwn_argv, cmdOptions_t *options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t physicalportWWN, virtualnodeWWN, virtualportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN portWWN, vnodeWWN, vportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES npivattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 portIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 npivportIndex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char nwwn[17], pwwn[17];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int randomflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwnCount != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Parameter\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; options->optval; options++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (options->optval) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'p':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isValidWWN(options->optarg)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Port WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte randomflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'n':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isValidWWN(options->optarg)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Node WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte randomflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!isValidWWN(wwn_argv[0])) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Invalid Physical Port WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnCount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printStatus(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[0], "%016llx", &physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte physicalportWWN = htonll(physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, portWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: HBA port %s: not found\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn_argv[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (randomflag != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_AdapterCreateWWN(handle, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &vnodeWWN, &vportWWN, NULL, HBA_CREATE_WWN_RANDOM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Fail to get Random WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte virtualnodeWWN = htonll(virtualnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vnodeWWN.wwn, &virtualnodeWWN, sizeof (virtualnodeWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte virtualportWWN = htonll(virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(vnodeWWN.wwn, vportWWN.wwn, 8) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Port WWN is same as Node WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveNPIVAttrs(handle, portWWN, &npivattrs, &portIndex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs.MaxNumberOfNPIVPorts == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: NPIV not Supported\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs.MaxNumberOfNPIVPorts ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivattrs.NumberOfNPIVPorts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Can not create more NPIV port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vnodeWWN, vportWWN, &npivportIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times++ < HBA_MAX_RETRIES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vnodeWWN, vportWWN, &npivportIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to create a npiv port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to get port NPIV attributes\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWN2str(nwwn, &vnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte WWN2str(pwwn, &vportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivAddRemoveNPIVEntry(wwn_argv[0],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nwwn, pwwn, npivportIndex, NPIV_ADD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_npivport(char *ppwwn_str, char *vnwwn_str,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *vpwwn_str, int vindex)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t physicalportWWN, virtualnodeWWN, virtualportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_WWN portWWN, vnodeWWN, vportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_STATUS status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_HANDLE handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES npivattrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 portIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_UINT32 npivportIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(ppwwn_str, "%016llx", &physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte physicalportWWN = htonll(physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(vnwwn_str, "%016llx", &virtualnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte virtualnodeWWN = htonll(virtualnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vnodeWWN.wwn, &virtualnodeWWN, sizeof (virtualnodeWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(vpwwn_str, "%016llx", &virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte virtualportWWN = htonll(virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivportIndex = vindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, portWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(FCADM_SLEEP_TIME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_OpenAdapterByWWN(&handle, portWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > FCADM_RETRY_TIMES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveNPIVAttrs(handle, portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &npivattrs, &portIndex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs.MaxNumberOfNPIVPorts == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (npivattrs.MaxNumberOfNPIVPorts ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte npivattrs.NumberOfNPIVPorts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vnodeWWN, vportWWN, &npivportIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte times = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status == HBA_STATUS_ERROR_TRY_AGAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status == HBA_STATUS_ERROR_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sleep(FCADM_SLEEP_TIME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vnodeWWN, vportWWN, &npivportIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (times++ > FCADM_RETRY_TIMES) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_CloseAdapter(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_create_portlist()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_handle_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_service_t *svc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_propertygroup_t *pg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_t *tran = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_entry_t *entry = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_property_t *prop = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_t *valueLookup = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_iter_t *valueIter = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[NPIV_PORT_LIST_LENGTH] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int commitRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte commitRet = cfgInit(&handle, &svc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (commitRet != NPIV_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((pg = scf_pg_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tran = scf_transaction_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((entry = scf_entry_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((prop = scf_property_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((valueIter = scf_iter_create(handle)) == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get property group or create it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_service_get_pg(svc, NPIV_PG_NAME, pg) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_pg_get_property(pg, NPIV_PORT_LIST, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "get property failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueLookup = scf_value_create(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueLookup == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "scf value alloc failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "iter value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (HBA_LoadLibrary() != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_GetNumberOfAdapters();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char ppwwn[17] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char vnwwn[17] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char vpwwn[17] = {0};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vindex = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "iter value failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_strerror(scf_error()));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(buf, "%16s:%16s:%16s:%d", ppwwn, vpwwn, vnwwn, &vindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte create_npivport(ppwwn, vnwwn, vpwwn, vindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_FreeLibrary();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_handle_destroy(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svc != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_service_destroy(svc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_pg_destroy(pg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tran != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_transaction_destroy(tran);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_entry_destroy(entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prop != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_property_destroy(prop);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueIter != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_iter_destroy(valueIter);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (valueLookup != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scf_value_destroy(valueLookup);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed/* ARGSUSED */
a79493184c9332129c9c91500069322f6f3fafddReedint
a79493184c9332129c9c91500069322f6f3fafddReedfc_util_force_lip(int objects, char *argv[])
a79493184c9332129c9c91500069322f6f3fafddReed{
a79493184c9332129c9c91500069322f6f3fafddReed uint64_t hbaWWN;
a79493184c9332129c9c91500069322f6f3fafddReed HBA_WWN myWWN;
a79493184c9332129c9c91500069322f6f3fafddReed HBA_HANDLE handle;
a79493184c9332129c9c91500069322f6f3fafddReed HBA_STATUS status;
a79493184c9332129c9c91500069322f6f3fafddReed int rval = 0;
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, gettext("Failed to load FC-HBA library\n"));
a79493184c9332129c9c91500069322f6f3fafddReed printStatus(status);
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, "\n");
a79493184c9332129c9c91500069322f6f3fafddReed return (1);
a79493184c9332129c9c91500069322f6f3fafddReed }
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed sscanf(argv[0], "%016llx", &hbaWWN);
a79493184c9332129c9c91500069322f6f3fafddReed hbaWWN = htonll(hbaWWN);
a79493184c9332129c9c91500069322f6f3fafddReed memcpy(myWWN.wwn, &hbaWWN, sizeof (hbaWWN));
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed /*
a79493184c9332129c9c91500069322f6f3fafddReed * Try target mode first
a79493184c9332129c9c91500069322f6f3fafddReed */
a79493184c9332129c9c91500069322f6f3fafddReed if ((status = Sun_HBA_OpenTgtAdapterByWWN(&handle, myWWN)) !=
a79493184c9332129c9c91500069322f6f3fafddReed HBA_STATUS_OK) {
a79493184c9332129c9c91500069322f6f3fafddReed /*
a79493184c9332129c9c91500069322f6f3fafddReed * Continue to try initiator mode
a79493184c9332129c9c91500069322f6f3fafddReed */
a79493184c9332129c9c91500069322f6f3fafddReed if ((status = HBA_OpenAdapterByWWN(&handle, myWWN)) !=
a79493184c9332129c9c91500069322f6f3fafddReed HBA_STATUS_OK) {
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, gettext("Error: HBA %s not found\n"),
a79493184c9332129c9c91500069322f6f3fafddReed argv[0]);
a79493184c9332129c9c91500069322f6f3fafddReed return (0);
a79493184c9332129c9c91500069322f6f3fafddReed }
a79493184c9332129c9c91500069322f6f3fafddReed }
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed status = Sun_HBA_ForceLip(handle, &rval);
a79493184c9332129c9c91500069322f6f3fafddReed if ((status != HBA_STATUS_OK) || (rval != 0)) {
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, gettext("Error: Failed to reinitialize the "
a79493184c9332129c9c91500069322f6f3fafddReed "link of HBA %s\n"), argv[0]);
a79493184c9332129c9c91500069322f6f3fafddReed }
a79493184c9332129c9c91500069322f6f3fafddReed
a79493184c9332129c9c91500069322f6f3fafddReed return (0);
a79493184c9332129c9c91500069322f6f3fafddReed}