bdev/null: Check if the number of blocks of read I/O is not larger than allowed.

Add a check if the number of blocks of read I/O is not larger
than allowed. This is a preparation to the subsequent patches that
support DIF in NULL bdev.

Change-Id: I82d4c835788d2f347fd5fdef82e1def313dd49a1
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446052
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-02-25 12:44:10 +09:00 committed by Changpeng Liu
parent 6716729c9c
commit 11839b805c

View File

@ -39,6 +39,7 @@
#include "spdk/thread.h" #include "spdk/thread.h"
#include "spdk/json.h" #include "spdk/json.h"
#include "spdk/string.h" #include "spdk/string.h"
#include "spdk/likely.h"
#include "spdk/bdev_module.h" #include "spdk/bdev_module.h"
#include "spdk_internal/log.h" #include "spdk_internal/log.h"
@ -93,8 +94,17 @@ bdev_null_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_
case SPDK_BDEV_IO_TYPE_READ: case SPDK_BDEV_IO_TYPE_READ:
if (bdev_io->u.bdev.iovs[0].iov_base == NULL) { if (bdev_io->u.bdev.iovs[0].iov_base == NULL) {
assert(bdev_io->u.bdev.iovcnt == 1); assert(bdev_io->u.bdev.iovcnt == 1);
bdev_io->u.bdev.iovs[0].iov_base = g_null_read_buf; if (spdk_likely(bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen <=
bdev_io->u.bdev.iovs[0].iov_len = bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen; SPDK_BDEV_LARGE_BUF_MAX_SIZE)) {
bdev_io->u.bdev.iovs[0].iov_base = g_null_read_buf;
bdev_io->u.bdev.iovs[0].iov_len = bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen;
} else {
SPDK_ERRLOG("Overflow occurred. Read I/O size %" PRIu64 " was larger than permitted %d\n",
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen,
SPDK_BDEV_LARGE_BUF_MAX_SIZE);
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
return;
}
} }
TAILQ_INSERT_TAIL(&ch->io, bdev_io, module_link); TAILQ_INSERT_TAIL(&ch->io, bdev_io, module_link);
break; break;