diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index d8c94a8c2..d58f67edf 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -99,6 +99,12 @@ struct spdk_bdev_channel { struct spdk_bdev_io_stat stat; + /* + * Count of I/O submitted to bdev module and waiting for completion. + * Incremented before submit_request() is called on an spdk_bdev_io. + */ + uint64_t io_outstanding; + #ifdef SPDK_CONFIG_VTUNE uint64_t start_tsc; uint64_t interval_tsc; @@ -483,6 +489,7 @@ __submit_request(struct spdk_bdev *bdev, struct spdk_bdev_io *bdev_io) ch = bdev_io->ch->channel; + bdev_io->ch->io_outstanding++; bdev_io->in_submit_request = true; bdev->fn_table->submit_request(ch, bdev_io); bdev_io->in_submit_request = false; @@ -509,6 +516,12 @@ spdk_bdev_io_resubmit(struct spdk_bdev_io *bdev_io, struct spdk_bdev *new_bdev) */ bdev_io->gencnt = new_bdev->gencnt; + /* + * This bdev_io was already submitted so decrement io_outstanding to ensure it + * does not get double-counted. + */ + assert(bdev_io->ch->io_outstanding > 0); + bdev_io->ch->io_outstanding--; __submit_request(new_bdev, bdev_io); } @@ -583,6 +596,7 @@ spdk_bdev_channel_create(void *io_device, void *ctx_buf) ch->channel = bdev->fn_table->get_io_channel(bdev->ctxt); ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr); memset(&ch->stat, 0, sizeof(ch->stat)); + ch->io_outstanding = 0; #ifdef SPDK_CONFIG_VTUNE { @@ -626,6 +640,7 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf) _spdk_bdev_abort_io(&mgmt_channel->need_buf_small, ch); _spdk_bdev_abort_io(&mgmt_channel->need_buf_large, ch); + assert(ch->io_outstanding == 0); spdk_put_io_channel(ch->channel); spdk_put_io_channel(ch->mgmt_channel); } @@ -1132,6 +1147,8 @@ spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status sta return; } + assert(bdev_io->ch->io_outstanding > 0); + bdev_io->ch->io_outstanding--; if (bdev_io->type == SPDK_BDEV_IO_TYPE_RESET) { /* Successful reset */ if (status == SPDK_BDEV_IO_STATUS_SUCCESS) {