xref: /onnv-gate/usr/src/lib/sun_sas/common/Sun_sasCloseAdapter.c (revision 10652:9d0aff74d6fd)
1*10652SHyon.Kim@Sun.COM /*
2*10652SHyon.Kim@Sun.COM  * CDDL HEADER START
3*10652SHyon.Kim@Sun.COM  *
4*10652SHyon.Kim@Sun.COM  * The contents of this file are subject to the terms of the
5*10652SHyon.Kim@Sun.COM  * Common Development and Distribution License (the "License").
6*10652SHyon.Kim@Sun.COM  * You may not use this file except in compliance with the License.
7*10652SHyon.Kim@Sun.COM  *
8*10652SHyon.Kim@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10652SHyon.Kim@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*10652SHyon.Kim@Sun.COM  * See the License for the specific language governing permissions
11*10652SHyon.Kim@Sun.COM  * and limitations under the License.
12*10652SHyon.Kim@Sun.COM  *
13*10652SHyon.Kim@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*10652SHyon.Kim@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10652SHyon.Kim@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*10652SHyon.Kim@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*10652SHyon.Kim@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10652SHyon.Kim@Sun.COM  *
19*10652SHyon.Kim@Sun.COM  * CDDL HEADER END
20*10652SHyon.Kim@Sun.COM  */
21*10652SHyon.Kim@Sun.COM 
22*10652SHyon.Kim@Sun.COM /*
23*10652SHyon.Kim@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*10652SHyon.Kim@Sun.COM  * Use is subject to license terms.
25*10652SHyon.Kim@Sun.COM  */
26*10652SHyon.Kim@Sun.COM 
27*10652SHyon.Kim@Sun.COM #include    <sun_sas.h>
28*10652SHyon.Kim@Sun.COM 
29*10652SHyon.Kim@Sun.COM /*
30*10652SHyon.Kim@Sun.COM  * Closes an adapter
31*10652SHyon.Kim@Sun.COM  *
32*10652SHyon.Kim@Sun.COM  * the handle is removed from the open_handles list
33*10652SHyon.Kim@Sun.COM  */
34*10652SHyon.Kim@Sun.COM void
Sun_sasCloseAdapter(HBA_HANDLE handle)35*10652SHyon.Kim@Sun.COM Sun_sasCloseAdapter(HBA_HANDLE handle)
36*10652SHyon.Kim@Sun.COM {
37*10652SHyon.Kim@Sun.COM 	const char			ROUTINE[] = "Sun_sasCloseAdapter";
38*10652SHyon.Kim@Sun.COM 	struct open_handle		*open_handle_ptr, *open_handle_prev_ptr;
39*10652SHyon.Kim@Sun.COM 	int				found = 0;
40*10652SHyon.Kim@Sun.COM 
41*10652SHyon.Kim@Sun.COM 	if (global_hba_head == NULL) {
42*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE,
43*10652SHyon.Kim@Sun.COM 		    "Attempted to close an invalid handle %08lx. "
44*10652SHyon.Kim@Sun.COM 		    "There are no hba handles loaded in the VSL.",
45*10652SHyon.Kim@Sun.COM 		    handle);
46*10652SHyon.Kim@Sun.COM 		return;
47*10652SHyon.Kim@Sun.COM 	}
48*10652SHyon.Kim@Sun.COM 
49*10652SHyon.Kim@Sun.COM 	/* Removing handle from open_handles; */
50*10652SHyon.Kim@Sun.COM 	lock(&open_handles_lock);
51*10652SHyon.Kim@Sun.COM 	if (global_hba_head->open_handles == NULL) {
52*10652SHyon.Kim@Sun.COM 		/* check to see if there are any open global_hba_head */
53*10652SHyon.Kim@Sun.COM 		log(LOG_DEBUG, ROUTINE,
54*10652SHyon.Kim@Sun.COM 		    "Attempted to close an invalid handle %08lx. "
55*10652SHyon.Kim@Sun.COM 		    "There are no open handles in the VSL.",
56*10652SHyon.Kim@Sun.COM 		    handle);
57*10652SHyon.Kim@Sun.COM 	} else if (global_hba_head->open_handles->next == NULL) {
58*10652SHyon.Kim@Sun.COM 		/* there is only one handle open */
59*10652SHyon.Kim@Sun.COM 		if (global_hba_head->open_handles->handle == handle) {
60*10652SHyon.Kim@Sun.COM 			free(global_hba_head->open_handles);
61*10652SHyon.Kim@Sun.COM 			global_hba_head->open_handles = NULL;
62*10652SHyon.Kim@Sun.COM 		} else {
63*10652SHyon.Kim@Sun.COM 			log(LOG_DEBUG, ROUTINE,
64*10652SHyon.Kim@Sun.COM 			    "Attempted to close an invalid handle %08lx. "
65*10652SHyon.Kim@Sun.COM 			    "Unable to find handle to close.", handle);
66*10652SHyon.Kim@Sun.COM 		}
67*10652SHyon.Kim@Sun.COM 	} else {	/* there is more than one handle open */
68*10652SHyon.Kim@Sun.COM 		open_handle_ptr = global_hba_head->open_handles;
69*10652SHyon.Kim@Sun.COM 		if (open_handle_ptr->handle == handle) {
70*10652SHyon.Kim@Sun.COM 			global_hba_head->open_handles = open_handle_ptr->next;
71*10652SHyon.Kim@Sun.COM 			free(open_handle_ptr);
72*10652SHyon.Kim@Sun.COM 		} else {
73*10652SHyon.Kim@Sun.COM 			for (open_handle_ptr = open_handle_ptr->next,
74*10652SHyon.Kim@Sun.COM 			    open_handle_prev_ptr =
75*10652SHyon.Kim@Sun.COM 			    global_hba_head->open_handles;
76*10652SHyon.Kim@Sun.COM 			    open_handle_ptr != NULL;
77*10652SHyon.Kim@Sun.COM 			    open_handle_ptr = open_handle_ptr->next) {
78*10652SHyon.Kim@Sun.COM 				if (open_handle_ptr->handle == handle) {
79*10652SHyon.Kim@Sun.COM 					open_handle_prev_ptr->next =
80*10652SHyon.Kim@Sun.COM 					    open_handle_ptr->next;
81*10652SHyon.Kim@Sun.COM 					free(open_handle_ptr);
82*10652SHyon.Kim@Sun.COM 					found = 1;
83*10652SHyon.Kim@Sun.COM 					break;
84*10652SHyon.Kim@Sun.COM 				} else {
85*10652SHyon.Kim@Sun.COM 					open_handle_prev_ptr =
86*10652SHyon.Kim@Sun.COM 					    open_handle_prev_ptr->next;
87*10652SHyon.Kim@Sun.COM 				}
88*10652SHyon.Kim@Sun.COM 			}
89*10652SHyon.Kim@Sun.COM 			if (found == 0) {
90*10652SHyon.Kim@Sun.COM 				log(LOG_DEBUG, ROUTINE,
91*10652SHyon.Kim@Sun.COM 				    "Attempted to close an invalid handle "
92*10652SHyon.Kim@Sun.COM 				    "%08lx.  Unable to find handle to close.",
93*10652SHyon.Kim@Sun.COM 				    handle);
94*10652SHyon.Kim@Sun.COM 			}
95*10652SHyon.Kim@Sun.COM 		}
96*10652SHyon.Kim@Sun.COM 	}
97*10652SHyon.Kim@Sun.COM 
98*10652SHyon.Kim@Sun.COM 	unlock(&open_handles_lock);
99*10652SHyon.Kim@Sun.COM }
100