fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
a79493184c9332129c9c91500069322f6f3fafddReed * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned char *pc = (unsigned char *)&(wwn->wwn[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize scf stmf service access
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle - returned handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * service - returned service handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortecfgInit(scf_handle_t **handle, scf_service_t **service)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*handle = scf_handle_create(SCF_VERSION)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*service = scf_service_create(*handle)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((scope = scf_scope_create(*handle)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_handle_get_scope(*handle, SCF_SCOPE_LOCAL, scope) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_scope_get_service(scope, NPIV_SERVICE, *service) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* log error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(memberName, "%s:%s:%s:%d", ppwwn, vpwwn, vnwwn, vindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tran = scf_transaction_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((prop = scf_property_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((valueIter = scf_iter_create(handle)) == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get property group or create it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_service_get_pg(svc, NPIV_PG_NAME, pg) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Begin the transaction */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte valueSet = (scf_value_t **)calloc(1, sizeof (*valueSet)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_transaction_property_new(tran, entry, NPIV_PORT_LIST,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "transaction property new failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "transaction property change failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_pg_get_property(pg, NPIV_PORT_LIST, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(buf, memberName, strlen(memberName)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_set_ustring(valueSet[i], buf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now create the new entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set the new member name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_set_ustring(valueSet[i], memberName) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add the new member
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_entry_add_value(entry, valueSet[i]) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((commitRet = scf_transaction_commit(tran)) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "transaction commit failed - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free valueSet scf resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < valueArraySize; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now free the pointer array to the resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteretrieveNPIVAttrs(HBA_HANDLE handle, HBA_WWN portWWN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte HBA_PORTNPIVATTRIBUTES *npivattrs, HBA_UINT32 *portIndex) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* argument checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&attrs, 0, sizeof (HBA_ADAPTERATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = HBA_GetAdapterAttributes(handle, &attrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset(&portattrs, 0, sizeof (HBA_PORTATTRIBUTES));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (portCtr = 0; portCtr < attrs.NumberOfPorts; portCtr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_GetPortNPIVAttributes(handle, portCtr, npivattrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefc_util_delete_npivport(int wwnCount, char **wwn_argv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[0], "%016llx", &physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveNPIVAttrs(handle, portWWN, &npivattrs, &portIndex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delete a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_DeleteNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_DeleteNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to delete a npiv port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to get port NPIV attributes\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t physicalportWWN, virtualnodeWWN, virtualportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(options->optarg, "%016llx", &virtualnodeWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = HBA_LoadLibrary()) != HBA_STATUS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Failed to load FC-HBA common library\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(wwn_argv[0], "%016llx", &physicalportWWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &vnodeWWN, &vportWWN, NULL, HBA_CREATE_WWN_RANDOM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vnodeWWN.wwn, &virtualnodeWWN, sizeof (virtualnodeWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp(vnodeWWN.wwn, vportWWN.wwn, 8) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Port WWN is same as Node WWN\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retrieveNPIVAttrs(handle, portWWN, &npivattrs, &portIndex) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: Can not create more NPIV port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to create a npiv port\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("Error: failed to get port NPIV attributes\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t physicalportWWN, virtualnodeWWN, virtualportWWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(portWWN.wwn, &physicalportWWN, sizeof (physicalportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vnodeWWN.wwn, &virtualnodeWWN, sizeof (virtualnodeWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memcpy(vportWWN.wwn, &virtualportWWN, sizeof (virtualportWWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get physical port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check port NPIV attributes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create a virtual port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = Sun_HBA_CreateNPIVPort(handle, portIndex,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tran = scf_transaction_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((prop = scf_property_create(handle)) == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((valueIter = scf_iter_create(handle)) == NULL)) {
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_pg_get_property(pg, NPIV_PORT_LIST, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_iter_property_values(valueIter, prop) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (scf_iter_next_value(valueIter, valueLookup) == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scf_value_get_ustring(valueLookup, buf, MAXNAMELEN) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sscanf(buf, "%16s:%16s:%16s:%d", ppwwn, vpwwn, vnwwn, &vindex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free resources
a79493184c9332129c9c91500069322f6f3fafddReed/* ARGSUSED */
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, gettext("Failed to load FC-HBA library\n"));
a79493184c9332129c9c91500069322f6f3fafddReed return (1);
a79493184c9332129c9c91500069322f6f3fafddReed * Try target mode first
a79493184c9332129c9c91500069322f6f3fafddReed if ((status = Sun_HBA_OpenTgtAdapterByWWN(&handle, myWWN)) !=
a79493184c9332129c9c91500069322f6f3fafddReed * Continue to try initiator mode
a79493184c9332129c9c91500069322f6f3fafddReed return (0);
a79493184c9332129c9c91500069322f6f3fafddReed fprintf(stderr, gettext("Error: Failed to reinitialize the "
a79493184c9332129c9c91500069322f6f3fafddReed return (0);