1 // SPDX-License-Identifier: GPL-2.0
3 //! This is a Rust implementation of the C null block driver.
5 //! Supported features:
8 //! - direct completion
11 //! The driver is not configurable.
17 gen_disk::{self, GenDisk},
30 author: "Andreas Hindborg",
31 description: "Rust implementation of the C null block driver",
35 struct NullBlkModule {
36 _disk: Pin<KBox<Mutex<GenDisk<NullBlkDevice>>>>,
39 impl kernel::Module for NullBlkModule {
40 fn init(_module: &'static ThisModule) -> Result<Self> {
41 pr_info!("Rust null_blk loaded\n");
42 let tagset = Arc::pin_init(TagSet::new(1, 256, 1), flags::GFP_KERNEL)?;
44 let disk = gen_disk::GenDiskBuilder::new()
45 .capacity_sectors(4096 << 11)
46 .logical_block_size(4096)?
47 .physical_block_size(4096)?
49 .build(format_args!("rnullb{}", 0), tagset)?;
51 let disk = KBox::pin_init(new_mutex!(disk, "nullb:disk"), flags::GFP_KERNEL)?;
53 Ok(Self { _disk: disk })
60 impl Operations for NullBlkDevice {
62 fn queue_rq(rq: ARef<mq::Request<Self>>, _is_last: bool) -> Result {
63 mq::Request::end_ok(rq)
64 .map_err(|_e| kernel::error::code::EIO)
65 // We take no refcounts on the request, so we expect to be able to
66 // end the request. The request reference must be unique at this
67 // point, and so `end_ok` cannot fail.
68 .expect("Fatal error - expected to be able to end request");