From 83a76190711924ff1393ca372139c3f5a033c0a5 Mon Sep 17 00:00:00 2001 From: Ershaad Basheer Date: Tue, 2 Sep 2025 18:39:41 -0700 Subject: [PATCH] Rename ringbuf map and other reviewer suggestions --- test/integration-ebpf/src/ring_buf_pinned.rs | 4 ++-- test/integration-test/src/tests/ring_buf.rs | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/integration-ebpf/src/ring_buf_pinned.rs b/test/integration-ebpf/src/ring_buf_pinned.rs index 769896fa..13f4713b 100644 --- a/test/integration-ebpf/src/ring_buf_pinned.rs +++ b/test/integration-ebpf/src/ring_buf_pinned.rs @@ -11,7 +11,7 @@ use integration_common::ring_buf::Registers; extern crate ebpf_panic; #[map] -static RING_BUF: RingBuf = RingBuf::pinned(0, 0); +static pinned_ringbuf_reuse_test: RingBuf = RingBuf::pinned(0, 0); // Use a PerCpuArray to store the registers so that we can update the values from multiple CPUs // without needing synchronization. Atomics exist [1], but aren't exposed. @@ -26,7 +26,7 @@ pub fn ring_buf_test(ctx: ProbeContext) { Some(regs) => unsafe { &mut *regs }, None => return, }; - let mut entry = match RING_BUF.reserve::(0) { + let mut entry = match pinned_ringbuf_reuse_test.reserve::(0) { Some(entry) => entry, None => { *dropped += 1; diff --git a/test/integration-test/src/tests/ring_buf.rs b/test/integration-test/src/tests/ring_buf.rs index dbf67698..036c0da2 100644 --- a/test/integration-test/src/tests/ring_buf.rs +++ b/test/integration-test/src/tests/ring_buf.rs @@ -38,7 +38,7 @@ struct PinnedRingBufTest { // that's not the case because the actual size will be rounded up, and fewer entries will be dropped // than expected. const RING_BUF_MAX_ENTRIES: usize = 512; -const RING_BUF_PIN_PATH: &str = "/sys/fs/bpf/RING_BUF"; +const RING_BUF_PIN_PATH: &str = "/sys/fs/bpf/pinned_ringbuf_reuse_test"; impl RingBufTest { fn new() -> Self { @@ -82,10 +82,10 @@ impl PinnedRingBufTest { (RING_BUF_MAX_ENTRIES * (mem::size_of::() + BPF_RINGBUF_HDR_SZ as usize)) as u32; let mut bpf = EbpfLoader::new() - .set_max_entries("RING_BUF", RING_BUF_BYTE_SIZE) + .set_max_entries("pinned_ringbuf_reuse_test", RING_BUF_BYTE_SIZE) .load(crate::RING_BUF_PINNED) .unwrap(); - // We assume the map has been pinned as part of the loading process + // We assume the map has been pinned as part of the loading process. let ring_buf = MapData::from_pin(RING_BUF_PIN_PATH).unwrap(); let ring_buf = Map::RingBuf(ring_buf); let ring_buf = RingBuf::try_from(ring_buf).unwrap(); @@ -196,7 +196,7 @@ fn ring_buf(n: usize) { // This test checks for a bug that the consumer index always started at position 0 of a // newly-loaded ring-buffer map. This assumption is not true for a map that is pinned to the bpffs // filesystem since the map "remembers" the last consumer index position even if all processes -// unloaded it +// unloaded it. fn pinned_ring_buf(n: usize) { let run_test = |mut ring_buf: RingBuf, regs: PerCpuArray, @@ -253,7 +253,7 @@ fn pinned_ring_buf(n: usize) { run_test(ring_buf, regs, data, expected_capacity); - // Close pinned map and re-open + // Close pinned map and re-open. drop(_bpf); let PinnedWithData( @@ -264,7 +264,8 @@ fn pinned_ring_buf(n: usize) { }, data, ) = PinnedWithData::new(n); - // Clean up the pinned map from the filesystem + // Remove the pinned map from the filesystem namespace. Users of the map are unaffected since + // they have an active reference to it. fs::remove_file(RING_BUF_PIN_PATH).unwrap(); run_test(ring_buf, regs, data, expected_capacity);