From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 646BB76F2A for ; Mon, 26 Apr 2021 15:04:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 578571624A for ; Mon, 26 Apr 2021 15:04:25 +0200 (CEST) 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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9769A16238 for ; Mon, 26 Apr 2021 15:04:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 701B5428F9 for ; Mon, 26 Apr 2021 15:04:24 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Mon, 26 Apr 2021 15:04:14 +0200 Message-Id: <20210426130417.20979-1-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 Adjusted score from AWL reputation of From: address 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 Subject: [pbs-devel] [PATCH proxmox-backup 1/4] file-restore: add size to image files and components 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: , X-List-Received-Date: Mon, 26 Apr 2021 13:04:55 -0000 Read image sizes (.pxar.fidx/.img.didx) from manifest and partition sizes from /sys/... Requires a change to ArchiveEntry, as DirEntryAttribute::Directory does not have a size associated with it (and that's probably good). Signed-off-by: Stefan Reiter --- src/api2/types/mod.rs | 19 ++++++++++++++----- src/bin/proxmox-file-restore.rs | 2 +- src/bin/proxmox_restore_daemon/api.rs | 5 +++-- src/bin/proxmox_restore_daemon/disk.rs | 23 +++++++++++++++++++---- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index cfb4ec74..66b4d258 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -1354,6 +1354,18 @@ pub struct ArchiveEntry { impl ArchiveEntry { pub fn new(filepath: &[u8], entry_type: Option<&DirEntryAttribute>) -> Self { + let size = match entry_type { + Some(DirEntryAttribute::File { size, .. }) => Some(*size), + _ => None, + }; + Self::new_with_size(filepath, entry_type, size) + } + + pub fn new_with_size( + filepath: &[u8], + entry_type: Option<&DirEntryAttribute>, + size: Option, + ) -> Self { Self { filepath: base64::encode(filepath), text: String::from_utf8_lossy(filepath.split(|x| *x == b'/').last().unwrap()) @@ -1363,13 +1375,10 @@ impl ArchiveEntry { None => "v".to_owned(), }, leaf: !matches!(entry_type, None | Some(DirEntryAttribute::Directory { .. })), - size: match entry_type { - Some(DirEntryAttribute::File { size, .. }) => Some(*size), - _ => None - }, + size, mtime: match entry_type { Some(DirEntryAttribute::File { mtime, .. }) => Some(*mtime), - _ => None + _ => None, }, } } diff --git a/src/bin/proxmox-file-restore.rs b/src/bin/proxmox-file-restore.rs index ffc8b0a5..5766b279 100644 --- a/src/bin/proxmox-file-restore.rs +++ b/src/bin/proxmox-file-restore.rs @@ -194,7 +194,7 @@ async fn list( } else { None }; - entries.push(ArchiveEntry::new(path.as_bytes(), attr)); + entries.push(ArchiveEntry::new_with_size(path.as_bytes(), attr, Some(file.size))); } Ok(entries) diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs index 82ead647..f1d601ce 100644 --- a/src/bin/proxmox_restore_daemon/api.rs +++ b/src/bin/proxmox_restore_daemon/api.rs @@ -200,11 +200,12 @@ fn list( for c in comps { let mut c_path = path.clone(); c_path.push(b'/'); - c_path.extend(c.as_bytes()); - res.push(ArchiveEntry::new( + c_path.extend(c.0.as_bytes()); + res.push(ArchiveEntry::new_with_size( &c_path[..], // this marks the beginning of a filesystem, i.e. '/', so this is a Directory Some(&DirEntryAttribute::Directory { start: 0 }), + Some(c.1), )); } } diff --git a/src/bin/proxmox_restore_daemon/disk.rs b/src/bin/proxmox_restore_daemon/disk.rs index f9d7c8aa..08fe7490 100644 --- a/src/bin/proxmox_restore_daemon/disk.rs +++ b/src/bin/proxmox_restore_daemon/disk.rs @@ -36,13 +36,14 @@ lazy_static! { pub enum ResolveResult { Path(PathBuf), BucketTypes(Vec<&'static str>), - BucketComponents(Vec), + BucketComponents(Vec<(String, u64)>), } struct PartitionBucketData { dev_node: String, number: i32, mountpoint: Option, + size: u64, } /// A "Bucket" represents a mapping found on a disk, e.g. a partition, a zfs dataset or an LV. A @@ -83,6 +84,12 @@ impl Bucket { Bucket::Partition(data) => data.number.to_string(), } } + + fn size(&self) -> u64 { + match self { + Bucket::Partition(data) => data.size, + } + } } /// Functions related to the local filesystem. This mostly exists so we can use 'supported_fs' in @@ -209,15 +216,23 @@ impl DiskState { .trim() .parse::()?; + // this *always* contains the number of 512-byte sectors, regardless of the true + // blocksize of this disk - which should always be 512 here anyway + let size = fs::file_read_firstline(&format!("{}/size", part_path))? + .trim() + .parse::()? + * 512; + info!( - "drive '{}' ('{}'): found partition '{}' ({})", - name, fidx, devnode, number + "drive '{}' ('{}'): found partition '{}' ({}, {}B)", + name, fidx, devnode, number, size ); let bucket = Bucket::Partition(PartitionBucketData { dev_node: devnode, mountpoint: None, number, + size, }); parts.push(bucket); @@ -281,7 +296,7 @@ impl DiskState { let comps = buckets .iter() .filter(|b| b.type_string() == bucket_type) - .map(Bucket::component_string) + .map(|b| (b.component_string(), b.size())) .collect(); return Ok(ResolveResult::BucketComponents(comps)); } -- 2.20.1