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 2137271F92 for ; Wed, 30 Jun 2021 17:58:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1EDD71BD3E for ; Wed, 30 Jun 2021 17:58:13 +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 3947E1BD12 for ; Wed, 30 Jun 2021 17:58:11 +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 0F0124681E for ; Wed, 30 Jun 2021 17:58:11 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 30 Jun 2021 17:57:56 +0200 Message-Id: <20210630155759.1894155-3-s.reiter@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210630155759.1894155-1-s.reiter@proxmox.com> References: <20210630155759.1894155-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.680 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [data.name, api.rs, disk.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/5] file-restore-daemon/disk: dedup BucketComponents and make size optional 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: Wed, 30 Jun 2021 15:58:13 -0000 To support nested BucketComponents, it is necessary to dedup them, as otherwise two components like: /foo/bar /foo/baz will result in /foo being shown twice at the first hierarchy. Also make the size property based on index and optional, as for example /foo in the example above might not have a size, and bar/baz might have differing sizes. Signed-off-by: Stefan Reiter --- src/bin/proxmox_restore_daemon/api.rs | 2 +- src/bin/proxmox_restore_daemon/disk.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs index 42328fb7..d7355370 100644 --- a/src/bin/proxmox_restore_daemon/api.rs +++ b/src/bin/proxmox_restore_daemon/api.rs @@ -208,7 +208,7 @@ fn list( &c_path[..], // this marks the beginning of a filesystem, i.e. '/', so this is a Directory Some(&DirEntryAttribute::Directory { start: 0 }), - Some(c.1), + c.1, )); } } diff --git a/src/bin/proxmox_restore_daemon/disk.rs b/src/bin/proxmox_restore_daemon/disk.rs index 9d0cbe32..b90d2a28 100644 --- a/src/bin/proxmox_restore_daemon/disk.rs +++ b/src/bin/proxmox_restore_daemon/disk.rs @@ -44,7 +44,7 @@ lazy_static! { pub enum ResolveResult { Path(PathBuf), BucketTypes(Vec<&'static str>), - BucketComponents(Vec<(String, u64)>), + BucketComponents(Vec<(String, Option)>), } #[derive(Clone)] @@ -59,7 +59,7 @@ struct PartitionBucketData { struct ZFSBucketData { name: String, mountpoint: Option, - size: u64, + size: Option, } /// A "Bucket" represents a mapping found on a disk, e.g. a partition, a zfs dataset or an LV. A @@ -139,9 +139,9 @@ impl Bucket { }) } - fn size(&self) -> u64 { + fn size(&self, idx: usize) -> Option { match self { - Bucket::Partition(data) | Bucket::RawFs(data) => data.size, + Bucket::Partition(data) | Bucket::RawFs(data) => Some(data.size), Bucket::ZPool(data) => data.size, } } @@ -261,7 +261,7 @@ impl Filesystems { cmd.args(["list", "-o", "size", "-Hp", &data.name].iter()); let size = run_command(cmd, None)?; if let Ok(size) = size.trim().parse::() { - data.size = size; + data.size = Some(size); } let mp = PathBuf::from(mntpath); @@ -409,7 +409,7 @@ impl DiskState { for (pool, disks) in Self::parse_zpool_import(&result) { let mut bucket = Bucket::ZPool(ZFSBucketData { name: pool.clone(), - size: 0, + size: None, mountpoint: None, }); @@ -418,11 +418,11 @@ impl DiskState { if disks.len() <= 5 { let mp = filesystems.ensure_mounted(&mut bucket); info!( - "zpool '{}' (on: {:?}) auto-mounted at '{:?}' (size: {}B)", + "zpool '{}' (on: {:?}) auto-mounted at '{:?}' (size: {:?})", &pool, &disks, mp, - bucket.size() + bucket.size(0) ); } else { info!( @@ -503,18 +503,20 @@ impl DiskState { Some(c) => bail!("invalid bucket component in path: {:?}", c), None => { // list bucket components available at this level - let comps = buckets + let mut comps = buckets .iter() .filter_map(|b| { if b.type_string() != bucket_type { return None; } match b.component_string(components.len()) { - Ok(cs) => Some((cs.to_owned(), b.size())), + Ok(cs) => Some((cs.to_owned(), b.size(components.len()))), Err(_) => None, } }) - .collect(); + .collect::)>>(); + comps.sort_by(|a, b| a.0.cmp(&b.0)); + comps.dedup(); return Ok(ResolveResult::BucketComponents(comps)); } }; -- 2.30.2