Add methods to `GenDiskBuilder` for enabling the write cache and FUA feature flags. These flags are set in the `queue_limits` structure when building the disk. Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/gen_disk.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs index eedba691e167..5367ca92b7aa 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -9,6 +9,7 @@ bindings, block::mq::{ operations::OperationsVTable, + Feature, Operations, RequestQueue, TagSet, // @@ -55,6 +56,8 @@ pub struct GenDiskBuilder { zone_size_sectors: u32, #[cfg(CONFIG_BLK_DEV_ZONED)] zone_append_max_sectors: u32, + write_cache: bool, + forced_unit_access: bool, _p: PhantomData, } @@ -72,6 +75,8 @@ fn default() -> Self { zone_size_sectors: 0, #[cfg(CONFIG_BLK_DEV_ZONED)] zone_append_max_sectors: 0, + write_cache: false, + forced_unit_access: false, _p: PhantomData, } } @@ -164,6 +169,18 @@ pub fn zone_append_max(mut self, sectors: u32) -> Self { self } + /// Declare that this device supports forced unit access. + pub fn forced_unit_access(mut self, enable: bool) -> Self { + self.forced_unit_access = enable; + self + } + + /// Declare that this device has a write-back cache. + pub fn write_cache(mut self, enable: bool) -> Self { + self.write_cache = enable; + self + } + /// Build a new `GenDisk` and add it to the VFS. pub fn build( self, @@ -183,7 +200,7 @@ pub fn build( lim.physical_block_size = self.physical_block_size; lim.max_hw_discard_sectors = self.max_hw_discard_sectors; if self.rotational { - lim.features |= bindings::BLK_FEAT_ROTATIONAL; + lim.features = Feature::Rotational.into(); } #[cfg(CONFIG_BLK_DEV_ZONED)] @@ -192,11 +209,19 @@ pub fn build( return Err(error::code::EINVAL); } - lim.features |= bindings::BLK_FEAT_ZONED; + lim.features |= Feature::Zoned; lim.chunk_sectors = self.zone_size_sectors; lim.max_hw_zone_append_sectors = self.zone_append_max_sectors; } + if self.write_cache { + lim.features |= Feature::WriteCache; + } + + if self.forced_unit_access { + lim.features |= Feature::ForcedUnitAccess; + } + // SAFETY: `tagset.raw_tag_set()` points to a valid and initialized tag set let gendisk = from_err_ptr(unsafe { bindings::__blk_mq_alloc_disk( -- 2.51.2