public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH v3 stable-2 pxar] format/decoder/accessor: backport PXAR_FORMAT_VERSION header
Date: Thu, 06 Jun 2024 12:09:27 +0200	[thread overview]
Message-ID: <1717668438.2tbev2v16f.astroid@yuna.none> (raw)
In-Reply-To: <20240606094449.228306-1-c.ebner@proxmox.com>

On June 6, 2024 11:44 am, Christian Ebner wrote:
> Backports the PXAR_FORMAT_VERSION header, introduced with version
> 0.11 of the pxar library in order to early bail for decoder and
> accessor instances not supporting the updated pxar format version.
> 
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
> ---
> changes since version 2:
> - drop unneeded patches on proxmox-backup, the pxar patches already
>   cover all cases
> - drop unneeded failsafe checks on decoder/accessor
> 
>  examples/mk-format-hashes.rs |  5 +++++
>  src/accessor/mod.rs          | 14 +++++++++++++-
>  src/decoder/mod.rs           |  4 ++++
>  src/format/mod.rs            |  4 ++++
>  4 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/mk-format-hashes.rs b/examples/mk-format-hashes.rs
> index 6e00654..afd0924 100644
> --- a/examples/mk-format-hashes.rs
> +++ b/examples/mk-format-hashes.rs
> @@ -1,6 +1,11 @@
>  use pxar::format::hash_filename;
>  
>  const CONSTANTS: &[(&str, &str, &str)] = &[
> +    (
> +        "Pxar format version entry, fallback to version 1 if not present",
> +        "PXAR_FORMAT_VERSION",
> +        "__PROXMOX_FORMAT_VERSION__",
> +    ),
>      (
>          "Beginning of an entry (current version).",
>          "PXAR_ENTRY",
> diff --git a/src/accessor/mod.rs b/src/accessor/mod.rs
> index 6a2de73..80bf89b 100644
> --- a/src/accessor/mod.rs
> +++ b/src/accessor/mod.rs
> @@ -185,11 +185,23 @@ pub(crate) struct AccessorImpl<T> {
>  }
>  
>  impl<T: ReadAt> AccessorImpl<T> {
> -    pub async fn new(input: T, size: u64) -> io::Result<Self> {
> +    pub async fn new(mut input: T, size: u64) -> io::Result<Self> {

nit: the mut here is not needed

>          if size < (size_of::<GoodbyeItem>() as u64) {
>              io_bail!("too small to contain a pxar archive");
>          }
>  
> +        let header: format::Header = read_entry_at(&mut input, 0).await?;

since this takes a regular &

> +        header.check_header_size()?;
> +
> +        if header.htype == format::PXAR_FORMAT_VERSION {
> +            let version: u64 = read_entry_at(
> +                &mut input,

and this as well

or am I missing something?

> +                size_of::<format::Header>() as u64,
> +            )
> +            .await?;
> +            io_bail!("format version {version} not compatible with this client");
> +        }
> +
>          Ok(Self {
>              input,
>              size,
> diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
> index d1fb911..9c74a5c 100644
> --- a/src/decoder/mod.rs
> +++ b/src/decoder/mod.rs
> @@ -374,6 +374,10 @@ impl<I: SeqRead> DecoderImpl<I> {
>              self.entry.kind = EntryKind::Hardlink(self.read_hardlink().await?);
>  
>              Ok(Some(self.entry.take()))
> +        } else if header.htype == format::PXAR_FORMAT_VERSION {
> +            self.current_header = header;
> +            let version: u64 = seq_read_entry(&mut self.input).await?;
> +            io_bail!("format version {version} not compatible with this client");
>          } else if header.htype == format::PXAR_ENTRY || header.htype == format::PXAR_ENTRY_V1 {
>              if header.htype == format::PXAR_ENTRY {
>                  self.entry.metadata = Metadata {
> diff --git a/src/format/mod.rs b/src/format/mod.rs
> index bfea9f6..50d0e26 100644
> --- a/src/format/mod.rs
> +++ b/src/format/mod.rs
> @@ -6,6 +6,7 @@
>  //! item data.
>  //!
>  //! An archive contains items in the following order:
> +//!  * `FORMAT_VERSION`     -- (optional for v1), version of encoding format
>  //!  * `ENTRY`              -- containing general stat() data and related bits
>  //!   * `XATTR`             -- one extended attribute
>  //!   * ...                 -- more of these when there are multiple defined
> @@ -79,6 +80,8 @@ pub mod mode {
>  }
>  
>  // Generated by `cargo run --example mk-format-hashes`
> +/// Pxar format version entry, fallback to version 1 if not present
> +pub const PXAR_FORMAT_VERSION: u64 = 0x730f6c75df16a40d;
>  /// Beginning of an entry (current version).
>  pub const PXAR_ENTRY: u64 = 0xd5956474e588acef;
>  /// Previous version of the entry struct
> @@ -177,6 +180,7 @@ impl Header {
>  impl Display for Header {
>      fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
>          let readable = match self.htype {
> +            PXAR_FORMAT_VERSION => "FORMAT_VERSION",
>              PXAR_FILENAME => "FILENAME",
>              PXAR_SYMLINK => "SYMLINK",
>              PXAR_HARDLINK => "HARDLINK",
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  reply	other threads:[~2024-06-06 10:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06  9:44 Christian Ebner
2024-06-06 10:09 ` Fabian Grünbichler [this message]
2024-06-06 10:34 ` Christian Ebner

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=1717668438.2tbev2v16f.astroid@yuna.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal