[PATCH v2 21/83] block: rust: add Request::sectors() method

From: Andreas Hindborg

Date: Tue Jun 09 2026 - 15:39:28 EST


Add a new method to get the size of a request in number of sectors.

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/block/mq/request.rs | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs
index 19bdf17de166..54fe580b7b42 100644
--- a/rust/kernel/block/mq/request.rs
+++ b/rust/kernel/block/mq/request.rs
@@ -183,6 +183,13 @@ pub fn sector(&self) -> usize {
unsafe { (*self.0.get()).__sector as usize }
}

+ /// Get the size of the request in number of sectors.
+ #[inline(always)]
+ pub fn sectors(&self) -> usize {
+ // SAFETY: By type invariant of `Self`, `self.0` is valid and live.
+ (unsafe { (*self.0.get()).__data_len as usize }) >> crate::block::SECTOR_SHIFT
+ }
+
/// Return a pointer to the [`RequestDataWrapper`] stored in the private area
/// of the request structure.
///

--
2.51.2