[pbs-devel] [PATCH proxmox-fuse] update to tokio 1.0

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Jan 12 14:58:27 CET 2021


PollEvented is no more (it's an internal API now, since tokio no longer
wants to expose mio parts in its public API). Switch to AsyncFd, which
provides similar mechanisms for non-blocking raw FDs and allows us to
drop our own direct mio dependency as well.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 Cargo.toml     |  7 +++++--
 debian/control | 22 ++++++++++------------
 src/fuse_fd.rs | 30 ------------------------------
 src/session.rs | 14 ++++++--------
 4 files changed, 21 insertions(+), 52 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index ef3fa2b..0303522 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,5 +12,8 @@ exclude = [ "build", "debian" ]
 anyhow = "1.0"
 futures = "0.3"
 libc = "0.2"
-mio = "0.6.21"
-tokio = { version = "0.2", features = ["io-driver", "macros", "signal", "stream"] }
+tokio = { version = "1.0", features = ["macros", "net", "signal"] }
+tokio-stream = "0.1"
+
+[dev-dependencies]
+tokio = { version = "1.0", features = ["rt-multi-thread"] }
diff --git a/debian/control b/debian/control
index 7e8c45d..4d20e04 100644
--- a/debian/control
+++ b/debian/control
@@ -9,12 +9,11 @@ Build-Depends: debhelper (>= 11),
  librust-anyhow-1+default-dev <!nocheck>,
  librust-futures-0.3+default-dev <!nocheck>,
  librust-libc-0.2+default-dev <!nocheck>,
- librust-mio-0.6+default-dev (>= 0.6.21-~~) <!nocheck>,
- librust-tokio-0.2+default-dev <!nocheck>,
- librust-tokio-0.2+io-driver-dev <!nocheck>,
- librust-tokio-0.2+macros-dev <!nocheck>,
- librust-tokio-0.2+signal-dev <!nocheck>,
- librust-tokio-0.2+stream-dev <!nocheck>,
+ librust-tokio-1+default-dev <!nocheck>,
+ librust-tokio-1+macros-dev <!nocheck>,
+ librust-tokio-1+net-dev <!nocheck>,
+ librust-tokio-1+signal-dev <!nocheck>,
+ librust-tokio-stream-0.1+default-dev <!nocheck>,
  libfuse3-dev <!nocheck>
 Maintainer: Proxmox Support Team <support at proxmox.com>
 Standards-Version: 4.4.1
@@ -29,12 +28,11 @@ Depends:
  librust-anyhow-1+default-dev,
  librust-futures-0.3+default-dev,
  librust-libc-0.2+default-dev,
- librust-mio-0.6+default-dev (>= 0.6.21-~~),
- librust-tokio-0.2+default-dev,
- librust-tokio-0.2+io-driver-dev,
- librust-tokio-0.2+macros-dev,
- librust-tokio-0.2+signal-dev,
- librust-tokio-0.2+stream-dev,
+ librust-tokio-1+default-dev,
+ librust-tokio-1+macros-dev,
+ librust-tokio-1+net-dev,
+ librust-tokio-1+signal-dev,
+ librust-tokio-stream-0.1+default-dev,
  libfuse3-dev
 Provides:
  librust-proxmox-fuse+default-dev (= ${binary:Version}),
diff --git a/src/fuse_fd.rs b/src/fuse_fd.rs
index 68d9e79..0217689 100644
--- a/src/fuse_fd.rs
+++ b/src/fuse_fd.rs
@@ -3,10 +3,6 @@
 use std::io;
 use std::os::unix::io::{AsRawFd, RawFd};
 
-use mio::event::Evented;
-use mio::unix::EventedFd;
-use mio::{Poll, PollOpt, Ready, Token};
-
 pub struct FuseFd {
     fd: RawFd,
 }
@@ -38,29 +34,3 @@ impl AsRawFd for FuseFd {
         self.fd
     }
 }
-
-impl Evented for FuseFd {
-    fn register(
-        &self,
-        poll: &Poll,
-        token: Token,
-        interest: Ready,
-        opts: PollOpt,
-    ) -> io::Result<()> {
-        EventedFd(&self.fd).register(poll, token, interest, opts)
-    }
-
-    fn reregister(
-        &self,
-        poll: &Poll,
-        token: Token,
-        interest: Ready,
-        opts: PollOpt,
-    ) -> io::Result<()> {
-        EventedFd(&self.fd).reregister(poll, token, interest, opts)
-    }
-
-    fn deregister(&self, poll: &Poll) -> io::Result<()> {
-        EventedFd(&self.fd).deregister(poll)
-    }
-}
diff --git a/src/session.rs b/src/session.rs
index 125492a..78f558d 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -12,7 +12,7 @@ use std::{io, mem};
 use anyhow::{bail, format_err, Error};
 use futures::ready;
 use futures::stream::{FusedStream, Stream};
-use tokio::io::PollEvented;
+use tokio::io::unix::AsyncFd;
 
 use crate::fuse_fd::FuseFd;
 use crate::requests::{self, Request, RequestGuard};
@@ -610,7 +610,7 @@ impl FuseSession {
             bail!("failed to get fuse session file descriptor");
         }
 
-        let fuse_fd = PollEvented::new(FuseFd::from_raw(fd)?)?;
+        let fuse_fd = AsyncFd::new(FuseFd::from_raw(fd)?)?;
 
         // disable mount guard
         self.mounted = false;
@@ -650,7 +650,7 @@ unsafe impl Sync for SessionPtr {}
 pub struct Fuse {
     session: SessionPtr,
     fuse_data: Box<FuseData>,
-    fuse_fd: PollEvented<FuseFd>,
+    fuse_fd: AsyncFd<FuseFd>,
 }
 
 // We lose these via the raw session pointer:
@@ -691,7 +691,7 @@ impl Stream for Fuse {
                 return Poll::Ready(None);
             }
 
-            ready!(this.fuse_fd.poll_read_ready(cx, mio::Ready::readable()))?;
+            let mut ready_guard = ready!(this.fuse_fd.poll_read_ready(cx))?;
 
             let buf: &mut sys::FuseBuf = match Arc::get_mut(&mut this.fuse_data.fbuf) {
                 Some(buf) => buf,
@@ -705,10 +705,8 @@ impl Stream for Fuse {
             let rc = unsafe { sys::fuse_session_receive_buf(this.session.as_ptr(), Some(buf)) };
 
             if rc == -libc::EAGAIN {
-                match this.fuse_fd.clear_read_ready(cx, mio::Ready::readable()) {
-                    Ok(()) => continue,
-                    Err(err) => return Poll::Ready(Some(Err(err))),
-                }
+                ready_guard.clear_ready();
+                continue;
             } else if rc < 0 {
                 return Poll::Ready(Some(Err(io::Error::from_raw_os_error(-rc))));
             } else if rc == 0 {
-- 
2.20.1






More information about the pbs-devel mailing list