Example #1
0
DAT_RETURN
dapl_cr_handoff(
	IN DAT_CR_HANDLE cr_handle,
	IN DAT_CONN_QUAL cr_handoff)		/* handoff */
{
	DAPL_CR *cr_ptr;
	DAT_RETURN dat_status;

	if (DAPL_BAD_HANDLE(cr_handle, DAPL_MAGIC_CR)) {
		return (DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_CR));
	}

	cr_ptr = (DAPL_CR *)cr_handle;
	dat_status = dapls_ib_handoff_connection(cr_ptr, cr_handoff);

	/* Remove the CR from the queue, then free it */
	dapl_sp_remove_cr(cr_ptr->sp_ptr, cr_ptr);
	dapls_cr_free(cr_ptr);

	return (dat_status);
}
Example #2
0
/*
 * dapli_get_sp_ep
 *
 * Passive side of a connection is now fully established. Clean
 * up resources and obtain the EP pointer associated with a CR in
 * the SP
 *
 * Input:
 * 	ib_cm_handle,
 * 	sp_ptr
 *	connection_event
 *
 * Output:
 *	none
 *
 * Returns
 * 	ep_ptr
 *
 */
DAPL_EP *dapli_get_sp_ep(IN dp_ib_cm_handle_t ib_cm_handle,
			 IN DAPL_SP * sp_ptr, IN DAT_EVENT_NUMBER dat_event_num)
{
	DAPL_CR *cr_ptr;
	DAPL_EP *ep_ptr;

	/*
	 * acquire the lock, we may be racing with other threads here
	 */
	dapl_os_lock(&sp_ptr->header.lock);

	/* Verify under lock that the SP is still valid */
	if (sp_ptr->header.magic == DAPL_MAGIC_INVALID) {
		dapl_os_unlock(&sp_ptr->header.lock);
		return NULL;
	}
	/*
	 * There are potentially multiple connections in progress. Need to
	 * go through the list and find the one we are interested
	 * in. There is no guarantee of order. dapl_sp_search_cr
	 * leaves the CR on the SP queue.
	 */
	cr_ptr = dapl_sp_search_cr(sp_ptr, ib_cm_handle);
	if (cr_ptr == NULL) {
		dapl_os_unlock(&sp_ptr->header.lock);
		return NULL;
	}

	ep_ptr = (DAPL_EP *) cr_ptr->param.local_ep_handle;

	/* Quick check to ensure our EP is still valid */
	if ((DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP))) {
		ep_ptr = NULL;
	}

	/* The CR record is discarded in all except for the CONNECTED case,
	 * as it will have no further relevance.
	 */
	if (dat_event_num != DAT_CONNECTION_EVENT_ESTABLISHED) {
		/* Remove the CR from the queue */
		dapl_sp_remove_cr(sp_ptr, cr_ptr);

		if (ep_ptr != NULL) {
			ep_ptr->cr_ptr = NULL;
		}

		/*
		 * If this SP has been removed from service, free it
		 * up after the last CR is removed
		 */
		if (sp_ptr->listening != DAT_TRUE && sp_ptr->cr_list_count == 0
		    && sp_ptr->state != DAPL_SP_STATE_FREE
		    && sp_ptr->state != DAPL_SP_STATE_RSP_LISTENING) {
			dapl_dbg_log(DAPL_DBG_TYPE_CM,
				     "--> dapli_get_sp_ep! disconnect dump sp: %p \n",
				     sp_ptr);
			/* Decrement the ref count on the EVD */
			if (sp_ptr->evd_handle) {
				dapl_os_atomic_dec(&
						   ((DAPL_EVD *) sp_ptr->
						    evd_handle)->evd_ref_count);
				sp_ptr->evd_handle = NULL;
			}
			sp_ptr->state = DAPL_SP_STATE_FREE;
			dapl_os_unlock(&sp_ptr->header.lock);
			(void)dapls_ib_remove_conn_listener(sp_ptr->header.
							    owner_ia, sp_ptr);
			dapls_ia_unlink_sp((DAPL_IA *) sp_ptr->header.owner_ia,
					   sp_ptr);
			dapls_sp_free_sp(sp_ptr);
			dapls_cr_free(cr_ptr);
			goto skip_unlock;
		}

		dapl_os_unlock(&sp_ptr->header.lock);
		/* free memory outside of the lock */
		dapls_cr_free(cr_ptr);
	} else {
		dapl_os_unlock(&sp_ptr->header.lock);
	}

      skip_unlock:
	return ep_ptr;
}
Example #3
0
/*
 * dapli_connection_request
 *
 * Process a connection request on the Passive side of a connection.
 * Create a CR record and link it on to the SP so we can update it
 * and free it later. Create an EP if specified by the PSP flags.
 *
 * Input:
 * 	ib_cm_handle,
 * 	sp_ptr
 * 	event_ptr
 *	prd_ptr
 *
 * Output:
 * 	None
 *
 * Returns
 *	DAT_INSUFFICIENT_RESOURCES
 *	DAT_SUCCESS
 *
 */
