Skip to content

chore: Bump versions of nix and libc #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ bitflags = "1.1"
dbs-snapshot = { version = "1.5.2", optional = true }
io-uring = { version = "0.5.8", optional = true }
lazy_static = "1.4"
libc = "0.2.68"
libc = "0.2.172"
log = "0.4.6"
mio = { version = "0.8", features = ["os-poll", "os-ext"] }
nix = "0.24"
nix = { version = "0.30", features = ["event", "fs", "ioctl", "mount", "poll", "uio", "user"] }
radix_trie = "0.2.1"
tokio = { version = "1", optional = true }
tokio-uring = { version = "0.4.0", optional = true }
Expand Down
40 changes: 23 additions & 17 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,21 +1412,18 @@ mod tests {
use crate::transport::FuseBuf;

use std::fs::File;
use std::os::unix::io::AsRawFd;
use std::os::fd::AsFd;
use vmm_sys_util::tempfile::TempFile;

fn prepare_srvcontext<'a>(
file: &'a File,
read_buf: &'a mut [u8],
write_buf: &'a mut [u8],
) -> (SrvContext<'a, PassthroughFs>, File) {
let file = TempFile::new().unwrap().into_file();
) -> SrvContext<'a, PassthroughFs> {
let reader = Reader::<()>::from_fuse_buffer(FuseBuf::new(read_buf)).unwrap();
let writer = FuseDevWriter::<()>::new(file.as_raw_fd(), write_buf).unwrap();
let writer = FuseDevWriter::<()>::new(file.as_fd(), write_buf).unwrap();
let in_header = InHeader::default();
(
SrvContext::<PassthroughFs>::new(in_header, reader, writer.into()),
file,
)
SrvContext::<PassthroughFs>::new(in_header, reader, writer.into())
}

#[test]
Expand All @@ -1441,7 +1438,8 @@ mod tests {
0x0, 0x0, 0x0, 0x0, // flags = 0x0000
];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

let res = server.init(ctx).unwrap();
assert_eq!(res, 80);
Expand All @@ -1453,7 +1451,8 @@ mod tests {
0x0, 0x0, 0x0, 0x0, // flags = 0x0000
];
let mut write_buf1 = [0u8; 4096];
let (ctx1, _file) = prepare_srvcontext(&mut read_buf1, &mut write_buf1);
let file = TempFile::new().unwrap().into_file();
let ctx1 = prepare_srvcontext(&file, &mut read_buf1, &mut write_buf1);

