all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Robert Obkircher <r.obkircher@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-backup v2 2/5] datastore: data blob: refactor decoding method
Date: Wed, 22 Jul 2026 13:31:06 +0200	[thread overview]
Message-ID: <178471986678.177215.16619713207450916356.b4-review@b4> (raw)
In-Reply-To: <20260507130135.589100-3-c.ebner@proxmox.com>

> Improve code style and readability by using a single match statement
> instead of chained if statements and deduplicate the common digest
> verificaton, performed on the decoded blob data.
> 
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
>
> diff --git a/pbs-datastore/src/data_blob.rs b/pbs-datastore/src/data_blob.rs
> index 465bcb280..9fd791af5 100644
> --- a/pbs-datastore/src/data_blob.rs
> +++ b/pbs-datastore/src/data_blob.rs
> @@ -180,57 +180,57 @@ impl DataBlob {
>          config: Option<&CryptConfig>,
>          digest: Option<&[u8; 32]>,
>      ) -> Result<Vec<u8>, Error> {
> -        let magic = self.magic();
> +        let magic = *self.magic();
>  
> -        if magic == &UNCOMPRESSED_BLOB_MAGIC_1_0 {
> -            let data_start = std::mem::size_of::<DataBlobHeader>();
> -            let data = self.raw_data[data_start..].to_vec();
> -            if let Some(digest) = digest {
> -                Self::verify_digest(&data, None, digest)?;
> +        let (data, crypt_config) = match magic {
> +            UNCOMPRESSED_BLOB_MAGIC_1_0 => {
> +                let data_start = std::mem::size_of::<DataBlobHeader>();
> +                let data = self.raw_data[data_start..].to_vec();
> +                (data, None)
>              }
> -            Ok(data)
> -        } else if magic == &COMPRESSED_BLOB_MAGIC_1_0 {
> -            let data_start = std::mem::size_of::<DataBlobHeader>();
> -            let mut reader = &self.raw_data[data_start..];
> -            let data = zstd::stream::decode_all(&mut reader)?;
> -            // zstd::block::decompress is about 10% slower
> -            // let data = zstd::block::decompress(&self.raw_data[data_start..], MAX_BLOB_SIZE)?;
> -            if let Some(digest) = digest {
> -                Self::verify_digest(&data, None, digest)?;
> +            COMPRESSED_BLOB_MAGIC_1_0 => {
> +                let data_start = std::mem::size_of::<DataBlobHeader>();
> +                let mut reader = &self.raw_data[data_start..];
> +                let data = zstd::stream::decode_all(&mut reader)?;
> +                // zstd::block::decompress is about 10% slower
> +                // let data = zstd::block::decompress(&self.raw_data[data_start..], MAX_BLOB_SIZE)?;
> +                (data, None)
>              }
> -            Ok(data)
> -        } else if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 || magic == &ENCRYPTED_BLOB_MAGIC_1_0 {
> -            let header_len = std::mem::size_of::<EncryptedDataBlobHeader>();
> -            let head = unsafe {
> -                (&self.raw_data[..header_len]).read_le_value::<EncryptedDataBlobHeader>()?
> -            };
> +            ENCR_COMPR_BLOB_MAGIC_1_0 | ENCRYPTED_BLOB_MAGIC_1_0 => {
> +                let header_len = std::mem::size_of::<EncryptedDataBlobHeader>();
> +                let head = unsafe {
> +                    (&self.raw_data[..header_len]).read_le_value::<EncryptedDataBlobHeader>()?
> +                };
>  
> -            if let Some(config) = config {
> -                let data = if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 {
> -                    Self::decode_compressed_chunk(
> -                        config,
> -                        &self.raw_data[header_len..],
> -                        &head.iv,
> -                        &head.tag,
> -                    )?
> +                if let Some(config) = config {
nit: this could be `let Some(config) = config else { bail!(..); };`
to reduce indentation.

-- 
Robert Obkircher <r.obkircher@proxmox.com>




  reply	other threads:[~2026-07-22 11:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 13:01 [PATCH proxmox-backup v2 0/5] restrict previous manifest reuse checks for push sync jobs Christian Ebner
2026-05-07 13:01 ` [PATCH proxmox-backup v2 1/5] datastore: data blob: refactor crypt mode method Christian Ebner
2026-05-07 13:01 ` [PATCH proxmox-backup v2 2/5] datastore: data blob: refactor decoding method Christian Ebner
2026-07-22 11:31   ` Robert Obkircher [this message]
2026-05-07 13:01 ` [PATCH proxmox-backup v2 3/5] client: backup writer: pass no crypt config to manifest blob decoder Christian Ebner
2026-05-07 13:01 ` [PATCH proxmox-backup v2 4/5] client: allow skipping signature check on previous manifest fetching Christian Ebner
2026-05-07 13:01 ` [PATCH proxmox-backup v2 5/5] sync: push: gracefully handle previous manifest signature mismatches Christian Ebner
2026-07-22 11:31   ` Robert Obkircher
2026-07-22 14:49     ` Christian Ebner
2026-07-21 11:03 ` [PATCH proxmox-backup v2 0/5] restrict previous manifest reuse checks for push sync jobs Christian Ebner
2026-07-22 11:31 ` Robert Obkircher

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=178471986678.177215.16619713207450916356.b4-review@b4 \
    --to=r.obkircher@proxmox.com \
    --cc=c.ebner@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 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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal