-
Notifications
You must be signed in to change notification settings - Fork 2.5k
virtio-blk: add discard request support #5908
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
8a4f71c
e7a7be4
560d2f8
6b74e51
1692379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ use std::mem::size_of; | |
|
|
||
| use vm_memory::GuestMemoryError; | ||
|
|
||
| use super::{io as block_io, VirtioBlockError, MAX_DISCARD_SECTORS, SECTOR_SHIFT, SECTOR_SIZE}; | ||
| use super::{MAX_DISCARD_SECTORS, SECTOR_SHIFT, SECTOR_SIZE, VirtioBlockError, io as block_io}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assume these are from |
||
| use crate::devices::virtio::block::virtio::device::DiskProperties; | ||
| use crate::devices::virtio::block::virtio::metrics::BlockDeviceMetrics; | ||
| pub use crate::devices::virtio::generated::virtio_blk::{ | ||
|
|
@@ -19,7 +19,7 @@ pub use crate::devices::virtio::generated::virtio_blk::{ | |
| VIRTIO_BLK_T_OUT, | ||
| }; | ||
| use crate::devices::virtio::queue::DescriptorChain; | ||
| use crate::logger::{error, IncMetric}; | ||
| use crate::logger::{IncMetric, error}; | ||
| use crate::rate_limiter::{RateLimiter, TokenType}; | ||
| use crate::vstate::memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemoryMmap}; | ||
|
|
||
|
|
@@ -500,7 +500,7 @@ mod tests { | |
|
|
||
| use super::*; | ||
| use crate::devices::virtio::queue::{Queue, VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE}; | ||
| use crate::devices::virtio::test_utils::{default_mem, VirtQueue}; | ||
| use crate::devices::virtio::test_utils::{VirtQueue, default_mem}; | ||
| use crate::vstate::memory::{Address, GuestAddress, GuestMemory}; | ||
|
|
||
| const NUM_DISK_SECTORS: u64 = 1024; | ||
|
|
@@ -915,8 +915,8 @@ mod tests { | |
| } | ||
|
|
||
| #[allow(clippy::let_with_type_underscore)] | ||
| fn random_request_parse( | ||
| ) -> impl Strategy<Value = (Result<Request, VirtioBlockError>, GuestMemoryMmap, Queue)> { | ||
| fn random_request_parse() | ||
| -> impl Strategy<Value = (Result<Request, VirtioBlockError>, GuestMemoryMmap, Queue)> { | ||
| // In this strategy we are going to generate random Requests/Errors and map them | ||
| // to an input descriptor chain. | ||
| // | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,12 @@ | |
|
|
||
| import host_tools.drive as drive_tools | ||
| from framework import utils | ||
| from framework.artifacts import GUEST_KERNEL_DEFAULT, pin_guest_kernel, pin_rootfs_mode | ||
| from framework.artifacts import ( | ||
| GUEST_KERNEL_DEFAULT, | ||
| pin_guest_kernel, | ||
| pin_pci, | ||
| pin_rootfs_mode, | ||
| ) | ||
| from framework.utils_drive import partuuid_and_disk_path | ||
|
|
||
| MB = 1024 * 1024 | ||
|
|
@@ -324,6 +329,47 @@ def test_no_flush(uvm, io_engine): | |
| assert fc_metrics["block"]["flush_count"] == 0 | ||
|
|
||
|
|
||
| @pin_guest_kernel(GUEST_KERNEL_DEFAULT) | ||
| @pin_pci(False) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason to pin test to only run without PCI? There should be no difference, but we prefer to test all combinations by default |
||
| def test_discard(uvm): | ||
| """ | ||
| Verify discard is advertised and punches holes in a file-backed drive. | ||
| """ | ||
| test_microvm = uvm | ||
| test_microvm.spawn() | ||
|
|
||
| test_microvm.basic_config(vcpu_count=1) | ||
| test_microvm.add_net_iface() | ||
|
|
||
| fs = drive_tools.FilesystemFile( | ||
| os.path.join(test_microvm.fsfiles, "discard"), size=64 | ||
| ) | ||
| test_microvm.add_drive("discard", fs.path, io_engine="Sync", discard=True) | ||
|
|
||
| test_microvm.start() | ||
|
|
||
| _, stdout, stderr = test_microvm.ssh.run( | ||
| "cat /sys/block/vdb/queue/discard_granularity" | ||
| ) | ||
| assert stderr == "" | ||
| assert int(stdout.strip()) > 0 | ||
|
|
||
| _, _, stderr = test_microvm.ssh.run( | ||
| "dd if=/dev/zero of=/dev/vdb bs=1M count=32 oflag=direct conv=fsync status=none", | ||
| timeout=30.0, | ||
| ) | ||
| assert stderr == "" | ||
|
|
||
| blocks_before = os.stat(fs.path).st_blocks | ||
| assert blocks_before > 0 | ||
|
|
||
| _, _, stderr = test_microvm.ssh.run("blkdiscard -f /dev/vdb", timeout=30.0) | ||
| assert stderr in ("", "blkdiscard: Operation forced, data will be lost!\n") | ||
|
|
||
| blocks_after = os.stat(fs.path).st_blocks | ||
| assert blocks_after < blocks_before | ||
|
|
||
|
|
||
| @pin_guest_kernel(GUEST_KERNEL_DEFAULT) | ||
| @pin_rootfs_mode("rw") | ||
| def test_flush(uvm, io_engine): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rust changes in the
tests: cover virtio-blk discard APIcommit should be squashed withvirtio-blk: add discard request supportcommit. Python integration tests can stay in a separate commit, but please add a reasonable commit name and body for it.