This adds a helper function that sets up the atomic value based on a block_device similar to what we do for unmap. Signed-off-by: Mike Christie <michael.christie@xxxxxxxxxx> --- drivers/target/target_core_device.c | 18 ++++++++++++++++++ include/target/target_core_backend.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index b709a64c0ff3..4741de3d1061 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -793,6 +793,24 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) return dev; } +void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib, + struct block_device *bdev) +{ + struct request_queue *q = bdev_get_queue(bdev); + int block_size = bdev_logical_block_size(bdev); + + if (!bdev_can_atomic_write(bdev)) + return; + + attrib->atomic_supported = true; + attrib->atomic_max_len = queue_atomic_write_max_bytes(q) / block_size; + attrib->atomic_granularity = queue_atomic_write_unit_min_bytes(q) / + block_size; + attrib->atomic_max_with_boundary = 0; + attrib->atomic_max_boundary = 0; +} +EXPORT_SYMBOL_GPL(target_configure_write_atomic_from_bdev); + /* * Check if the underlying struct block_device supports discard and if yes * configure the UNMAP parameters. diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index d394306f8f49..e32de80854b6 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -123,6 +123,8 @@ bool target_sense_desc_format(struct se_device *dev); sector_t target_to_linux_sector(struct se_device *dev, sector_t lb); bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib, struct block_device *bdev); +void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib, + struct block_device *bdev); static inline bool target_dev_configured(struct se_device *se_dev) { -- 2.34.1