lib/nvmf/vfio_user.c
/*
 * Deletes a completion or submission I/O queue.
 */
Deletes a completion or submission I/O queue.
Deletes a completion or submission I / O queue .
static int
handle_del_io_q(struct nvmf_vfio_user_ctrlr *ctrlr,
		struct spdk_nvme_cmd *cmd, const bool is_cq)
{
	uint16_t sct = SPDK_NVME_SCT_GENERIC;
	uint16_t sc = SPDK_NVME_SC_SUCCESS;
	struct nvmf_vfio_user_qpair *vu_qpair;
	struct vfio_user_delete_cq_ctx *ctx;
	SPDK_DEBUGLOG(nvmf_vfio, "%s: delete I/O %cQ: QID=%d\n",
		      ctrlr_id(ctrlr), is_cq ? 'C' : 'S',
		      cmd->cdw10_bits.delete_io_q.qid);
	if (!io_q_exists(ctrlr, cmd->cdw10_bits.delete_io_q.qid, is_cq)) {
		SPDK_ERRLOG("%s: I/O %cQ%d does not exist\n", ctrlr_id(ctrlr),
			    is_cq ? 'C' : 'S', cmd->cdw10_bits.delete_io_q.qid);
		sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
		sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER;
		goto out;
	}
	vu_qpair = ctrlr->qp[cmd->cdw10_bits.delete_io_q.qid];
	if (is_cq) {
		if (vu_qpair->state != VFIO_USER_QPAIR_SQ_DELETED) {
			SPDK_ERRLOG("%s: the associated SQ must be deleted first\n", ctrlr_id(ctrlr));
			sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
			sc = SPDK_NVME_SC_INVALID_QUEUE_DELETION;
			goto out;
		}
		ctx = calloc(1, sizeof(*ctx));
		if (!ctx) {
			sct = SPDK_NVME_SCT_GENERIC;
			sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
			goto out;
		}
		ctx->vu_ctrlr = ctrlr;
		ctx->delete_io_cq_cmd = *cmd;
		spdk_nvmf_qpair_disconnect(&vu_qpair->qpair, vfio_user_qpair_delete_cb, ctx);
		return 0;
	} else {
		if (vu_qpair->state == VFIO_USER_QPAIR_SQ_DELETED) {
			SPDK_DEBUGLOG(nvmf_vfio, "%s: SQ%u is already deleted\n", ctrlr_id(ctrlr),
				      cmd->cdw10_bits.delete_io_q.qid);
			sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
			sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER;
			goto out;
		}
		vu_qpair->state = VFIO_USER_QPAIR_SQ_DELETED;
		vfu_unmap_sg(ctrlr->endpoint->vfu_ctx, vu_qpair->sq.sg, &vu_qpair->sq.iov, 1);
		vu_qpair->sq.addr = NULL;
	}
out:
	return post_completion(ctrlr, &ctrlr->qp[0]->cq, 0, 0, cmd->cid, sc, sct);
}
static int handle_del_io_q ( struct nvmf_vfio_user_ctrlr * ctrlr , struct spdk_nvme_cmd * cmd , const bool is_cq ) { uint16_t sct = SPDK_NVME_SCT_GENERIC ; uint16_t sc = SPDK_NVME_SC_SUCCESS ; struct nvmf_vfio_user_qpair * vu_qpair ; struct vfio_user_delete_cq_ctx * ctx ; SPDK_DEBUGLOG ( nvmf_vfio , " \n " , ctrlr_id ( ctrlr ) , is_cq ? ' ' : ' ' , cmd -> cdw10_bits . delete_io_q . qid ) ; if ( ! io_q_exists ( ctrlr , cmd -> cdw10_bits . delete_io_q . qid , is_cq ) ) { SPDK_ERRLOG ( " \n " , ctrlr_id ( ctrlr ) , is_cq ? ' ' : ' ' , cmd -> cdw10_bits . delete_io_q . qid ) ; sct = SPDK_NVME_SCT_COMMAND_SPECIFIC ; sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER ; goto out ; } vu_qpair = ctrlr -> qp [ cmd -> cdw10_bits . delete_io_q . qid ] ; if ( is_cq ) { if ( vu_qpair -> state != VFIO_USER_QPAIR_SQ_DELETED ) { SPDK_ERRLOG ( " \n " , ctrlr_id ( ctrlr ) ) ; sct = SPDK_NVME_SCT_COMMAND_SPECIFIC ; sc = SPDK_NVME_SC_INVALID_QUEUE_DELETION ; goto out ; } ctx = calloc ( 1 , sizeof ( * ctx ) ) ; if ( ! ctx ) { sct = SPDK_NVME_SCT_GENERIC ; sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR ; goto out ; } ctx -> vu_ctrlr = ctrlr ; ctx -> delete_io_cq_cmd = * cmd ; spdk_nvmf_qpair_disconnect ( & vu_qpair -> qpair , vfio_user_qpair_delete_cb , ctx ) ; return 0 ; } else { if ( vu_qpair -> state == VFIO_USER_QPAIR_SQ_DELETED ) { SPDK_DEBUGLOG ( nvmf_vfio , " \n " , ctrlr_id ( ctrlr ) , cmd -> cdw10_bits . delete_io_q . qid ) ; sct = SPDK_NVME_SCT_COMMAND_SPECIFIC ; sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER ; goto out ; } vu_qpair -> state = VFIO_USER_QPAIR_SQ_DELETED ; vfu_unmap_sg ( ctrlr -> endpoint -> vfu_ctx , vu_qpair -> sq . sg , & vu_qpair -> sq . iov , 1 ) ; vu_qpair -> sq . addr = NULL ; } out : return post_completion ( ctrlr , & ctrlr -> qp [ 0 ] -> cq , 0 , 0 , cmd -> cid , sc , sct ) ; }
Deletes a completion or submission I/O queue.
Deletes a completion or submission I / O queue .
/* SQ must have been deleted first */ /*
		 * This doesn't actually delete the SQ, We're merely telling the poll_group_poll
		 * function to skip checking this SQ.  The queue pair will be disconnected in Delete
		 * IO CQ command.
		 */