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 73C746776F for ; Tue, 12 Jan 2021 14:59:23 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6A53C271D6 for ; Tue, 12 Jan 2021 14:58:53 +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 884BF271CB for ; Tue, 12 Jan 2021 14:58:51 +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 4DC6545637 for ; Tue, 12 Jan 2021 14:58:51 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 12 Jan 2021 14:58:30 +0100 Message-Id: <20210112135830.2798301-21-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> References: <20210112135830.2798301-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.373 Adjusted score from AWL reputation of From: address KAM_ASCII_DIVIDERS 0.8 Spam that uses ascii formatting tricks KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [aio.rs, this.at, mod.rs] Subject: [pbs-devel] [RFC pxar 3/3] remove futures-io feature X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2021 13:59:23 -0000 we don't use it, and it adds unnecessary duplication/complexity. Signed-off-by: Fabian Grünbichler --- Notes: I am not particularly fond of FileContents::poll_read scaling the buffer Vec like that.. Cargo.toml | 6 +-- debian/control | 78 ++++++++++---------------------- src/accessor/aio.rs | 42 ++++------------- src/decoder/aio.rs | 108 -------------------------------------------- src/encoder/aio.rs | 81 --------------------------------- src/encoder/mod.rs | 21 ++------- 6 files changed, 37 insertions(+), 299 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 875de7a..703525e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,16 +53,14 @@ tokio = { version = "1.0", optional = true, default-features = false } libc = "0.2" [features] -default = [ "futures-io", "tokio-io" ] -futures-io = [ "futures" ] +default = [ "tokio-io" ] tokio-io = [ "tokio" ] tokio-fs = [ "tokio-io", "tokio/fs" ] -full = [ "tokio-fs", "futures-io" ] +full = [ "tokio-fs"] async-example = [ "anyhow", - "futures-io", "tokio-io", "tokio-fs", "tokio/rt-multi-thread", diff --git a/debian/control b/debian/control index 0409da8..dbbd0d6 100644 --- a/debian/control +++ b/debian/control @@ -9,10 +9,9 @@ Build-Depends: debhelper (>= 11), librust-bitflags-1+default-dev (>= 1.2.1-~~) , librust-endian-trait-0.6+arrays-dev , librust-endian-trait-0.6+default-dev , - librust-futures-0.3+default-dev (>= 0.3.1-~~) , librust-libc-0.2+default-dev , librust-siphasher-0.3+default-dev , - librust-tokio-0.2-dev (>= 0.2.10-~~) + librust-tokio-1-dev Maintainer: Proxmox Support Team Standards-Version: 4.4.1 Vcs-Git: @@ -29,13 +28,11 @@ Depends: librust-libc-0.2+default-dev, librust-siphasher-0.3+default-dev Recommends: - librust-pxar+default-dev (= ${binary:Version}) + librust-pxar+tokio-dev (= ${binary:Version}) Suggests: librust-pxar+anyhow-dev (= ${binary:Version}), librust-pxar+async-example-dev (= ${binary:Version}), - librust-pxar+full-dev (= ${binary:Version}), librust-pxar+futures-dev (= ${binary:Version}), - librust-pxar+tokio-dev (= ${binary:Version}), librust-pxar+tokio-fs-dev (= ${binary:Version}) Provides: librust-pxar+test-harness-dev (= ${binary:Version}), @@ -70,13 +67,11 @@ Multi-Arch: same Depends: ${misc:Depends}, librust-pxar-dev (= ${binary:Version}), - librust-pxar+futures-io-dev (= ${binary:Version}), librust-pxar+tokio-io-dev (= ${binary:Version}), librust-pxar+tokio-fs-dev (= ${binary:Version}), librust-anyhow-1+default-dev, - librust-tokio-0.2+io-driver-dev (>= 0.2.10-~~), - librust-tokio-0.2+macros-dev (>= 0.2.10-~~), - librust-tokio-0.2+rt-threaded-dev (>= 0.2.10-~~) + librust-tokio-1+macros-dev, + librust-tokio-1+rt-multi-thread-dev Provides: librust-pxar-0+async-example-dev (= ${binary:Version}), librust-pxar-0.6+async-example-dev (= ${binary:Version}), @@ -85,38 +80,6 @@ Description: Proxmox Archive format support library - feature "async-example" This metapackage enables feature "async-example" for the Rust pxar crate, by pulling in any additional dependencies needed by that feature. -Package: librust-pxar+default-dev -Architecture: any -Multi-Arch: same -Depends: - ${misc:Depends}, - librust-pxar-dev (= ${binary:Version}), - librust-pxar+futures-io-dev (= ${binary:Version}), - librust-pxar+tokio-io-dev (= ${binary:Version}) -Provides: - librust-pxar-0+default-dev (= ${binary:Version}), - librust-pxar-0.6+default-dev (= ${binary:Version}), - librust-pxar-0.6.2+default-dev (= ${binary:Version}) -Description: Proxmox Archive format support library - feature "default" - This metapackage enables feature "default" for the Rust pxar crate, by pulling - in any additional dependencies needed by that feature. - -Package: librust-pxar+full-dev -Architecture: any -Multi-Arch: same -Depends: - ${misc:Depends}, - librust-pxar-dev (= ${binary:Version}), - librust-pxar+tokio-fs-dev (= ${binary:Version}), - librust-pxar+futures-io-dev (= ${binary:Version}) -Provides: - librust-pxar-0+full-dev (= ${binary:Version}), - librust-pxar-0.6+full-dev (= ${binary:Version}), - librust-pxar-0.6.2+full-dev (= ${binary:Version}) -Description: Proxmox Archive format support library - feature "full" - This metapackage enables feature "full" for the Rust pxar crate, by pulling in - any additional dependencies needed by that feature. - Package: librust-pxar+futures-dev Architecture: any Multi-Arch: same @@ -125,18 +88,12 @@ Depends: librust-pxar-dev (= ${binary:Version}), librust-futures-0.3+default-dev (>= 0.3.1-~~) Provides: - librust-pxar+futures-io-dev (= ${binary:Version}), librust-pxar-0+futures-dev (= ${binary:Version}), - librust-pxar-0+futures-io-dev (= ${binary:Version}), librust-pxar-0.6+futures-dev (= ${binary:Version}), - librust-pxar-0.6+futures-io-dev (= ${binary:Version}), - librust-pxar-0.6.2+futures-dev (= ${binary:Version}), - librust-pxar-0.6.2+futures-io-dev (= ${binary:Version}) -Description: Proxmox Archive format support library - feature "futures" and 1 more + librust-pxar-0.6.2+futures-dev (= ${binary:Version}) +Description: Proxmox Archive format support library - feature "futures" This metapackage enables feature "futures" for the Rust pxar crate, by pulling in any additional dependencies needed by that feature. - . - Additionally, this package also provides the "futures-io" feature. Package: librust-pxar+tokio-dev Architecture: any @@ -144,20 +101,25 @@ Multi-Arch: same Depends: ${misc:Depends}, librust-pxar-dev (= ${binary:Version}), - librust-tokio-0.2-dev (>= 0.2.10-~~) + librust-tokio-1-dev Provides: + librust-pxar+default-dev (= ${binary:Version}), librust-pxar+tokio-io-dev (= ${binary:Version}), librust-pxar-0+tokio-dev (= ${binary:Version}), + librust-pxar-0+default-dev (= ${binary:Version}), librust-pxar-0+tokio-io-dev (= ${binary:Version}), librust-pxar-0.6+tokio-dev (= ${binary:Version}), + librust-pxar-0.6+default-dev (= ${binary:Version}), librust-pxar-0.6+tokio-io-dev (= ${binary:Version}), librust-pxar-0.6.2+tokio-dev (= ${binary:Version}), + librust-pxar-0.6.2+default-dev (= ${binary:Version}), librust-pxar-0.6.2+tokio-io-dev (= ${binary:Version}) -Description: Proxmox Archive format support library - feature "tokio" and 1 more +Description: Proxmox Archive format support library - feature "tokio" and 2 more This metapackage enables feature "tokio" for the Rust pxar crate, by pulling in any additional dependencies needed by that feature. . - Additionally, this package also provides the "tokio-io" feature. + Additionally, this package also provides the "default", and "tokio-io" + features. Package: librust-pxar+tokio-fs-dev Architecture: any @@ -166,11 +128,17 @@ Depends: ${misc:Depends}, librust-pxar-dev (= ${binary:Version}), librust-pxar+tokio-io-dev (= ${binary:Version}), - librust-tokio-0.2+fs-dev (>= 0.2.10-~~) + librust-tokio-1+fs-dev Provides: + librust-pxar+full-dev (= ${binary:Version}), librust-pxar-0+tokio-fs-dev (= ${binary:Version}), + librust-pxar-0+full-dev (= ${binary:Version}), librust-pxar-0.6+tokio-fs-dev (= ${binary:Version}), - librust-pxar-0.6.2+tokio-fs-dev (= ${binary:Version}) -Description: Proxmox Archive format support library - feature "tokio-fs" + librust-pxar-0.6+full-dev (= ${binary:Version}), + librust-pxar-0.6.2+tokio-fs-dev (= ${binary:Version}), + librust-pxar-0.6.2+full-dev (= ${binary:Version}) +Description: Proxmox Archive format support library - feature "tokio-fs" and 1 more This metapackage enables feature "tokio-fs" for the Rust pxar crate, by pulling in any additional dependencies needed by that feature. + . + Additionally, this package also provides the "full" feature. diff --git a/src/accessor/aio.rs b/src/accessor/aio.rs index dd017ae..c48ca8f 100644 --- a/src/accessor/aio.rs +++ b/src/accessor/aio.rs @@ -348,20 +348,19 @@ pub struct FileContents { unsafe impl Send for FileContents {} unsafe impl Sync for FileContents {} -#[cfg(any(feature = "futures-io", feature = "tokio-io"))] -impl FileContents { - /// Similar implementation exists for SeqReadAtAdapter in mod.rs - fn do_poll_read( +#[cfg(feature = "tokio-io")] +impl tokio::io::AsyncRead for FileContents { + fn poll_read( self: Pin<&mut Self>, cx: &mut Context, - dest: &mut [u8], - ) -> Poll> { + dest: &mut tokio::io::ReadBuf, + ) -> Poll> { let this = unsafe { Pin::into_inner_unchecked(self) }; loop { match this.future.take() { None => { let mut buffer = mem::take(&mut this.buffer); - util::scale_read_buffer(&mut buffer, dest.len()); + util::scale_read_buffer(&mut buffer, dest.remaining()); let reader: accessor::FileContentsImpl = this.inner.clone(); let at = this.at; let future: Pin>>> = @@ -384,9 +383,9 @@ impl FileContents { Poll::Ready(Ok(ReadResult { len: got, buffer })) => { this.buffer = buffer; this.at += got as u64; - let len = got.min(dest.len()); - dest[..len].copy_from_slice(&this.buffer[..len]); - return Poll::Ready(Ok(len)); + let len = got.min(dest.remaining()); + dest.put_slice(&this.buffer[..len]); + return Poll::Ready(Ok(())); } }, } @@ -394,29 +393,6 @@ impl FileContents { } } -#[cfg(feature = "futures-io")] -impl futures::io::AsyncRead for FileContents { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { - Self::do_poll_read(self, cx, buf) - } -} - -#[cfg(feature = "tokio-io")] -impl tokio::io::AsyncRead for FileContents { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut tokio::io::ReadBuf, - ) -> Poll> { - Self::do_poll_read(self, cx, &mut buf.initialize_unfilled()) - .map_ok(|bytes| { buf.set_filled(bytes); () }) - } -} - impl ReadAt for FileContents { fn start_read_at<'a>( self: Pin<&'a Self>, diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs index 1a5f5ea..82030b0 100644 --- a/src/decoder/aio.rs +++ b/src/decoder/aio.rs @@ -16,15 +16,6 @@ pub struct Decoder { inner: decoder::DecoderImpl, } -#[cfg(feature = "futures-io")] -impl Decoder> { - /// Decode a `pxar` archive from a `futures::io::AsyncRead` input. - #[inline] - pub async fn from_futures(input: T) -> io::Result { - Decoder::new(FuturesReader::new(input)).await - } -} - #[cfg(feature = "tokio-io")] impl Decoder> { /// Decode a `pxar` archive from a `tokio::io::AsyncRead` input. @@ -69,107 +60,8 @@ impl Decoder { pub fn enable_goodbye_entries(&mut self, on: bool) { self.inner.with_goodbye_tables = on; } - - /// Turn this decoder into a `Stream`. - #[cfg(feature = "futures-io")] - pub fn into_stream(self) -> DecoderStream { - DecoderStream::new(self) - } -} - -#[cfg(feature = "futures-io")] -mod stream { - use std::future::Future; - use std::io; - use std::pin::Pin; - use std::task::{Context, Poll}; - - use super::{Entry, SeqRead}; - - /// A wrapper for the async decoder implementing `futures::stream::Stream`. - /// - /// As long as streams are poll-based this wrapper is required to turn `async fn next()` into - /// `Stream`'s `poll_next()` interface. - #[allow(clippy::type_complexity)] // yeah no - pub struct DecoderStream { - inner: super::Decoder, - future: Option>>>>>, - } - - impl DecoderStream { - pub fn new(inner: super::Decoder) -> Self { - Self { - inner, - future: None, - } - } - } - - impl futures::stream::Stream for DecoderStream { - type Item = io::Result; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - let this = unsafe { self.get_unchecked_mut() }; - loop { - if let Some(mut fut) = this.future.take() { - match fut.as_mut().poll(cx) { - Poll::Ready(res) => return Poll::Ready(res), - Poll::Pending => { - this.future = Some(fut); - return Poll::Pending; - } - } - } - unsafe { - let fut: Box> = Box::new(this.inner.next()); - // Discard the lifetime: - let fut: *mut (dyn Future>> + 'static) = - core::mem::transmute(Box::into_raw(fut)); - let fut = Box::from_raw(fut); - this.future = Some(Pin::new_unchecked(fut)); - } - } - } - } -} - -#[cfg(feature = "futures-io")] -pub use stream::DecoderStream; - -#[cfg(feature = "futures-io")] -mod fut { - use std::io; - use std::pin::Pin; - use std::task::{Context, Poll}; - - /// Read adapter for `futures::io::AsyncRead` - pub struct FuturesReader { - inner: T, - } - - impl FuturesReader { - pub fn new(inner: T) -> Self { - Self { inner } - } - } - - impl crate::decoder::SeqRead for FuturesReader { - fn poll_seq_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { - unsafe { - self.map_unchecked_mut(|this| &mut this.inner) - .poll_read(cx, buf) - } - } - } } -#[cfg(feature = "futures-io")] -use fut::FuturesReader; - #[cfg(feature = "tokio-io")] mod tok { use std::io; diff --git a/src/encoder/aio.rs b/src/encoder/aio.rs index d989abd..908e019 100644 --- a/src/encoder/aio.rs +++ b/src/encoder/aio.rs @@ -9,11 +9,6 @@ use crate::encoder::{self, LinkOffset, SeqWrite}; use crate::format; use crate::Metadata; -// #[cfg(feature = "futures-io")] -// use crate::decoder::aio::FuturesReader; -// #[cfg(feature = "tokio-io")] -// use crate::decoder::aio::TokioReader; - /// Asynchronous `pxar` encoder. /// /// This is the `async` version of the `pxar` encoder. @@ -22,18 +17,6 @@ pub struct Encoder<'a, T: SeqWrite + 'a> { inner: encoder::EncoderImpl<'a, T>, } -#[cfg(feature = "futures-io")] -impl<'a, T: futures::io::AsyncWrite + 'a> Encoder<'a, FuturesWriter> { - /// Encode a `pxar` archive into a `futures::io::AsyncWrite` output. - #[inline] - pub async fn from_futures( - output: T, - metadata: &Metadata, - ) -> io::Result>> { - Encoder::new(FuturesWriter::new(output), metadata).await - } -} - #[cfg(feature = "tokio-io")] impl<'a, T: tokio::io::AsyncWrite + 'a> Encoder<'a, TokioWriter> { /// Encode a `pxar` archive into a `tokio::io::AsyncWrite` output. @@ -214,21 +197,6 @@ impl<'a> File<'a> { } } -#[cfg(feature = "futures-io")] -impl<'a> futures::io::AsyncWrite for File<'a> { - fn poll_write(self: Pin<&mut Self>, cx: &mut Context, data: &[u8]) -> Poll> { - unsafe { self.map_unchecked_mut(|this| &mut this.inner) }.poll_write(cx, data) - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - unsafe { self.map_unchecked_mut(|this| &mut this.inner) }.poll_flush(cx) - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - unsafe { self.map_unchecked_mut(|this| &mut this.inner) }.poll_close(cx) - } -} - #[cfg(feature = "tokio-io")] impl<'a> tokio::io::AsyncWrite for File<'a> { fn poll_write(self: Pin<&mut Self>, cx: &mut Context, data: &[u8]) -> Poll> { @@ -244,55 +212,6 @@ impl<'a> tokio::io::AsyncWrite for File<'a> { } } -/// Pxar encoder write adapter for `futures::io::AsyncWrite`. -#[cfg(feature = "futures-io")] -mod futures_writer { - use std::io; - use std::pin::Pin; - use std::task::{Context, Poll}; - - use crate::encoder::SeqWrite; - - pub struct FuturesWriter { - inner: Option, - } - - impl FuturesWriter { - pub fn new(inner: T) -> Self { - Self { inner: Some(inner) } - } - - fn inner_mut(&mut self) -> io::Result> { - let inner = self - .inner - .as_mut() - .ok_or_else(|| io_format_err!("write after close"))?; - Ok(unsafe { Pin::new_unchecked(inner) }) - } - - fn inner(self: Pin<&mut Self>) -> io::Result> { - unsafe { self.get_unchecked_mut() }.inner_mut() - } - } - - impl SeqWrite for FuturesWriter { - fn poll_seq_write( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &[u8], - ) -> Poll> { - let this = unsafe { self.get_unchecked_mut() }; - this.inner_mut()?.poll_write(cx, buf) - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - self.inner()?.poll_flush(cx) - } - } -} - -pub use futures_writer::FuturesWriter; - /// Pxar encoder write adapter for `tokio::io::AsyncWrite`. #[cfg(feature = "tokio-io")] mod tokio_writer { diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index f186aa8..fdd04ae 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -818,7 +818,7 @@ impl<'a> FileImpl<'a> { } /// Poll write interface to more easily connect to tokio/futures. - #[cfg(any(feature = "tokio-io", feature = "futures-io"))] + #[cfg(feature = "tokio-io")] pub fn poll_write( self: Pin<&mut Self>, cx: &mut Context, @@ -838,7 +838,7 @@ impl<'a> FileImpl<'a> { } /// Poll flush interface to more easily connect to tokio/futures. - #[cfg(any(feature = "tokio-io", feature = "futures-io"))] + #[cfg(feature = "tokio-io")] pub fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { unsafe { self.map_unchecked_mut(|this| &mut this.output) @@ -850,7 +850,7 @@ impl<'a> FileImpl<'a> { /// /// This just calls flush, though, since we're just a virtual writer writing to the file /// provided by our encoder. - #[cfg(any(feature = "tokio-io", feature = "futures-io"))] + #[cfg(feature = "tokio-io")] pub fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { unsafe { self.map_unchecked_mut(|this| &mut this.output) @@ -897,18 +897,3 @@ impl<'a> tokio::io::AsyncWrite for FileImpl<'a> { FileImpl::poll_close(self, cx) } } - -#[cfg(feature = "futures-io")] -impl<'a> futures::io::AsyncWrite for FileImpl<'a> { - fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll> { - FileImpl::poll_write(self, cx, buf) - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - FileImpl::poll_flush(self, cx) - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - FileImpl::poll_close(self, cx) - } -} -- 2.20.1