xref: /illumos-gate/usr/src/lib/sun_fc/common/IOError.cc (revision 8b80e8cb6855118d46f605e91b5ed4ce83417395)
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 
27 
28 #include "Exceptions.h"
29 #include "Trace.h"
30 #include "sun_fc.h"
31 #include <iostream>
32 #include <iomanip>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <stropts.h>
38 #include <cstring>
39 #include <cerrno>
40 using namespace std;
41 
42 /**
43  * @memo	    Log a simple I/O error message
44  * @param	    message The message to log
45  */
46 IOError::IOError(string message) : HBAException(HBA_STATUS_ERROR) {
47 	Trace log("IOError::IOError(string)");
48 	log.genericIOError("%s (%s)", message.c_str(), strerror(errno));
49 }
50 
51 /**
52  * @memo	    Log a handle I/O error message
53  * @param	    handle The handle where the I/O error took place
54  */
55 IOError::IOError(Handle *handle) : HBAException(HBA_STATUS_ERROR) {
56 	Trace log("IOError::IOError(Handle)");
57 	log.genericIOError(
58 		"On handle %08lx (%s)", handle->getHandle(), strerror(errno));
59 }
60 
61 /**
62  * @memo	    Log an HBAPort I/O error message
63  * @param	    port The port where the I/O error took place
64  */
65 IOError::IOError(HBAPort *port) : HBAException(HBA_STATUS_ERROR) {
66 	Trace log("IOError::IOError(HBAPort)");
67 	log.genericIOError(
68 		"On HBA port %016llx (%s)", port->getPortWWN(),
69 		strerror(errno));
70 }
71 
72 /**
73  * @memo	    Log a target I/O error message
74  * @param	    port The port where the I/O error took place
75  * @param	    target The target wwn which failed
76  */
77 IOError::IOError(HBAPort *port, uint64_t target) :
78 	    HBAException(HBA_STATUS_ERROR) {
79 	Trace log("IOError::IOError(HBAPort, wwn)");
80 	log.genericIOError(
81 		"On HBA port %016llx target %016llx (%s)", port->getPortWWN(),
82 		target, strerror(errno));
83 }
84 
85 /**
86  * @memo	    Log a LUN I/O error message
87  * @param	    port The port where the I/O error took place
88  * @param	    target The target wwn which failed
89  * @param	    lun The unit number which failed
90  */
91 IOError::IOError(HBAPort *port, uint64_t target, uint64_t lun) :
92 	HBAException(HBA_STATUS_ERROR) {
93 	Trace log("IOError::IOError(HBAPort, wwn, lun)");
94 	log.genericIOError(
95 		"On HBA port %016llx target %016llx lun %016llx (%s)",
96 		port->getPortWWN(),
97 		target,
98 		lun, strerror(errno));
99 }
100