Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New virtio blk driver #96

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ categories = ["hardware-support", "no-std"]
log = "0.4"
bitflags = "2.3.0"
zerocopy = "0.6.1"
spin = "0.9"


[features]
default = ["alloc"]
Expand Down
8 changes: 5 additions & 3 deletions examples/aarch64/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,18 @@ fn virtio_device(transport: impl Transport) {
}

fn virtio_blk<T: Transport>(transport: T) {
let mut blk = VirtIOBlk::<HalImpl, T>::new(transport).expect("failed to create blk driver");
let mut blk =
VirtIOBlk::<HalImpl, T>::new(transport, true).expect("failed to create blk driver");
assert!(!blk.readonly());
let mut input = [0xffu8; 512];
let mut output = [0; 512];
for i in 0..32 {
for x in input.iter_mut() {
*x = i as u8;
}
blk.write_block(i, &input).expect("failed to write");
blk.read_block(i, &mut output).expect("failed to read");
blk.write_blocks(i, &[&input]).expect("failed to write");
blk.read_blocks(i, &mut [&mut output])
.expect("failed to read");
assert_eq!(input, output);
}
info!("virtio-blk test finished");
Expand Down
2 changes: 1 addition & 1 deletion examples/riscv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ qemu: kernel $(img)
-kernel $(kernel) \
-global virtio-mmio.force-legacy=false \
-drive file=$(img),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0 \
-device virtio-blk-device,packed=on,drive=x0 \
-device virtio-gpu-device \
-device virtio-mouse-device \
-device virtio-net-device,netdev=net0 \
Expand Down
8 changes: 5 additions & 3 deletions examples/riscv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ fn virtio_device(transport: impl Transport) {
}

fn virtio_blk<T: Transport>(transport: T) {
let mut blk = VirtIOBlk::<HalImpl, T>::new(transport).expect("failed to create blk driver");
let mut blk =
VirtIOBlk::<HalImpl, T>::new(transport, true).expect("failed to create blk driver");
let mut input = vec![0xffu8; 512];
let mut output = vec![0; 512];
for i in 0..32 {
for x in input.iter_mut() {
*x = i as u8;
}
blk.write_block(i, &input).expect("failed to write");
blk.read_block(i, &mut output).expect("failed to read");
blk.write_blocks(i, &[&input]).expect("failed to write");
blk.read_blocks(i, &mut [&mut output])
.expect("failed to read");
assert_eq!(input, output);
}
info!("virtio-blk test finished");
Expand Down
8 changes: 5 additions & 3 deletions examples/x86_64/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ fn virtio_device(transport: impl Transport) {
}

fn virtio_blk<T: Transport>(transport: T) {
let mut blk = VirtIOBlk::<HalImpl, T>::new(transport).expect("failed to create blk driver");
let mut blk =
VirtIOBlk::<HalImpl, T>::new(transport, true).expect("failed to create blk driver");
assert!(!blk.readonly());
let mut input = [0xffu8; 512];
let mut output = [0; 512];
for i in 0..32 {
for x in input.iter_mut() {
*x = i as u8;
}
blk.write_block(i, &input).expect("failed to write");
blk.read_block(i, &mut output).expect("failed to read");
blk.write_blocks(i, &[&input]).expect("failed to write");
blk.read_blocks(i, &mut [&mut output])
.expect("failed to read");
assert_eq!(input, output);
}
info!("virtio-blk test finished");
Expand Down
Loading