Skip to content
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

chore: update crate dependencies #101

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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
720 changes: 289 additions & 431 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ members = [
[workspace.dependencies]
a653rs = "0.5"
log = "0"
nix = { version = "0.27", features = ["socket", "process", "fs", "uio", "signal", "user", "mount", "event", "sched"] }
memmap2 = "0.9"
procfs = "0.16"
polling = "3.4"
itertools = "0.12.1"
once_cell = "1.19"
10 changes: 5 additions & 5 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ license = "MIT OR Apache-2.0"
[dependencies]
a653rs.workspace = true
a653rs.features = [ "bindings" ]
nix.workspace = true
memmap2.workspace = true
procfs.workspace = true
polling.workspace = true
itertools.workspace = true

nix = "0.25"
anyhow = "1.0"
procfs = "0.14"
itertools = "0.10"
log = "0"
walkdir = "2.3"
polling = "2.2"
serde = { version = "1.0", features = ["derive"] }
memmap2 = "0.5.5"
memfd = "0.6"
bincode = "1.3"
thiserror = "1.0"
Expand Down
5 changes: 3 additions & 2 deletions core/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn mount_point() -> anyhow::Result<PathBuf> {
// TODO: This is an awful old function, replace it!
procfs::process::Process::myself()?
.mountinfo()?
.iter()
.into_iter()
.find(|m| m.fs_type.eq("cgroup2")) // TODO A process can have several cgroup mounts
.ok_or_else(|| anyhow!("no cgroup2 mount found"))
.map(|m| m.mount_point.clone())
Expand All @@ -244,7 +244,8 @@ pub fn mount_point() -> anyhow::Result<PathBuf> {
pub fn current_cgroup() -> anyhow::Result<PathBuf> {
let path = procfs::process::Process::myself()?
.cgroups()?
.first()
.into_iter()
.next()
.ok_or(anyhow!("cannot obtain cgroup"))?
.pathname
.clone();
Expand Down
6 changes: 3 additions & 3 deletions core/src/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::{Duration, Instant};
use anyhow::{anyhow, Result};
use nix::libc::{c_uint, syscall, SYS_pidfd_open};
use nix::unistd::Pid;
use polling::{Event, Poller};
use polling::{Event, Events, Poller};

use crate::error::{ResultExt, SystemError, TypedError, TypedResult};

Expand Down Expand Up @@ -48,12 +48,12 @@ impl PidFd {
// epoll(2) internals, which demand providing a "user data variable" -- a
// feature that we make no use of.
poller
.modify(self.0.as_raw_fd(), Event::readable(42))
.modify(&self.0, Event::readable(42))
.map_err(anyhow::Error::from)
.typ(SystemError::Panic)?;

let poll_res = poller.wait(
Vec::new().as_mut(),
&mut Events::new(),
Some(timeout.saturating_sub(now.elapsed())),
);
match poll_res {
Expand Down
72 changes: 60 additions & 12 deletions core/src/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Implementation of IPC
use std::io::{ErrorKind, IoSlice, IoSliceMut};
use std::marker::PhantomData;
use std::os::fd::{AsFd, BorrowedFd, OwnedFd};
use std::os::unix::net::UnixDatagram;
use std::os::unix::prelude::{AsRawFd, FromRawFd, RawFd};
use std::time::Duration;
Expand All @@ -12,7 +13,7 @@ use nix::sys::socket::{
recvmsg, sendmsg, socketpair, AddressFamily, ControlMessage, ControlMessageOwned, MsgFlags,
SockFlag, SockType,
};
use polling::{Event, Poller};
use polling::{Event, Events, Poller};
use serde::{Deserialize, Serialize};

use crate::error::{ResultExt, SystemError, TypedResult};
Expand Down Expand Up @@ -75,11 +76,12 @@ where
/// duration
pub fn try_recv_timeout(&self, duration: Duration) -> TypedResult<Option<T>> {
let poller = Poller::new().typ(SystemError::Panic)?;
poller
.add(self.socket.as_raw_fd(), Event::readable(42))
.typ(SystemError::Panic)?;

let poll_res = poller.wait(Vec::new().as_mut(), Some(duration));
unsafe {
poller
.add(&self.socket, Event::readable(42))
.typ(SystemError::Panic)?;
}
let poll_res = poller.wait(&mut Events::new(), Some(duration));
if let Err(_) | Ok(0) = poll_res {
return Ok(None);
}
Expand All @@ -102,12 +104,10 @@ where
)
.typ(SystemError::Panic)?;

unsafe {
let tx = IpcSender::from_raw_fd(tx);
let rx = IpcReceiver::from_raw_fd(rx);
let tx = IpcSender::from(tx);
let rx = IpcReceiver::from(rx);

Ok((tx, rx))
}
Ok((tx, rx))
}

impl<T> AsRawFd for IpcSender<T> {
Expand All @@ -122,6 +122,36 @@ impl<T> AsRawFd for IpcReceiver<T> {
}
}

impl<T> AsFd for IpcSender<T> {
fn as_fd(&self) -> BorrowedFd<'_> {
self.socket.as_fd()
}
}

impl<T> AsFd for IpcReceiver<T> {
fn as_fd(&self) -> BorrowedFd<'_> {
self.socket.as_fd()
}
}

impl<T> From<OwnedFd> for IpcSender<T> {
fn from(value: OwnedFd) -> Self {
Self {
socket: UnixDatagram::from(value),
_p: PhantomData,
}
}
}

impl<T> From<OwnedFd> for IpcReceiver<T> {
fn from(value: OwnedFd) -> Self {
Self {
socket: UnixDatagram::from(value),
_p: PhantomData,
}
}
}

impl<T> FromRawFd for IpcSender<T> {
unsafe fn from_raw_fd(fd: RawFd) -> Self {
Self {
Expand Down Expand Up @@ -150,7 +180,7 @@ pub fn io_pair<T>() -> TypedResult<(IoSender<T>, IoReceiver<T>)> {
SockFlag::empty(),
)
.typ(SystemError::Panic)?;
unsafe { Ok((IoSender::from_raw_fd(tx), IoReceiver::from_raw_fd(rx))) }
Ok((IoSender::from(tx), IoReceiver::from(rx)))
}

#[derive(Debug)]
Expand Down Expand Up @@ -229,6 +259,24 @@ impl<T> AsRawFd for IoReceiver<T> {
}
}

impl<T> From<OwnedFd> for IoSender<T> {
fn from(value: OwnedFd) -> Self {
Self {
socket: UnixDatagram::from(value),
_p: PhantomData,
}
}
}

impl<T> From<OwnedFd> for IoReceiver<T> {
fn from(value: OwnedFd) -> Self {
Self {
socket: UnixDatagram::from(value),
_p: PhantomData,
}
}
}

impl<T> FromRawFd for IoSender<T> {
unsafe fn from_raw_fd(fd: RawFd) -> Self {
Self {
Expand Down
8 changes: 4 additions & 4 deletions examples/fuel_tank_controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license = "MIT OR Apache-2.0"
[dependencies]
a653rs = { workspace = true, features = ["macros"] }
a653rs-linux = { path = "../../partition" }
nix.workspace = true
memmap2.workspace = true
procfs.workspace = true
once_cell.workspace = true
serde = "1.0"
procfs = "0.14"
log = "0"
nix = "0.25"
memmap2 = "0.5.5"
once_cell = "1.13"
8 changes: 4 additions & 4 deletions examples/fuel_tank_simulation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ license = "MIT OR Apache-2.0"
a653rs = { workspace = true, features = ["macros"] }
a653rs-linux = { path = "../../partition" }
serde = { version = "1.0", features = ["derive"] }
procfs = "0.14"
procfs.workspace = true
nix.workspace = true
memmap2.workspace = true
once_cell.workspace = true
log = "0"
nix = "0.25"
memmap2 = "0.5.5"
once_cell = "1.13"
8 changes: 4 additions & 4 deletions examples/hello_part/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ license = "MIT OR Apache-2.0"
a653rs = { workspace = true, features = ["macros"] }
a653rs-postcard = { git = "https://github.com/DLR-FT/a653rs-postcard.git", branch = "main" }
a653rs-linux = { path = "../../partition" }
nix.workspace = true
memmap2.workspace = true
procfs.workspace = true
once_cell.workspace = true
serde = "1.0"
procfs = "0.14"
log = "0"
nix = "0.25"
memmap2 = "0.5.5"
humantime = "2.1"
once_cell = "1.13"
19 changes: 9 additions & 10 deletions hypervisor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@ a653rs.features = [ "bindings" ]
#apex-hal = { path = "../../a653rs", features = ["p4"] }
a653rs-linux-core = { path = "../core" }


# Required
nix = "0.25"
nix.workspace = true
memmap2.workspace = true
procfs.workspace = true
polling.workspace = true
itertools.workspace = true
once_cell.workspace = true
anyhow = "1.0"
tempfile = "3.3"
clone3 = "0.2"
serde = { version = "1.0", features = ["derive"] }
libc = "0.2"
procfs = "0.14"
itertools = "0.10"
clap = { version = "4", features = [ "derive" ] }
serde_yaml = "0"
humantime = "1"
humantime = "2.1"
humantime-serde = "1"
memmap2 = "0.5.5"
log = "0"
pretty_env_logger = "0.5"
quit = "1.1"
quit = "2.0"
memfd = "0.6"
num = "0.4"
once_cell = "1.13"
polling = "2.2"
thiserror = "1.0"
which = "4.4.0"
which = "6.0"
35 changes: 19 additions & 16 deletions hypervisor/src/hypervisor/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use itertools::Itertools;
use nix::mount::{mount, umount2, MntFlags, MsFlags};
use nix::sys::socket::{self, bind, AddressFamily, SockFlag, SockType, UnixAddr};
use nix::unistd::{chdir, close, pivot_root, setgid, setuid, Gid, Pid, Uid};
use polling::{Event, Poller};
use polling::{Event, Events, Poller};
use procfs::process::Process;
use tempfile::{tempdir, TempDir};

Expand Down Expand Up @@ -308,7 +308,11 @@ impl Run {
)
.unwrap();

bind(syscall_socket, &UnixAddr::new(SYSCALL_SOCKET_PATH).unwrap()).unwrap();
bind(
syscall_socket.as_raw_fd(),
&UnixAddr::new(SYSCALL_SOCKET_PATH).unwrap(),
)
.unwrap();

let constants: RawFd = PartitionConstants {
name: base.name.clone(),
Expand Down Expand Up @@ -998,13 +1002,15 @@ impl PeriodicPoller {
let events = run.periodic_events()?;

let poll = Poller::new().typ(SystemError::Panic)?;
poll.add(events.as_raw_fd(), Event::readable(Self::EVENTS_ID))
unsafe {
poll.add(events.as_raw_fd(), Event::readable(Self::EVENTS_ID))
.typ(SystemError::Panic)?;
poll.add(
run.receiver().as_raw_fd(),
Event::readable(Self::RECEIVER_ID),
)
.typ(SystemError::Panic)?;
poll.add(
run.receiver().as_raw_fd(),
Event::readable(Self::RECEIVER_ID),
)
.typ(SystemError::Panic)?;
}

Ok(PeriodicPoller { poll, events })
}
Expand All @@ -1015,18 +1021,18 @@ impl PeriodicPoller {
}

while timeout.has_time_left() {
let mut events = vec![];
let mut events = Events::new();
self.poll
.wait(events.as_mut(), Some(timeout.remaining_time()))
.wait(&mut events, Some(timeout.remaining_time()))
.typ(SystemError::Panic)?;

for e in events {
for e in events.iter() {
match e.key {
// Got a Frozen event
Self::EVENTS_ID => {
// Re-sub the readable event
self.poll
.modify(self.events.as_raw_fd(), Event::readable(Self::EVENTS_ID))
.modify(&mut self.events, Event::readable(Self::EVENTS_ID))
.typ(SystemError::Panic)?;

// Then check if the cg is actually frozen
Expand All @@ -1042,10 +1048,7 @@ impl PeriodicPoller {
// accidentally missing an event (at the expense of one extra loop per
// receive)
self.poll
.modify(
run.receiver().as_raw_fd(),
Event::readable(Self::RECEIVER_ID),
)
.modify(run.receiver(), Event::readable(Self::RECEIVER_ID))
.typ(SystemError::Panic)?;

// Now receive anything
Expand Down
Loading
Loading