[pbs-devel] [PATCH proxmox-backup 3/3] restore daemon: search disk also with truncated serial

Dominik Csapak d.csapak at proxmox.com
Wed May 15 11:55:13 CEST 2024


the disk serial given to virtio disks only can be 20 characters, so
looking for a disk with a longer serial will always fail (like
'drive-tpmstate0-backup'). If the serial is longer, also try with the
truncated one. Leave the first try in place in case the limit changes.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 .../src/proxmox_restore_daemon/disk.rs        | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
index db96ced0b..4991479c2 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
@@ -634,12 +634,21 @@ impl DiskState {
             _ => bail!("no or invalid image in path"),
         };
 
-        let buckets = match self.disk_map.get_mut(
-            req_fidx
-                .strip_suffix(".img.fidx")
-                .unwrap_or_else(|| req_fidx.as_ref()),
-        ) {
+        let serial = req_fidx
+            .strip_suffix(".img.fidx")
+            .unwrap_or_else(|| req_fidx.as_ref());
+        let buckets = match self.disk_map.get_mut(serial) {
             Some(x) => x,
+            None if serial.len() > 20 => {
+                let (truncated_serial, _) = serial.split_at(20);
+                eprintln!(
+                    "given image '{req_fidx}' not found with '{serial}', trying with '{truncated_serial}'."
+                );
+                match self.disk_map.get_mut(truncated_serial) {
+                    Some(x) => x,
+                    None => bail!("given image '{req_fidx}' not found with '{truncated_serial}'"),
+                }
+            }
             None => bail!("given image '{req_fidx}' not found"),
         };
 
-- 
2.39.2





More information about the pbs-devel mailing list