FreeBSD/sys/dev/xen/blkback/blkback.c
/**
 * Request resources and do basic request setup.
 *
 * \param xbb          Per-instance xbb configuration structure.
 * \param reqlist      Pointer to reqlist pointer.
 * \param ring_req     Pointer to a block ring request.
 * \param ring_index   The ring index of this request.
 *
 * \return  0 for success, non-zero for failure.
 */
Request resources and do basic request setup.
\param xbb          Per-instance xbb configuration structure.
\param reqlist      Pointer to reqlist pointer.
\param ring_req     Pointer to a block ring request.
\param ring_index   The ring index of this request.

\return  0 for success, non-zero for failure.
Request resources and do basic request setup . \ param xbb Per - instance xbb configuration structure . \ param reqlist Pointer to reqlist pointer . \ param ring_req Pointer to a block ring request . \ param ring_index The ring index of this request . \ return 0 for success non - zero for failure .
static int
xbb_get_resources(struct xbb_softc *xbb, struct xbb_xen_reqlist **reqlist,
		  blkif_request_t *ring_req, RING_IDX ring_idx)
{
	struct xbb_xen_reqlist *nreqlist;
	struct xbb_xen_req     *nreq;
	nreqlist = NULL;
	nreq     = NULL;
	mtx_lock(&xbb->lock);
	if ((xbb->flags & XBBF_SHUTDOWN) != 0) {
		mtx_unlock(&xbb->lock);
		return (1);
	}
	if (*reqlist == NULL) {
		nreqlist = xbb_get_reqlist(xbb);
		if (nreqlist == NULL)
			goto bailout_error;
	}
	nreq = xbb_get_req(xbb);
	if (nreq == NULL)
		goto bailout_error;
	mtx_unlock(&xbb->lock);
	if (*reqlist == NULL) {
		*reqlist = nreqlist;
		nreqlist->operation = ring_req->operation;
		nreqlist->starting_sector_number = ring_req->sector_number;
		STAILQ_INSERT_TAIL(&xbb->reqlist_pending_stailq, nreqlist,
				   links);
	}
	nreq->reqlist = *reqlist;
	nreq->req_ring_idx = ring_idx;
	nreq->id = ring_req->id;
	nreq->operation = ring_req->operation;
	if (xbb->abi != BLKIF_PROTOCOL_NATIVE) {
		bcopy(ring_req, &nreq->ring_req_storage, sizeof(*ring_req));
		nreq->ring_req = &nreq->ring_req_storage;
	} else {
		nreq->ring_req = ring_req;
	}
	binuptime(&nreq->ds_t0);
	devstat_start_transaction(xbb->xbb_stats_in, &nreq->ds_t0);
	STAILQ_INSERT_TAIL(&(*reqlist)->contig_req_list, nreq, links);
	(*reqlist)->num_children++;
	(*reqlist)->nr_segments += ring_req->nr_segments;
	return (0);
bailout_error:
	xbb->flags |= XBBF_RESOURCE_SHORTAGE;
	xbb->request_shortages++;
	if (nreq != NULL)
		xbb_release_req(xbb, nreq);
	if (nreqlist != NULL)
		xbb_release_reqlist(xbb, nreqlist,  0);
	mtx_unlock(&xbb->lock);
	return (1);
}
static int xbb_get_resources ( struct xbb_softc * xbb , struct xbb_xen_reqlist * * reqlist , blkif_request_t * ring_req , RING_IDX ring_idx ) { struct xbb_xen_reqlist * nreqlist ; struct xbb_xen_req * nreq ; nreqlist = NULL ; nreq = NULL ; mtx_lock ( & xbb -> lock ) ; if ( ( xbb -> flags & XBBF_SHUTDOWN ) != 0 ) { mtx_unlock ( & xbb -> lock ) ; return ( 1 ) ; } if ( * reqlist == NULL ) { nreqlist = xbb_get_reqlist ( xbb ) ; if ( nreqlist == NULL ) goto bailout_error ; } nreq = xbb_get_req ( xbb ) ; if ( nreq == NULL ) goto bailout_error ; mtx_unlock ( & xbb -> lock ) ; if ( * reqlist == NULL ) { * reqlist = nreqlist ; nreqlist -> operation = ring_req -> operation ; nreqlist -> starting_sector_number = ring_req -> sector_number ; STAILQ_INSERT_TAIL ( & xbb -> reqlist_pending_stailq , nreqlist , links ) ; } nreq -> reqlist = * reqlist ; nreq -> req_ring_idx = ring_idx ; nreq -> id = ring_req -> id ; nreq -> operation = ring_req -> operation ; if ( xbb -> abi != BLKIF_PROTOCOL_NATIVE ) { bcopy ( ring_req , & nreq -> ring_req_storage , sizeof ( * ring_req ) ) ; nreq -> ring_req = & nreq -> ring_req_storage ; } else { nreq -> ring_req = ring_req ; } binuptime ( & nreq -> ds_t0 ) ; devstat_start_transaction ( xbb -> xbb_stats_in , & nreq -> ds_t0 ) ; STAILQ_INSERT_TAIL ( & ( * reqlist ) -> contig_req_list , nreq , links ) ; ( * reqlist ) -> num_children ++ ; ( * reqlist ) -> nr_segments += ring_req -> nr_segments ; return ( 0 ) ; bailout_error : xbb -> flags |= XBBF_RESOURCE_SHORTAGE ; xbb -> request_shortages ++ ; if ( nreq != NULL ) xbb_release_req ( xbb , nreq ) ; if ( nreqlist != NULL ) xbb_release_reqlist ( xbb , nreqlist , 0 ) ; mtx_unlock ( & xbb -> lock ) ; return ( 1 ) ; }
Request resources and do basic request setup.
Request resources and do basic request setup .
/*
	 * We don't allow new resources to be allocated if we're in the
	 * process of shutting down.
	 */ /*
	 * Allocate a reqlist if the caller doesn't have one already.
	 */ /* We always allocate a request. */ /*
	 * We're out of resources, so set the shortage flag.  The next time
	 * a request is released, we'll try waking up the work thread to
	 * see if we can allocate more resources.
	 */ /*wakeup*/