mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-14 10:48:24 +00:00
api: move disk: fork before locking
using the familiar early+repeated checks pattern from other API calls. Only intended functional changes are with regard to locking/forking. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
dbecb46f2a
commit
bdf6ba1e7d
@ -3396,7 +3396,7 @@ __PACKAGE__->register_method({
|
||||
|
||||
my $storecfg = PVE::Storage::config();
|
||||
|
||||
my $move_updatefn = sub {
|
||||
my $load_and_check_move = sub {
|
||||
my $conf = PVE::QemuConfig->load_config($vmid);
|
||||
PVE::QemuConfig->check_lock($conf);
|
||||
|
||||
@ -3416,8 +3416,8 @@ __PACKAGE__->register_method({
|
||||
$oldfmt = $1;
|
||||
}
|
||||
|
||||
die "you can't move to the same storage with same format\n" if $oldstoreid eq $storeid &&
|
||||
(!$format || !$oldfmt || $oldfmt eq $format);
|
||||
die "you can't move to the same storage with same format\n"
|
||||
if $oldstoreid eq $storeid && (!$format || !$oldfmt || $oldfmt eq $format);
|
||||
|
||||
# this only checks snapshots because $disk is passed!
|
||||
my $snapshotted = PVE::QemuServer::Drive::is_volume_in_use(
|
||||
@ -3429,6 +3429,13 @@ __PACKAGE__->register_method({
|
||||
die "you can't move a disk with snapshots and delete the source\n"
|
||||
if $snapshotted && $param->{delete};
|
||||
|
||||
return ($conf, $drive, $oldstoreid, $snapshotted);
|
||||
};
|
||||
|
||||
my $move_updatefn = sub {
|
||||
my ($conf, $drive, $oldstoreid, $snapshotted) = $load_and_check_move->();
|
||||
my $old_volid = $drive->{file};
|
||||
|
||||
PVE::Cluster::log_msg(
|
||||
'info',
|
||||
$authuser,
|
||||
@ -3439,7 +3446,6 @@ __PACKAGE__->register_method({
|
||||
|
||||
PVE::Storage::activate_volumes($storecfg, [ $drive->{file} ]);
|
||||
|
||||
my $realcmd = sub {
|
||||
my $newvollist = [];
|
||||
|
||||
eval {
|
||||
@ -3515,9 +3521,6 @@ __PACKAGE__->register_method({
|
||||
}
|
||||
};
|
||||
|
||||
return $rpcenv->fork_worker('qmmove', $vmid, $authuser, $realcmd);
|
||||
};
|
||||
|
||||
my $load_and_check_reassign_configs = sub {
|
||||
my $vmlist = PVE::Cluster::get_vmlist()->{ids};
|
||||
|
||||
@ -3695,7 +3698,14 @@ __PACKAGE__->register_method({
|
||||
|
||||
die "cannot move disk '$disk', only configured disks can be moved to another storage\n"
|
||||
if $disk =~ m/^unused\d+$/;
|
||||
return PVE::QemuConfig->lock_config($vmid, $move_updatefn);
|
||||
|
||||
$load_and_check_move->(); # early checks before forking/locking
|
||||
|
||||
my $realcmd = sub {
|
||||
PVE::QemuConfig->lock_config($vmid, $move_updatefn);
|
||||
};
|
||||
|
||||
return $rpcenv->fork_worker('qmmove', $vmid, $authuser, $realcmd);
|
||||
} else {
|
||||
my $msg = "both 'storage' and 'target-vmid' missing, either needs to be set";
|
||||
raise_param_exc({ 'target-vmid' => $msg, 'storage' => $msg });
|
||||
|
Loading…
Reference in New Issue
Block a user