mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 23:11:16 +00:00
net: Make TAP registration functions immutable
By making the registration functions immutable, this patch prevents from self borrowing issues with the RwLock on self.mem. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
0b8856d148
commit
dfb18ef14a
@ -144,6 +144,7 @@ impl NetEpollHandler {
|
|||||||
// Queue has no available descriptors
|
// Queue has no available descriptors
|
||||||
if self.rx_tap_listening {
|
if self.rx_tap_listening {
|
||||||
self.unregister_tap_rx_listener().unwrap();
|
self.unregister_tap_rx_listener().unwrap();
|
||||||
|
self.rx_tap_listening = false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -302,25 +303,23 @@ impl NetEpollHandler {
|
|||||||
self.tap.read(&mut self.rx.frame_buf)
|
self.tap.read(&mut self.rx.frame_buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_tap_rx_listener(&mut self) -> std::result::Result<(), std::io::Error> {
|
fn register_tap_rx_listener(&self) -> std::result::Result<(), std::io::Error> {
|
||||||
epoll::ctl(
|
epoll::ctl(
|
||||||
self.epoll_fd,
|
self.epoll_fd,
|
||||||
epoll::ControlOptions::EPOLL_CTL_ADD,
|
epoll::ControlOptions::EPOLL_CTL_ADD,
|
||||||
self.tap.as_raw_fd(),
|
self.tap.as_raw_fd(),
|
||||||
epoll::Event::new(epoll::Events::EPOLLIN, u64::from(RX_TAP_EVENT)),
|
epoll::Event::new(epoll::Events::EPOLLIN, u64::from(RX_TAP_EVENT)),
|
||||||
)?;
|
)?;
|
||||||
self.rx_tap_listening = true;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unregister_tap_rx_listener(&mut self) -> std::result::Result<(), std::io::Error> {
|
fn unregister_tap_rx_listener(&self) -> std::result::Result<(), std::io::Error> {
|
||||||
epoll::ctl(
|
epoll::ctl(
|
||||||
self.epoll_fd,
|
self.epoll_fd,
|
||||||
epoll::ControlOptions::EPOLL_CTL_DEL,
|
epoll::ControlOptions::EPOLL_CTL_DEL,
|
||||||
self.tap.as_raw_fd(),
|
self.tap.as_raw_fd(),
|
||||||
epoll::Event::new(epoll::Events::EPOLLIN, u64::from(RX_TAP_EVENT)),
|
epoll::Event::new(epoll::Events::EPOLLIN, u64::from(RX_TAP_EVENT)),
|
||||||
)?;
|
)?;
|
||||||
self.rx_tap_listening = false;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,6 +343,7 @@ impl NetEpollHandler {
|
|||||||
.map_err(DeviceError::EpollCtl)?;
|
.map_err(DeviceError::EpollCtl)?;
|
||||||
self.register_tap_rx_listener()
|
self.register_tap_rx_listener()
|
||||||
.map_err(DeviceError::EpollCtl)?;
|
.map_err(DeviceError::EpollCtl)?;
|
||||||
|
self.rx_tap_listening = true;
|
||||||
epoll::ctl(
|
epoll::ctl(
|
||||||
self.epoll_fd,
|
self.epoll_fd,
|
||||||
epoll::ControlOptions::EPOLL_CTL_ADD,
|
epoll::ControlOptions::EPOLL_CTL_ADD,
|
||||||
@ -387,6 +387,7 @@ impl NetEpollHandler {
|
|||||||
self.resume_rx().unwrap();
|
self.resume_rx().unwrap();
|
||||||
if !self.rx_tap_listening {
|
if !self.rx_tap_listening {
|
||||||
self.register_tap_rx_listener().unwrap();
|
self.register_tap_rx_listener().unwrap();
|
||||||
|
self.rx_tap_listening = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TX_QUEUE_EVENT => {
|
TX_QUEUE_EVENT => {
|
||||||
|
Loading…
Reference in New Issue
Block a user