4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
36 #define FCADM_RETRY_TIMES 10
37 #define FCADM_SLEEP_TIME 1
40 WWN2str(char *buf
, HBA_WWN
*wwn
) {
42 unsigned char *pc
= (unsigned char *)&(wwn
->wwn
[0]);
44 for (j
= 0; j
< 16; j
+= 2) {
45 sprintf(&buf
[j
], "%02X", (int)*pc
++);
59 if (strlen(wwn
) != 16) {
63 for (index
= 0; index
< 16; index
++) {
64 if (isxdigit(wwn
[index
])) {
74 * Initialize scf stmf service access
75 * handle - returned handle
76 * service - returned service handle
79 cfgInit(scf_handle_t
**handle
, scf_service_t
**service
)
81 scf_scope_t
*scope
= NULL
;
84 if ((*handle
= scf_handle_create(SCF_VERSION
)) == NULL
) {
90 if (scf_handle_bind(*handle
) == -1) {
96 if ((*service
= scf_service_create(*handle
)) == NULL
) {
102 if ((scope
= scf_scope_create(*handle
)) == NULL
) {
108 if (scf_handle_get_scope(*handle
, SCF_SCOPE_LOCAL
, scope
) == -1) {
114 if (scf_scope_get_service(scope
, NPIV_SERVICE
, *service
) == -1) {
116 ret
= NPIV_ERROR_SERVICE_NOT_FOUND
;
120 scf_scope_destroy(scope
);
122 return (NPIV_SUCCESS
);
125 if (*handle
!= NULL
) {
126 scf_handle_destroy(*handle
);
128 if (*service
!= NULL
) {
129 scf_service_destroy(*service
);
133 scf_scope_destroy(scope
);
139 npivAddRemoveNPIVEntry(char *ppwwn
, char *vnwwn
,
140 char *vpwwn
, int vindex
, int addRemoveFlag
) {
141 scf_handle_t
*handle
= NULL
;
142 scf_service_t
*svc
= NULL
;
143 scf_propertygroup_t
*pg
= NULL
;
144 scf_transaction_t
*tran
= NULL
;
145 scf_transaction_entry_t
*entry
= NULL
;
146 scf_property_t
*prop
= NULL
;
147 scf_value_t
*valueLookup
= NULL
;
148 scf_iter_t
*valueIter
= NULL
;
149 scf_value_t
**valueSet
= NULL
;
150 int ret
= NPIV_SUCCESS
;
151 boolean_t createProp
= B_FALSE
;
153 char buf
[NPIV_PORT_LIST_LENGTH
] = {0};
154 char memberName
[NPIV_PORT_LIST_LENGTH
] = {0};
155 boolean_t found
= B_FALSE
;
157 int valueArraySize
= 0;
161 sprintf(memberName
, "%s:%s:%s:%d", ppwwn
, vpwwn
, vnwwn
, vindex
);
163 sprintf(memberName
, "%s:%s", ppwwn
, vpwwn
);
166 ret
= cfgInit(&handle
, &svc
);
167 if (ret
!= NPIV_SUCCESS
) {
171 if (((pg
= scf_pg_create(handle
)) == NULL
) ||
172 ((tran
= scf_transaction_create(handle
)) == NULL
) ||
173 ((entry
= scf_entry_create(handle
)) == NULL
) ||
174 ((prop
= scf_property_create(handle
)) == NULL
) ||
175 ((valueIter
= scf_iter_create(handle
)) == NULL
)) {
180 /* get property group or create it */
181 if (scf_service_get_pg(svc
, NPIV_PG_NAME
, pg
) == -1) {
182 if ((scf_error() == SCF_ERROR_NOT_FOUND
) &&
183 (addRemoveFlag
== NPIV_ADD
)) {
184 if (scf_service_add_pg(svc
, NPIV_PG_NAME
,
185 SCF_GROUP_APPLICATION
, 0, pg
) == -1) {
186 syslog(LOG_ERR
, "add pg failed - %s",
187 scf_strerror(scf_error()));
192 } else if (scf_error() == SCF_ERROR_NOT_FOUND
) {
193 ret
= NPIV_ERROR_NOT_FOUND
;
195 syslog(LOG_ERR
, "get pg failed - %s",
196 scf_strerror(scf_error()));
199 if (ret
!= NPIV_SUCCESS
) {
204 /* Begin the transaction */
205 if (scf_transaction_start(tran
, pg
) == -1) {
206 syslog(LOG_ERR
, "start transaction failed - %s",
207 scf_strerror(scf_error()));
212 valueSet
= (scf_value_t
**)calloc(1, sizeof (*valueSet
)
213 * (lastAlloc
= PORT_LIST_ALLOC
));
214 if (valueSet
== NULL
) {
215 ret
= NPIV_ERROR_NOMEM
;
220 if (scf_transaction_property_new(tran
, entry
, NPIV_PORT_LIST
,
221 SCF_TYPE_USTRING
) == -1) {
222 if (scf_error() == SCF_ERROR_EXISTS
) {
223 ret
= NPIV_ERROR_EXISTS
;
226 "transaction property new failed - %s",
227 scf_strerror(scf_error()));
233 if (scf_transaction_property_change(tran
, entry
,
234 NPIV_PORT_LIST
, SCF_TYPE_USTRING
) == -1) {
236 "transaction property change failed - %s",
237 scf_strerror(scf_error()));
242 if (scf_pg_get_property(pg
, NPIV_PORT_LIST
, prop
) == -1) {
243 syslog(LOG_ERR
, "get property failed - %s",
244 scf_strerror(scf_error()));
249 valueLookup
= scf_value_create(handle
);
250 if (valueLookup
== NULL
) {
251 syslog(LOG_ERR
, "scf value alloc failed - %s",
252 scf_strerror(scf_error()));
257 if (scf_iter_property_values(valueIter
, prop
) == -1) {
258 syslog(LOG_ERR
, "iter value failed - %s",
259 scf_strerror(scf_error()));
264 while (scf_iter_next_value(valueIter
, valueLookup
) == 1) {
265 bzero(buf
, sizeof (buf
));
266 if (scf_value_get_ustring(valueLookup
,
267 buf
, MAXNAMELEN
) == -1) {
268 syslog(LOG_ERR
, "iter value failed - %s",
269 scf_strerror(scf_error()));
274 if ((strlen(buf
) >= strlen(memberName
)) &&
275 bcmp(buf
, memberName
, strlen(memberName
)) == 0) {
276 if (addRemoveFlag
== NPIV_ADD
) {
277 ret
= NPIV_ERROR_EXISTS
;
285 valueSet
[i
] = scf_value_create(handle
);
286 if (valueSet
[i
] == NULL
) {
287 syslog(LOG_ERR
, "scf value alloc failed - %s",
288 scf_strerror(scf_error()));
293 if (scf_value_set_ustring(valueSet
[i
], buf
) == -1) {
294 syslog(LOG_ERR
, "set value failed - %s",
295 scf_strerror(scf_error()));
300 if (scf_entry_add_value(entry
, valueSet
[i
]) == -1) {
301 syslog(LOG_ERR
, "add value failed - %s",
302 scf_strerror(scf_error()));
309 if (i
>= lastAlloc
) {
310 lastAlloc
+= PORT_LIST_ALLOC
;
311 valueSet
= realloc(valueSet
,
312 sizeof (*valueSet
) * lastAlloc
);
313 if (valueSet
== NULL
) {
322 if (!found
&& (addRemoveFlag
== NPIV_REMOVE
)) {
323 ret
= NPIV_ERROR_MEMBER_NOT_FOUND
;
325 if (ret
!= NPIV_SUCCESS
) {
329 if (addRemoveFlag
== NPIV_ADD
) {
331 * Now create the new entry
333 valueSet
[i
] = scf_value_create(handle
);
334 if (valueSet
[i
] == NULL
) {
335 syslog(LOG_ERR
, "scf value alloc failed - %s",
336 scf_strerror(scf_error()));
344 * Set the new member name
346 if (scf_value_set_ustring(valueSet
[i
], memberName
) == -1) {
347 syslog(LOG_ERR
, "set value failed - %s",
348 scf_strerror(scf_error()));
356 if (scf_entry_add_value(entry
, valueSet
[i
]) == -1) {
357 syslog(LOG_ERR
, "add value failed - %s",
358 scf_strerror(scf_error()));
364 if ((commitRet
= scf_transaction_commit(tran
)) != 1) {
365 syslog(LOG_ERR
, "transaction commit failed - %s",
366 scf_strerror(scf_error()));
367 if (commitRet
== 0) {
368 ret
= NPIV_ERROR_BUSY
;
379 if (handle
!= NULL
) {
380 scf_handle_destroy(handle
);
383 scf_service_destroy(svc
);
389 scf_transaction_destroy(tran
);
392 scf_entry_destroy(entry
);
395 scf_property_destroy(prop
);
397 if (valueIter
!= NULL
) {
398 scf_iter_destroy(valueIter
);
400 if (valueLookup
!= NULL
) {
401 scf_value_destroy(valueLookup
);
405 * Free valueSet scf resources
407 if (valueArraySize
> 0) {
408 for (i
= 0; i
< valueArraySize
; i
++) {
409 scf_value_destroy(valueSet
[i
]);
413 * Now free the pointer array to the resources
415 if (valueSet
!= NULL
) {
423 retrieveNPIVAttrs(HBA_HANDLE handle
, HBA_WWN portWWN
,
424 HBA_PORTNPIVATTRIBUTES
*npivattrs
, HBA_UINT32
*portIndex
) {
426 HBA_ADAPTERATTRIBUTES attrs
;
427 HBA_PORTATTRIBUTES portattrs
;
431 /* argument checking */
432 if (npivattrs
== NULL
|| portIndex
== NULL
) {
436 memset(&attrs
, 0, sizeof (HBA_ADAPTERATTRIBUTES
));
437 status
= HBA_GetAdapterAttributes(handle
, &attrs
);
438 while ((status
== HBA_STATUS_ERROR_TRY_AGAIN
||
439 status
== HBA_STATUS_ERROR_BUSY
) &&
441 status
= HBA_GetAdapterAttributes(handle
, &attrs
);
442 if (status
== HBA_STATUS_OK
) {
447 if (status
!= HBA_STATUS_OK
) {
451 memset(&portattrs
, 0, sizeof (HBA_PORTATTRIBUTES
));
452 for (portCtr
= 0; portCtr
< attrs
.NumberOfPorts
; portCtr
++) {
453 status
= HBA_GetAdapterPortAttributes(handle
,
454 portCtr
, &portattrs
);
456 while ((status
== HBA_STATUS_ERROR_TRY_AGAIN
||
457 status
== HBA_STATUS_ERROR_BUSY
) &&
458 times
++ < HBA_MAX_RETRIES
) {
459 status
= HBA_GetAdapterPortAttributes(handle
,
460 portCtr
, &portattrs
);
461 if (status
== HBA_STATUS_OK
) {
467 if (status
!= HBA_STATUS_OK
) {
471 if (memcmp(portWWN
.wwn
, portattrs
.PortWWN
.wwn
,
472 sizeof (portattrs
.PortWWN
.wwn
)) == 0) {
476 if (portCtr
>= attrs
.NumberOfPorts
) {
480 *portIndex
= portCtr
;
482 status
= Sun_HBA_GetPortNPIVAttributes(handle
, portCtr
, npivattrs
);
484 while ((status
== HBA_STATUS_ERROR_TRY_AGAIN
||
485 status
== HBA_STATUS_ERROR_BUSY
) &&
486 times
++ < HBA_MAX_RETRIES
) {
487 status
= Sun_HBA_GetPortNPIVAttributes(handle
,
489 if (status
== HBA_STATUS_OK
) {
494 if (status
!= HBA_STATUS_OK
) {
503 fc_util_delete_npivport(int wwnCount
, char **wwn_argv
,
504 cmdOptions_t
*options
)
506 uint64_t physicalportWWN
, virtualportWWN
;
507 HBA_WWN portWWN
, vportWWN
;
510 HBA_PORTNPIVATTRIBUTES npivattrs
;
511 HBA_UINT32 portIndex
;
517 gettext("Invalid Parameter\n"));
521 for (; options
->optval
; options
++) {
522 switch (options
->optval
) {
524 if (!isValidWWN(options
->optarg
)) {
526 gettext("Invalid Port WWN\n"));
529 sscanf(options
->optarg
, "%016llx", &virtualportWWN
);
536 if (!isValidWWN(wwn_argv
[0])) {
538 gettext("Invalid Physical Port WWN\n"));
542 if ((status
= HBA_LoadLibrary()) != HBA_STATUS_OK
) {
544 gettext("Failed to load FC-HBA common library\n"));
546 fprintf(stderr
, "\n");
549 sscanf(wwn_argv
[0], "%016llx", &physicalportWWN
);
550 physicalportWWN
= htonll(physicalportWWN
);
551 memcpy(portWWN
.wwn
, &physicalportWWN
, sizeof (physicalportWWN
));
553 virtualportWWN
= htonll(virtualportWWN
);
554 memcpy(vportWWN
.wwn
, &virtualportWWN
, sizeof (virtualportWWN
));
556 status
= HBA_OpenAdapterByWWN(&handle
, portWWN
);
557 if (status
!= HBA_STATUS_OK
) {
559 gettext("Error: HBA port %s: not found\n"),
565 /* Get physical port NPIV attributes */
566 if (retrieveNPIVAttrs(handle
, portWWN
, &npivattrs
, &portIndex
) == 0) {
567 /* Check port NPIV attributes */
568 if (npivattrs
.MaxNumberOfNPIVPorts
== 0) {
570 gettext("Error: NPIV not Supported\n"));
571 HBA_CloseAdapter(handle
);
576 /* Delete a virtual port */
577 status
= Sun_HBA_DeleteNPIVPort(handle
, portIndex
,
580 while ((status
== HBA_STATUS_ERROR_TRY_AGAIN
||
581 status
== HBA_STATUS_ERROR_BUSY
) &&
582 times
++ < HBA_MAX_RETRIES
) {
584 status
= Sun_HBA_DeleteNPIVPort(handle
, portIndex
,
586 if (status
== HBA_STATUS_OK
) {
590 if (status
!= HBA_STATUS_OK
) {
592 gettext("Error: failed to delete a npiv port\n"));
593 HBA_CloseAdapter(handle
);
599 gettext("Error: failed to get port NPIV attributes\n"));
600 HBA_CloseAdapter(handle
);
605 HBA_CloseAdapter(handle
);
608 WWN2str(pwwn
, &vportWWN
);
609 npivAddRemoveNPIVEntry(wwn_argv
[0],
610 NULL
, pwwn
, 0, NPIV_REMOVE
);
616 fc_util_create_npivport(int wwnCount
,
617 char **wwn_argv
, cmdOptions_t
*options
)
619 uint64_t physicalportWWN
, virtualnodeWWN
, virtualportWWN
;
620 HBA_WWN portWWN
, vnodeWWN
, vportWWN
;
623 HBA_PORTNPIVATTRIBUTES npivattrs
;
624 HBA_UINT32 portIndex
;
625 HBA_UINT32 npivportIndex
= 0;
626 char nwwn
[17], pwwn
[17];
632 gettext("Invalid Parameter\n"));
636 for (; options
->optval
; options
++) {
637 switch (options
->optval
) {
639 if (!isValidWWN(options
->optarg
)) {
641 gettext("Invalid Port WWN\n"));
644 sscanf(options
->optarg
, "%016llx", &virtualportWWN
);
648 if (!isValidWWN(options
->optarg
)) {
650 gettext("Invalid Node WWN\n"));
653 sscanf(options
->optarg
, "%016llx", &virtualnodeWWN
);
661 if (!isValidWWN(wwn_argv
[0])) {
663 gettext("Invalid Physical Port WWN\n"));
668 if ((status
= HBA_LoadLibrary()) != HBA_STATUS_OK
) {
670 gettext("Failed to load FC-HBA common library\n"));
672 fprintf(stderr
, "\n");
676 sscanf(wwn_argv
[0], "%016llx", &physicalportWWN
);
677 physicalportWWN
= htonll(physicalportWWN
);
678 memcpy(portWWN
.wwn
, &physicalportWWN
, sizeof (physicalportWWN
));
680 status
= HBA_OpenAdapterByWWN(&handle
, portWWN
);
681 if (status
!= HBA_STATUS_OK
) {
683 gettext("Error: HBA port %s: not found\n"),
689 if (randomflag
!= 2) {
690 status
= Sun_HBA_AdapterCreateWWN(handle
, 0,
691 &vnodeWWN
, &vportWWN
, NULL
, HBA_CREATE_WWN_RANDOM
);
692 if (status
!= HBA_STATUS_OK
) {
694 gettext("Error: Fail to get Random WWN\n"));
695 HBA_CloseAdapter(handle
);
700 virtualnodeWWN
= htonll(virtualnodeWWN
);
701 memcpy(vnodeWWN
.wwn
, &virtualnodeWWN
, sizeof (virtualnodeWWN
));
702 virtualportWWN
= htonll(virtualportWWN
);
703 memcpy(vportWWN
.wwn
, &virtualportWWN
, sizeof (virtualportWWN
));
706 if (memcmp(vnodeWWN
.wwn
, vportWWN
.wwn
, 8) == 0) {
708 gettext("Error: Port WWN is same as Node WWN\n"));
709 HBA_CloseAdapter(handle
);
714 /* Get physical port NPIV attributes */
715 if (retrieveNPIVAttrs(handle
, portWWN
, &npivattrs
, &portIndex
) == 0) {
716 /* Check port NPIV attributes */
717 if (npivattrs
.MaxNumberOfNPIVPorts
== 0) {
719 gettext("Error: NPIV not Supported\n"));
720 HBA_CloseAdapter(handle
);
724 if (npivattrs
.MaxNumberOfNPIVPorts
==
725 npivattrs
.NumberOfNPIVPorts
) {
727 gettext("Error: Can not create more NPIV port\n"));
728 HBA_CloseAdapter(handle
);
733 /* Create a virtual port */
734 status
= Sun_HBA_CreateNPIVPort(handle
, portIndex
,
735 vnodeWWN
, vportWWN
, &npivportIndex
);
737 while ((status
== HBA_STATUS_ERROR_TRY_AGAIN
||
738 status
== HBA_STATUS_ERROR_BUSY
) &&
739 times
++ < HBA_MAX_RETRIES
) {
741 status
= Sun_HBA_CreateNPIVPort(handle
, portIndex
,
742 vnodeWWN
, vportWWN
, &npivportIndex
);
743 if (status
== HBA_STATUS_OK
) {
748 if (status
!= HBA_STATUS_OK
) {
750 gettext("Error: failed to create a npiv port\n"));
751 HBA_CloseAdapter(handle
);
757 gettext("Error: failed to get port NPIV attributes\n"));
758 HBA_CloseAdapter(handle
);
763 HBA_CloseAdapter(handle
);
766 WWN2str(nwwn
, &vnodeWWN
);
767 WWN2str(pwwn
, &vportWWN
);
768 npivAddRemoveNPIVEntry(wwn_argv
[0],
769 nwwn
, pwwn
, npivportIndex
, NPIV_ADD
);
775 create_npivport(char *ppwwn_str
, char *vnwwn_str
,
776 char *vpwwn_str
, int vindex
)
778 uint64_t physicalportWWN
, virtualnodeWWN
, virtualportWWN
;
779 HBA_WWN portWWN
, vnodeWWN
, vportWWN
;
782 HBA_PORTNPIVATTRIBUTES npivattrs
;
783 HBA_UINT32 portIndex
;
784 HBA_UINT32 npivportIndex
;
787 sscanf(ppwwn_str
, "%016llx", &physicalportWWN
);
788 physicalportWWN
= htonll(physicalportWWN
);
789 memcpy(portWWN
.wwn
, &physicalportWWN
, sizeof (physicalportWWN
));
790 sscanf(vnwwn_str
, "%016llx", &virtualnodeWWN
);
791 virtualnodeWWN
= htonll(virtualnodeWWN
);
792 memcpy(vnodeWWN
.wwn
, &virtualnodeWWN
, sizeof (virtualnodeWWN
));
793 sscanf(vpwwn_str
, "%016llx", &virtualportWWN
);
794 virtualportWWN
= htonll(virtualportWWN
);
795 memcpy(vportWWN
.wwn
, &virtualportWWN
, sizeof (virtualportWWN
));
796 npivportIndex
= vindex
;
798 status
= HBA_OpenAdapterByWWN(&handle
, portWWN
);
799 while (status
== HBA_STATUS_ERROR_TRY_AGAIN
||
800 status
== HBA_STATUS_ERROR_BUSY
) {
801 (void) sleep(FCADM_SLEEP_TIME
);
802 status
= HBA_OpenAdapterByWWN(&handle
, portWWN
);
803 if (times
++ > FCADM_RETRY_TIMES
) {
808 /* Get physical port NPIV attributes */
809 if (retrieveNPIVAttrs(handle
, portWWN
,
810 &npivattrs
, &portIndex
) == 0) {
811 /* Check port NPIV attributes */
812 if (npivattrs
.MaxNumberOfNPIVPorts
== 0) {
815 if (npivattrs
.MaxNumberOfNPIVPorts
==
816 npivattrs
.NumberOfNPIVPorts
) {
820 /* Create a virtual port */
821 status
= Sun_HBA_CreateNPIVPort(handle
, portIndex
,
822 vnodeWWN
, vportWWN
, &npivportIndex
);
824 while (status
== HBA_STATUS_ERROR_TRY_AGAIN
||
825 status
== HBA_STATUS_ERROR_BUSY
) {
826 (void) sleep(FCADM_SLEEP_TIME
);
827 status
= Sun_HBA_CreateNPIVPort(handle
, portIndex
,
828 vnodeWWN
, vportWWN
, &npivportIndex
);
829 if (times
++ > FCADM_RETRY_TIMES
) {
836 HBA_CloseAdapter(handle
);
842 fc_util_create_portlist()
844 scf_handle_t
*handle
= NULL
;
845 scf_service_t
*svc
= NULL
;
846 scf_propertygroup_t
*pg
= NULL
;
847 scf_transaction_t
*tran
= NULL
;
848 scf_transaction_entry_t
*entry
= NULL
;
849 scf_property_t
*prop
= NULL
;
850 scf_value_t
*valueLookup
= NULL
;
851 scf_iter_t
*valueIter
= NULL
;
852 char buf
[NPIV_PORT_LIST_LENGTH
] = {0};
855 commitRet
= cfgInit(&handle
, &svc
);
856 if (commitRet
!= NPIV_SUCCESS
) {
860 if (((pg
= scf_pg_create(handle
)) == NULL
) ||
861 ((tran
= scf_transaction_create(handle
)) == NULL
) ||
862 ((entry
= scf_entry_create(handle
)) == NULL
) ||
863 ((prop
= scf_property_create(handle
)) == NULL
) ||
864 ((valueIter
= scf_iter_create(handle
)) == NULL
)) {
868 /* get property group or create it */
869 if (scf_service_get_pg(svc
, NPIV_PG_NAME
, pg
) == -1) {
873 if (scf_pg_get_property(pg
, NPIV_PORT_LIST
, prop
) == -1) {
874 syslog(LOG_ERR
, "get property failed - %s",
875 scf_strerror(scf_error()));
879 valueLookup
= scf_value_create(handle
);
880 if (valueLookup
== NULL
) {
881 syslog(LOG_ERR
, "scf value alloc failed - %s",
882 scf_strerror(scf_error()));
886 if (scf_iter_property_values(valueIter
, prop
) == -1) {
887 syslog(LOG_ERR
, "iter value failed - %s",
888 scf_strerror(scf_error()));
892 if (HBA_LoadLibrary() != HBA_STATUS_OK
) {
895 HBA_GetNumberOfAdapters();
897 while (scf_iter_next_value(valueIter
, valueLookup
) == 1) {
898 char ppwwn
[17] = {0};
899 char vnwwn
[17] = {0};
900 char vpwwn
[17] = {0};
903 bzero(buf
, sizeof (buf
));
904 if (scf_value_get_ustring(valueLookup
, buf
, MAXNAMELEN
) == -1) {
905 syslog(LOG_ERR
, "iter value failed - %s",
906 scf_strerror(scf_error()));
910 sscanf(buf
, "%16s:%16s:%16s:%d", ppwwn
, vpwwn
, vnwwn
, &vindex
);
911 create_npivport(ppwwn
, vnwwn
, vpwwn
, vindex
);
919 if (handle
!= NULL
) {
920 scf_handle_destroy(handle
);
923 scf_service_destroy(svc
);
929 scf_transaction_destroy(tran
);
932 scf_entry_destroy(entry
);
935 scf_property_destroy(prop
);
937 if (valueIter
!= NULL
) {
938 scf_iter_destroy(valueIter
);
940 if (valueLookup
!= NULL
) {
941 scf_value_destroy(valueLookup
);
949 fc_util_force_lip(int objects
, char *argv
[])
957 if ((status
= HBA_LoadLibrary()) != HBA_STATUS_OK
) {
958 fprintf(stderr
, gettext("Failed to load FC-HBA library\n"));
960 fprintf(stderr
, "\n");
964 sscanf(argv
[0], "%016llx", &hbaWWN
);
965 hbaWWN
= htonll(hbaWWN
);
966 memcpy(myWWN
.wwn
, &hbaWWN
, sizeof (hbaWWN
));
969 * Try target mode first
971 if ((status
= Sun_HBA_OpenTgtAdapterByWWN(&handle
, myWWN
)) !=
974 * Continue to try initiator mode
976 if ((status
= HBA_OpenAdapterByWWN(&handle
, myWWN
)) !=
978 fprintf(stderr
, gettext("Error: HBA %s not found\n"),
984 status
= Sun_HBA_ForceLip(handle
, &rval
);
985 if ((status
!= HBA_STATUS_OK
) || (rval
!= 0)) {
986 fprintf(stderr
, gettext("Error: Failed to reinitialize the "
987 "link of HBA %s\n"), argv
[0]);