mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
base: rename EventFd to Event
Note that - the file/symbols within `src/sys/unix/eventfd.rs` have not changed yet. - base still exports EventFd to keep common/cros_asyncv2 happy BUG=b:213153157 TEST=presubmit Change-Id: Ie0a4308e8501d2e91364b049e6575d656af866cd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3624568 Reviewed-by: Noah Gold <nkgold@google.com> Commit-Queue: Vikram Auradkar <auradkar@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
6ec88e1c1d
commit
cdb9e125ae
9 changed files with 58 additions and 57 deletions
|
@ -8,16 +8,17 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
|
||||
pub use crate::platform::EventReadResult;
|
||||
use crate::{generate_scoped_event, platform::EventFd, RawDescriptor, Result};
|
||||
use crate::{generate_scoped_event, platform::Event as PlatformEvent, RawDescriptor, Result};
|
||||
|
||||
/// See [EventFd](crate::platform::EventFd) for struct- and method-level
|
||||
/// See [PlatformEvent](crate::platform::PlatformEvent) for struct- and method-level
|
||||
/// documentation.
|
||||
// TODO(b:231344063) Move/update documentation.
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Event(pub EventFd);
|
||||
pub struct Event(pub PlatformEvent);
|
||||
impl Event {
|
||||
pub fn new() -> Result<Event> {
|
||||
EventFd::new().map(Event)
|
||||
PlatformEvent::new().map(Event)
|
||||
}
|
||||
|
||||
pub fn write(&self, v: u64) -> Result<()> {
|
||||
|
@ -45,7 +46,7 @@ impl AsRawDescriptor for Event {
|
|||
|
||||
impl FromRawDescriptor for Event {
|
||||
unsafe fn from_raw_descriptor(descriptor: RawDescriptor) -> Self {
|
||||
Event(EventFd::from_raw_descriptor(descriptor))
|
||||
Event(PlatformEvent::from_raw_descriptor(descriptor))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ impl FileFlags {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{pipe, EventFd},
|
||||
super::{pipe, Event},
|
||||
*,
|
||||
};
|
||||
|
||||
|
@ -48,8 +48,8 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn eventfd() {
|
||||
let evt = EventFd::new().unwrap();
|
||||
fn event() {
|
||||
let evt = Event::new().unwrap();
|
||||
assert_eq!(FileFlags::from_file(&evt).unwrap(), FileFlags::ReadWrite);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,10 @@ pub use acpi_event::*;
|
|||
pub use base_poll_token_derive::*;
|
||||
pub use capabilities::drop_capabilities;
|
||||
pub use descriptor::*;
|
||||
pub use eventfd::*;
|
||||
// EventFd is deprecated. Use Event instead. EventFd will be removed as soon as rest of the current
|
||||
// users migrate.
|
||||
// TODO(b:231344063): Remove EventFd.
|
||||
pub use eventfd::{EventFd as Event, EventFd, EventReadResult};
|
||||
pub use file_flags::*;
|
||||
pub use get_filesystem_type::*;
|
||||
pub use ioctl::*;
|
||||
|
|
|
@ -500,10 +500,10 @@ impl<T: PollToken> IntoRawDescriptor for EpollContext<T> {
|
|||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use base::platform::{Result, EventFd, PollContext, PollEvents};
|
||||
/// # use base::platform::{Result, Event, PollContext, PollEvents};
|
||||
/// # fn test() -> Result<()> {
|
||||
/// let evt1 = EventFd::new()?;
|
||||
/// let evt2 = EventFd::new()?;
|
||||
/// let evt1 = Event::new()?;
|
||||
/// let evt2 = Event::new()?;
|
||||
/// evt2.write(1)?;
|
||||
///
|
||||
/// let ctx: PollContext<u32> = PollContext::new()?;
|
||||
|
@ -692,14 +692,14 @@ impl<T: PollToken> IntoRawDescriptor for PollContext<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::EventFd, *};
|
||||
use super::{super::Event, *};
|
||||
use base_poll_token_derive::PollToken;
|
||||
use std::{os::unix::net::UnixStream, time::Instant};
|
||||
|
||||
#[test]
|
||||
fn poll_context() {
|
||||
let evt1 = EventFd::new().unwrap();
|
||||
let evt2 = EventFd::new().unwrap();
|
||||
let evt1 = Event::new().unwrap();
|
||||
let evt2 = Event::new().unwrap();
|
||||
evt1.write(1).unwrap();
|
||||
evt2.write(1).unwrap();
|
||||
let ctx: PollContext<u32> = PollContext::build_with(&[(&evt1, 1), (&evt2, 2)]).unwrap();
|
||||
|
@ -730,7 +730,7 @@ mod tests {
|
|||
let ctx: PollContext<usize> = PollContext::new().unwrap();
|
||||
let mut evts = Vec::with_capacity(EVT_COUNT);
|
||||
for i in 0..EVT_COUNT {
|
||||
let evt = EventFd::new().unwrap();
|
||||
let evt = Event::new().unwrap();
|
||||
evt.write(1).unwrap();
|
||||
ctx.add(&evt, i).unwrap();
|
||||
evts.push(evt);
|
||||
|
|
|
@ -421,7 +421,7 @@ mod tests {
|
|||
|
||||
use libc::cmsghdr;
|
||||
|
||||
use super::super::EventFd;
|
||||
use super::super::Event;
|
||||
|
||||
// Doing this as a macro makes it easier to see the line if it fails
|
||||
macro_rules! CMSG_SPACE_TEST {
|
||||
|
@ -483,7 +483,7 @@ mod tests {
|
|||
fn send_recv_only_fd() {
|
||||
let (s1, s2) = UnixDatagram::pair().expect("failed to create socket pair");
|
||||
|
||||
let evt = EventFd::new().expect("failed to create eventfd");
|
||||
let evt = Event::new().expect("failed to create event");
|
||||
let ioslice = IoSlice::new([].as_ref());
|
||||
let write_count = s1
|
||||
.send_with_fd(&[ioslice], evt.as_raw_fd())
|
||||
|
@ -507,14 +507,14 @@ mod tests {
|
|||
file.write_all(unsafe { from_raw_parts(&1203u64 as *const u64 as *const u8, 8) })
|
||||
.expect("failed to write to sent fd");
|
||||
|
||||
assert_eq!(evt.read().expect("failed to read from eventfd"), 1203);
|
||||
assert_eq!(evt.read().expect("failed to read from event"), 1203);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_recv_with_fd() {
|
||||
let (s1, s2) = UnixDatagram::pair().expect("failed to create socket pair");
|
||||
|
||||
let evt = EventFd::new().expect("failed to create eventfd");
|
||||
let evt = Event::new().expect("failed to create event");
|
||||
let ioslice = IoSlice::new([237].as_ref());
|
||||
let write_count = s1
|
||||
.send_with_fds(&[ioslice], &[evt.as_raw_fd()])
|
||||
|
@ -541,6 +541,6 @@ mod tests {
|
|||
file.write_all(unsafe { from_raw_parts(&1203u64 as *const u64 as *const u8, 8) })
|
||||
.expect("failed to write to sent fd");
|
||||
|
||||
assert_eq!(evt.read().expect("failed to read from eventfd"), 1203);
|
||||
assert_eq!(evt.read().expect("failed to read from event"), 1203);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#[cfg(test)]
|
||||
use super::{FdExecutor, URingExecutor};
|
||||
use crate::{AsyncResult, EventAsync, Executor};
|
||||
use base::Event as EventFd;
|
||||
use base::Event;
|
||||
|
||||
impl EventAsync {
|
||||
pub fn new(event: EventFd, ex: &Executor) -> AsyncResult<EventAsync> {
|
||||
pub fn new(event: Event, ex: &Executor) -> AsyncResult<EventAsync> {
|
||||
ex.async_from(event)
|
||||
.map(|io_source| EventAsync { io_source })
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ impl EventAsync {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new_poll(event: EventFd, ex: &FdExecutor) -> AsyncResult<EventAsync> {
|
||||
pub(crate) fn new_poll(event: Event, ex: &FdExecutor) -> AsyncResult<EventAsync> {
|
||||
super::executor::async_poll_from(event, ex).map(|io_source| EventAsync { io_source })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new_uring(event: EventFd, ex: &URingExecutor) -> AsyncResult<EventAsync> {
|
||||
pub(crate) fn new_uring(event: Event, ex: &URingExecutor) -> AsyncResult<EventAsync> {
|
||||
super::executor::async_uring_from(event, ex).map(|io_source| EventAsync { io_source })
|
||||
}
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn next_val_reads_value() {
|
||||
async fn go(event: EventFd, ex: &Executor) -> u64 {
|
||||
async fn go(event: Event, ex: &Executor) -> u64 {
|
||||
let event_async = EventAsync::new(event, ex).unwrap();
|
||||
event_async.next_val().await.unwrap()
|
||||
}
|
||||
|
||||
let eventfd = EventFd::new().unwrap();
|
||||
let eventfd = Event::new().unwrap();
|
||||
eventfd.write(0xaa).unwrap();
|
||||
let ex = Executor::new().unwrap();
|
||||
let val = ex.run_until(go(eventfd, &ex)).unwrap();
|
||||
|
@ -59,7 +59,7 @@ mod tests {
|
|||
event_async.next_val().await.unwrap()
|
||||
}
|
||||
|
||||
let eventfd = EventFd::new().unwrap();
|
||||
let eventfd = Event::new().unwrap();
|
||||
eventfd.write(0xaa).unwrap();
|
||||
let uring_ex = URingExecutor::new().unwrap();
|
||||
let val = uring_ex
|
||||
|
@ -67,7 +67,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(val, 0xaa);
|
||||
|
||||
let eventfd = EventFd::new().unwrap();
|
||||
let eventfd = Event::new().unwrap();
|
||||
eventfd.write(0xaa).unwrap();
|
||||
let poll_ex = FdExecutor::new().unwrap();
|
||||
let val = poll_ex
|
||||
|
|
|
@ -23,10 +23,7 @@ use std::{
|
|||
};
|
||||
|
||||
use async_task::Task;
|
||||
use base::{
|
||||
add_fd_flags, warn, AsRawDescriptor, EpollContext, EpollEvents, Event as EventFd,
|
||||
WatchingEvents,
|
||||
};
|
||||
use base::{add_fd_flags, warn, AsRawDescriptor, EpollContext, EpollEvents, Event, WatchingEvents};
|
||||
use futures::task::noop_waker;
|
||||
use pin_utils::pin_mut;
|
||||
use remain::sorted;
|
||||
|
@ -43,12 +40,12 @@ use crate::{
|
|||
#[sorted]
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum Error {
|
||||
/// Failed to clone the EventFd for waking the executor.
|
||||
#[error("Failed to clone the EventFd for waking the executor: {0}")]
|
||||
CloneEventFd(base::Error),
|
||||
/// Failed to create the EventFd for waking the executor.
|
||||
#[error("Failed to create the EventFd for waking the executor: {0}")]
|
||||
CreateEventFd(base::Error),
|
||||
/// Failed to clone the Event for waking the executor.
|
||||
#[error("Failed to clone the Event for waking the executor: {0}")]
|
||||
CloneEvent(base::Error),
|
||||
/// Failed to create the Event for waking the executor.
|
||||
#[error("Failed to create the Event for waking the executor: {0}")]
|
||||
CreateEvent(base::Error),
|
||||
/// Creating a context to wait on FDs failed.
|
||||
#[error("An error creating the fd waiting context: {0}")]
|
||||
CreatingContext(base::Error),
|
||||
|
@ -77,8 +74,8 @@ impl From<Error> for io::Error {
|
|||
fn from(e: Error) -> Self {
|
||||
use Error::*;
|
||||
match e {
|
||||
CloneEventFd(e) => e.into(),
|
||||
CreateEventFd(e) => e.into(),
|
||||
CloneEvent(e) => e.into(),
|
||||
CreateEvent(e) => e.into(),
|
||||
DuplicatingFd(e) => e.into(),
|
||||
ExecutorGone => io::Error::new(io::ErrorKind::Other, e),
|
||||
CreatingContext(e) => e.into(),
|
||||
|
@ -217,15 +214,15 @@ impl Drop for PendingOperation {
|
|||
// * The executor then polls the non-epoll future that became ready, any epoll futures that
|
||||
// completed, and the notify_task function, which then queues up another read on the eventfd and
|
||||
// the process can repeat.
|
||||
async fn notify_task(notify: EventFd, raw: Weak<RawExecutor>) {
|
||||
async fn notify_task(notify: Event, raw: Weak<RawExecutor>) {
|
||||
add_fd_flags(notify.as_raw_descriptor(), libc::O_NONBLOCK)
|
||||
.expect("Failed to set notify EventFd as non-blocking");
|
||||
.expect("Failed to set notify Event as non-blocking");
|
||||
|
||||
loop {
|
||||
match notify.read() {
|
||||
Ok(_) => {}
|
||||
Err(e) if e.errno() == libc::EWOULDBLOCK => {}
|
||||
Err(e) => panic!("Unexpected error while reading notify EventFd: {}", e),
|
||||
Err(e) => panic!("Unexpected error while reading notify Event: {}", e),
|
||||
}
|
||||
|
||||
if let Some(ex) = raw.upgrade() {
|
||||
|
@ -234,7 +231,7 @@ async fn notify_task(notify: EventFd, raw: Weak<RawExecutor>) {
|
|||
notify.as_raw_descriptor(),
|
||||
WatchingEvents::empty().set_read(),
|
||||
)
|
||||
.expect("Failed to add notify EventFd to PollCtx");
|
||||
.expect("Failed to add notify Event to PollCtx");
|
||||
|
||||
// We don't want to hold an active reference to the executor in the .await below.
|
||||
mem::drop(ex);
|
||||
|
@ -247,7 +244,7 @@ async fn notify_task(notify: EventFd, raw: Weak<RawExecutor>) {
|
|||
match op.await {
|
||||
Ok(()) => {}
|
||||
Err(Error::ExecutorGone) => break,
|
||||
Err(e) => panic!("Unexpected error while waiting for notify EventFd: {}", e),
|
||||
Err(e) => panic!("Unexpected error while waiting for notify Event: {}", e),
|
||||
}
|
||||
} else {
|
||||
// The executor is gone so we should also exit.
|
||||
|
@ -257,7 +254,7 @@ async fn notify_task(notify: EventFd, raw: Weak<RawExecutor>) {
|
|||
}
|
||||
|
||||
// Indicates that the executor is either within or about to make a PollContext::wait() call. When a
|
||||
// waker sees this value, it will write to the notify EventFd, which will cause the
|
||||
// waker sees this value, it will write to the notify Event, which will cause the
|
||||
// PollContext::wait() call to return.
|
||||
const WAITING: i32 = 0x1d5b_c019u32 as i32;
|
||||
|
||||
|
@ -273,11 +270,11 @@ struct RawExecutor {
|
|||
ops: Mutex<Slab<OpStatus>>,
|
||||
blocking_pool: BlockingPool,
|
||||
state: AtomicI32,
|
||||
notify: EventFd,
|
||||
notify: Event,
|
||||
}
|
||||
|
||||
impl RawExecutor {
|
||||
fn new(notify: EventFd) -> Result<Self> {
|
||||
fn new(notify: Event) -> Result<Self> {
|
||||
Ok(RawExecutor {
|
||||
queue: RunnableQueue::new(),
|
||||
poll_ctx: EpollContext::new().map_err(Error::CreatingContext)?,
|
||||
|
@ -496,10 +493,10 @@ pub struct FdExecutor {
|
|||
|
||||
impl FdExecutor {
|
||||
pub fn new() -> Result<FdExecutor> {
|
||||
let notify = EventFd::new().map_err(Error::CreateEventFd)?;
|
||||
let notify = Event::new().map_err(Error::CreateEvent)?;
|
||||
let raw = notify
|
||||
.try_clone()
|
||||
.map_err(Error::CloneEventFd)
|
||||
.map_err(Error::CloneEvent)
|
||||
.and_then(RawExecutor::new)
|
||||
.map(Arc::new)?;
|
||||
|
||||
|
|
|
@ -343,9 +343,9 @@ mod tests {
|
|||
return;
|
||||
}
|
||||
|
||||
use base::Event as EventFd;
|
||||
use base::Event;
|
||||
|
||||
async fn write_event(ev: EventFd, wait: EventFd, ex: &URingExecutor) {
|
||||
async fn write_event(ev: Event, wait: Event, ex: &URingExecutor) {
|
||||
let wait = UringSource::new(wait, ex).unwrap();
|
||||
ev.write(55).unwrap();
|
||||
read_u64(&wait).await;
|
||||
|
@ -355,7 +355,7 @@ mod tests {
|
|||
read_u64(&wait).await;
|
||||
}
|
||||
|
||||
async fn read_events(ev: EventFd, signal: EventFd, ex: &URingExecutor) {
|
||||
async fn read_events(ev: Event, signal: Event, ex: &URingExecutor) {
|
||||
let source = UringSource::new(ev, ex).unwrap();
|
||||
assert_eq!(read_u64(&source).await, 55);
|
||||
signal.write(1).unwrap();
|
||||
|
@ -365,8 +365,8 @@ mod tests {
|
|||
signal.write(1).unwrap();
|
||||
}
|
||||
|
||||
let event = EventFd::new().unwrap();
|
||||
let signal_wait = EventFd::new().unwrap();
|
||||
let event = Event::new().unwrap();
|
||||
let signal_wait = Event::new().unwrap();
|
||||
let ex = URingExecutor::new().unwrap();
|
||||
let write_task = write_event(
|
||||
event.try_clone().unwrap(),
|
||||
|
|
|
@ -354,7 +354,7 @@ impl GoldfishBattery {
|
|||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!(
|
||||
"{}: failed to create kill EventFd pair: {}",
|
||||
"{}: failed to create kill Event pair: {}",
|
||||
self.debug_label(),
|
||||
e
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue