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 --- rust/kernel/block/mq/tag_set.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rust/kernel/block/mq/tag_set.rs b/rust/kernel/block/mq/tag_set.rs index e6edc5bc39312..4d00979a83dbd 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::{ bindings, block::mq::{operations::OperationsVTable, request::RequestDataWrapper, Operations}, @@ -13,7 +11,7 @@ try_pin_init, types::{ForeignOwnable, Opaque}, }; -use core::{convert::TryInto, marker::PhantomData}; +use core::{convert::TryInto, marker::PhantomData, pin::Pin}; use pin_init::{pin_data, pinned_drop, PinInit}; mod flags; @@ -137,6 +135,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) -> ::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