bdev: validate I/O offset block alignment

Change-Id: I33506d6b9ff09c45c057326f7339d742eebc45b4
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/372861
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-08-04 14:18:13 -07:00
parent 906ce69413
commit 3754eedc9b
2 changed files with 6 additions and 2 deletions

View File

@ -742,6 +742,11 @@ spdk_bdev_has_write_cache(const struct spdk_bdev *bdev)
static bool
spdk_bdev_io_valid(struct spdk_bdev *bdev, uint64_t offset, uint64_t nbytes)
{
/* Return failure if offset is not a multiple of bdev->blocklen */
if (offset % bdev->blocklen) {
return false;
}
/* Return failure if nbytes is not a multiple of bdev->blocklen */
if (nbytes % bdev->blocklen) {
return false;

View File

@ -316,8 +316,7 @@ io_valid_test(void)
CU_ASSERT(spdk_bdev_io_valid(&bdev, 512, 1024) == true);
/* Offset not a block multiple */
/* TODO: add a check for this in spdk_bdev_io_valid() */
/* CU_ASSERT(spdk_bdev_io_valid(&bdev, 3, 512) == false); */
CU_ASSERT(spdk_bdev_io_valid(&bdev, 3, 512) == false);
/* Length not a block multiple */
CU_ASSERT(spdk_bdev_io_valid(&bdev, 512, 3) == false);