Skip to content

Commit ea0b6f9

Browse files
alexandruagacatangiu
authored andcommitted
vmm/lib.rs: api_event fd changes
Removed the api_event field from struct Vmm. The Vmm::new constructor now expects a control_fd: &AsRawFd parameter instead of the old api_event_fd: EventFd. The new parameter is only used to register an event source with the epoll set. Since it's now possible to handle control events from outside the Vmm implementation, the outer logic also handles the lifetime of the actual object that is associated with the epoll fd. The from_api member continues to be required, until we figure out what to do with the API server going forward. Signed-off-by: Alexandru Agache <[email protected]>
1 parent dfd1888 commit ea0b6f9

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

vmm/src/device_manager/mmio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ mod tests {
403403
let (_to_vmm, from_api) = channel();
404404
Vmm::new(
405405
shared_info,
406-
EventFd::new().expect("cannot create eventFD"),
406+
&EventFd::new().expect("cannot create eventFD"),
407407
from_api,
408408
0,
409409
)

vmm/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl EpollContext {
632632
/// Given a file descriptor `fd`, and an EpollDispatch token `token`,
633633
/// associate `token` with an `EPOLLIN` event for `fd`, through the
634634
/// `dispatch_table`.
635-
fn add_event<T: AsRawFd>(&mut self, fd: &T, token: EpollDispatch) -> Result<()> {
635+
fn add_event<T: AsRawFd + ?Sized>(&mut self, fd: &T, token: EpollDispatch) -> Result<()> {
636636
// The index in the dispatch where the new token will be added.
637637
let dispatch_index = self.dispatch_table.len() as u64;
638638

@@ -806,7 +806,6 @@ struct Vmm {
806806
epoll_context: EpollContext,
807807

808808
// API resources.
809-
api_event_fd: EventFd,
810809
from_api: Receiver<Box<VmmAction>>,
811810

812811
write_metrics_event_fd: TimerFd,
@@ -818,15 +817,15 @@ struct Vmm {
818817
impl Vmm {
819818
fn new(
820819
api_shared_info: Arc<RwLock<InstanceInfo>>,
821-
api_event_fd: EventFd,
820+
control_fd: &AsRawFd,
822821
from_api: Receiver<Box<VmmAction>>,
823822
seccomp_level: u32,
824823
) -> Result<Self> {
825824
let mut epoll_context = EpollContext::new()?;
826825
// If this fails, it's fatal; using expect() to crash.
827826
epoll_context
828-
.add_event(&api_event_fd, EpollDispatch::VmmActionRequest)
829-
.expect("Cannot add API eventfd to epoll.");
827+
.add_event(control_fd, EpollDispatch::VmmActionRequest)
828+
.expect("Cannot add API control_fd to epoll.");
830829

831830
let write_metrics_event_fd =
832831
TimerFd::new_custom(ClockId::Monotonic, true, true).map_err(Error::TimerFd)?;
@@ -861,7 +860,6 @@ impl Vmm {
861860
pio_device_manager: PortIODeviceManager::new().map_err(Error::CreateLegacyDevice)?,
862861
device_configs,
863862
epoll_context,
864-
api_event_fd,
865863
from_api,
866864
write_metrics_event_fd,
867865
seccomp_level,
@@ -2165,7 +2163,7 @@ pub fn start_vmm_thread(
21652163
.name("fc_vmm".to_string())
21662164
.spawn(move || {
21672165
// If this fails, consider it fatal. Use expect().
2168-
let mut vmm = Vmm::new(api_shared_info, api_event_fd, from_api, seccomp_level)
2166+
let mut vmm = Vmm::new(api_shared_info, &api_event_fd, from_api, seccomp_level)
21692167
.expect("Cannot create VMM");
21702168

21712169
if let Some(json) = config_json {
@@ -2200,7 +2198,7 @@ pub fn start_vmm_thread(
22002198
FC_EXIT_CODE_OK
22012199
}
22022200
EventLoopExitReason::ControlAction => {
2203-
if let Err(e) = vmm.api_event_fd.read() {
2201+
if let Err(e) = api_event_fd.read() {
22042202
error!("Error reading VMM API event_fd {:?}", e);
22052203
FC_EXIT_CODE_GENERIC_ERROR
22062204
} else {
@@ -2385,7 +2383,7 @@ mod tests {
23852383
let (_to_vmm, from_api) = channel();
23862384
Vmm::new(
23872385
shared_info,
2388-
EventFd::new().expect("cannot create eventFD"),
2386+
&EventFd::new().expect("cannot create eventFD"),
23892387
from_api,
23902388
seccomp::SECCOMP_LEVEL_NONE,
23912389
)

0 commit comments

Comments
 (0)