mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-06-25 06:05:07 +00:00
reserve config with create lock early
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
8ba8418ca1
commit
4fedc13b45
@ -534,28 +534,18 @@ __PACKAGE__->register_method({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $emsg = $is_restore ? "unable to restore VM $vmid -" : "unable to create VM $vmid -";
|
||||||
|
|
||||||
|
eval { PVE::QemuConfig->create_and_lock_config($vmid, $force) };
|
||||||
|
die "$emsg $@" if $@;
|
||||||
|
|
||||||
my $restorefn = sub {
|
my $restorefn = sub {
|
||||||
my $vmlist = PVE::Cluster::get_vmlist();
|
|
||||||
if ($vmlist->{ids}->{$vmid}) {
|
|
||||||
my $current_node = $vmlist->{ids}->{$vmid}->{node};
|
|
||||||
if ($current_node eq $node) {
|
|
||||||
my $conf = PVE::QemuConfig->load_config($vmid);
|
my $conf = PVE::QemuConfig->load_config($vmid);
|
||||||
|
|
||||||
PVE::QemuConfig->check_protection($conf, "unable to restore VM $vmid");
|
PVE::QemuConfig->check_protection($conf, $emsg);
|
||||||
|
|
||||||
die "unable to restore vm $vmid - config file already exists\n"
|
die "$emsg vm is running\n" if PVE::QemuServer::check_running($vmid);
|
||||||
if !$force;
|
die "$emsg vm is a template\n" if PVE::QemuConfig->is_template($conf);
|
||||||
|
|
||||||
die "unable to restore vm $vmid - vm is running\n"
|
|
||||||
if PVE::QemuServer::check_running($vmid);
|
|
||||||
|
|
||||||
die "unable to restore vm $vmid - vm is a template\n"
|
|
||||||
if PVE::QemuConfig->is_template($conf);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
die "unable to restore vm $vmid - already existing on cluster node '$current_node'\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my $realcmd = sub {
|
my $realcmd = sub {
|
||||||
PVE::QemuServer::restore_archive($archive, $vmid, $authuser, {
|
PVE::QemuServer::restore_archive($archive, $vmid, $authuser, {
|
||||||
@ -574,10 +564,6 @@ __PACKAGE__->register_method({
|
|||||||
};
|
};
|
||||||
|
|
||||||
my $createfn = sub {
|
my $createfn = sub {
|
||||||
|
|
||||||
# test after locking
|
|
||||||
PVE::Cluster::check_vmid_unused($vmid);
|
|
||||||
|
|
||||||
# ensure no old replication state are exists
|
# ensure no old replication state are exists
|
||||||
PVE::ReplicationState::delete_guest_states($vmid);
|
PVE::ReplicationState::delete_guest_states($vmid);
|
||||||
|
|
||||||
@ -611,7 +597,7 @@ __PACKAGE__->register_method({
|
|||||||
eval { PVE::Storage::vdisk_free($storecfg, $volid); };
|
eval { PVE::Storage::vdisk_free($storecfg, $volid); };
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
}
|
}
|
||||||
die "create failed - $err";
|
die "$emsg $err";
|
||||||
}
|
}
|
||||||
|
|
||||||
PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
|
PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
|
||||||
|
Loading…
Reference in New Issue
Block a user