From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 944836AE36 for ; Wed, 17 Feb 2021 11:39:47 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8AC9420B25 for ; Wed, 17 Feb 2021 11:39:47 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id DB4CF20B1B for ; Wed, 17 Feb 2021 11:39:46 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A3E3941AB3 for ; Wed, 17 Feb 2021 11:39:46 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Wed, 17 Feb 2021 11:39:38 +0100 Message-Id: <20210217103938.687367-1-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.223 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_NUMSUBJECT 0.5 Subject ends in numbers excluding current years RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs, pipe.rs] Subject: [pve-devel] [PATCH lxc-syscalld] update to tokio 1.0 X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2021 10:39:47 -0000 and switch from PollEvented to AsyncFd, dropping the direct mio dependency in turn. Signed-off-by: Fabian Grünbichler --- 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 AsyncRead for Pipe { fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { + buf: &mut ReadBuf, + ) -> Poll> { 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, + fd: AsyncFd, } impl PolledFd { pub fn new(fd: Fd) -> tokio::io::Result { 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, ) -> Poll> { - 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, ) -> Poll> { - 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