vmm: config: Expose disk lock granularity option

Add a per-disk lock_granularity parameter that lets users choose
between byte-range OFD locks and whole-file OFD locks:

  --disk path=/foo.img,lock_granularity=byte-range
  --disk path=/bar.img,lock_granularity=full

Byte-range is the default and matches QEMU behavior, working
best with storage backends where whole-file OFD locks are treated
as mandatory. The full option restores the original whole-file
locking for environments that depend on it.

The LockGranularityChoice enum and its FromStr impl live in the
block crate alongside the existing LockGranularity type. The
Block device converts the user-facing choice to the internal
LockGranularity at lock time, keeping device_manager.rs simple.

Closes: #7553

Signed-off-by: Victor Vieux <vieux@repl.it>
This commit is contained in:
Victor Vieux
2026-03-06 12:09:09 -08:00
committed by Rob Bradford
parent da0d0a2090
commit 7c690ffec0
7 changed files with 91 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ use std::sync::Arc;
use std::{ffi, io};
use block::async_io::DiskFile;
use block::fcntl::LockGranularityChoice;
use block::raw_sync::RawFileDiskSync;
use libfuzzer_sys::{fuzz_target, Corpus};
use seccompiler::SeccompAction;
@@ -69,6 +70,7 @@ fuzz_target!(|bytes: &[u8]| -> Corpus {
queue_affinity,
true,
false,
LockGranularityChoice::default(),
)
.unwrap();