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",
34 struct NullBlkModule {
35 _disk: Pin<KBox<Mutex<GenDisk<NullBlkDevice>>>>,
38 impl kernel::Module for NullBlkModule {
39 fn init(_module: &'static ThisModule) -> Result<Self> {
40 pr_info!("Rust null_blk loaded\n");
41 let tagset = Arc::pin_init(TagSet::new(1, 256, 1), flags::GFP_KERNEL)?;
43 let disk = gen_disk::GenDiskBuilder::new()
44 .capacity_sectors(4096 << 11)
45 .logical_block_size(4096)?
46 .physical_block_size(4096)?
48 .build(format_args!("rnullb{}", 0), tagset)?;
50 let disk = KBox::pin_init(new_mutex!(disk, "nullb:disk"), flags::GFP_KERNEL)?;
52 Ok(Self { _disk: disk })
59 impl Operations for NullBlkDevice {
61 fn queue_rq(rq: ARef<mq::Request<Self>>, _is_last: bool) -> Result {
62 mq::Request::end_ok(rq)
63 .map_err(|_e| kernel::error::code::EIO)
64 // We take no refcounts on the request, so we expect to be able to
65 // end the request. The request reference must be unique at this
66 // point, and so `end_ok` cannot fail.
67 .expect("Fatal error - expected to be able to end request");