From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Stefan Reiter <s.reiter@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH pxar 01/22] decoder/aio: add contents() and content_size() calls
Date: Wed, 17 Feb 2021 08:56:54 +0100 [thread overview]
Message-ID: <20210217075654.yokzlgbb3anix6mi@olga.proxmox.com> (raw)
In-Reply-To: <20210216170710.31767-2-s.reiter@proxmox.com>
On Tue, Feb 16, 2021 at 06:06:49PM +0100, Stefan Reiter wrote:
> Returns a tokio AsyncRead implementation for its "Contents" to keep with
> the aio theme.
>
> Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
> ---
> src/decoder/aio.rs | 43 ++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/src/decoder/aio.rs b/src/decoder/aio.rs
> index 82030b0..5cc6694 100644
> --- a/src/decoder/aio.rs
> +++ b/src/decoder/aio.rs
> @@ -56,6 +56,18 @@ impl<T: SeqRead> Decoder<T> {
> self.inner.next_do().await.transpose()
> }
>
> + /// Get a reader for the contents of the current entry, if the entry has contents.
> + /// Only available for feature "tokio-io", since it returns an AsyncRead reader.
> + #[cfg(feature = "tokio-io")]
^ Don't do this.
We basically have our own async I/O "entry point" with the SeqRead
trait, and if you want to use it with another I/O runtime (say async-std
or w/e futures or w/e else there is), you want to be able to use
`Contents` there as well and just wrap it an alternative to the
provided `TokioReader` manually.
So just leave `Contents` as a public just-`SeqRead` type.
> + pub fn contents(&mut self) -> Option<Contents<T>> {
> + self.inner.content_reader().map(|inner| Contents { inner })
> + }
> +
> + /// Get the size of the current contents, if the entry has contents.
> + pub fn content_size(&self) -> Option<u64> {
> + self.inner.content_size()
> + }
> +
> /// Include goodbye tables in iteration.
> pub fn enable_goodbye_entries(&mut self, on: bool) {
> self.inner.with_goodbye_tables = on;
> @@ -93,7 +105,36 @@ mod tok {
> }
> }
> }
> +
> + pub struct Contents<'a, T: crate::decoder::SeqRead> {
> + pub(crate) inner: crate::decoder::Contents<'a, T>,
^ no need for the `pub(crate)` then when you move it up
> + }
> +
> + impl<'a, T: crate::decoder::SeqRead> tokio::io::AsyncRead for Contents<'a, T> {
> + fn poll_read(
> + self: Pin<&mut Self>,
> + cx: &mut Context<'_>,
> + buf: &mut tokio::io::ReadBuf<'_>,
> + ) -> Poll<io::Result<()>> {
> + unsafe {
> + // Safety: poll_seq_read will only write to the buffer, so we don't need to
> + // initialize it first, we can treat is a &[u8] immediately as long as we uphold
> + // the ReadBuf invariants in the conditional below
^ This comment is actually wrong. `poll_seq_read` will do whatever the
heck the implementer of the trait decides to do ;-)
Personally, I really don't mind doing this *anyway* until a definitive
"solution" actually lands in the *standard* library. Because if someone
f's up a read impl even if it causes wild codegen bugs with tentacles then...
sorry not sorry.
> + let write_buf =
> + &mut *(buf.unfilled_mut() as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]);
> + let result = self
> + .map_unchecked_mut(|this| &mut this.inner as &mut dyn crate::decoder::SeqRead)
> + .poll_seq_read(cx, write_buf);
> + if let Poll::Ready(Ok(n)) = result {
> + // if we've written data, advance both initialized and filled bytes cursor
> + buf.assume_init(buf.filled().len() + n);
> + buf.advance(n);
> + }
> + result.map(|_| Ok(()))
> + }
> + }
> + }
> }
>
> #[cfg(feature = "tokio-io")]
> -use tok::TokioReader;
> +use tok::{Contents, TokioReader};
^ Needs a `pub` otherwise the type *can* exist as the return type of a
function, but users have no way to actually *type out* the type...
next prev parent reply other threads:[~2021-02-17 7:57 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-16 17:06 [pbs-devel] [PATCH 00/22] Single file restore for VM images Stefan Reiter
2021-02-16 17:06 ` [pbs-devel] [PATCH pxar 01/22] decoder/aio: add contents() and content_size() calls Stefan Reiter
2021-02-17 7:56 ` Wolfgang Bumiller [this message]
2021-02-16 17:06 ` [pbs-devel] [PATCH pxar 02/22] decoder: add peek() Stefan Reiter
2021-02-17 8:20 ` Wolfgang Bumiller
2021-02-17 8:38 ` Stefan Reiter
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-restore-vm-data 03/22] initial commit Stefan Reiter
2021-03-15 18:35 ` [pbs-devel] applied: " Thomas Lamprecht
2021-03-16 15:33 ` Stefan Reiter
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 04/22] api2/admin/datastore: refactor list_dir_content in catalog_reader Stefan Reiter
2021-02-17 7:50 ` [pbs-devel] applied: " Thomas Lamprecht
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 05/22] api2/admin/datastore: accept "/" as path for root Stefan Reiter
2021-02-17 7:50 ` [pbs-devel] applied: " Thomas Lamprecht
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 06/22] api2/admin/datastore: refactor create_zip into pxar/extract Stefan Reiter
2021-02-17 7:50 ` [pbs-devel] applied: " Thomas Lamprecht
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 07/22] pxar/extract: add extract_sub_dir Stefan Reiter
2021-02-17 7:51 ` [pbs-devel] applied: " Thomas Lamprecht
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 08/22] pxar/extract: add sequential variants to create_zip, extract_sub_dir Stefan Reiter
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 09/22] client: extract common functions to proxmox_client_tools module Stefan Reiter
2021-02-17 6:49 ` Dietmar Maurer
2021-02-17 7:58 ` Stefan Reiter
2021-02-17 8:50 ` Dietmar Maurer
2021-02-17 9:47 ` Stefan Reiter
2021-02-17 10:12 ` Dietmar Maurer
2021-02-17 9:13 ` [pbs-devel] applied: " Dietmar Maurer
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 10/22] proxmox_client_tools: extract 'key' from client module Stefan Reiter
2021-02-17 9:11 ` Dietmar Maurer
2021-02-16 17:06 ` [pbs-devel] [PATCH proxmox-backup 11/22] file-restore: add binary and basic commands Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 12/22] file-restore: allow specifying output-format Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 13/22] rest: implement tower service for UnixStream Stefan Reiter
2021-02-17 6:52 ` [pbs-devel] applied: " Dietmar Maurer
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 14/22] client: add VsockClient to connect to virtio-vsock VMs Stefan Reiter
2021-02-17 7:24 ` [pbs-devel] applied: " Dietmar Maurer
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 15/22] file-restore-daemon: add binary with virtio-vsock API server Stefan Reiter
2021-02-17 10:17 ` Dietmar Maurer
2021-02-17 10:25 ` Dietmar Maurer
2021-02-17 10:30 ` Stefan Reiter
2021-02-17 11:13 ` Dietmar Maurer
2021-02-17 11:26 ` Dietmar Maurer
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 16/22] file-restore-daemon: add watchdog module Stefan Reiter
2021-02-17 10:52 ` Wolfgang Bumiller
2021-02-17 11:14 ` Stefan Reiter
2021-02-17 11:29 ` Wolfgang Bumiller
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 17/22] file-restore-daemon: add disk module Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 18/22] file-restore: add basic VM/block device support Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 19/22] file-restore: improve logging of VM with logrotate Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 20/22] debian/client: add postinst hook to rebuild file-restore initramfs Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 21/22] file-restore(-daemon): implement list API Stefan Reiter
2021-02-16 17:07 ` [pbs-devel] [PATCH proxmox-backup 22/22] file-restore: add 'extract' command for VM file restore Stefan Reiter
2021-02-16 17:11 ` [pbs-devel] [PATCH 00/22] Single file restore for VM images Stefan Reiter
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=20210217075654.yokzlgbb3anix6mi@olga.proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=s.reiter@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.