[PATCH v2 57/83] block: rust: add accessors to `TagSet`

From: Andreas Hindborg

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


Add `hw_queue_count()` to query the number of hardware queues and
`data()` to borrow the private tag set data associated with a `TagSet`.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/block/mq/tag_set.rs | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/block/mq/tag_set.rs b/rust/kernel/block/mq/tag_set.rs
index e62dfd267fd9..858c1b952b00 100644
--- a/rust/kernel/block/mq/tag_set.rs
+++ b/rust/kernel/block/mq/tag_set.rs
@@ -4,8 +4,6 @@
//!
//! C header: [`include/linux/blk-mq.h`](srctree/include/linux/blk-mq.h)

-use core::pin::Pin;
-
use crate::{
alloc::NumaNode,
bindings,
@@ -26,7 +24,8 @@
};
use core::{
convert::TryInto,
- marker::PhantomData, //
+ marker::PhantomData,
+ pin::Pin, //
};
use pin_init::{
pin_data,
@@ -164,6 +163,22 @@ pub fn update_maps(self: Pin<&mut Self>, mut cb: impl FnMut(QueueMap)) -> Result

Ok(())
}
+
+ /// Return the number of hardware queues for this tag set.
+ pub fn hw_queue_count(&self) -> u32 {
+ // SAFETY: By type invariant, `self.inner` is valid.
+ unsafe { (*self.inner.get()).nr_hw_queues }
+ }
+
+ /// Borrow the [`T::TagSetData`] associated with this tag set.
+ pub fn data(&self) -> <T::TagSetData as ForeignOwnable>::Borrowed<'_> {
+ // SAFETY: By type invariant, `self.inner` is valid.
+ let ptr = unsafe { (*self.inner.get()).driver_data };
+
+ // SAFETY: `ptr` was created by `into_foreign` during initialization and the target is not
+ // converted back with `from_foreign` while `&self` is live.
+ unsafe { T::TagSetData::borrow(ptr) }
+ }
}

#[pinned_drop]

--
2.51.2