Skip to content

Commit 5f66d15

Browse files
fogtijounathaen
authored andcommitted
chore(isolation): remove slab support
1 parent 69b92cc commit 5f66d15

File tree

3 files changed

+10
-88
lines changed

3 files changed

+10
-88
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ toml = "0.9.8"
7272
serde = { version = "1.0", features = ["derive"] }
7373
merge = { version = "0.2" }
7474
yoke = "0.8"
75-
slab = { version = "0.4", optional = true }
76-
nohash = "0.2.0"
75+
nohash = "0.2"
7776

7877
[target.'cfg(target_os = "linux")'.dependencies]
7978
kvm-bindings = "0.14"

src/isolation/fd.rs

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
#[cfg(not(feature = "slab"))]
2-
use std::{collections::HashMap, hash::BuildHasherDefault};
31
use std::{
2+
collections::HashMap,
43
fmt,
4+
hash::BuildHasherDefault,
55
os::fd::{FromRawFd, OwnedFd, RawFd},
66
};
77

8-
#[cfg(not(feature = "slab"))]
98
use nohash::NoHashHasher;
10-
#[cfg(feature = "slab")]
11-
use slab::Slab;
129
use yoke::{Yoke, erased::ErasedArcCart};
1310

1411
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -20,14 +17,6 @@ impl fmt::Display for GuestFd {
2017
}
2118
}
2219

23-
#[cfg(feature = "slab")]
24-
impl From<usize> for GuestFd {
25-
fn from(x: usize) -> Self {
26-
// The following should never panic unless someone allocates more than i32::MAX file descriptors
27-
Self(x.try_into().unwrap())
28-
}
29-
}
30-
3120
impl From<u32> for GuestFd {
3221
fn from(x: u32) -> Self {
3322
// The following should never panic unless someone allocates more than i32::MAX file descriptors
@@ -47,12 +36,6 @@ impl GuestFd {
4736
self.0 < 3
4837
}
4938

50-
#[cfg(feature = "slab")]
51-
fn get(self) -> usize {
52-
self.0.try_into().unwrap()
53-
}
54-
55-
#[cfg(not(feature = "slab"))]
5639
fn get(self) -> u32 {
5740
self.0.try_into().unwrap()
5841
}
@@ -96,28 +79,11 @@ impl FromRawFd for FdData {
9679

9780
#[derive(Debug)]
9881
pub struct UhyveFileDescriptorLayer {
99-
#[cfg(feature = "slab")]
100-
fds: Slab<FdData>,
101-
102-
#[cfg(not(feature = "slab"))]
10382
fds: HashMap<u32, FdData, BuildHasherDefault<NoHashHasher<u32>>>,
104-
105-
#[cfg(not(feature = "slab"))]
10683
next_fd: u32,
10784
}
10885

10986
impl Default for UhyveFileDescriptorLayer {
110-
#[cfg(feature = "slab")]
111-
fn default() -> Self {
112-
let mut fds = Slab::new();
113-
// fill the first 3 fds (0, 1, 2) = the standard streams to avoid weird effects
114-
fds.insert(FdData::Raw(0));
115-
fds.insert(FdData::Raw(1));
116-
fds.insert(FdData::Raw(2));
117-
Self { fds }
118-
}
119-
120-
#[cfg(not(feature = "slab"))]
12187
fn default() -> Self {
12288
let mut fds = HashMap::with_capacity_and_hasher(3, BuildHasherDefault::default());
12389
// fill the first 3 fds (0, 1, 2) = the standard streams to avoid weird effects
@@ -143,23 +109,11 @@ impl UhyveFileDescriptorLayer {
143109
}
144110

145111
debug!("Adding fd {data:?} to fdset: {self}");
146-
let ret = {
147-
#[cfg(feature = "slab")]
148-
{
149-
self.fds.insert(data)
150-
}
151-
152-
#[cfg(not(feature = "slab"))]
153-
{
154-
let ret = self.next_fd;
155-
assert!(self.fds.insert(ret, data).is_none());
156-
self.next_fd = ret.checked_add(1).unwrap();
157-
ret
158-
}
159-
}
160-
.into();
112+
let ret = self.next_fd;
113+
assert!(self.fds.insert(ret, data).is_none());
114+
self.next_fd = ret.checked_add(1).unwrap();
161115
debug!("=> {}", ret);
162-
Some(ret)
116+
Some(ret.into())
163117
}
164118

165119
/// Removes a file descriptor. Invoked by [crate::hypercall::close].
@@ -174,15 +128,7 @@ impl UhyveFileDescriptorLayer {
174128
let ret = if fd.is_standard() {
175129
None
176130
} else {
177-
#[cfg(feature = "slab")]
178-
{
179-
self.fds.try_remove(fd.get())
180-
}
181-
182-
#[cfg(not(feature = "slab"))]
183-
{
184-
self.fds.remove(&fd.get())
185-
}
131+
self.fds.remove(&fd.get())
186132
};
187133
if ret.is_none() {
188134
warn!("Guest attempted to remove invalid {fd}, ignoring...")
@@ -191,15 +137,7 @@ impl UhyveFileDescriptorLayer {
191137
}
192138

193139
pub fn get_mut(&mut self, fd: GuestFd) -> Option<&mut FdData> {
194-
#[cfg(feature = "slab")]
195-
{
196-
self.fds.get_mut(fd.get())
197-
}
198-
199-
#[cfg(not(feature = "slab"))]
200-
{
201-
self.fds.get_mut(&fd.get())
202-
}
140+
self.fds.get_mut(&fd.get())
203141
}
204142

205143
/// Checks whether an fd exists in this structure, i.e. whether the guest
@@ -210,15 +148,7 @@ impl UhyveFileDescriptorLayer {
210148
/// * `fd` - File descriptor of to-be-operated file.
211149
pub fn is_fd_present(&self, fd: GuestFd) -> bool {
212150
debug!("Check if {fd} in fdset: {self}");
213-
#[cfg(feature = "slab")]
214-
{
215-
self.fds.contains(fd.get())
216-
}
217-
218-
#[cfg(not(feature = "slab"))]
219-
{
220-
self.fds.contains_key(&fd.get())
221-
}
151+
self.fds.contains_key(&fd.get())
222152
}
223153
}
224154

0 commit comments

Comments
 (0)