src/dpdk/lib/librte_vhost/vhost_user.c
static int
vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
			struct VhostUserMsg *msg)
{
	uint32_t vring_idx;

	switch (msg->request.master) {
	case VHOST_USER_SET_VRING_KICK:
	case VHOST_USER_SET_VRING_CALL:
	case VHOST_USER_SET_VRING_ERR:
		vring_idx = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
		break;
	case VHOST_USER_SET_VRING_NUM:
	case VHOST_USER_SET_VRING_BASE:
	case VHOST_USER_SET_VRING_ENABLE:
		vring_idx = msg->payload.state.index;
		break;
	case VHOST_USER_SET_VRING_ADDR:
		vring_idx = msg->payload.addr.index;
		break;
	default:
		return 0;
	}

	if (vring_idx >= VHOST_MAX_VRING) {
		VHOST_LOG_CONFIG(ERR,
			"invalid vring index: %u\n", vring_idx);
		return -1;
	}

	if (dev->virtqueue[vring_idx])
		return 0;

	return alloc_vring_queue(dev, vring_idx);
}
/*
 * Allocate a queue pair if it hasn't been allocated yet
 */
Allocate a queue pair if it hasn't been allocated yet
Allocate a queue pair if it hasn ' t been allocated yet
static int
vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
			struct VhostUserMsg *msg)
{
	uint32_t vring_idx;
	switch (msg->request.master) {
	case VHOST_USER_SET_VRING_KICK:
	case VHOST_USER_SET_VRING_CALL:
	case VHOST_USER_SET_VRING_ERR:
		vring_idx = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
		break;
	case VHOST_USER_SET_VRING_NUM:
	case VHOST_USER_SET_VRING_BASE:
	case VHOST_USER_SET_VRING_ENABLE:
		vring_idx = msg->payload.state.index;
		break;
	case VHOST_USER_SET_VRING_ADDR:
		vring_idx = msg->payload.addr.index;
		break;
	default:
		return 0;
	}
	if (vring_idx >= VHOST_MAX_VRING) {
		VHOST_LOG_CONFIG(ERR,
			"invalid vring index: %u\n", vring_idx);
		return -1;
	}
	if (dev->virtqueue[vring_idx])
		return 0;
	return alloc_vring_queue(dev, vring_idx);
}
static int vhost_user_check_and_alloc_queue_pair ( struct virtio_net * dev , struct VhostUserMsg * msg ) { uint32_t vring_idx ; switch ( msg -> request . master ) { case VHOST_USER_SET_VRING_KICK : case VHOST_USER_SET_VRING_CALL : case VHOST_USER_SET_VRING_ERR : vring_idx = msg -> payload . u64 & VHOST_USER_VRING_IDX_MASK ; break ; case VHOST_USER_SET_VRING_NUM : case VHOST_USER_SET_VRING_BASE : case VHOST_USER_SET_VRING_ENABLE : vring_idx = msg -> payload . state . index ; break ; case VHOST_USER_SET_VRING_ADDR : vring_idx = msg -> payload . addr . index ; break ; default : return 0 ; } if ( vring_idx >= VHOST_MAX_VRING ) { VHOST_LOG_CONFIG ( ERR , " \n " , vring_idx ) ; return -1 ; } if ( dev -> virtqueue [ vring_idx ] ) return 0 ; return alloc_vring_queue ( dev , vring_idx ) ; }
Allocate a queue pair if it hasn't been allocated yet
Allocate a queue pair if it hasn ' t been allocated yet