]> git.proxmox.com Git - qemu-server.git/commitdiff
Fix #848: deactivate old volume after clone before deletion
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 11 Apr 2016 13:19:46 +0000 (15:19 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 13 Apr 2016 06:24:13 +0000 (08:24 +0200)
Otherwise some move operations will fail to delete the old
disk (eg. when moving from ceph to local storage).

Note that in order for the deactivation to succeed we need
to make sure qemu has closed its file descriptors, so we
need to wait for the job to disappear the same way we do in
$cancel_job().
Factored the waiting out into $finish_job().

PVE/API2/Qemu.pm
PVE/QemuServer.pm

index 8bb68a4879bde01ecc363dade87551da00016627..409653ab25d7b25ed239fa2d882f138427488d72 100644 (file)
@@ -2502,7 +2502,10 @@ __PACKAGE__->register_method({
                        PVE::QemuConfig->add_unused_volume($conf, $old_volid);
                        PVE::QemuConfig->write_config($vmid, $conf);
                    } else {
-                       eval { PVE::Storage::vdisk_free($storecfg, $old_volid); };
+                       eval {
+                           PVE::Storage::deactivate_volumes($storecfg, [$old_volid]);
+                           PVE::Storage::vdisk_free($storecfg, $old_volid);
+                       };
                        warn $@ if $@;
                    }
                }
index b61974daedb20446f38c3bc753b0a999b327b8d6..2d8da43533b61e0471c174a081f9956705f9d338 100644 (file)
@@ -5923,6 +5923,15 @@ sub qemu_drive_mirror {
 
     print "drive mirror is starting (scanning bitmap) : this step can take some minutes/hours, depend of disk size and storage speed\n";
 
+    my $finish_job = sub {
+       while (1) {
+           my $stats = vm_mon_cmd($vmid, "query-block-jobs");
+           my $stat = @$stats[0];
+           last if !$stat;
+           sleep 1;
+       }
+    };
+
     eval {
     vm_mon_cmd($vmid, "drive-mirror", %$opts);
        while (1) {
@@ -5949,7 +5958,10 @@ sub qemu_drive_mirror {
 
                # try to switch the disk if source and destination are on the same guest
                eval { vm_mon_cmd($vmid, "block-job-complete", device => "drive-$drive") };
-               last if !$@;
+               if (!$@) {
+                   &$finish_job();
+                   last;
+               }
                die $@ if $@ !~ m/cannot be completed/;
            }
            sleep 1;
@@ -5961,12 +5973,7 @@ sub qemu_drive_mirror {
 
     my $cancel_job = sub {
        vm_mon_cmd($vmid, "block-job-cancel", device => "drive-$drive");
-       while (1) {
-           my $stats = vm_mon_cmd($vmid, "query-block-jobs");
-           my $stat = @$stats[0];
-           last if !$stat;
-           sleep 1;
-       }
+       &$finish_job();
     };
 
     if ($err) {