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: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13791
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Changpeng Liu 2022-07-26 15:46:39 +08:00 committed by Tomasz Zawadzki
parent 515d028ec4
commit a02483e67c
3 changed files with 7 additions and 36 deletions

View File

@ -161,26 +161,24 @@ virtio_free_queues(struct virtio_dev *dev)
} }
static int 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; uint16_t i;
int ret; int ret;
nr_vq = request_vq_num + fixed_vq_num; if (max_queues == 0) {
if (nr_vq == 0) {
/* perfectly fine to have a device with no virtqueues. */ /* perfectly fine to have a device with no virtqueues. */
return 0; return 0;
} }
assert(dev->vqs == NULL); 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) { 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; return -ENOMEM;
} }
for (i = 0; i < nr_vq; i++) { for (i = 0; i < max_queues; i++) {
ret = virtio_init_queue(dev, i); ret = virtio_init_queue(dev, i);
if (ret < 0) { if (ret < 0) {
virtio_free_queues(dev); 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; dev->fixed_queues_num = fixed_vq_num;
return 0; return 0;
} }

View File

@ -357,7 +357,7 @@ virtio_user_scsi_dev_create(const char *name, const char *path,
feature_bits = VIRTIO_SCSI_DEV_SUPPORTED_FEATURES; feature_bits = VIRTIO_SCSI_DEV_SUPPORTED_FEATURES;
feature_bits |= (1ULL << VHOST_USER_F_PROTOCOL_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) { if (rc != 0) {
virtio_dev_destruct(vdev); virtio_dev_destruct(vdev);
free(svdev); free(svdev);

View File

@ -209,33 +209,6 @@ virtio_dev_init(struct virtio_dev *vdev, const char *socket_path, uint64_t flags
static int static int
blk_dev_init(struct virtio_dev *vdev, const char *socket_path, uint16_t max_queues) 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); return virtio_dev_init(vdev, socket_path, VIRTIO_BLK_DEV_SUPPORTED_FEATURES, max_queues);
} }