On 11/18/24 14:31, Fiona Ebner wrote:
Am 15.11.24 um 16:17 schrieb Dominik Csapak:
@@ -416,6 +427,23 @@ my sub create_disks : prototype($$$$$$$$$$) {
my ($source_storage, $source_volid) =
PVE::Storage::parse_volume_id($source, 1);
if ($source_storage) { # PVE-managed volume
+ my ($vtype, undef, undef, undef, undef, undef, $fmt)
+ = PVE::Storage::parse_volname($storecfg, $source);
+ my $needs_extraction =
PVE::QemuServer::Helpers::needs_extraction($vtype, $fmt);
+ if ($needs_extraction) {
+ print "extracting $source\n";
+ my $extracted_volid
+ =
PVE::GuestImport::extract_disk_from_import_file($source, $vmid);
+ print "finished extracting to $extracted_volid\n";
+ push @$vollist, $extracted_volid;
+ $source = $extracted_volid;
+
+ my (undef, undef, undef, $parent)
+ = PVE::Storage::volume_size_info($storecfg,
$source);
+ die "importing from extracted images with backing file
($parent) not allowed\n"
+ if $parent;
+ }
+
if ($live_import && $ds ne 'efidisk0') {
my $path = PVE::Storage::path($storecfg, $source)
or die "failed to get a path for '$source'\n";
Below here is a $source = $path
@@ -424,9 +452,11 @@ my sub create_disks : prototype($$$$$$$$$$) {
die "could not get file size of $source\n" if !$size;
$live_import_mapping->{$ds} = {
- path => $source,
+ path => $path,
So this doesn't change anything. It's nicer to read though :P
format => $source_format,
};
+ $live_import_mapping->{$ds}->{'delete-after-finish'} =
$source
But here you already have $path assigned to $source rather than the
original volume ID. Doesn't vdisk_free() fail later then?
yep, i noticed that 5 minutes ago ;)
i'll change it so that source does not get overwritten and we save the volid
to delete instead of the path
+ if $needs_extraction;
} else {
my $dest_info = {
vmid => $vmid,
@@ -438,8 +468,14 @@ my sub create_disks : prototype($$$$$$$$$$) {
$dest_info->{efisize} =
PVE::QemuServer::get_efivars_size($conf, $disk)
if $ds eq 'efidisk0';
- ($dst_volid, $size) = eval {
- $import_from_volid->($storecfg, $source,
$dest_info, $vollist);
+ eval {
+ ($dst_volid, $size)
+ = $import_from_volid->($storecfg, $source,
$dest_info, $vollist);
+
+ # remove extracted volumes after importing
+ PVE::Storage::vdisk_free($storecfg, $source) if
$needs_extraction;
+ print "cleaned up extracted image $source\n";
+ @$vollist = grep { $_ ne $source } @$vollist;
};
die "cannot import from '$source' - $@" if $@;
}
@@ -1964,7 +2000,6 @@ my $update_vm_api = sub {
assert_scsi_feature_compatibility($opt, $conf, $storecfg, $param->{$opt})
if $opt =~ m/^scsi\d+$/;
-
my (undef, $created_opts) = create_disks(
$rpcenv,
$authuser,
Unrelated hunk should not be here
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel