Skip to content

Commit

Permalink
Merge pull request #2 from ublk-org/bug_fix
Browse files Browse the repository at this point in the history
qcow2-rs: don't enable direct-io on macos
  • Loading branch information
ming1 authored Jan 15, 2024
2 parents 4dae444 + 8caddea commit 0b4ef52
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@ pub struct Qcow2IoSync {

impl Qcow2IoSync {
pub fn new(path: &PathBuf, ro: bool, dio: bool) -> Qcow2IoSync {
#[cfg(target_os = "macos")]
fn set_dio(_file: &File) {}

#[cfg(not(target_os = "macos"))]
fn set_dio(file: &File) {
unsafe {
libc::fcntl(file.as_raw_fd(), libc::F_SETFL, libc::O_DIRECT);
}
}

let file = OpenOptions::new()
.read(true)
.write(!ro)
.open(path.clone())
.unwrap();

if dio {
unsafe {
libc::fcntl(file.as_raw_fd(), libc::F_SETFL, libc::O_DIRECT);
}
set_dio(&file);
}

let fd = file.as_raw_fd();
Expand Down

0 comments on commit 0b4ef52

Please sign in to comment.