xref: /titanic_50/usr/src/lib/sun_fc/common/Exceptions.h (revision 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_EXCEPTIONS_H
27 #define	_EXCEPTIONS_H
28 
29 
30 
31 #include <hbaapi.h>
32 #include "Handle.h"
33 #include "HBAPort.h"
34 #include "Trace.h"
35 #include <string>
36 
37 /**
38  * @memo	    Superclass for all Exception we'll throw.
39  *
40  * @doc		    To ensure
41  * no uncaught exceptions squeeze through, all exceptions
42  * will map to some HBA_STATUS error code so we can easily
43  * handle them in catch blocks in our external API.
44  */
45 class HBAException {
46 public:
47     HBAException(HBA_STATUS err) : errorCode(err) {
48 	Trace log("HBAException");
49 	log.debug("Error code: %d", err);
50 	log.stackTrace();
51     }
52     HBA_STATUS getErrorCode() { return errorCode; }
53 private:
54     HBA_STATUS errorCode;
55 };
56 
57 
58 /**
59  * @memo	    Represents HBA API "Not Supported" error
60  */
61 class NotSupportedException : public HBAException {
62 public:
63     NotSupportedException() : HBAException(HBA_STATUS_ERROR_NOT_SUPPORTED) { }
64 };
65 
66 /**
67  * @memo	    Represents HBA API "Invalid Handle" error
68  */
69 class InvalidHandleException : public HBAException {
70 public:
71     InvalidHandleException() : HBAException(HBA_STATUS_ERROR_INVALID_HANDLE) { }
72 };
73 
74 /**
75  * @memo	    Represents HBA API "Bad Argument" error
76 
77  */
78 class BadArgumentException : public HBAException {
79 public:
80     BadArgumentException() : HBAException(HBA_STATUS_ERROR_ARG) { }
81 };
82 
83 /**
84  * @memo	    Represents HBA API "Illegal WWN" error
85  */
86 class IllegalWWNException : public HBAException {
87 public:
88     IllegalWWNException() : HBAException(HBA_STATUS_ERROR_ILLEGAL_WWN) { }
89 };
90 
91 /**
92  * @memo	    Represents HBA API "Illegal Index" error
93  */
94 class IllegalIndexException : public HBAException {
95 public:
96     IllegalIndexException() : HBAException(HBA_STATUS_ERROR_ILLEGAL_INDEX) { }
97 };
98 
99 /**
100  * @memo	    Represents HBA API "More Data" error
101  */
102 class MoreDataException : public HBAException {
103 public:
104     MoreDataException() : HBAException(HBA_STATUS_ERROR_MORE_DATA) { }
105 };
106 
107 /**
108  * @memo	    Represents HBA API "Stale Data" error
109  */
110 class StaleDataException : public HBAException {
111 public:
112     StaleDataException() : HBAException(HBA_STATUS_ERROR_STALE_DATA) { }
113 };
114 
115 /**
116  * @memo	    Represents HBA API "SCSI Check Condition" error
117  */
118 class CheckConditionException : public HBAException {
119 public:
120     CheckConditionException() : HBAException(HBA_STATUS_SCSI_CHECK_CONDITION) { }
121 };
122 
123 /**
124  * @memo	    Represents HBA API "Busy" error
125  */
126 class BusyException : public HBAException {
127 public:
128     BusyException() : HBAException(HBA_STATUS_ERROR_BUSY) { }
129 };
130 
131 /**
132  * @memo	    Represents HBA API "Try Again" error
133  */
134 class TryAgainException : public HBAException {
135 public:
136     TryAgainException() : HBAException(HBA_STATUS_ERROR_TRY_AGAIN) { }
137 };
138 
139 /**
140  * @memo	    Represents HBA API "Unavailable" error
141  */
142 class UnavailableException : public HBAException {
143 public:
144     UnavailableException() : HBAException(HBA_STATUS_ERROR_UNAVAILABLE) { }
145 };
146 
147 /**
148  * @memo	    Represents HBA API "ELS Rejection" error
149  */
150 class ELSRejectException : public HBAException {
151 public:
152     ELSRejectException() : HBAException(HBA_STATUS_ERROR_ELS_REJECT) { }
153 };
154 
155 /**
156  * @memo	    Represents HBA API "Invalid Logical Unit Number" error
157  */
158 class InvalidLUNException : public HBAException {
159 public:
160     InvalidLUNException() : HBAException(HBA_STATUS_ERROR_INVALID_LUN) { }
161 };
162 
163 /**
164  * @memo	    Represents HBA API "Incompatible" error
165  */
166 class IncompatibleException : public HBAException {
167 public:
168     IncompatibleException() : HBAException(HBA_STATUS_ERROR_INCOMPATIBLE) { }
169 };
170 
171 /**
172  * @memo	    Represents HBA API "Ambiguous WWN" error
173  */
174 class AmbiguousWWNException : public HBAException {
175 public:
176     AmbiguousWWNException() : HBAException(HBA_STATUS_ERROR_AMBIGUOUS_WWN) { }
177 };
178 
179 /**
180  * @memo	    Represents HBA API "Not a Target" error
181  */
182 class NotATargetException : public HBAException {
183 public:
184     NotATargetException() : HBAException(HBA_STATUS_ERROR_NOT_A_TARGET) { }
185 };
186 
187 /**
188  * @memo	    Represents HBA API "Unsupported FC4 type" error
189  */
190 class UnsupportedFC4Exception : public HBAException {
191 public:
192     UnsupportedFC4Exception() : HBAException(HBA_STATUS_ERROR_UNSUPPORTED_FC4) { }
193 };
194 
195 /**
196  * @memo	    Represents HBA API "Incapable" error
197  */
198 class IncapableException : public HBAException {
199 public:
200     IncapableException() : HBAException(HBA_STATUS_ERROR_INCAPABLE) { }
201 };
202 
203 /**
204  * @memo	    Encapsulate I/O error scenarios.
205  *
206  * @doc		    If logging is enabled, this will
207  * automatically log the failure with as much detail as possible.
208  */
209 class IOError : public HBAException {
210 public:
211     IOError(std::string message);
212     IOError(Handle *handle);
213     IOError(HBAPort *port);
214     IOError(HBAPort *port, uint64_t target);
215     IOError(HBAPort *port, uint64_t target, uint64_t lun);
216 };
217 
218 /**
219  * @memo	    Generic error of unknown type
220  *
221  * @doc
222  * Grab bag for something catastrophic occuring in the internal
223  * logic of the VSL.  Hopefully, this should never ever happen.
224  */
225 class InternalError : public HBAException {
226 public:
227     InternalError();
228     InternalError(std::string message);
229 };
230 
231 #endif /* _EXCEPTIONS_H */
232