#include <sun_sas.h>
void
Sun_sasCloseAdapter(HBA_HANDLE handle)
{
const char ROUTINE[] = "Sun_sasCloseAdapter";
struct open_handle *open_handle_ptr, *open_handle_prev_ptr;
int found = 0;
if (global_hba_head == NULL) {
log(LOG_DEBUG, ROUTINE,
"Attempted to close an invalid handle %08lx. "
"There are no hba handles loaded in the VSL.",
handle);
return;
}
lock(&open_handles_lock);
if (global_hba_head->open_handles == NULL) {
log(LOG_DEBUG, ROUTINE,
"Attempted to close an invalid handle %08lx. "
"There are no open handles in the VSL.",
handle);
} else if (global_hba_head->open_handles->next == NULL) {
if (global_hba_head->open_handles->handle == handle) {
free(global_hba_head->open_handles);
global_hba_head->open_handles = NULL;
} else {
log(LOG_DEBUG, ROUTINE,
"Attempted to close an invalid handle %08lx. "
"Unable to find handle to close.", handle);
}
} else {
open_handle_ptr = global_hba_head->open_handles;
if (open_handle_ptr->handle == handle) {
global_hba_head->open_handles = open_handle_ptr->next;
free(open_handle_ptr);
} else {
for (open_handle_ptr = open_handle_ptr->next,
open_handle_prev_ptr =
global_hba_head->open_handles;
open_handle_ptr != NULL;
open_handle_ptr = open_handle_ptr->next) {
if (open_handle_ptr->handle == handle) {
open_handle_prev_ptr->next =
open_handle_ptr->next;
free(open_handle_ptr);
found = 1;
break;
} else {
open_handle_prev_ptr =
open_handle_prev_ptr->next;
}
}
if (found == 0) {
log(LOG_DEBUG, ROUTINE,
"Attempted to close an invalid handle "
"%08lx. Unable to find handle to close.",
handle);
}
}
}
unlock(&open_handles_lock);
}