Add a method to `TagSet` that allows changing the number of hardware queues dynamically. Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/tag_set.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rust/kernel/block/mq/tag_set.rs b/rust/kernel/block/mq/tag_set.rs index 858c1b952b00..e89c76987b54 100644 --- a/rust/kernel/block/mq/tag_set.rs +++ b/rust/kernel/block/mq/tag_set.rs @@ -170,6 +170,20 @@ pub fn hw_queue_count(&self) -> u32 { unsafe { (*self.inner.get()).nr_hw_queues } } + /// Update the number of hardware queues for this tag set. + /// + /// This operation may fail if memory for tags cannot be allocated. + pub fn update_hw_queue_count(&self, nr_hw_queues: u32) -> Result { + // SAFETY: blk_mq_update_nr_hw_queues applies internal synchronization. + unsafe { bindings::blk_mq_update_nr_hw_queues(self.inner.get(), nr_hw_queues) } + + if self.hw_queue_count() == nr_hw_queues { + Ok(()) + } else { + Err(ENOMEM) + } + } + /// Borrow the [`T::TagSetData`] associated with this tag set. pub fn data(&self) -> ::Borrowed<'_> { // SAFETY: By type invariant, `self.inner` is valid. -- 2.51.2