diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 4f9db00258..6515435152 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -4927,6 +4927,10 @@ spdk_bdev_nvme_admin_passthru(struct spdk_bdev_desc *desc, struct spdk_io_channe return -EBADF; } + if (spdk_unlikely(!bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_NVME_ADMIN))) { + return -ENOTSUP; + } + bdev_io = bdev_channel_get_io(channel); if (!bdev_io) { return -ENOMEM; @@ -4965,6 +4969,10 @@ spdk_bdev_nvme_io_passthru(struct spdk_bdev_desc *desc, struct spdk_io_channel * return -EBADF; } + if (spdk_unlikely(!bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_NVME_IO))) { + return -ENOTSUP; + } + bdev_io = bdev_channel_get_io(channel); if (!bdev_io) { return -ENOMEM; @@ -5003,6 +5011,10 @@ spdk_bdev_nvme_io_passthru_md(struct spdk_bdev_desc *desc, struct spdk_io_channe return -EBADF; } + if (spdk_unlikely(!bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_NVME_IO_MD))) { + return -ENOTSUP; + } + bdev_io = bdev_channel_get_io(channel); if (!bdev_io) { return -ENOMEM; diff --git a/test/unit/lib/bdev/bdev.c/bdev_ut.c b/test/unit/lib/bdev/bdev.c/bdev_ut.c index bd6602f9b0..7a5f7b886e 100644 --- a/test/unit/lib/bdev/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/bdev.c/bdev_ut.c @@ -967,6 +967,20 @@ bdev_io_types_test(void) ut_enable_io_type(SPDK_BDEV_IO_TYPE_WRITE_ZEROES, true); ut_enable_io_type(SPDK_BDEV_IO_TYPE_WRITE, true); + /* NVME_IO, NVME_IO_MD and NVME_ADMIN are not supported */ + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_IO, false); + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_IO_MD, false); + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_ADMIN, false); + rc = spdk_bdev_nvme_io_passthru(desc, io_ch, NULL, NULL, 0, NULL, NULL); + CU_ASSERT(rc == -ENOTSUP); + rc = spdk_bdev_nvme_io_passthru_md(desc, io_ch, NULL, NULL, 0, NULL, 0, NULL, NULL); + CU_ASSERT(rc == -ENOTSUP); + rc = spdk_bdev_nvme_admin_passthru(desc, io_ch, NULL, NULL, 0, NULL, NULL); + CU_ASSERT(rc == -ENOTSUP); + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_IO, true); + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_IO_MD, true); + ut_enable_io_type(SPDK_BDEV_IO_TYPE_NVME_ADMIN, true); + spdk_put_io_channel(io_ch); spdk_bdev_close(desc); free_bdev(bdev);