Skip to content

Commit

Permalink
refactor: split some logic
Browse files Browse the repository at this point in the history
Signed-off-by: akitaSummer <[email protected]>
  • Loading branch information
akitaSummer committed Jan 20, 2024
1 parent 28f93e3 commit 2318011
Show file tree
Hide file tree
Showing 10 changed files with 852 additions and 727 deletions.
4 changes: 2 additions & 2 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ impl<F: FileSystem + Sync> Server<F> {
x if x == Opcode::Rename2 as u32 => self.rename2(ctx),
#[cfg(target_os = "linux")]
x if x == Opcode::Lseek as u32 => self.lseek(ctx),
#[cfg(feature = "virtiofs")]
#[cfg(all(target_os = "linux", feature = "virtiofs"))]
x if x == Opcode::SetupMapping as u32 => self.setupmapping(ctx, vu_req),
#[cfg(feature = "virtiofs")]
#[cfg(all(target_os = "linux", feature = "virtiofs"))]
x if x == Opcode::RemoveMapping as u32 => self.removemapping(ctx, vu_req),
// Group reqeusts don't need reply together
x => match x {
Expand Down
2 changes: 2 additions & 0 deletions src/passthrough/file_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ impl OpenableFileHandle {
#[cfg(test)]
mod tests {
use super::*;
#[cfg(target_os = "macos")]
use nix::unistd::getuid;
use std::ffi::CString;
#[cfg(target_os = "macos")]
use std::io::Read;

fn generate_c_file_handle(
Expand Down
16 changes: 5 additions & 11 deletions src/passthrough/inode_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;
#[cfg(target_os = "linux")]
use super::file_handle::FileHandle;
#[cfg(target_os = "macos")]
use super::stat::Stat;
use super::stat::Stat as StatExt;
#[cfg(target_os = "linux")]
use super::statx::StatExt;

Expand All @@ -25,24 +25,15 @@ pub struct InodeId {
}

impl InodeId {
#[cfg(target_os = "linux")]
#[inline]
pub(super) fn from_stat(st: &StatExt) -> Self {
InodeId {
ino: st.st.st_ino,
dev: st.st.st_dev,
#[cfg(target_os = "linux")]
mnt: st.mnt_id,
}
}

#[cfg(target_os = "macos")]
#[inline]
pub(super) fn from_stat(st: &Stat) -> Self {
InodeId {
ino: st.st.st_ino,
dev: st.st.st_dev,
}
}
}

#[derive(Default)]
Expand Down Expand Up @@ -125,7 +116,9 @@ mod test {
use super::super::*;
use super::*;

#[cfg(target_os = "linux")]
use std::ffi::CStr;
#[cfg(target_os = "linux")]
use std::mem::MaybeUninit;
use std::os::unix::io::AsRawFd;
use std::sync::atomic::Ordering;
Expand All @@ -134,6 +127,7 @@ mod test {
#[cfg(target_os = "linux")]
use vmm_sys_util::tempfile::TempFile;

#[cfg(target_os = "macos")]
use stat::stat;

impl PartialEq for InodeData {
Expand Down
Loading

0 comments on commit 2318011

Please sign in to comment.