all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: [pve-devel] applied: [PATCH lxc-syscalld] update to tokio 1.0
Date: Wed, 17 Feb 2021 12:02:59 +0100	[thread overview]
Message-ID: <20210217110259.jvde42s45zdue2zz@olga.proxmox.com> (raw)
In-Reply-To: <20210217103938.687367-1-f.gruenbichler@proxmox.com>

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@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




      reply	other threads:[~2021-02-17 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 10:39 [pve-devel] " Fabian Grünbichler
2021-02-17 11:02 ` Wolfgang Bumiller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210217110259.jvde42s45zdue2zz@olga.proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal