Remove "async" feature

This feature is equivalent to async_tokio || async_std; removing it
avoids warnings emitted during `cargo hack check --feature-powerset`
where async is selected without either of the other features.
reviewable/pr650/r4
Tamir Duberstein 2 years ago
parent 242d8c33c4
commit 077323ae1e
No known key found for this signature in database

@ -29,20 +29,19 @@ jobs:
- uses: dtolnay/rust-toolchain@master - uses: dtolnay/rust-toolchain@master
with: with:
toolchain: stable toolchain: stable
targets: ${{matrix.arch}}
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack - uses: taiki-e/install-action@cargo-hack
- name: Check - name: Check
run: cargo hack check --all-targets --feature-powerset --ignore-private run: cargo hack check --all-targets --workspace --feature-powerset --target ${{matrix.arch}}
- uses: Swatinem/rust-cache@v2
- name: Prereqs
run: cargo install cross --git https://github.com/cross-rs/cross
- uses: taiki-e/install-action@cross
- name: Build - name: Build
run: cross build --verbose --target ${{matrix.arch}} run: cross build --verbose --target ${{matrix.arch}}
- name: Run test - name: Test
env: env:
RUST_BACKTRACE: full RUST_BACKTRACE: full
run: | run: cross test --verbose --target ${{matrix.arch}}
cross test --verbose --target ${{matrix.arch}}

@ -25,11 +25,14 @@ jobs:
toolchain: nightly toolchain: nightly
components: rustfmt, clippy, miri, rust-src components: rustfmt, clippy, miri, rust-src
- uses: Swatinem/rust-cache@v2
- name: Check formatting - name: Check formatting
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
- uses: taiki-e/install-action@cargo-hack
- name: Run clippy - name: Run clippy
run: cargo clippy --all-targets --workspace -- --deny warnings run: cargo hack clippy --all-targets --workspace --feature-powerset -- --deny warnings
- name: Run miri - name: Run miri
run: cargo miri test --all-targets run: cargo miri test --all-targets

@ -68,7 +68,7 @@ use thiserror::Error;
use aya::{ use aya::{
maps::{ maps::{
perf::{AsyncPerfEventArray, PerfBufferError}, perf::{AsyncPerfEventArray, Events, PerfBufferError},
MapError, MapError,
}, },
util::online_cpus, util::online_cpus,
@ -121,12 +121,10 @@ impl BpfLogger {
let mut buffers = vec![BytesMut::with_capacity(LOG_BUF_CAPACITY); 10]; let mut buffers = vec![BytesMut::with_capacity(LOG_BUF_CAPACITY); 10];
loop { loop {
let events = buf.read_events(&mut buffers).await.unwrap(); let Events { read, lost: _ } = buf.read_events(&mut buffers).await.unwrap();
#[allow(clippy::needless_range_loop)] for buf in buffers.iter().take(read) {
for i in 0..events.read { log_buf(buf.as_ref(), &*log).unwrap();
let buf = &mut buffers[i];
log_buf(buf, &*log).unwrap();
} }
} }
}); });

@ -39,9 +39,8 @@ matches = "0.1.8"
[features] [features]
default = [] default = []
async = [] async_tokio = ["tokio"]
async_tokio = ["tokio", "async"] async_std = ["async-io"]
async_std = ["async-io", "async"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true

@ -77,8 +77,8 @@ pub use array::{Array, PerCpuArray, ProgramArray};
pub use bloom_filter::BloomFilter; pub use bloom_filter::BloomFilter;
pub use hash_map::{HashMap, PerCpuHashMap}; pub use hash_map::{HashMap, PerCpuHashMap};
pub use lpm_trie::LpmTrie; pub use lpm_trie::LpmTrie;
#[cfg(feature = "async")] #[cfg(any(feature = "async_tokio", feature = "async_std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))] #[cfg_attr(docsrs, doc(cfg(any(feature = "async_tokio", feature = "async_std"))))]
pub use perf::AsyncPerfEventArray; pub use perf::AsyncPerfEventArray;
pub use perf::PerfEventArray; pub use perf::PerfEventArray;
pub use queue::Queue; pub use queue::Queue;
@ -349,8 +349,8 @@ impl_try_from_map!(
StackTraceMap from Map::StackTraceMap, StackTraceMap from Map::StackTraceMap,
); );
#[cfg(feature = "async")] #[cfg(any(feature = "async_tokio", feature = "async_std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))] #[cfg_attr(docsrs, doc(cfg(any(feature = "async_tokio", feature = "async_std"))))]
impl_try_from_map!( impl_try_from_map!(
AsyncPerfEventArray from Map::PerfEventArray, AsyncPerfEventArray from Map::PerfEventArray,
); );

