[pve-devel] [PATCH 14/14] add qemu_drive_mirror

Alexandre Derumier aderumier at odiso.com
Thu Jan 10 14:16:22 CET 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 643080f..a8c87de 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4572,4 +4572,45 @@ sub qemu_img_format {
     }
 }
 
+sub qemu_drive_mirror {
+    my ($vmid, $drive, $dst_volid, $vmiddst) = @_;
+
+    my $storecfg = PVE::Storage::config();
+    my ($dst_storeid, $dst_volname) = PVE::Storage::parse_volume_id($dst_volid, 1);
+
+    if ($dst_storeid) {
+	my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
+
+	my $format = undef;
+        if ($dst_volname =~ m/\.(raw|qcow2)$/){
+	    $format = $1;
+	}
+
+	my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
+
+	if($format){
+	    PVE::QemuServer::vm_mon_cmd($vmid, "drive-mirror", device => "drive-$drive", mode => "existing", sync => "full", target => $dst_path, format => $format);
+	}else{
+	    PVE::QemuServer::vm_mon_cmd($vmid, "drive-mirror", device => "drive-$drive", mode => "existing", sync => "full", target => $dst_path);
+	}
+
+	while (1) {
+	    my $stats = PVE::QemuServer::vm_mon_cmd($vmid, "query-block-jobs");
+	    my $stat = @$stats[0];
+	    die "error job is not mirroring" if $stat->{type} ne "mirror";
+	    print $stat->{offset}."/".$stat->{len}."\n";
+	    last if ($stat->{len} == $stat->{offset});
+	    sleep 1;
+	}
+
+	if($vmiddst){
+	    #if we clone a disk for a new target vm, we don't switch the disk
+	    PVE::QemuServer::vm_mon_cmd($vmid, "block-job-cancel", device => "drive-$drive");
+	}else{
+	    #if source and destination are on the same guest
+	    PVE::QemuServer::vm_mon_cmd($vmid, "block-job-complete", device => "drive-$drive");
+	}
+    }
+}
+
 1;
-- 
1.7.10.4




More information about the pve-devel mailing list