file-restore: strip .img.fidx suffix from drive serials

Drive serials have a character limit of 20, longer names like
"drive-virtio0.img.fidx" or "drive-efidisk0.img.fidx" would get cut off.

Fix this by removing the suffix, it is not necessary to uniquely
identify an image.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2021-04-27 15:35:45 +02:00 committed by Thomas Lamprecht
parent aac424674c
commit 606828cc65
2 changed files with 7 additions and 2 deletions

View File

@ -201,7 +201,8 @@ pub async fn start_vm(
)); ));
drives.push("-device".to_owned()); drives.push("-device".to_owned());
// drive serial is used by VM to map .fidx files to /dev paths // drive serial is used by VM to map .fidx files to /dev paths
drives.push(format!("virtio-blk-pci,drive=drive{},serial={}", id, file)); let serial = file.strip_suffix(".img.fidx").unwrap_or(&file);
drives.push(format!("virtio-blk-pci,drive=drive{},serial={}", id, serial));
id += 1; id += 1;
} }

View File

@ -268,7 +268,11 @@ impl DiskState {
_ => bail!("no or invalid image in path"), _ => bail!("no or invalid image in path"),
}; };
let buckets = match self.disk_map.get_mut(req_fidx.as_ref()) { let buckets = match self.disk_map.get_mut(
req_fidx
.strip_suffix(".img.fidx")
.unwrap_or_else(|| req_fidx.as_ref()),
) {
Some(x) => x, Some(x) => x,
None => bail!("given image '{}' not found", req_fidx), None => bail!("given image '{}' not found", req_fidx),
}; };