@ -4,7 +4,7 @@ use std::{
os::fd::{AsRawFd, RawFd}, os::fd::{AsRawFd, RawFd},
}; };
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] #[cfg(feature = "async_std")]
use async_io::Async; use async_io::Async;
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
@ -98,16 +98,17 @@ impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArray<T> {
index: u32, index: u32,
page_count: Option<usize>, page_count: Option<usize>,
) -> Result<AsyncPerfEventArrayBuffer<T>, PerfBufferError> { ) -> Result<AsyncPerfEventArrayBuffer<T>, PerfBufferError> {
let buf = self.perf_map.open(index, page_count)?; let Self { perf_map } = self;
let buf = perf_map.open(index, page_count)?;
let fd = buf.as_raw_fd(); let fd = buf.as_raw_fd();
Ok(AsyncPerfEventArrayBuffer { Ok(AsyncPerfEventArrayBuffer {
buf, buf,
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
async_fd: AsyncFd::new(fd)?, async_tokio_fd: AsyncFd::new(fd)?,
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] #[cfg(feature = "async_std")]
async_fd: Async::new(fd)?, async_std_fd: Async::new(fd)?,
}) })
} }
} }
@ -131,13 +132,12 @@ pub struct AsyncPerfEventArrayBuffer<T> {
buf: PerfEventArrayBuffer<T>, buf: PerfEventArrayBuffer<T>,
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
async_fd: AsyncFd<RawFd>, async_tokio_fd: AsyncFd<RawFd>,
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] #[cfg(feature = "async_std")]
async_fd: Async<RawFd>, async_std_fd: Async<RawFd>,
} }
#[cfg(feature = "async_tokio")]
impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArrayBuffer<T> { impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
/// Reads events from the buffer. /// Reads events from the buffer.
/// ///
@ -152,12 +152,28 @@ impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
&mut self, &mut self,
buffers: &mut [BytesMut], buffers: &mut [BytesMut],
) -> Result<Events, PerfBufferError> { ) -> Result<Events, PerfBufferError> {
let Self {
buf,
#[cfg(feature = "async_tokio")]
async_tokio_fd,
#[cfg(feature = "async_std")]
async_std_fd,
} = self;
loop { loop {
let mut guard = self.async_fd.readable_mut().await?; #[cfg(feature = "async_tokio")]
let mut guard = async_tokio_fd.readable_mut().await?;
match self.buf.read_events(buffers) { #[cfg(feature = "async_std")]
Ok(events) if events.read > 0 || events.lost > 0 => return Ok(events), if !buf.readable() {
Ok(_) => { async_std_fd.readable().await?;
}
match buf.read_events(buffers) {
Ok(events @ Events { read, lost }) => {
if read > 0 || lost > 0 {
return Ok(events);
}
#[cfg(feature = "async_tokio")]
guard.clear_ready(); guard.clear_ready();
continue; continue;
} }
@ -166,32 +182,3 @@ impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
} }
} }
} }
#[cfg(all(not(feature = "async_tokio"), feature = "async_std"))]
impl<T: BorrowMut<MapData> + Borrow<MapData>> AsyncPerfEventArrayBuffer<T> {
/// Reads events from the buffer.
///
/// This method reads events into the provided slice of buffers, filling
/// each buffer in order stopping when there are no more events to read or
/// all the buffers have been filled.
///
/// Returns the number of events read and the number of events lost. Events
/// are lost when user space doesn't read events fast enough and the ring
/// buffer fills up.
pub async fn read_events(
&mut self,
buffers: &mut [BytesMut],
) -> Result<Events, PerfBufferError> {
loop {
if !self.buf.readable() {
let _ = self.async_fd.readable().await?;
}
match self.buf.read_events(buffers) {
Ok(events) if events.read > 0 || events.lost > 0 => return Ok(events),
Ok(_) => continue,
Err(e) => return Err(e),
}
}
}
}

