[pve-devel] [PATCH] Added methods to allocate and free storage for migration
Kamil Trzcinski
ayufan at ayufan.eu
Mon Nov 3 12:12:56 CET 2014
Signed-off-by: Kamil Trzcinski <ayufan at ayufan.eu>
---
PVE/Storage.pm | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 3cc9581..2e3c1ec 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -477,6 +477,68 @@ sub storage_migrate {
}
}
+sub storage_migrate_alloc {
+ my ($self, $cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
+
+ my ($storeid, $volname) = parse_volume_id($volid);
+ $target_volname = $volname if !$target_volname;
+
+ my $scfg = storage_config($cfg, $storeid);
+
+ # no need to migrate shared content
+ return if $storeid eq $target_storeid && $scfg->{shared};
+
+ my $tcfg = storage_config($cfg, $target_storeid);
+
+ my $target_volid = "${target_storeid}:${target_volname}";
+
+ my $sshoptions = "-o 'BatchMode=yes'";
+ my $ssh = "/usr/bin/ssh $sshoptions";
+
+ my ($size, $format) = PVE::Storage::volume_size_info($cfg, $volid);
+
+ my ($vtype, $name, $vmid) = parse_volname($cfg, $target_volid);
+
+ my $remote_cmd = <<'END_MESSAGE';
+use PVE::Storage;
+$cfg = PVE::Storage::config();
+PVE::Storage::vdisk_alloc($cfg, $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4]);
+END_MESSAGE
+
+ ## start on remote node
+ my $cmd = [@{$self->{rem_ssh}}, 'perl', '-', $target_storeid, $vmid, $format, $name, ($size/1024)];
+ PVE::Tools::run_command($cmd, input => $remote_cmd);
+}
+
+sub storage_migrate_free {
+ my ($self, $cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
+
+ my ($storeid, $volname) = parse_volume_id($volid);
+ $target_volname = $volname if !$target_volname;
+
+ my $scfg = storage_config($cfg, $storeid);
+
+ # no need to migrate shared content
+ return if $storeid eq $target_storeid && $scfg->{shared};
+
+ my $tcfg = storage_config($cfg, $target_storeid);
+
+ my $target_volid = "${target_storeid}:${target_volname}";
+
+ my $sshoptions = "-o 'BatchMode=yes'";
+ my $ssh = "/usr/bin/ssh $sshoptions";
+
+ my $remote_cmd = <<'END_MESSAGE';
+use PVE::Storage;
+$cfg = PVE::Storage::config();
+PVE::Storage::vdisk_free($cfg, $ARGV[0]);
+END_MESSAGE
+
+ ## start on remote node
+ my $cmd = [@{$self->{rem_ssh}}, 'perl', '-', $target_volid];
+ PVE::Tools::run_command($cmd, input => $remote_cmd);
+}
+
sub vdisk_clone {
my ($cfg, $volid, $vmid, $snap) = @_;
--
1.9.3 (Apple Git-50)
More information about the pve-devel
mailing list