migrate volumes used inside snapshots including vmstate

Introduce new helper function foreach_volid()
This commit is contained in:
Dietmar Maurer 2012-09-25 07:42:01 +02:00
parent a06c7f7ec4
commit d5769dc253
2 changed files with 41 additions and 11 deletions

View File

@ -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;

View File

@ -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,15 +3042,14 @@ 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 $volid =~ m|^/|;
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
return if !$sid;
my $volid = $drive->{file};
return if !$volid || $volid =~ m|^/|;
push @$vollist, $volid;
});