Skip to content

Commit

Permalink
module/bdev_virtio_scsi: use the correct num_queues value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
changpe1 authored and tomzawadzki committed Aug 4, 2022
1 parent 515d028 commit a02483e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
14 changes: 6 additions & 8 deletions lib/virtio/virtio.c
Expand Up @@ -161,34 +161,32 @@ 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);
return ret;
}
}

dev->max_queues = nr_vq;
dev->max_queues = max_queues;
dev->fixed_queues_num = fixed_vq_num;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion module/bdev/virtio/bdev_virtio_scsi.c
Expand Up @@ -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);
Expand Down
27 changes: 0 additions & 27 deletions test/app/fuzz/vhost_fuzz/vhost_fuzz.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit a02483e

Please sign in to comment.