[PATCH 57/79] block: rust: allow setting write cache and FUA flags for `GenDisk`

Andreas Hindborg
2026-02-15T23:46:16Z

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 <a.hindborg@kernel.org>
---
rust/kernel/block/mq/gen_disk.rs | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index a6f113ea4bea4..c6b9839864012 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -7,7 +7,7 @@

use crate::{
bindings,
- block::mq::{operations::OperationsVTable, Operations, RequestQueue, TagSet},
+ block::mq::{operations::OperationsVTable, Feature, Operations, RequestQueue, TagSet},
error::{self, from_err_ptr, Result},
fmt::{self, Write},
prelude::*,
@@ -34,6 +34,8 @@ pub struct GenDiskBuilder<T> {
zone_size_sectors: u32,
#[cfg(CONFIG_BLK_DEV_ZONED)]
zone_append_max_sectors: u32,
+ write_cache: bool,
+ forced_unit_access: bool,
_p: PhantomData<T>,
}

@@ -51,6 +53,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,
}
}
@@ -143,6 +147,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,
@@ -163,7 +179,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)]
@@ -172,11 +188,19 @@ pub fn build(
return Err(error::code::EINVAL);
}

- lim.features |= bindings::BLK_FEAT_ZONED;
+ //lim.features |= request::Feature::Zoned.into();
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