let res = server.init(ctx1).unwrap();
assert_eq!(res, 24);
Expand All @@ -1466,7 +1465,8 @@ mod tests {

let mut read_buf = [0u8; 4096];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

let res = server.write(ctx).unwrap();
assert_eq!(res, 16);
Expand All @@ -1479,7 +1479,8 @@ mod tests {

let mut read_buf = [0u8; 4096];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

let res = server.read(ctx).unwrap();
assert_eq!(res, 16);
Expand All @@ -1492,7 +1493,8 @@ mod tests {

let mut read_buf = [0u8; 4096];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

let res = server.do_readdir(ctx, true).unwrap();
assert_eq!(res, 16);
Expand All @@ -1505,7 +1507,8 @@ mod tests {

let mut read_buf = [0u8; 4096];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

let res = server.ioctl(ctx).unwrap();
assert!(res > 0);
Expand All @@ -1520,7 +1523,8 @@ mod tests {
0x0, 0x0, 0x0, 0x0, //out_size = 0
];
let mut write_buf_fail = [0u8; 48];
let (ctx_fail, _file) = prepare_srvcontext(&mut read_buf_fail, &mut write_buf_fail);
let file = TempFile::new().unwrap().into_file();
let ctx_fail = prepare_srvcontext(&file, &mut read_buf_fail, &mut write_buf_fail);
let res = server.ioctl(ctx_fail).unwrap();
assert!(res > 0);
}
Expand All @@ -1532,7 +1536,8 @@ mod tests {

let mut read_buf = [0u8; 4096];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);
// forget should return 0 anyway
assert_eq!(server.batch_forget(ctx).unwrap(), 0);
}
Expand All @@ -1544,7 +1549,8 @@ mod tests {

let mut read_buf = [0x1u8, 0x2u8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0];
let mut write_buf = [0u8; 4096];
let (ctx, _file) = prepare_srvcontext(&mut read_buf, &mut write_buf);
let file = TempFile::new().unwrap().into_file();
let ctx = prepare_srvcontext(&file, &mut read_buf, &mut write_buf);

assert_eq!(server.forget(ctx).unwrap(), 0);
}
Expand Down
38 changes: 17 additions & 21 deletions src/transport/fusedev/linux_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::fs::{File, OpenOptions};
use std::ops::Deref;
use std::os::fd::AsFd;
use std::os::unix::fs::PermissionsExt;
use std::os::unix::io::AsRawFd;
use std::os::unix::net::UnixStream;
Expand All @@ -20,8 +21,8 @@ use mio::{Events, Poll, Token, Waker};
use nix::errno::Errno;
use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
use nix::mount::{mount, umount2, MntFlags, MsFlags};
use nix::poll::{poll, PollFd, PollFlags};
use nix::sys::epoll::{epoll_ctl, EpollEvent, EpollFlags, EpollOp};
use nix::poll::{poll, PollFd, PollFlags, PollTimeout};
use nix::sys::epoll::{Epoll, EpollCreateFlags, EpollEvent, EpollFlags};
use nix::unistd::{getgid, getuid, read};

use super::{
Expand Down Expand Up @@ -199,7 +200,7 @@ impl FuseSession {
&self.fusermount,
)?;

fcntl(file.as_raw_fd(), FcntlArg::F_SETFL(OFlag::O_NONBLOCK))
fcntl(file.as_fd(), FcntlArg::F_SETFL(OFlag::O_NONBLOCK))
.map_err(|e| SessionFailure(format!("set fd nonblocking: {e}")))?;
self.file = Some(file);
self.keep_alive = socket;
Expand Down Expand Up @@ -244,7 +245,7 @@ impl FuseSession {
F: FnOnce(FuseDevWriter),
{
if let Some(file) = &self.file {
let fd = file.as_raw_fd();
let fd = file.as_fd();
let mut buf = vec![0x0u8; self.bufsize];
let writer = FuseDevWriter::new(fd, &mut buf).unwrap();
f(writer);
Expand Down Expand Up @@ -301,15 +302,11 @@ impl FuseChannel {
// mio default add EPOLLET to event flags, so epoll will use edge-triggered mode.
// It may let poll miss some event, so manually register the fd with only EPOLLIN flag
// to use level-triggered mode.
let epoll = poll.as_raw_fd();
let mut event = EpollEvent::new(EpollFlags::EPOLLIN, usize::from(FUSE_DEV_EVENT) as u64);
epoll_ctl(
epoll,
EpollOp::EpollCtlAdd,
file.as_raw_fd(),
Some(&mut event),
)
.map_err(|e| SessionFailure(format!("epoll register channel fd: {e}")))?;
let epoll = Epoll::new(EpollCreateFlags::empty()).unwrap();
let event = EpollEvent::new(EpollFlags::EPOLLIN, usize::from(FUSE_DEV_EVENT) as u64);
epoll
.add(&file, event)
.map_err(|e| SessionFailure(format!("epoll register channel fd: {e}")))?;

Ok(FuseChannel {
file,
Expand Down Expand Up @@ -366,7 +363,7 @@ impl FuseChannel {
return Ok(None);
}
if fusereq_available {
let fd = self.file.as_raw_fd();
let fd = self.file.as_fd();
match read(fd, &mut self.buf) {
Ok(len) => {
// ###############################################
Expand Down Expand Up @@ -403,7 +400,7 @@ impl FuseChannel {
return Ok(None);
}
e => {
warn! {"read fuse dev failed on fd {}: {}", fd, e};
warn! {"read fuse dev failed on fd {}: {}", fd.as_raw_fd(), e};
return Err(SessionFailure(format!("read new request: {e:?}")));
}
},
Expand Down Expand Up @@ -562,7 +559,7 @@ fn fuse_fusermount_mount(
// When its partner recv closes, fusermount will unmount.
// Remove the close-on-exec flag from the socket, so we can pass it to
// fusermount.
fcntl(send.as_raw_fd(), FcntlArg::F_SETFD(FdFlag::empty()))
fcntl(send.as_fd(), FcntlArg::F_SETFD(FdFlag::empty()))
.map_err(|e| SessionFailure(format!("Failed to remove close-on-exec flag: {e}")))?;

let mut cmd = match target_mntns {
Expand Down Expand Up @@ -619,9 +616,9 @@ fn fuse_fusermount_mount(

/// Umount a fuse file system
fn fuse_kern_umount(mountpoint: &str, file: File, fusermount: &str) -> Result<()> {
let mut fds = [PollFd::new(file.as_raw_fd(), PollFlags::empty())];
let mut fds = [PollFd::new(file.as_fd(), PollFlags::empty())];

if poll(&mut fds, 0).is_ok() {
if poll(&mut fds, PollTimeout::ZERO).is_ok() {
// POLLERR means the file system is already umounted,
// or the connection has been aborted via /sys/fs/fuse/connections/NNN/abort
if let Some(event) = fds[0].revents() {
Expand Down Expand Up @@ -666,7 +663,6 @@ fn fuse_fusermount_umount(mountpoint: &str, fusermount: &str) -> Result<()> {
mod tests {
use super::*;
use std::fs::File;
use std::os::unix::io::FromRawFd;
use std::path::Path;
use vmm_sys_util::tempdir::TempDir;

Expand All @@ -682,8 +678,8 @@ mod tests {

#[test]
fn test_new_channel() {
let fd = nix::unistd::dup(std::io::stdout().as_raw_fd()).unwrap();
let file = unsafe { File::from_raw_fd(fd) };
let fd = nix::unistd::dup(std::io::stdout().as_fd()).unwrap();
let file = File::from(fd);
let _ = FuseChannel::new(file, 3).unwrap();
}

Expand Down
Loading