Skip to content

Commit 6bd8420

Browse files
lwz23kawasaki
authored andcommitted
block: rnull: support BLK_MQ_F_BLOCKING via configfs
Add a new configfs boolean attribute named blocking. Advertise blocking in the rnull features list. On power-on, map blocking=1 to TagSetFlags::BLOCKING. Create the tag set with TagSet::new_with_flags(). Keep default blocking=0 to preserve existing behavior. Like other parameters, blocking writes return -EBUSY while powered on. Validated with LLVM=-15 out-of-tree builds and QEMU runtime tests. Signed-off-by: Wenzhao Liao <wenzhaoliao@ruc.edu.cn>
1 parent 0896bfc commit 6bd8420

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

drivers/block/rnull/configfs.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl AttributeOperations<0> for Config {
3535

3636
fn show(_this: &Config, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
3737
let mut writer = kernel::str::Formatter::new(page);
38-
writer.write_str("blocksize,size,rotational,irqmode\n")?;
38+
writer.write_str("blocksize,size,rotational,irqmode,blocking\n")?;
3939
Ok(writer.bytes_written())
4040
}
4141
}
@@ -58,6 +58,7 @@ impl configfs::GroupOperations for Config {
5858
rotational: 2,
5959
size: 3,
6060
irqmode: 4,
61+
blocking: 5,
6162
],
6263
};
6364

@@ -73,6 +74,7 @@ impl configfs::GroupOperations for Config {
7374
disk: None,
7475
capacity_mib: 4096,
7576
irq_mode: IRQMode::None,
77+
blocking: false,
7678
name: name.try_into()?,
7779
}),
7880
}),
@@ -122,6 +124,7 @@ struct DeviceConfigInner {
122124
rotational: bool,
123125
capacity_mib: u64,
124126
irq_mode: IRQMode,
127+
blocking: bool,
125128
disk: Option<GenDisk<NullBlkDevice>>,
126129
}
127130

@@ -152,6 +155,7 @@ impl configfs::AttributeOperations<0> for DeviceConfig {
152155
guard.rotational,
153156
guard.capacity_mib,
154157
guard.irq_mode,
158+
guard.blocking,
155159
)?);
156160
guard.powered = true;
157161
} else if guard.powered && !power_op {
@@ -259,3 +263,29 @@ impl configfs::AttributeOperations<4> for DeviceConfig {
259263
Ok(())
260264
}
261265
}
266+
267+
#[vtable]
268+
impl configfs::AttributeOperations<5> for DeviceConfig {
269+
type Data = DeviceConfig;
270+
271+
fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
272+
let mut writer = kernel::str::Formatter::new(page);
273+
274+
if this.data.lock().blocking {
275+
writer.write_str("1\n")?;
276+
} else {
277+
writer.write_str("0\n")?;
278+
}
279+
280+
Ok(writer.bytes_written())
281+
}
282+
283+
fn store(this: &DeviceConfig, page: &[u8]) -> Result {
284+
if this.data.lock().powered {
285+
return Err(EBUSY);
286+
}
287+
288+
this.data.lock().blocking = kstrtobool_bytes(page)?;
289+
Ok(())
290+
}
291+
}

drivers/block/rnull/rnull.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use kernel::{
1111
mq::{
1212
self,
1313
gen_disk::{self, GenDisk},
14-
Operations, TagSet,
14+
Operations, TagSet, TagSetFlags,
1515
},
1616
},
1717
prelude::*,
@@ -51,8 +51,15 @@ impl NullBlkDevice {
5151
rotational: bool,
5252
capacity_mib: u64,
5353
irq_mode: IRQMode,
54+
blocking: bool,
5455
) -> Result<GenDisk<Self>> {
55-
let tagset = Arc::pin_init(TagSet::new(1, 256, 1), GFP_KERNEL)?;
56+
let flags = if blocking {
57+
TagSetFlags::BLOCKING
58+
} else {
59+
TagSetFlags::empty()
60+
};
61+
62+
let tagset = Arc::pin_init(TagSet::new_with_flags(1, 256, 1, flags), GFP_KERNEL)?;
5663

5764
let queue_data = Box::new(QueueData { irq_mode }, GFP_KERNEL)?;
5865

0 commit comments

Comments
 (0)