Import OVF: Lock config with "lock" property

Previously a VMID conflict was possible when creating a VM on another node
between locking the config with lock_config_full and writing to it for the
first time with write_config.

Using create_and_lock_config eliminates this possibility. This means that now
the "lock" property is set in the config instead of using flock only.

$param was empty when it was assigned the three values "name", "memory" and
"cores" before being assigned to $conf later on. Assigning those values
directly to $conf avoids confusion about what the two variables contain.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
This commit is contained in:
Dominic Jäger 2019-10-28 12:47:34 +01:00 committed by Thomas Lamprecht
parent 7f384190de
commit 439390e868

View File

@ -621,15 +621,16 @@ __PACKAGE__->register_method ({
return;
}
$param->{name} = $parsed->{qm}->{name} if defined($parsed->{qm}->{name});
$param->{memory} = $parsed->{qm}->{memory} if defined($parsed->{qm}->{memory});
$param->{cores} = $parsed->{qm}->{cores} if defined($parsed->{qm}->{cores});
eval { PVE::QemuConfig->create_and_lock_config($vmid, 0) };
die "Reserving empty config for OVF import failed: $@" if $@;
my $importfn = sub {
my $conf = PVE::QemuConfig->load_config($vmid);
die "Internal error: Expected 'create' lock in config of VM $vmid!"
if !PVE::QemuConfig->has_lock($conf, "create");
PVE::Cluster::check_vmid_unused($vmid);
my $conf = $param;
$conf->{name} = $parsed->{qm}->{name} if defined($parsed->{qm}->{name});
$conf->{memory} = $parsed->{qm}->{memory} if defined($parsed->{qm}->{memory});
$conf->{cores} = $parsed->{qm}->{cores} if defined($parsed->{qm}->{cores});
eval {
# order matters, as do_import() will load_config() internally
@ -640,7 +641,7 @@ __PACKAGE__->register_method ({
foreach my $disk (@{ $parsed->{disks} }) {
my ($file, $drive) = ($disk->{backing_file}, $disk->{disk_address});
PVE::QemuServer::ImportDisk::do_import($file, $vmid, $storeid,
0, { drive_name => $drive, format => $format });
1, { drive_name => $drive, format => $format });
}
# reload after disks entries have been created
@ -658,10 +659,7 @@ __PACKAGE__->register_method ({
warn "Could not destroy VM $vmid: $@" if "$@";
die "import failed - $err";
}
};
my $wait_for_lock = 1;
PVE::QemuConfig->lock_config_full($vmid, $wait_for_lock, $importfn);
PVE::QemuConfig->remove_lock ($vmid, "create");
return undef;