lib/nvmf/vfio_user.c
/* This function can only fail because of memory allocation errors. */
This function can only fail because of memory allocation errors.
This function can only fail because of memory allocation errors .
static int
init_qp(struct nvmf_vfio_user_ctrlr *ctrlr, struct spdk_nvmf_transport *transport,
	const uint32_t qsize, const uint16_t id)
{
	uint32_t i;
	struct nvmf_vfio_user_qpair *qpair;
	struct nvmf_vfio_user_req *vu_req, *tmp;
	struct spdk_nvmf_request *req;
	assert(ctrlr != NULL);
	assert(transport != NULL);
	qpair = calloc(1, sizeof(*qpair));
	if (qpair == NULL) {
		return -ENOMEM;
	}
	qpair->sq.sg = calloc(1, dma_sg_size());
	if (qpair->sq.sg == NULL) {
		free(qpair);
		return -ENOMEM;
	}
	qpair->cq.sg = calloc(1, dma_sg_size());
	if (qpair->cq.sg == NULL) {
		free(qpair->sq.sg);
		free(qpair);
		return -ENOMEM;
	}
	qpair->qpair.qid = id;
	qpair->qpair.transport = transport;
	qpair->ctrlr = ctrlr;
	qpair->qsize = qsize;
	TAILQ_INIT(&qpair->reqs);
	qpair->reqs_internal = calloc(qsize, sizeof(struct nvmf_vfio_user_req));
	if (qpair->reqs_internal == NULL) {
		SPDK_ERRLOG("%s: error allocating reqs: %m\n", ctrlr_id(ctrlr));
		goto reqs_err;
	}
	for (i = 0; i < qsize; i++) {
		vu_req = &qpair->reqs_internal[i];
		vu_req->sg = calloc(NVMF_VFIO_USER_MAX_IOVECS, dma_sg_size());
		if (vu_req->sg == NULL) {
			goto sg_err;
		}
		req = &vu_req->req;
		req->qpair = &qpair->qpair;
		req->rsp = (union nvmf_c2h_msg *)&vu_req->rsp;
		req->cmd = (union nvmf_h2c_msg *)&vu_req->cmd;
		TAILQ_INSERT_TAIL(&qpair->reqs, vu_req, link);
	}
	ctrlr->qp[id] = qpair;
	return 0;
sg_err:
	TAILQ_FOREACH_SAFE(vu_req, &qpair->reqs, link, tmp) {
		free(vu_req->sg);
	}
	free(qpair->reqs_internal);
reqs_err:
	free(qpair->sq.sg);
	free(qpair->cq.sg);
	free(qpair);
	return -ENOMEM;
}
static int init_qp ( struct nvmf_vfio_user_ctrlr * ctrlr , struct spdk_nvmf_transport * transport , const uint32_t qsize , const uint16_t id ) { uint32_t i ; struct nvmf_vfio_user_qpair * qpair ; struct nvmf_vfio_user_req * vu_req , * tmp ; struct spdk_nvmf_request * req ; assert ( ctrlr != NULL ) ; assert ( transport != NULL ) ; qpair = calloc ( 1 , sizeof ( * qpair ) ) ; if ( qpair == NULL ) { return - ENOMEM ; } qpair -> sq . sg = calloc ( 1 , dma_sg_size ( ) ) ; if ( qpair -> sq . sg == NULL ) { free ( qpair ) ; return - ENOMEM ; } qpair -> cq . sg = calloc ( 1 , dma_sg_size ( ) ) ; if ( qpair -> cq . sg == NULL ) { free ( qpair -> sq . sg ) ; free ( qpair ) ; return - ENOMEM ; } qpair -> qpair . qid = id ; qpair -> qpair . transport = transport ; qpair -> ctrlr = ctrlr ; qpair -> qsize = qsize ; TAILQ_INIT ( & qpair -> reqs ) ; qpair -> reqs_internal = calloc ( qsize , sizeof ( struct nvmf_vfio_user_req ) ) ; if ( qpair -> reqs_internal == NULL ) { SPDK_ERRLOG ( " \n " , ctrlr_id ( ctrlr ) ) ; goto reqs_err ; } for ( i = 0 ; i < qsize ; i ++ ) { vu_req = & qpair -> reqs_internal [ i ] ; vu_req -> sg = calloc ( NVMF_VFIO_USER_MAX_IOVECS , dma_sg_size ( ) ) ; if ( vu_req -> sg == NULL ) { goto sg_err ; } req = & vu_req -> req ; req -> qpair = & qpair -> qpair ; req -> rsp = ( union nvmf_c2h_msg * ) & vu_req -> rsp ; req -> cmd = ( union nvmf_h2c_msg * ) & vu_req -> cmd ; TAILQ_INSERT_TAIL ( & qpair -> reqs , vu_req , link ) ; } ctrlr -> qp [ id ] = qpair ; return 0 ; sg_err : TAILQ_FOREACH_SAFE ( vu_req , & qpair -> reqs , link , tmp ) { free ( vu_req -> sg ) ; } free ( qpair -> reqs_internal ) ; reqs_err : free ( qpair -> sq . sg ) ; free ( qpair -> cq . sg ) ; free ( qpair ) ; return - ENOMEM ; }
This function can only fail because of memory allocation errors.
This function can only fail because of memory allocation errors .