Skip to content

Commit

Permalink
macos: clean up code related to macos
Browse files Browse the repository at this point in the history
Clean up code related to macos.

Follow up of cloud-hypervisor#162

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Oct 26, 2023
1 parent a8d8cd9 commit 8e2c9e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
6 changes: 2 additions & 4 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,8 @@ impl<F: FileSystem + Sync> Server<F> {
return ctx.reply_ok(Some(out), None);
}

#[cfg(not(target_os = "macos"))]
let mut flags_u64 = flags as u64;
#[cfg(target_os = "macos")]
let flags_u64 = flags as u64;
let mut flags_u64;
flags_u64 = flags as u64;
#[cfg(not(target_os = "macos"))]
if flags_u64 & FsOptions::INIT_EXT.bits() != 0 {
let InitIn2 { flags2, unused: _ } = ctx.r.read_obj().map_err(Error::DecodeMessage)?;
Expand Down
47 changes: 27 additions & 20 deletions src/api/vfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ struct MountPointData {
#[derive(Debug, Copy, Clone)]
/// vfs init options
pub struct VfsOptions {
/// Make readdir/readdirplus request return zero dirent even if dir has children.
pub no_readdir: bool,
/// Reject requests which will change the file size, or allocate file
/// blocks exceed file size.
pub seal_size: bool,
/// File system options passed in from client
pub in_opts: FsOptions,
/// File system options returned to client
pub out_opts: FsOptions,
/// Declaration of ID mapping, in the format (internal ID, external ID, range).
/// For example, (0, 1, 65536) represents mapping the external UID/GID range of `1~65536`
/// to the range of `0~65535` within the filesystem.
pub id_mapping: (u32, u32, u32),

/// Disable fuse open request handling. When enabled, fuse open
/// requests are always replied with ENOSYS.
#[cfg(not(target_os = "macos"))]
Expand All @@ -232,24 +246,11 @@ pub struct VfsOptions {
/// buffer writes.
#[cfg(not(target_os = "macos"))]
pub no_writeback: bool,
/// Make readdir/readdirplus request return zero dirent even if dir has children.
pub no_readdir: bool,
/// Enable fuse killpriv_v2 support. When enabled, fuse file system makes sure
/// to remove security.capability xattr and setuid/setgid bits. See details in
/// comments for HANDLE_KILLPRIV_V2
#[cfg(not(target_os = "macos"))]
pub killpriv_v2: bool,
/// Reject requests which will change the file size, or allocate file
/// blocks exceed file size.
pub seal_size: bool,
/// File system options passed in from client
pub in_opts: FsOptions,
/// File system options returned to client
pub out_opts: FsOptions,
/// Declaration of ID mapping, in the format (internal ID, external ID, range).
/// For example, (0, 1, 65536) represents mapping the external UID/GID range of `1~65536`
/// to the range of `0~65535` within the filesystem.
pub id_mapping: (u32, u32, u32),
}

impl VfsOptions {
Expand All @@ -259,8 +260,8 @@ impl VfsOptions {
}

impl Default for VfsOptions {
#[cfg(not(target_os = "macos"))]
fn default() -> Self {
#[cfg(not(target_os = "macos"))]
let out_opts = FsOptions::ASYNC_READ
| FsOptions::PARALLEL_DIROPS
| FsOptions::BIG_WRITES
Expand All @@ -278,24 +279,30 @@ impl Default for VfsOptions {
| FsOptions::ZERO_MESSAGE_OPENDIR
| FsOptions::HANDLE_KILLPRIV_V2
| FsOptions::PERFILE_DAX;
#[cfg(target_os = "macos")]
let out_opts = FsOptions::ASYNC_READ | FsOptions::BIG_WRITES | FsOptions::ATOMIC_O_TRUNC;
VfsOptions {
#[cfg(not(target_os = "macos"))]
no_open: true,
#[cfg(not(target_os = "macos"))]
no_opendir: true,
#[cfg(not(target_os = "macos"))]
no_writeback: false,
no_readdir: false,
seal_size: false,
#[cfg(not(target_os = "macos"))]
killpriv_v2: false,
in_opts: FsOptions::empty(),
out_opts,
id_mapping: (0, 0, 0),
}
}

#[cfg(target_os = "macos")]
fn default() -> Self {
let out_opts = FsOptions::ASYNC_READ | FsOptions::BIG_WRITES | FsOptions::ATOMIC_O_TRUNC;
VfsOptions {
no_readdir: false,
seal_size: false,
in_opts: FsOptions::empty(),
out_opts,
id_mapping: (0, 0, 0),
}
}
}

/// A union fs that combines multiple backend file systems.
Expand Down

0 comments on commit 8e2c9e5

Please sign in to comment.