diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b4714625..9f85733e37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## v19.10: (Upcoming Release) +### bdev + +Added `spdk_bdev_get_write_unit_size()` function for retrieving required number +of logical blocks for write operation. + ### nvmf The `spdk_nvmf_tgt_create` function now accepts an object of type `spdk_nvmf_target_opts` diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index cd55e63d58..4bf4810b4d 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -368,6 +368,21 @@ const char *spdk_bdev_get_product_name(const struct spdk_bdev *bdev); */ uint32_t spdk_bdev_get_block_size(const struct spdk_bdev *bdev); +/** + * Get the write unit size for this bdev. + * + * Write unit size is required number of logical blocks to perform write + * operation on block device. + * + * Unit of write unit size is logical block and the minimum of write unit + * size is one. Write operations must be multiple of write unit size. + * + * \param bdev Block device to query. + * + * \return The write unit size in logical blocks. + */ +uint32_t spdk_bdev_get_write_unit_size(const struct spdk_bdev *bdev); + /** * Get size of block device in logical blocks. * diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index 1af89306d0..97f279cbfa 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -265,6 +265,9 @@ struct spdk_bdev { /** Number of blocks */ uint64_t blockcnt; + /** Number of blocks required for write */ + uint32_t write_unit_size; + /** * Specifies an alignment requirement for data buffers associated with an spdk_bdev_io. * 0 = no alignment requirement diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 9704372493..0740d25749 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -2437,6 +2437,12 @@ spdk_bdev_get_block_size(const struct spdk_bdev *bdev) return bdev->blocklen; } +uint32_t +spdk_bdev_get_write_unit_size(const struct spdk_bdev *bdev) +{ + return bdev->write_unit_size; +} + uint64_t spdk_bdev_get_num_blocks(const struct spdk_bdev *bdev) { @@ -4073,6 +4079,11 @@ spdk_bdev_init(struct spdk_bdev *bdev) } } + /* If the user didn't specify a write unit size, set it to one. */ + if (bdev->write_unit_size == 0) { + bdev->write_unit_size = 1; + } + TAILQ_INIT(&bdev->internal.open_descs); TAILQ_INIT(&bdev->aliases);