fix epoll_ctl deadlock

This commit is contained in:
WangRunji 2019-04-11 19:10:12 +08:00
parent f9121a025e
commit bd9a3dd578

@ -126,11 +126,15 @@ pub fn do_epoll_ctl(
let current_ref = process::get_current(); let current_ref = process::get_current();
let mut proc = current_ref.lock().unwrap(); let mut proc = current_ref.lock().unwrap();
let mut file_ref = proc.get_files().lock().unwrap().get(epfd)?; let mut file_table_ref = proc.get_files().lock().unwrap();
let mut file_ref = file_table_ref.get(epfd)?;
let mut epoll = file_ref.as_epoll()?.inner.lock().unwrap(); let mut epoll = file_ref.as_epoll()?.inner.lock().unwrap();
match op { match op {
EpollOp::Add(event) => epoll.add(fd, event)?, EpollOp::Add(event) => {
let host_fd = file_table_ref.get(fd)?.as_socket()?.fd() as FileDesc;
epoll.add(fd, host_fd, event)?;
},
EpollOp::Modify(event) => epoll.modify(fd, event)?, EpollOp::Modify(event) => epoll.modify(fd, event)?,
EpollOp::Delete => epoll.remove(fd)?, EpollOp::Delete => epoll.remove(fd)?,
} }
@ -232,16 +236,10 @@ impl EpollFileInner {
/// Add `fd` to the interest list and associate the settings /// Add `fd` to the interest list and associate the settings
/// specified in `event` with the internal file linked to `fd`. /// specified in `event` with the internal file linked to `fd`.
pub fn add(&mut self, fd: FileDesc, mut event: libc::epoll_event) -> Result<(), Error> { pub fn add(&mut self, fd: FileDesc, host_fd: FileDesc, mut event: libc::epoll_event) -> Result<(), Error> {
if self.fd_to_host.contains_key(&fd) { if self.fd_to_host.contains_key(&fd) {
return Err(Error::new(EEXIST, "fd is exist in epoll")); return Err(Error::new(EEXIST, "fd is exist in epoll"));
} }
// query host fd
let current_ref = process::get_current();
let mut proc = current_ref.lock().unwrap();
let file_ref = proc.get_files().lock().unwrap().get(fd)?;
let host_fd = file_ref.as_socket()?.fd() as FileDesc;
let ret = unsafe { let ret = unsafe {
libc::ocall::epoll_ctl( libc::ocall::epoll_ctl(
self.epoll_fd, self.epoll_fd,