[pve-devel] [PATCH qemu-server 1/1] fix #1905: Allow moving unused disks

Filip Schauer f.schauer at proxmox.com
Mon Feb 19 12:11:39 CET 2024


Allow moving unused/detached disks to another storage.

Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
---
 PVE/API2/Qemu.pm  | 3 ---
 PVE/QemuServer.pm | 5 +++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 69c5896..97216a3 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -4283,9 +4283,6 @@ __PACKAGE__->register_method({
 	} elsif ($storeid) {
 	    $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
 
-	    die "cannot move disk '$disk', only configured disks can be moved to another storage\n"
-		if $disk =~ m/^unused\d+$/;
-
 	    $load_and_check_move->(); # early checks before forking/locking
 
 	    my $realcmd = sub {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b45507a..4527276 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -8036,7 +8036,8 @@ sub clone_disk {
     my ($newvmid, $dst_drivename, $efisize) = $dest->@{qw(vmid drivename efisize)};
     my ($storage, $format) = $dest->@{qw(storage format)};
 
-    my $use_drive_mirror = $full && $running && $src_drivename && !$snapname;
+    my $unused = $src_drivename =~ /^unused/;
+    my $use_drive_mirror = $full && $running && $src_drivename && !$snapname && !$unused;
 
     if ($src_drivename && $dst_drivename && $src_drivename ne $dst_drivename) {
 	die "cloning from/to EFI disk requires EFI disk\n"
@@ -8142,7 +8143,7 @@ no_data_clone:
     my $disk = dclone($drive);
     delete $disk->{format};
     $disk->{file} = $newvolid;
-    $disk->{size} = $size if defined($size);
+    $disk->{size} = $size if defined($size) && !$unused;
 
     return $disk;
 }
-- 
2.39.2





More information about the pve-devel mailing list