From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id AB7991FF161 for ; Tue, 8 Oct 2024 16:33:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A5FCE1876A; Tue, 8 Oct 2024 16:34:19 +0200 (CEST) From: Filip Schauer To: pbs-devel@lists.proxmox.com Date: Tue, 8 Oct 2024 16:34:02 +0200 Message-Id: <20241008143404.193345-4-f.schauer@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241008143404.193345-1-f.schauer@proxmox.com> References: <20241008143404.193345-1-f.schauer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.050 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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. [vma2pbs.rs, vma.rs] Subject: [pbs-devel] [PATCH v2 vma-to-pbs 3/5] remove hard coded values 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Filip Schauer --- src/vma.rs | 2 +- src/vma2pbs.rs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vma.rs b/src/vma.rs index 518de8a..63ee3b5 100644 --- a/src/vma.rs +++ b/src/vma.rs @@ -22,7 +22,7 @@ const VMA_MAX_CONFIGS: usize = 256; /// Maximum number of block devices /// See VMA Header in pve-qemu.git/vma_spec.txt -const VMA_MAX_DEVICES: usize = 256; +pub const VMA_MAX_DEVICES: usize = 256; /// VMA magic string /// See VMA Header in pve-qemu.git/vma_spec.txt diff --git a/src/vma2pbs.rs b/src/vma2pbs.rs index 05294f3..1eb510c 100644 --- a/src/vma2pbs.rs +++ b/src/vma2pbs.rs @@ -25,7 +25,7 @@ use proxmox_time::epoch_to_rfc3339; use scopeguard::defer; use serde_json::Value; -use crate::vma::VmaReader; +use crate::vma::{VmaReader, VMA_MAX_DEVICES}; const VMA_CLUSTER_SIZE: usize = 65536; @@ -173,20 +173,21 @@ where fn register_block_devices( vma_reader: &VmaReader, pbs: *mut ProxmoxBackupHandle, -) -> Result<[Option; 256], Error> +) -> Result<[Option; VMA_MAX_DEVICES], Error> where T: Read, { - let mut block_device_infos: [Option; 256] = [None; 256]; + let mut block_device_infos: [Option; VMA_MAX_DEVICES] = + [None; VMA_MAX_DEVICES]; let mut pbs_err: *mut c_char = ptr::null_mut(); - for device_id in 0..255 { - if !vma_reader.contains_device(device_id) { + for (device_id, block_device_info) in block_device_infos.iter_mut().enumerate() { + if !vma_reader.contains_device(device_id.try_into()?) { continue; } - let device_name = vma_reader.get_device_name(device_id)?; - let device_size = vma_reader.get_device_size(device_id)?; + let device_name = vma_reader.get_device_name(device_id.try_into()?)?; + let device_size = vma_reader.get_device_size(device_id.try_into()?)?; println!( "DEV: dev_id={} size: {} devname: {}", @@ -206,12 +207,10 @@ where handle_pbs_error(pbs_err, "proxmox_backup_register_image")?; } - let block_device_info = BlockDeviceInfo { + *block_device_info = Some(BlockDeviceInfo { pbs_device_id: pbs_device_id as u8, device_size, - }; - - block_device_infos[device_id as usize] = Some(block_device_info); + }); } Ok(block_device_infos) @@ -359,7 +358,7 @@ where let mut pbs_err: *mut c_char = ptr::null_mut(); - for block_device_info in block_device_infos.iter().take(255) { + for block_device_info in block_device_infos { let block_device_info = match block_device_info { Some(block_device_info) => block_device_info, None => continue, -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel