Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions alioth/src/virtio/dev/blk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ impl Block {
.write(!param.readonly)
.open(&param.path)
.context(access_disk)?;

let ctx_lock = error::LockFile {
path: param.path.as_ref(),
};
if param.readonly {
disk.try_lock_shared().context(ctx_lock)
} else {
disk.try_lock().context(ctx_lock)
}?;

let len = disk.metadata().context(access_disk)?.len();
let config = BlockConfig {
capacity: len / SECTOR_SIZE as u64,
Expand Down
5 changes: 5 additions & 0 deletions alioth/src/virtio/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub enum Error {
path: Box<Path>,
error: std::io::Error,
},
#[snafu(display("Failed to lock file {path:?}"))]
LockFile {
path: Box<Path>,
error: std::fs::TryLockError,
},
#[snafu(display("Error from OS"), context(false))]
System { error: std::io::Error },
#[snafu(display("Failed to create a poll"))]
Expand Down