lib/vhost: Fix ENOMEM resubmission for vhost_blk

In the current behavior the iovcnt is lowered before sending it to
the next BDEV in the stack - however if the returned value is ENOMEM
(due to eg. not enough bdev requests in the pool), the request needs
to be returned to its original state, as it would be resubmitted with
skipped iov entries.

Signed-off-by: Kozlowski Mateusz <mateusz.kozlowski@intel.com>
Change-Id: I7240510a2ec04594b248f7347e86ac11ecfd26a0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11976
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Kozlowski Mateusz 2022-03-17 16:15:27 +01:00 committed by Tomasz Zawadzki
parent a2340f36fa
commit adc36d5be3

View File

@ -458,6 +458,7 @@ process_blk_request(struct spdk_vhost_blk_task *task,
uint32_t type;
uint64_t flush_bytes;
uint32_t payload_len;
uint16_t iovcnt;
int rc;
iov = &task->iovs[0];
@ -483,7 +484,7 @@ process_blk_request(struct spdk_vhost_blk_task *task,
payload_len = task->payload_size;
task->status = iov->iov_base;
payload_len -= sizeof(*req) + sizeof(*task->status);
task->iovcnt -= 2;
iovcnt = task->iovcnt - 2;
type = req->type;
#ifdef VIRTIO_BLK_T_BARRIER
@ -504,12 +505,12 @@ process_blk_request(struct spdk_vhost_blk_task *task,
if (type == VIRTIO_BLK_T_IN) {
task->used_len = payload_len + sizeof(*task->status);
rc = spdk_bdev_readv(bvdev->bdev_desc, bvsession->io_channel,
&task->iovs[1], task->iovcnt, req->sector * 512,
&task->iovs[1], iovcnt, req->sector * 512,
payload_len, blk_request_complete_cb, task);
} else if (!bvdev->readonly) {
task->used_len = sizeof(*task->status);
rc = spdk_bdev_writev(bvdev->bdev_desc, bvsession->io_channel,
&task->iovs[1], task->iovcnt, req->sector * 512,
&task->iovs[1], iovcnt, req->sector * 512,
payload_len, blk_request_complete_cb, task);
} else {
SPDK_DEBUGLOG(vhost_blk, "Device is in read-only mode!\n");
@ -604,7 +605,7 @@ process_blk_request(struct spdk_vhost_blk_task *task,
}
break;
case VIRTIO_BLK_T_GET_ID:
if (!task->iovcnt || !payload_len) {
if (!iovcnt || !payload_len) {
invalid_blk_request(task, VIRTIO_BLK_S_UNSUPP);
return -1;
}