Commit a02483e6 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

module/bdev_virtio_scsi: use the correct `num_queues` value



Parameter `num_queues` for virtio_scsi PCI device means
maximum number of queues, it SHOULD include the `eventq`
and `controlq`, while for `vhost_user` RPC call, it means
the number of IO queues, so here we use it as `max_queues`
in lib/virtio and add the fixed number queues for `vhost_user`
SCSI device.

Also fix `vhost_fuzz` to get `num_queues` earlier than
negotiate the feature bits.

Change-Id: I41b3da5e4b4dc37127befd414226ea6eafcd9ad0
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13791


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 515d028e
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -161,26 +161,24 @@ virtio_free_queues(struct virtio_dev *dev)
}

static int
virtio_alloc_queues(struct virtio_dev *dev, uint16_t request_vq_num, uint16_t fixed_vq_num)
virtio_alloc_queues(struct virtio_dev *dev, uint16_t max_queues, uint16_t fixed_vq_num)
{
	uint16_t nr_vq;
	uint16_t i;
	int ret;

	nr_vq = request_vq_num + fixed_vq_num;
	if (nr_vq == 0) {
	if (max_queues == 0) {
		/* perfectly fine to have a device with no virtqueues. */
		return 0;
	}

	assert(dev->vqs == NULL);
	dev->vqs = calloc(1, sizeof(struct virtqueue *) * nr_vq);
	dev->vqs = calloc(1, sizeof(struct virtqueue *) * max_queues);
	if (!dev->vqs) {
		SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", nr_vq);
		SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", max_queues);
		return -ENOMEM;
	}

	for (i = 0; i < nr_vq; i++) {
	for (i = 0; i < max_queues; i++) {
		ret = virtio_init_queue(dev, i);
		if (ret < 0) {
			virtio_free_queues(dev);
@@ -188,7 +186,7 @@ virtio_alloc_queues(struct virtio_dev *dev, uint16_t request_vq_num, uint16_t fi
		}
	}

	dev->max_queues = nr_vq;
	dev->max_queues = max_queues;
	dev->fixed_queues_num = fixed_vq_num;
	return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -357,7 +357,7 @@ virtio_user_scsi_dev_create(const char *name, const char *path,

	feature_bits = VIRTIO_SCSI_DEV_SUPPORTED_FEATURES;
	feature_bits |= (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
	rc = virtio_scsi_dev_init(svdev, num_queues, feature_bits);
	rc = virtio_scsi_dev_init(svdev, num_queues + SPDK_VIRTIO_SCSI_QUEUE_NUM_FIXED, feature_bits);
	if (rc != 0) {
		virtio_dev_destruct(vdev);
		free(svdev);
+0 −27
Original line number Diff line number Diff line
@@ -209,33 +209,6 @@ virtio_dev_init(struct virtio_dev *vdev, const char *socket_path, uint64_t flags
static int
blk_dev_init(struct virtio_dev *vdev, const char *socket_path, uint16_t max_queues)
{
	uint16_t host_max_queues;
	int rc;

	if (virtio_dev_has_feature(vdev, VIRTIO_BLK_F_MQ)) {
		rc = virtio_dev_read_dev_config(vdev, offsetof(struct virtio_blk_config, num_queues),
						&host_max_queues, sizeof(host_max_queues));
		if (rc) {
			fprintf(stderr, "%s: config read failed: %s\n", vdev->name, spdk_strerror(-rc));
			return rc;
		}
	} else {
		host_max_queues = 1;
	}

	if (max_queues == 0) {
		fprintf(stderr, "%s: requested 0 request queues (%"PRIu16" available).\n",
			vdev->name, host_max_queues);
		return -EINVAL;
	}

	if (max_queues > host_max_queues) {
		fprintf(stderr, "%s: requested %"PRIu16" request queues "
			"but only %"PRIu16" available.\n",
			vdev->name, max_queues, host_max_queues);
		max_queues = host_max_queues;
	}

	return virtio_dev_init(vdev, socket_path, VIRTIO_BLK_DEV_SUPPORTED_FEATURES, max_queues);
}