8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / sun_fc / common / Sun_fcScsiReportLUNsV2.cc
blob88e69845ba97cd4935314d3ad944a1ccab05b516
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include "Trace.h"
29 #include "HBA.h"
30 #include "HBAPort.h"
31 #include "Exceptions.h"
32 #include "sun_fc.h"
33 #include <unistd.h>
35 #define BUSY_SLEEP 10000 /* 1/10 second */
36 #define BUSY_RETRY_TIMER 5000000000ULL /* Retry for 5 seconds */
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 /**
42 * @memo Send a SCSI report luns command to a remote WWN
43 * @return HBA_STATUS_OK or other error code
44 * scsiStatus should be checked to ensure SCSI command
45 * was a success.
46 * @param handle The HBA to operate on
47 * @param portWWN Indicates the HBA port to send command through
48 * @param targetPortWWN Indicates the target to send command to
49 * @param responseBuffer User-allocated response buffer
50 * @param responseSize Size of User-allocated response buffer
51 * @param scsiStatus User-allocated scsi status byte
53 * @doc This routine will attempt a limited number of retries
54 * When busy or again errors are encountered.
56 HBA_STATUS Sun_fcScsiReportLUNsV2(HBA_HANDLE handle, HBA_WWN portWWN,
57 HBA_WWN targetPortWWN,
58 void *responseBuffer, HBA_UINT32 *responseSize,
59 HBA_UINT8 *scsiStatus,
60 void *senseBuffer, HBA_UINT32 *senseSize) {
61 Trace log("Sun_fcScsiReportLUNsV2");
63 HBA_STATUS status = HBA_STATUS_OK;
65 hrtime_t start = gethrtime();
66 hrtime_t end = start + BUSY_RETRY_TIMER;
67 for (hrtime_t cur = start; cur < end; cur = gethrtime()) {
68 try {
69 Handle *myHandle = Handle::findHandle(handle);
70 HBA *hba = myHandle->getHBA();
71 HBAPort *port = hba->getPort(wwnConversion(portWWN.wwn));
72 port->sendReportLUNs(wwnConversion(targetPortWWN.wwn),
73 responseBuffer, responseSize, scsiStatus,
74 senseBuffer, senseSize);
75 return (HBA_STATUS_OK);
76 } catch (BusyException &e) {
77 usleep(BUSY_SLEEP);
78 status = HBA_STATUS_ERROR_BUSY;
79 continue;
80 } catch (TryAgainException &e) {
81 usleep(BUSY_SLEEP);
82 status = HBA_STATUS_ERROR_TRY_AGAIN;
83 continue;
84 } catch (HBAException &e) {
85 return (e.getErrorCode());
86 } catch (...) {
87 log.internalError(
88 "Uncaught exception");
89 return (HBA_STATUS_ERROR);
92 return (status);
94 #ifdef __cplusplus
96 #endif