@ -1,14 +1,14 @@
//! Ring buffer types used to receive events from eBPF programs using the linux `perf` API. //! Ring buffer types used to receive events from eBPF programs using the linux `perf` API.
//! //!
//! See the [`PerfEventArray`](crate::maps::PerfEventArray) and [`AsyncPerfEventArray`](crate::maps::perf::AsyncPerfEventArray). //! See the [`PerfEventArray`](crate::maps::PerfEventArray) and [`AsyncPerfEventArray`](crate::maps::perf::AsyncPerfEventArray).
#[cfg(feature = "async")] #[cfg(any(feature = "async_tokio", feature = "async_std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))] #[cfg_attr(docsrs, doc(cfg(any(feature = "async_tokio", feature = "async_std"))))]
mod async_perf_event_array; mod async_perf_event_array;
mod perf_buffer; mod perf_buffer;
mod perf_event_array; mod perf_event_array;
#[cfg(feature = "async")] #[cfg(any(feature = "async_tokio", feature = "async_std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))] #[cfg_attr(docsrs, doc(cfg(any(feature = "async_tokio", feature = "async_std"))))]
pub use async_perf_event_array::*; pub use async_perf_event_array::*;
pub use perf_buffer::*; pub use perf_buffer::*;
pub use perf_event_array::*; pub use perf_event_array::*;

@ -17,10 +17,6 @@ use crate::{
sys::{bpf_get_object, bpf_pin_object, bpf_prog_detach}, sys::{bpf_get_object, bpf_pin_object, bpf_prog_detach},
}; };
// for docs link
#[allow(unused)]
use crate::programs::cgroup_skb::CgroupSkb;
/// A Link. /// A Link.
pub trait Link: std::fmt::Debug + 'static { pub trait Link: std::fmt::Debug + 'static {
/// Unique Id /// Unique Id
@ -88,7 +84,7 @@ pub struct FdLinkId(pub(crate) RawFd);
/// A file descriptor link. /// A file descriptor link.
/// ///
/// Fd links are returned directly when attaching some program types (for /// Fd links are returned directly when attaching some program types (for
/// instance [`CgroupSkb`]), or can be obtained by converting other link /// instance [`crate::programs::cgroup_skb::CgroupSkb`]), or can be obtained by converting other link
/// types (see the `TryFrom` implementations). /// types (see the `TryFrom` implementations).
/// ///
/// An important property of fd links is that they can be pinned. Pinning /// An important property of fd links is that they can be pinned. Pinning

@ -585,7 +585,6 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes(
/// # Errors /// # Errors
/// ///
/// On failure, this function returns a negative value wrapped in an `Err`. /// On failure, this function returns a negative value wrapped in an `Err`.
#[allow(clippy::fn_to_numeric_cast_with_truncation)]
#[inline] #[inline]
pub unsafe fn bpf_probe_write_user<T>(dst: *mut T, src: *const T) -> Result<(), c_long> { pub unsafe fn bpf_probe_write_user<T>(dst: *mut T, src: *const T) -> Result<(), c_long> {
let ret = gen::bpf_probe_write_user( let ret = gen::bpf_probe_write_user(

Loading…
Cancel
Save