From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.schauer@proxmox.com>
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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id CE8C4B9133
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Mar 2024 15:05:14 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id B4B1418D08
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Mar 2024 15:04:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Mar 2024 15:04:40 +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 902FC43E54
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Mar 2024 15:04:40 +0100 (CET)
Message-ID: <8f97a7af-af75-4414-b40e-a77b51a23c10@proxmox.com>
Date: Tue, 12 Mar 2024 15:04:39 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: Max Carrara <m.carrara@proxmox.com>,
 Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com>
References: <20240305135645.96347-1-f.schauer@proxmox.com>
 <20240305135645.96347-6-f.schauer@proxmox.com>
 <9a4d9e4c-3175-44a4-aa02-61e68b2c4b2a@proxmox.com>
From: Filip Schauer <f.schauer@proxmox.com>
In-Reply-To: <9a4d9e4c-3175-44a4-aa02-61e68b2c4b2a@proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.094 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [vma2pbs.rs]
Subject: Re: [pbs-devel] [PATCH v4 vma-to-pbs 5/6] Add support for streaming
 the VMA file via stdin
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 12 Mar 2024 14:05:14 -0000

On 06/03/2024 16:49, Max Carrara wrote:
> Regarding `F: Fn(u8, u64, Option<Vec<u8>>) -> Result<()>`:
> * Why `Fn` and not `FnOnce`? You call this with a closure later on.

It is called multiple times in the for loop in restore_extent.


>> +            let is_zero = blockinfo.mask == 0;
> I'm usually in favour of assigning the result of conditional checks
> to variables first, but is that really necessary here?
>
>>   
>> -        while file_offset < vma_file_size {
>> -            self.vma_file.seek(SeekFrom::Start(file_offset))?;
>> -            let vma_extent_header = Self::read_extent_header(&mut self.vma_file)?;
>> -            file_offset += size_of::<VmaExtentHeader>() as u64;
>> +            let image_chunk_buffer = if is_zero {
> It's only used here after all, and inlining it wouldn't make the code
> more complex at all.

Not necessary but it improves readability in my opinion.


> Also,
> `Vec<u8>` could probably be `&[u8]`, couldn't it?
No, because then the image_chunk_buffer would not live long enough.
The chunk needs to live past func so it can be stored in the
images_chunks HashMap in vma2pbs.rs. This HashMap can hold multiple
chunks before they are sent off as one big chunk to the PBS.