[PATCH v2 2/3] rust: block: rnull: update to Pin<KBox<QueueData>> for PinInit
From: Adrián García Casado
Date: Sun Mar 15 2026 - 13:27:21 EST
Update the Rust rnull driver to use Pin<KBox<QueueData>> for queue data
allocation. This aligns the driver with the latest PinInit zero-copy
initialization abstractions in kernel 7.0 and fixes a type mismatch
with GenDiskBuilder::build().
Signed-off-by: Adrian Garcia Cicuelo <adriangarciacicuelo@xxxxxxxxx>
---
drivers/block/rnull/rnull.rs | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs
index 0ca8715fe..23df23936 100644
--- a/drivers/block/rnull/rnull.rs
+++ b/drivers/block/rnull/rnull.rs
@@ -54,7 +54,7 @@ fn new(
) -> Result<GenDisk<Self>> {
let tagset = Arc::pin_init(TagSet::new(1, 256, 1), GFP_KERNEL)?;
- let queue_data = Box::new(QueueData { irq_mode }, GFP_KERNEL)?;
+ let queue_data = Box::pin_init(QueueData { irq_mode }, GFP_KERNEL)?;
gen_disk::GenDiskBuilder::new()
.capacity_sectors(capacity_mib << (20 - block::SECTOR_SHIFT))
@@ -65,16 +65,21 @@ fn new(
}
}
+#[pin_data]
struct QueueData {
irq_mode: IRQMode,
}
#[vtable]
impl Operations for NullBlkDevice {
- type QueueData = KBox<QueueData>;
+ type QueueData = Pin<KBox<QueueData>>;
#[inline(always)]
- fn queue_rq(queue_data: &QueueData, rq: ARef<mq::Request<Self>>, _is_last: bool) -> Result {
+ fn queue_rq(
+ queue_data: Pin<&QueueData>,
+ rq: ARef<mq::Request<Self>>,
+ _is_last: bool,
+ ) -> Result {
match queue_data.irq_mode {
IRQMode::None => mq::Request::end_ok(rq)
.map_err(|_e| kernel::error::code::EIO)
@@ -87,7 +92,7 @@ fn queue_rq(queue_data: &QueueData, rq: ARef<mq::Request<Self>>, _is_last: bool)
Ok(())
}
- fn commit_rqs(_queue_data: &QueueData) {}
+ fn commit_rqs(_queue_data: Pin<&QueueData>) {}
fn complete(rq: ARef<mq::Request<Self>>) {
mq::Request::end_ok(rq)
--
2.47.3