Skip to content

Commit 7e24a63

Browse files
committed
macos: get rid of dependency on the diskarbitration-sys crate
The diskarbitration-sys crate is out of maintenance, and locks the core-foundataion-sys crate to an very old version. So avoid dependency on it. Signed-off-by: Jiang Liu <[email protected]>
1 parent 1a83f60 commit 7e24a63

File tree

5 files changed

+59
-27
lines changed

5 files changed

+59
-27
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fuse-backend-rs"
3-
version = "0.9.3"
3+
version = "0.9.4"
44
keywords = ["fuse", "virtio", "virtio-fs", "vhost-user-fs"]
55
categories = ["filesystem", "os::linux-apis"]
66
description = "A rust library for Fuse(filesystem in userspace) servers and virtio-fs devices"
@@ -14,6 +14,7 @@ license = "Apache-2.0 AND BSD-3-Clause"
1414
edition = "2018"
1515
repository = "https://github.com/cloud-hypervisor/fuse-backend-rs"
1616
homepage = "https://github.com/cloud-hypervisor/"
17+
build = "build.rs"
1718

1819
[dependencies]
1920
arc-swap = ">=0.4.6"
@@ -23,7 +24,7 @@ bitflags = "1.1"
2324
#iou = { version = "0.3.3", optional = true }
2425
libc = "0.2.68"
2526
log = "0.4.6"
26-
nix = "0.23"
27+
nix = "0.24"
2728
lazy_static = "1.4"
2829
#ringbahn = { version = "0.0.0-experimental.3", optional = true }
2930
vmm-sys-util = { version = "0.9", optional = true }
@@ -33,8 +34,7 @@ vhost = { version = "0.3", features = ["vhost-user-slave"], optional = true }
3334
mio = { version = "0.8", features = ["os-poll", "os-ext"]}
3435

3536
[target.'cfg(target_os = "macos")'.dependencies]
36-
core-foundation-sys = { version = "0.2.3", optional = true }
37-
diskarbitration-sys = { version = "0.0.4", optional = true }
37+
core-foundation-sys = { version = ">=0.8", optional = true }
3838

3939
[target.'cfg(target_os = "linux")'.dependencies]
4040
caps = { version = "0.3", optional = true }
@@ -48,7 +48,7 @@ vm-memory = { version = "0.7", features = ["backend-mmap", "backend-bitmap"] }
4848
[features]
4949
default = ["fusedev"]
5050
#async-io = ["async-trait", "futures", "iou", "ringbahn", "caps]
51-
fusedev = ["vmm-sys-util", "caps", "core-foundation-sys", "diskarbitration-sys"]
51+
fusedev = ["vmm-sys-util", "caps", "core-foundation-sys"]
5252
virtiofs = ["virtio-queue", "caps"]
5353
vhost-user-fs = ["virtiofs", "vhost", "caps"]
5454

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
#[cfg(target_os = "macos")]
3+
println!("cargo:rustc-link-lib=framework=DiskArbitration");
4+
}

src/transport/fusedev/macos_session.rs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
//! sequentially. A FUSE session is a connection from a FUSE mountpoint to a FUSE server daemon.
99
//! A FUSE session can have multiple FUSE channels so that FUSE requests are handled in parallel.
1010
11-
use core_foundation_sys::base::{CFIndex, CFRelease};
11+
use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFRelease};
1212
use core_foundation_sys::string::{kCFStringEncodingUTF8, CFStringCreateWithBytes};
13-
use core_foundation_sys::url::{kCFURLPOSIXPathStyle, CFURLCreateWithFileSystemPath};
14-
use diskarbitration_sys::base::{kDADiskUnmountOptionForce, DADiskUnmount};
15-
use diskarbitration_sys::disk::{DADiskCreateFromVolumePath, DADiskRef};
16-
use diskarbitration_sys::session::{DASessionCreate, DASessionRef};
13+
use core_foundation_sys::url::{kCFURLPOSIXPathStyle, CFURLCreateWithFileSystemPath, CFURLRef};
1714
use std::ffi::CString;
1815
use std::fs::File;
16+
use std::io::IoSliceMut;
1917
use std::os::unix::ffi::OsStrExt;
2018
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
2119
use std::path::{Path, PathBuf};
@@ -27,9 +25,9 @@ use nix::errno::Errno;
2725
use nix::fcntl::{fcntl, FdFlag, F_SETFD};
2826
use nix::sys::signal::{signal, SigHandler, Signal};
2927
use nix::sys::socket::{
30-
recvmsg, socketpair, AddressFamily, ControlMessageOwned, MsgFlags, SockFlag, SockType,
28+
recvmsg, socketpair, AddressFamily, ControlMessageOwned, MsgFlags, RecvMsg, SockFlag, SockType,
29+
UnixAddr,
3130
};
32-
use nix::sys::uio::IoVec;
3331
use nix::unistd::{close, execv, fork, getpid, read, ForkResult};
3432
use nix::{cmsg_space, NixPath};
3533

@@ -42,6 +40,37 @@ const FUSE_HEADER_SIZE: usize = 0x1000;
4240

4341
const OSXFUSE_MOUNT_PROG: &str = "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse";
4442

