[PATCH 18/79] block: rust: add Request::sectors() method

Andreas Hindborg
2026-02-15T23:45:11Z

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

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
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 0dd329ae93dfc..9d11ae5651983 100644
--- a/rust/kernel/block/mq/request.rs
+++ b/rust/kernel/block/mq/request.rs
@@ -144,6 +144,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