DAT_RETURN
dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,
			 IN DAPL_SP * sp_ptr,
			 IN DAPL_PRIVATE * prd_ptr, IN int private_data_size,
			 IN DAPL_EVD * evd_ptr)
{
	DAT_RETURN dat_status;

	DAPL_CR *cr_ptr;
	DAPL_EP *ep_ptr;
	DAPL_IA *ia_ptr;
	DAT_SP_HANDLE sp_handle;

	cr_ptr = dapls_cr_alloc(sp_ptr->header.owner_ia);
	if (cr_ptr == NULL) {
		/* Invoking function will call dapls_ib_cm_reject() */
		return DAT_INSUFFICIENT_RESOURCES;
	}

	/*
	 * Set up the CR
	 */
	cr_ptr->sp_ptr = sp_ptr;	/* maintain sp_ptr in case of reject */
	cr_ptr->param.remote_port_qual = 0;
	cr_ptr->ib_cm_handle = ib_cm_handle;
#ifdef IBHOSTS_NAMING
	/*
	 * Special case: pull the remote HCA address from the private data
	 * prefix. This is a spec violation as it introduces a protocol, but
	 * some implementations may find it necessary for a time.
	 */
	cr_ptr->remote_ia_address = prd_ptr->hca_address;
#endif				/* IBHOSTS_NAMING */
	cr_ptr->param.remote_ia_address_ptr =
	    (DAT_IA_ADDRESS_PTR) & cr_ptr->remote_ia_address;
	/*
	 * Copy the remote address and private data out of the private_data
	 * payload and put them in a local structure
	 */

	/* Private data size will be determined by the provider layer */
	cr_ptr->param.private_data = cr_ptr->private_data;
	cr_ptr->param.private_data_size = private_data_size;
	if (cr_ptr->param.private_data_size > 0) {
		dapl_os_memcpy(cr_ptr->private_data,
			       prd_ptr->private_data,
			       DAPL_MIN(cr_ptr->param.private_data_size,
					DAPL_MAX_PRIVATE_DATA_SIZE));
	}

	/* EP will be NULL unless RSP service point */
	ep_ptr = (DAPL_EP *) sp_ptr->ep_handle;

	if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
		/*
		 * Never true for RSP connections
		 *
		 * Create an EP for the user. If we can't allocate an
		 * EP we are out of resources and need to tell the
		 * requestor that we cant help them.
		 */
		ia_ptr = sp_ptr->header.owner_ia;
		ep_ptr = dapl_ep_alloc(ia_ptr, NULL);
		if (ep_ptr == NULL) {
			dapls_cr_free(cr_ptr);
			/* Invoking function will call dapls_ib_cm_reject() */
			return DAT_INSUFFICIENT_RESOURCES;
		}
		ep_ptr->param.ia_handle = ia_ptr;
		ep_ptr->param.local_ia_address_ptr =
		    (DAT_IA_ADDRESS_PTR) & ia_ptr->hca_ptr->hca_address;

		/* Link the EP onto the IA */
		dapl_ia_link_ep(ia_ptr, ep_ptr);
	}

	cr_ptr->param.local_ep_handle = ep_ptr;

	if (ep_ptr != NULL) {
		/* Assign valid EP fields: RSP and PSP_PROVIDER_FLAG only */
		if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
			ep_ptr->param.ep_state =
			    DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING;
		} else {
			/* RSP */
			dapl_os_assert(sp_ptr->header.handle_type ==
				       DAT_HANDLE_TYPE_RSP);
			ep_ptr->param.ep_state =
			    DAT_EP_STATE_PASSIVE_CONNECTION_PENDING;
		}
		dapl_ep_link_cm(ep_ptr, ib_cm_handle);
	}

	/* link the CR onto the SP so we can pick it up later */
	dapl_sp_link_cr(sp_ptr, cr_ptr);

	/* Post the event.  */
	/* assign sp_ptr to union to avoid typecast errors from some compilers */
	sp_handle.psp_handle = (DAT_PSP_HANDLE) sp_ptr;

	dat_status = dapls_evd_post_cr_arrival_event(evd_ptr,
						     DAT_CONNECTION_REQUEST_EVENT,
						     sp_handle,
						     (DAT_IA_ADDRESS_PTR)
						     & sp_ptr->header.owner_ia->
						     hca_ptr->hca_address,
						     sp_ptr->conn_qual,
						     (DAT_CR_HANDLE) cr_ptr);

	if (dat_status != DAT_SUCCESS) {
		(void)dapls_ib_reject_connection(ib_cm_handle,
						 DAT_CONNECTION_EVENT_BROKEN,
						 0, NULL);

		/* Take the CR off the list, we can't use it */
		dapl_os_lock(&sp_ptr->header.lock);
		dapl_sp_remove_cr(sp_ptr, cr_ptr);
		dapl_os_unlock(&sp_ptr->header.lock);
		dapls_cr_free(cr_ptr);
		return DAT_INSUFFICIENT_RESOURCES;
	}

	return DAT_SUCCESS;
}
Example #4
0
/*
 * 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) */
}