public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/5] file-restore-daemon/disk: dedup BucketComponents and make size optional
Date: Wed, 30 Jun 2021 17:57:56 +0200	[thread overview]
Message-ID: <20210630155759.1894155-3-s.reiter@proxmox.com> (raw)
In-Reply-To: <20210630155759.1894155-1-s.reiter@proxmox.com>

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 <s.reiter@proxmox.com>
---
 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<u64>)>),
 }
 
 #[derive(Clone)]
@@ -59,7 +59,7 @@ struct PartitionBucketData {
 struct ZFSBucketData {
     name: String,
     mountpoint: Option<PathBuf>,
-    size: u64,
+    size: Option<u64>,
 }
 
 /// 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<u64> {
         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::<u64>() {
-                    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::<Vec<(String, Option<u64>)>>();
+                    comps.sort_by(|a, b| a.0.cmp(&b.0));
+                    comps.dedup();
                     return Ok(ResolveResult::BucketComponents(comps));
                 }
             };
-- 
2.30.2





  parent reply	other threads:[~2021-06-30 15:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30 15:57 [pbs-devel] [PATCH 0/5] Add LVM (thin) support for single file restore Stefan Reiter
2021-06-30 15:57 ` [pbs-devel] [PATCH proxmox-backup-restore-image 1/5] add LVM (thin) tooling Stefan Reiter
2021-06-30 15:57 ` Stefan Reiter [this message]
2021-06-30 15:57 ` [pbs-devel] [PATCH proxmox-backup 3/5] file-restore-daemon/disk: fix component path errors Stefan Reiter
2021-06-30 15:57 ` [pbs-devel] [PATCH proxmox-backup 4/5] file-restore-daemon/disk: ignore already-mounted error and prefix zpool Stefan Reiter
2021-06-30 15:57 ` [pbs-devel] [PATCH proxmox-backup 5/5] file-restore-daemon/disk: add LVM (thin) support Stefan Reiter
2021-07-02 12:39 ` [pbs-devel] [PATCH 0/5] Add LVM (thin) support for single file restore Fabian Grünbichler
2021-07-05  6:26   ` Thomas Lamprecht
2021-07-05  7:18     ` Fabian Grünbichler
2021-07-05  6:12 ` [pbs-devel] applied-series: " Thomas Lamprecht

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=20210630155759.1894155-3-s.reiter@proxmox.com \
    --to=s.reiter@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal