From d5769dc2537d28adca28a4cc2de233db3948b6e0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 25 Sep 2012 07:42:01 +0200 Subject: [PATCH] migrate volumes used inside snapshots including vmstate Introduce new helper function foreach_volid() --- PVE/QemuMigrate.pm | 9 ++++----- PVE/QemuServer.pm | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index 764e5b19..07116816 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -199,17 +199,16 @@ sub sync_disks { }); } - # and add used,owned/non-shared disks (just to be sure we have all) + # and add used, owned/non-shared disks (just to be sure we have all) - PVE::QemuServer::foreach_drive($conf, sub { - my ($ds, $drive) = @_; + PVE::QemuServer::foreach_volid($conf, sub { + my ($volid, $is_cdrom) = @_; - my $volid = $drive->{file}; return if !$volid; die "cant migrate local file/device '$volid'\n" if $volid =~ m|^/|; - if (PVE::QemuServer::drive_is_cdrom($drive)) { + if ($is_cdrom) { die "cant migrate local cdrom drive\n" if $volid eq 'cdrom'; return if $volid eq 'none'; $cdromhash->{$volid} = 1; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index d5266a0c..02374a42 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2082,6 +2082,38 @@ sub foreach_drive { } } +sub foreach_volid { + my ($conf, $func) = @_; + + my $volhash = {}; + + my $test_volid = sub { + my ($volid, $is_cdrom) = @_; + + return if !$volid; + + $volhash->{$volid} = $is_cdrom || 0; + }; + + PVE::QemuServer::foreach_drive($conf, sub { + my ($ds, $drive) = @_; + &$test_volid($drive->{file}, drive_is_cdrom($drive)); + }); + + foreach my $snapname (keys %{$conf->{snapshots}}) { + my $snap = $conf->{snapshots}->{$snapname}; + &$test_volid($snap->{vmstate}, 0); + PVE::QemuServer::foreach_drive($snap, sub { + my ($ds, $drive) = @_; + &$test_volid($drive->{file}, drive_is_cdrom($drive)); + }); + } + + foreach my $volid (keys %$volhash) { + &$func($volid, $volhash->{$volid}); + } +} + sub config_to_command { my ($storecfg, $vmid, $conf, $defaults) = @_; @@ -3010,14 +3042,13 @@ sub get_vm_volumes { my ($conf) = @_; my $vollist = []; - foreach_drive($conf, sub { - my ($ds, $drive) = @_; + foreach_volid($conf, sub { + my ($volid, $is_cdrom) = @_; - my ($sid, $volname) = PVE::Storage::parse_volume_id($drive->{file}, 1); - return if !$sid; + return if $volid =~ m|^/|; - my $volid = $drive->{file}; - return if !$volid || $volid =~ m|^/|; + my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1); + return if !$sid; push @$vollist, $volid; }); -- 2.39.5