void *dapl_llist_peek_head(DAPL_LLIST_HEAD * head) { DAPL_LLIST_ENTRY *first; dapl_os_assert(!dapl_llist_is_empty(head)); first = *head; return (first->data); }
/* * dapl_sp_free * * Free the passed in PSP structure. * * Input: * entry point pointer * * Output: * none * * Returns: * none * */ void dapls_sp_free_sp( IN DAPL_SP *sp_ptr) { dapl_os_assert(sp_ptr->header.magic == DAPL_MAGIC_PSP || sp_ptr->header.magic == DAPL_MAGIC_RSP); dapl_os_assert(dapl_llist_is_empty(&sp_ptr->cr_list_head)); dapl_os_lock(&sp_ptr->header.lock); /* reset magic to prevent reuse */ sp_ptr->header.magic = DAPL_MAGIC_INVALID; dapl_os_unlock(&sp_ptr->header.lock); dapl_os_free(sp_ptr, sizeof (DAPL_SP)); }
/* * dapl_hca_unlink_ia * * Remove an ia from the hca info structure * * Input: * hca_ptr * ia_ptr * * Output: * none * * Returns: * none * */ void dapl_hca_unlink_ia(IN DAPL_HCA * hca_ptr, IN DAPL_IA * ia_ptr) { dapl_os_lock(&hca_ptr->lock); /* * If an error occurred when we were opening the IA it * will not be linked on the list; don't unlink an unlinked * list! */ if (!dapl_llist_is_empty(&hca_ptr->ia_list_head)) { dapl_llist_remove_entry(&hca_ptr->ia_list_head, &ia_ptr->hca_ia_list_entry); } dapl_os_unlock(&hca_ptr->lock); }
void *dapl_llist_next_entry(IN DAPL_LLIST_HEAD * head, IN DAPL_LLIST_ENTRY * cur_ent) { DAPL_LLIST_ENTRY *next; dapl_os_assert(!dapl_llist_is_empty(head)); if (cur_ent == NULL) { next = *head; } else { next = cur_ent->flink; if (next == *head) { return NULL; } } return (next->data); }
/* * dapl_llist_remove_entry() * * Purpose: Remove the specified entry from a linked list */ void *dapl_llist_remove_entry(DAPL_LLIST_HEAD * head, DAPL_LLIST_ENTRY * entry) { DAPL_LLIST_ENTRY *first; dapl_os_assert(!dapl_llist_is_empty(head)); first = *head; /* if it's the first entry, pull it off */ if (first == entry) { (*head) = first->flink; /* if it was the only entry, kill the list */ if (first->flink == first) { (*head) = NULL; } } #ifdef VERIFY_LINKED_LIST else { DAPL_LLIST_ENTRY *try_entry; try_entry = first->flink; for (;;) { if (try_entry == first) { /* not finding the element on the list is a BAD thing */ dapl_os_assert(0); break; } if (try_entry == entry) { break; } try_entry = try_entry->flink; } } #endif /* VERIFY_LINKED_LIST */ dapl_os_assert(entry->list_head == head); entry->list_head = NULL; entry->flink->blink = entry->blink; entry->blink->flink = entry->flink; entry->flink = NULL; entry->blink = NULL; return (entry->data); }
/* * dapl_cno_free * * DAPL Requirements Version xxx, 6.3.2.2 * * Destroy a consumer notification object instance * * Input: * cno_handle * * Output: * none * * Returns: * DAT_SUCCESS * DAT_INVALID_HANDLE * DAT_INVALID_STATE */ DAT_RETURN dapl_cno_free( IN DAT_CNO_HANDLE cno_handle) /* cno_handle */ { DAPL_CNO *cno_ptr; DAT_RETURN dat_status; dat_status = DAT_SUCCESS; cno_ptr = (DAPL_CNO *)cno_handle; if (DAPL_BAD_HANDLE(cno_handle, DAPL_MAGIC_CNO)) { dat_status = DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_CNO); goto bail; } if (cno_ptr->cno_ref_count != 0 || cno_ptr->cno_waiters != 0) { dat_status = DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_CNO_IN_USE); goto bail; } dapl_os_lock(&cno_ptr->header.lock); if (!dapl_llist_is_empty(&cno_ptr->evd_list_head)) { dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "cno_free: evd list not empty!\n"); dapl_os_unlock(&cno_ptr->header.lock); dat_status = DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_CNO_IN_USE); goto bail; } dapl_os_unlock(&cno_ptr->header.lock); dat_status = dapls_ib_cno_free(cno_ptr); if (dat_status != DAT_SUCCESS) { goto bail; } dapl_ia_unlink_cno(cno_ptr->header.owner_ia, cno_ptr); dapl_cno_dealloc(cno_ptr); bail: return (dat_status); }
/* * dapl_llist_remove_tail() * * Purpose: Remove the last entry of a linked list */ void *dapl_llist_remove_tail(DAPL_LLIST_HEAD * head) { DAPL_LLIST_ENTRY *last; dapl_os_assert(!dapl_llist_is_empty(head)); last = (*head)->blink; last->blink->flink = last->flink; last->flink->blink = last->blink; if (last->flink == last) { *head = NULL; } /* clean up the links for good measure */ last->flink = NULL; last->blink = NULL; last->list_head = NULL; return (last->data); }
/* * dapl_llist_remove_head() * * Purpose: Remove the first entry of a linked list */ void *dapl_llist_remove_head(DAPL_LLIST_HEAD * head) { DAPL_LLIST_ENTRY *first; dapl_os_assert(!dapl_llist_is_empty(head)); first = *head; *head = first->flink; first->flink->blink = first->blink; first->blink->flink = first->flink; if (first->flink == first) { *head = NULL; } /* clean up the links for good measure */ first->flink = NULL; first->blink = NULL; first->list_head = NULL; return (first->data); }
/* * dapl_llist_add_tail() * * Purpose: Add an entry to the tail of a linked list */ void dapl_llist_add_tail(DAPL_LLIST_HEAD * head, DAPL_LLIST_ENTRY * entry, void *data) { DAPL_LLIST_ENTRY *last; /* deal with empty list */ if (dapl_llist_is_empty(head)) { *head = entry; entry->flink = entry; entry->blink = entry; } else { last = (*head)->blink; entry->flink = last->flink; entry->blink = last; last->flink->blink = entry; last->flink = entry; } entry->data = data; entry->list_head = head; }
/* * dapl_sp_remove_cr * * Remove the CR from the PSP. Done prior to freeing the CR resource. * * Input: * sp_ptr * cr_ptr * * Output: * none * * Returns: * void * */ void dapl_sp_remove_cr( IN DAPL_SP *sp_ptr, IN DAPL_CR *cr_ptr) { dapl_os_lock(&sp_ptr->header.lock); if (dapl_llist_is_empty(&sp_ptr->cr_list_head)) { dapl_dbg_log(DAPL_DBG_TYPE_ERR, "***dapl_sp_remove_cr: removing from empty queue! sp %p\n", sp_ptr); dapl_os_unlock(&sp_ptr->header.lock); return; } (void) dapl_llist_remove_entry(&sp_ptr->cr_list_head, &cr_ptr->header.ia_list_entry); sp_ptr->cr_list_count--; dapl_os_unlock(&sp_ptr->header.lock); }
/* * dapl_llist_add_head() * * Purpose: Add an entry to the head of a linked list */ void dapl_llist_add_head(DAPL_LLIST_HEAD * head, DAPL_LLIST_ENTRY * entry, void *data) { DAPL_LLIST_ENTRY *first; /* deal with empty list */ if (dapl_llist_is_empty(head)) { entry->flink = entry; entry->blink = entry; } else { first = *head; entry->flink = first; entry->blink = first->blink; first->blink->flink = entry; first->blink = entry; } *head = entry; entry->data = data; entry->list_head = head; }
/* * dapls_osd_fork_cleanup * * Update val to value of passed in environment variable if present * * Input: * env_str * val Updated if environment variable exists * * Returns: * TRUE or FALSE */ void dapls_osd_fork_cleanup(void) { DAPL_PROVIDER_LIST_NODE *cur_node; DAPL_HCA *hca_ptr; DAPL_IA *ia_ptr; DAPL_LMR *lmr_ptr; DAPL_RMR *rmr_ptr; DAPL_PZ *pz_ptr; DAPL_CR *cr_ptr; DAPL_EP *ep_ptr; DAPL_EVD *evd_ptr; DAT_EP_PARAM *param; DAPL_SP *sp_ptr; while (NULL != g_dapl_provider_list.head) { cur_node = g_dapl_provider_list.head; g_dapl_provider_list.head = cur_node->next; hca_ptr = (DAPL_HCA *) cur_node->data.extension; /* * Walk the list of IA ptrs & clean up. This is purposely * a destructive list walk, we really don't want to preserve * any of it. */ while (!dapl_llist_is_empty(&hca_ptr->ia_list_head)) { ia_ptr = (DAPL_IA *) dapl_llist_peek_head(&hca_ptr->ia_list_head); /* * The rest of the cleanup code is similar to dapl_ia_close, * the big difference is that we don't release IB resources, * only memory; the underlying IB subsystem doesn't deal * with fork at all, so leave IB handles alone. */ while (!dapl_llist_is_empty(&ia_ptr->rmr_list_head)) { rmr_ptr = (DAPL_RMR *) dapl_llist_peek_head(&ia_ptr-> rmr_list_head); if (rmr_ptr->param.lmr_triplet. virtual_address != 0) { dapl_os_atomic_dec(&rmr_ptr->lmr-> lmr_ref_count); rmr_ptr->param.lmr_triplet. virtual_address = 0; } dapl_os_atomic_dec(&rmr_ptr->pz->pz_ref_count); dapl_ia_unlink_rmr(rmr_ptr->header.owner_ia, rmr_ptr); dapl_rmr_dealloc(rmr_ptr); } while (!dapl_llist_is_empty(&ia_ptr->rsp_list_head)) { sp_ptr = (DAPL_SP *) dapl_llist_peek_head(&ia_ptr-> rsp_list_head); dapl_os_atomic_dec(& ((DAPL_EVD *) sp_ptr-> evd_handle)->evd_ref_count); dapls_ia_unlink_sp(ia_ptr, sp_ptr); dapls_sp_free_sp(sp_ptr); } while (!dapl_llist_is_empty(&ia_ptr->ep_list_head)) { ep_ptr = (DAPL_EP *) dapl_llist_peek_head(&ia_ptr->ep_list_head); param = &ep_ptr->param; if (param->pz_handle != NULL) { dapl_os_atomic_dec(& ((DAPL_PZ *) param-> pz_handle)-> pz_ref_count); } if (param->recv_evd_handle != NULL) { dapl_os_atomic_dec(& ((DAPL_EVD *) param-> recv_evd_handle)-> evd_ref_count); } if (param->request_evd_handle) { dapl_os_atomic_dec(& ((DAPL_EVD *) param-> request_evd_handle)-> evd_ref_count); } if (param->connect_evd_handle != NULL) { dapl_os_atomic_dec(& ((DAPL_EVD *) param-> connect_evd_handle)-> evd_ref_count); } /* ...and free the resource */ dapl_ia_unlink_ep(ia_ptr, ep_ptr); dapl_ep_dealloc(ep_ptr); } while (!dapl_llist_is_empty(&ia_ptr->lmr_list_head)) { lmr_ptr = (DAPL_LMR *) dapl_llist_peek_head(&ia_ptr-> lmr_list_head); (void)dapls_hash_remove(lmr_ptr->header. owner_ia->hca_ptr-> lmr_hash_table, lmr_ptr->param. lmr_context, NULL); pz_ptr = (DAPL_PZ *) lmr_ptr->param.pz_handle; dapl_os_atomic_dec(&pz_ptr->pz_ref_count); dapl_ia_unlink_lmr(lmr_ptr->header.owner_ia, lmr_ptr); dapl_lmr_dealloc(lmr_ptr); } while (!dapl_llist_is_empty(&ia_ptr->psp_list_head)) { sp_ptr = (DAPL_SP *) dapl_llist_peek_head(&ia_ptr-> psp_list_head); while (!dapl_llist_is_empty (&sp_ptr->cr_list_head)) { cr_ptr = (DAPL_CR *) dapl_llist_peek_head(&sp_ptr-> cr_list_head); dapl_sp_remove_cr(sp_ptr, cr_ptr); dapls_cr_free(cr_ptr); } dapls_ia_unlink_sp(ia_ptr, sp_ptr); dapl_os_atomic_dec(& ((DAPL_EVD *) sp_ptr-> evd_handle)->evd_ref_count); dapls_sp_free_sp(sp_ptr); } while (!dapl_llist_is_empty(&ia_ptr->pz_list_head)) { pz_ptr = (DAPL_PZ *) dapl_llist_peek_head(&ia_ptr->pz_list_head); dapl_ia_unlink_pz(pz_ptr->header.owner_ia, pz_ptr); dapl_pz_dealloc(pz_ptr); } while (!dapl_llist_is_empty(&ia_ptr->evd_list_head)) { evd_ptr = (DAPL_EVD *) dapl_llist_peek_head(&ia_ptr-> evd_list_head); dapl_ia_unlink_evd(evd_ptr->header.owner_ia, evd_ptr); /* reset the cq_handle to avoid having it removed */ evd_ptr->ib_cq_handle = IB_INVALID_HANDLE; dapls_evd_dealloc(evd_ptr); } dapl_hca_unlink_ia(ia_ptr->hca_ptr, ia_ptr); /* asycn error evd was taken care of above, reset the pointer */ ia_ptr->async_error_evd = NULL; dapls_ia_free(ia_ptr); } /* end while ( ia_ptr != NULL ) */ dapl_os_free(cur_node, sizeof(DAPL_PROVIDER_LIST_NODE)); } /* end while (NULL != g_dapl_provider_list.head) */ }