[pve-devel] applied: [PATCH lxc-syscalld] update to tokio 1.0

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Feb 17 12:02:59 CET 2021


applied

On Wed, Feb 17, 2021 at 11:39:38AM +0100, Fabian Grünbichler wrote:
> and switch from PollEvented to AsyncFd, dropping the direct mio
> dependency in turn.
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
>  Cargo.toml          |  3 +--
>  src/io/pipe.rs      |  9 +++++----
>  src/io/polled_fd.rs | 45 +++++++--------------------------------------
>  src/main.rs         |  2 +-
>  4 files changed, 14 insertions(+), 45 deletions(-)
> 
> diff --git a/Cargo.toml b/Cargo.toml
> index 1dced97..a337d44 100644
> --- a/Cargo.toml
> +++ b/Cargo.toml
> @@ -17,5 +17,4 @@ anyhow = "1.0"
>  lazy_static = "1.4"
>  libc = "0.2"
>  nix = "0.19"
> -mio = "0.6.21"
> -tokio = { version = "0.2.9", features = [ "rt-threaded", "io-driver", "io-util" ] }
> +tokio = { version = "1.0", features = [ "rt-multi-thread", "io-util", "net" ] }
> diff --git a/src/io/pipe.rs b/src/io/pipe.rs
> index 6b583fb..3b312a8 100644
> --- a/src/io/pipe.rs
> +++ b/src/io/pipe.rs
> @@ -5,7 +5,7 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
>  use std::pin::Pin;
>  use std::task::{Context, Poll};
>  
> -use tokio::io::{AsyncRead, AsyncWrite};
> +use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
>  
>  use crate::error::io_err_other;
>  use crate::io::polled_fd::PolledFd;
> @@ -86,13 +86,14 @@ impl<RW: rw_traits::HasRead> AsyncRead for Pipe<RW> {
>      fn poll_read(
>          self: Pin<&mut Self>,
>          cx: &mut Context<'_>,
> -        buf: &mut [u8],
> -    ) -> Poll<io::Result<usize>> {
> +        buf: &mut ReadBuf,
> +    ) -> Poll<io::Result<()>> {
>          self.fd.wrap_read(cx, || {
>              let fd = self.as_raw_fd();
> +            let buf = buf.initialize_unfilled();
>              let size = libc::size_t::try_from(buf.len()).map_err(io_err_other)?;
>              c_result!(unsafe { libc::read(fd, buf.as_mut_ptr() as *mut libc::c_void, size) })
> -                .map(|res| res as usize)
> +                .map(|_| ())
>          })
>      }
>  }
> diff --git a/src/io/polled_fd.rs b/src/io/polled_fd.rs
> index 8a17d76..6ea1939 100644
> --- a/src/io/polled_fd.rs
> +++ b/src/io/polled_fd.rs
> @@ -2,11 +2,7 @@ use std::io;
>  use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
>  use std::task::{Context, Poll};
>  
> -use mio::event::Evented;
> -use mio::unix::EventedFd as MioEventedFd;
> -use mio::Poll as MioPoll;
> -use mio::{PollOpt, Ready, Token};
> -use tokio::io::PollEvented;
> +use tokio::io::unix::AsyncFd;
>  
>  use crate::tools::Fd;
>  
> @@ -43,41 +39,15 @@ impl IntoRawFd for EventedFd {
>      }
>  }
>  
> -impl Evented for EventedFd {
> -    fn register(
> -        &self,
> -        poll: &MioPoll,
> -        token: Token,
> -        interest: Ready,
> -        opts: PollOpt,
> -    ) -> io::Result<()> {
> -        MioEventedFd(self.fd.as_ref()).register(poll, token, interest, opts)
> -    }
> -
> -    fn reregister(
> -        &self,
> -        poll: &MioPoll,
> -        token: Token,
> -        interest: Ready,
> -        opts: PollOpt,
> -    ) -> io::Result<()> {
> -        MioEventedFd(self.fd.as_ref()).reregister(poll, token, interest, opts)
> -    }
> -
> -    fn deregister(&self, poll: &MioPoll) -> io::Result<()> {
> -        MioEventedFd(self.fd.as_ref()).deregister(poll)
> -    }
> -}
> -
>  #[repr(transparent)]
>  pub struct PolledFd {
> -    fd: PollEvented<EventedFd>,
> +    fd: AsyncFd<EventedFd>,
>  }
>  
>  impl PolledFd {
>      pub fn new(fd: Fd) -> tokio::io::Result<Self> {
>          Ok(Self {
> -            fd: PollEvented::new(EventedFd::new(fd))?,
> +            fd: AsyncFd::new(EventedFd::new(fd))?,
>          })
>      }
>  
> @@ -86,11 +56,11 @@ impl PolledFd {
>          cx: &mut Context,
>          func: impl FnOnce() -> io::Result<T>,
>      ) -> Poll<io::Result<T>> {
> -        ready!(self.fd.poll_read_ready(cx, mio::Ready::readable()))?;
> +        let mut ready_guard = ready!(self.fd.poll_read_ready(cx))?;
>          match func() {
>              Ok(out) => Poll::Ready(Ok(out)),
>              Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
> -                self.fd.clear_read_ready(cx, mio::Ready::readable())?;
> +                ready_guard.clear_ready();
>                  Poll::Pending
>              }
>              Err(err) => Poll::Ready(Err(err)),
> @@ -102,11 +72,11 @@ impl PolledFd {
>          cx: &mut Context,
>          func: impl FnOnce() -> io::Result<T>,
>      ) -> Poll<io::Result<T>> {
> -        ready!(self.fd.poll_write_ready(cx))?;
> +        let mut ready_guard = ready!(self.fd.poll_write_ready(cx))?;
>          match func() {
>              Ok(out) => Poll::Ready(Ok(out)),
>              Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => {
> -                self.fd.clear_write_ready(cx)?;
> +                ready_guard.clear_ready();
>                  Poll::Pending
>              }
>              Err(err) => Poll::Ready(Err(err)),
> @@ -128,7 +98,6 @@ impl IntoRawFd for PolledFd {
>          // its driver
>          self.fd
>              .into_inner()
> -            .expect("failed to remove polled file descriptor from reactor")
>              .into_raw_fd()
>      }
>  }
> diff --git a/src/main.rs b/src/main.rs
> index a0f34b7..ca4366d 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -100,7 +100,7 @@ fn main() {
>          }
>      };
>  
> -    let mut rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime");
> +    let rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime");
>  
>      if let Err(err) = rt.block_on(do_main(use_sd_notify, path)) {
>          eprintln!("error: {}", err);
> -- 
> 2.20.1




More information about the pve-devel mailing list