Skip to content

vmm: Support O_DIRECT for block devices#8

Open
saleemrashid wants to merge 1 commit intov1.14.2-flyfrom
saleem/o-direct
Open

vmm: Support O_DIRECT for block devices#8
saleemrashid wants to merge 1 commit intov1.14.2-flyfrom
saleem/o-direct

Conversation

@saleemrashid
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an is_direct option to virtio-block configuration so backing block devices can be opened with O_DIRECT, and propagates this through config conversion and snapshot persistence.

Changes:

  • Add is_direct to block device configs (BlockDeviceConfig / VirtioBlockConfig) and conversion logic.
  • Open/update backing files with O_DIRECT when is_direct is enabled.
  • Persist/restore the direct-I/O setting and update unit tests accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/vmm/src/vmm_config/drive.rs Adds is_direct to the user-facing block device config struct.
src/vmm/src/devices/virtio/block/virtio/test_utils.rs Extends default virtio-block test configs with is_direct: false.
src/vmm/src/devices/virtio/block/virtio/persist.rs Persists/restores the direct-I/O setting in snapshots.
src/vmm/src/devices/virtio/block/virtio/device.rs Implements O_DIRECT open flag plumbing and threads the setting through device lifecycle; updates tests.
src/vmm/src/devices/virtio/block/vhost_user/device.rs Ensures vhost-user block config serialization includes the new field (as None) and updates tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@@ -61,6 +61,7 @@ pub struct VirtioBlockState {
pub virtio_state: VirtioDeviceState,
rate_limiter_state: RateLimiterState,
file_engine_type: FileEngineTypeState,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VirtioBlockState adds a new required field is_direct: bool without a serde default. Because snapshots accept any patch version within the same major.minor, restoring an older snapshot that lacks this field will fail deserialization. Make this field backward-compatible (e.g., add #[serde(default)] and default to false, or change to Option<bool> and treat None as false during restore).

Suggested change
file_engine_type: FileEngineTypeState,
file_engine_type: FileEngineTypeState,
#[serde(default)]

Copilot uses AI. Check for mistakes.
String::from(f.as_path().to_str().unwrap()),
true,
engine,
true,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test now calls DiskProperties::new(..., is_direct: true) on a TempFile. Opening temp files with O_DIRECT is not supported on some common CI filesystems (e.g., tmpfs), which can cause spurious EINVAL failures. Consider keeping is_direct as false for these temp-file-based tests, or explicitly skip/feature-gate the test when O_DIRECT is unsupported on the backing filesystem.

Suggested change
true,
false,

Copilot uses AI. Check for mistakes.
Comment on lines 421 to 426
is_read_only: Some(true),
path_on_host: Some("path".to_string()),
rate_limiter: None,
file_engine_type: Some(FileEngineType::Sync),
is_direct: Some(true),

Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vhost-user TryFrom<&BlockDeviceConfig> validation currently doesn’t reject is_direct being set when socket is used, so a request like { socket: "...", is_direct: true } would be accepted and the field silently ignored. Add a negative test case covering socket: Some(..) + is_direct: Some(true) and update the conversion validation to require value.is_direct.is_none() for vhost-user configs.

Copilot uses AI. Check for mistakes.
@saleemrashid saleemrashid force-pushed the saleem/o-direct branch 2 times, most recently from 82896f5 to 6f5aee6 Compare March 4, 2026 00:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +63 to +64
/// If set to true, the drive is opened with O_DIRECT.
pub is_direct: Option<bool>,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BlockDeviceConfig gained a new is_direct field, but the test-only manual Clone impl and the many BlockDeviceConfig { ... } struct literals in this file haven't been updated to include it. As written, this will fail to compile; please add is_direct to the Clone impl and initialize it (e.g. None) in test configs as needed (or use ..Default::default()).

Copilot uses AI. Check for mistakes.
Comment on lines +794 to +800
let disk_properties = DiskProperties::new(
String::from(f.as_path().to_str().unwrap()),
true,
engine,
true,
)
.unwrap();
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test_disk_backing_file_helper unit test now uses is_direct = true with a TempFile. O_DIRECT is not supported on some common temp filesystems (e.g. tmpfs), which can make this test fail depending on where it runs. Consider using is_direct = false here, or conditionally skipping when opening with O_DIRECT returns EINVAL.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants