Skip to content

Commit

Permalink
bdev/uring: handle the out of resoruce from uring
Browse files Browse the repository at this point in the history
To fix issue: spdk#2775

Change-Id: I57172ba58419be56702157931d7a617c2e959041
Signed-off-by: GangCao <[email protected]>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15424
Tested-by: SPDK CI Jenkins <[email protected]>
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <[email protected]>
Reviewed-by: Xiaodong Liu <[email protected]>
Reviewed-by: wanghailiang <[email protected]>
Reviewed-by: Shuhei Matsumoto <[email protected]>
  • Loading branch information
Comphix authored and tomzawadzki committed Nov 15, 2022
1 parent 8dc8784 commit 969df28
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions module/bdev/uring/bdev_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ bdev_uring_readv(struct bdev_uring *uring, struct spdk_io_channel *ch,
struct io_uring_sqe *sqe;

sqe = io_uring_get_sqe(&group_ch->uring);
if (!sqe) {
SPDK_DEBUGLOG(uring, "get sqe failed as out of resource\n");
return -ENOMEM;
}

io_uring_prep_readv(sqe, uring->fd, iov, iovcnt, offset);
io_uring_sqe_set_data(sqe, uring_task);
uring_task->len = nbytes;
Expand All @@ -154,6 +159,11 @@ bdev_uring_writev(struct bdev_uring *uring, struct spdk_io_channel *ch,
struct io_uring_sqe *sqe;

sqe = io_uring_get_sqe(&group_ch->uring);
if (!sqe) {
SPDK_DEBUGLOG(uring, "get sqe failed as out of resource\n");
return -ENOMEM;
}

io_uring_prep_writev(sqe, uring->fd, iov, iovcnt, offset);
io_uring_sqe_set_data(sqe, uring_task);
uring_task->len = nbytes;
Expand Down Expand Up @@ -255,34 +265,40 @@ static void
bdev_uring_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
bool success)
{
int64_t ret = 0;

if (!success) {
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
return;
}

switch (bdev_io->type) {
case SPDK_BDEV_IO_TYPE_READ:
bdev_uring_readv((struct bdev_uring *)bdev_io->bdev->ctxt,
ch,
(struct bdev_uring_task *)bdev_io->driver_ctx,
bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt,
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen,
bdev_io->u.bdev.offset_blocks * bdev_io->bdev->blocklen);
ret = bdev_uring_readv((struct bdev_uring *)bdev_io->bdev->ctxt,
ch,
(struct bdev_uring_task *)bdev_io->driver_ctx,
bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt,
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen,
bdev_io->u.bdev.offset_blocks * bdev_io->bdev->blocklen);
break;
case SPDK_BDEV_IO_TYPE_WRITE:
bdev_uring_writev((struct bdev_uring *)bdev_io->bdev->ctxt,
ch,
(struct bdev_uring_task *)bdev_io->driver_ctx,
bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt,
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen,
bdev_io->u.bdev.offset_blocks * bdev_io->bdev->blocklen);
ret = bdev_uring_writev((struct bdev_uring *)bdev_io->bdev->ctxt,
ch,
(struct bdev_uring_task *)bdev_io->driver_ctx,
bdev_io->u.bdev.iovs,
bdev_io->u.bdev.iovcnt,
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen,
bdev_io->u.bdev.offset_blocks * bdev_io->bdev->blocklen);
break;
default:
SPDK_ERRLOG("Wrong io type\n");
break;
}

if (ret == -ENOMEM) {
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_NOMEM);
}
}

#ifdef SPDK_CONFIG_URING_ZNS
Expand Down

0 comments on commit 969df28

Please sign in to comment.