43+
static K_DADISK_UNMOUNT_OPTION_FORCE: u64 = 524288;
44+
45+
#[repr(C)]
46+
struct __DADisk(c_void);
47+
type DADiskRef = *const __DADisk;
48+
#[repr(C)]
49+
struct __DADissenter(c_void);
50+
type DADissenterRef = *const __DADissenter;
51+
#[repr(C)]
52+
struct __DASession(c_void);
53+
type DASessionRef = *const __DASession;
54+
55+
type DADiskUnmountCallback = ::std::option::Option<
56+
unsafe extern "C" fn(disk: DADiskRef, dissenter: DADissenterRef, context: *mut c_void),
57+
>;
58+
59+
extern "C" {
60+
fn DADiskUnmount(
61+
disk: DADiskRef,
62+
options: u64,
63+
callback: DADiskUnmountCallback,
64+
context: *mut c_void,
65+
);
66+
fn DADiskCreateFromVolumePath(
67+
allocator: CFAllocatorRef,
68+
session: DASessionRef,
69+
path: CFURLRef,
70+
) -> DADiskRef;
71+
fn DASessionCreate(allocator: CFAllocatorRef) -> DASessionRef;
72+
}
73+
4574
mod ioctl {
4675
use nix::ioctl_write_ptr;
4776

@@ -247,8 +276,9 @@ impl FuseChannel {
247276
fn receive_fd(sock_fd: RawFd) -> Result<RawFd> {
248277
let mut buffer = vec![0u8; 4];
249278
let mut cmsgspace = cmsg_space!(RawFd);
250-
let iov = [IoVec::from_mut_slice(&mut buffer)];
251-
let r = recvmsg(sock_fd, &iov, Some(&mut cmsgspace), MsgFlags::empty()).unwrap();
279+
let mut iov = [IoSliceMut::new(&mut buffer)];
280+
let r: RecvMsg<UnixAddr> =
281+
recvmsg(sock_fd, &mut iov, Some(&mut cmsgspace), MsgFlags::empty()).unwrap();
252282
if let Some(msg) = r.cmsgs().next() {
253283
match msg {
254284
ControlMessageOwned::ScmRights(fds) => {
@@ -362,7 +392,6 @@ fn create_disk(mountpoint: &Path, dasession: DASessionRef) -> DADiskRef {
362392
path_len as CFIndex,
363393
kCFStringEncodingUTF8,
364394
1u8,
365-
std::ptr::null(),
366395
);
367396
let url =
368397
CFURLCreateWithFileSystemPath(std::ptr::null(), url_str, kCFURLPOSIXPathStyle, 1u8);
@@ -385,7 +414,12 @@ fn fuse_kern_umount(file: File, disk: Option<DADiskRef>) -> Result<()> {
385414

386415
if let Some(disk) = disk {
387416
unsafe {
388-
DADiskUnmount(disk, kDADiskUnmountOptionForce, None, std::ptr::null_mut());
417+
DADiskUnmount(
418+
disk,
419+
K_DADISK_UNMOUNT_OPTION_FORCE,
420+
None,
421+
std::ptr::null_mut(),
422+
);
389423
CFRelease(std::mem::transmute(disk));
390424
}
391425
}

src/transport/fusedev/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::marker::PhantomData;
1111
use std::mem::ManuallyDrop;
1212
use std::os::unix::io::RawFd;
1313

14-
use nix::sys::uio::{writev, IoVec};
14+
use nix::sys::uio::writev;
1515
use nix::unistd::write;
1616
use vm_memory::{ByteValued, VolatileMemory, VolatileMemoryError, VolatileSlice};
1717

@@ -186,7 +186,7 @@ impl<'a, S: BitmapSlice> Writer<'a, S> {
186186
(0, _) => write(self.fd, o),
187187
(_, 0) => write(self.fd, self.buf.as_slice()),
188188
(_, _) => {
189-
let bufs = [IoVec::from_slice(self.buf.as_slice()), IoVec::from_slice(o)];
189+
let bufs = [IoSlice::new(self.buf.as_slice()), IoSlice::new(o)];
190190
writev(self.fd, &bufs)
191191
}
192192
};
@@ -351,16 +351,10 @@ impl<'a, S: BitmapSlice> io::Write for Writer<'a, S> {
351351
});
352352
Ok(count)
353353
} else {
354-
let buf: Vec<IoVec<&[u8]>> = bufs
355-
.iter()
356-
.filter(|b| !b.is_empty())
357-
.map(|b| IoVec::from_slice(b))
358-
.collect();
359-
360-
if buf.is_empty() {
354+
if bufs.is_empty() {
361355
return Ok(0);
362356
}
363-
writev(self.fd, buf.as_slice())
357+
writev(self.fd, bufs)
364358
.map(|x| {
365359
self.account_written(x);
366360
x

tests/macfuse_smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod macfuse_tests {
6666
}
6767

6868
#[test]
69-
// #[ignore] // it depends on privileged mode to pass through /dev/fuse
69+
#[ignore] // it depends on privileged mode to pass through /dev/fuse
7070
fn integration_test_macfuse_hello() -> Result<()> {
7171
// test the fuse-rs repository
7272
let tmp_dir = TempDir::new().unwrap();

0 commit comments

Comments
 (0)