[PATCH v2 04/83] block: rnull: add module parameters

From: Andreas Hindborg

Date: Tue Jun 09 2026 - 15:23:03 EST


Module parameter support for Rust modules was merged a few releases back.
Add module parameter support to the rnull driver.

This allows the user to control the driver either via configfs or module
parameters, just like the C counterpart.

Please note that the rust module parameters do not support boolean values.
Flags that should have been booleans are parsed as integers and compared to
zero.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
drivers/block/rnull/rnull.rs | 50 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs
index d58d2c4c5f63..77ccc6850961 100644
--- a/drivers/block/rnull/rnull.rs
+++ b/drivers/block/rnull/rnull.rs
@@ -18,10 +18,14 @@
TagSet, //
},
},
+ error::Result,
+ new_mutex, pr_info,
prelude::*,
+ str::CString,
sync::{
aref::ARef,
- Arc, //
+ Arc,
+ Mutex, //
},
};

@@ -31,20 +35,64 @@
authors: ["Andreas Hindborg"],
description: "Rust implementation of the C null block driver",
license: "GPL v2",
+ params: {
+ gb: u64 {
+ default: 4,
+ description: "Device capacity in GiB",
+ },
+ rotational: bool {
+ default: false,
+ description: "Set the rotational feature for the device.",
+ },
+ bs: u32 {
+ default: 4096,
+ description: "Block size (in bytes)",
+ },
+ nr_devices: u64 {
+ default: 1,
+ description: "Number of devices to register",
+ },
+ irqmode: u8 {
+ default: 0,
+ description: "IRQ completion handler. 0-none, 1-softirq",
+ },
+ },
}

#[pin_data]
struct NullBlkModule {
#[pin]
configfs_subsystem: kernel::configfs::Subsystem<configfs::Config>,
+ #[pin]
+ param_disks: Mutex<KVec<GenDisk<NullBlkDevice>>>,
}

impl kernel::InPlaceModule for NullBlkModule {
fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
pr_info!("Rust null_blk loaded\n");

+ let mut disks = KVec::new();
+
+ let defer_init = move || -> Result<_, Error> {
+ for i in 0..module_parameters::nr_devices.value() {
+ let name = CString::try_from_fmt(fmt!("rnullb{}", i))?;
+
+ let disk = NullBlkDevice::new(
+ &name,
+ module_parameters::bs.value(),
+ module_parameters::rotational.value(),
+ module_parameters::gb.value() * 1024,
+ module_parameters::irqmode.value().try_into()?,
+ )?;
+ disks.push(disk, GFP_KERNEL)?;
+ }
+
+ Ok(disks)
+ };
+
try_pin_init!(Self {
configfs_subsystem <- configfs::subsystem(),
+ param_disks <- new_mutex!(defer_init()?),
})
}
}

--
2.51.2