+ eval {
+ &$test_volid($volid, $snapname);
+ };
+
+ &$log_error($@, $volid) if $@;
+ };
+
+ # first unused / lost volumes owned by this container
+ my @sids = PVE::Storage::storage_ids($self->{storecfg});
+ foreach my $storeid (@sids) {
+ my $scfg = PVE::Storage::storage_config($self->{storecfg}, $storeid);
+ next if $scfg->{shared};
+ next if !PVE::Storage::storage_check_enabled($self->{storecfg}, $storeid, undef, 1);
+
+ # get list from PVE::Storage (for unused volumes)
+ my $dl = PVE::Storage::vdisk_list($self->{storecfg}, $storeid, $vmid);
+
+ next if @{$dl->{$storeid}} == 0;
+
+ # check if storage is available on target node
+ PVE::Storage::storage_check_node($self->{storecfg}, $storeid, $self->{node});
+
+ PVE::Storage::foreach_volid($dl, sub {
+ my ($volid, $sid, $volname) = @_;
+
+ $volhash->{$volid} = 'storage';
+ });
+ }
+
+ # then all volumes referenced in snapshots
+ foreach my $snapname (keys %{$conf->{snapshots}}) {
+ &$test_volid($conf->{snapshots}->{$snapname}->{'vmstate'}, 0, undef)
+ if defined($conf->{snapshots}->{$snapname}->{'vmstate'});
+ PVE::LXC::Config->foreach_mountpoint($conf->{snapshots}->{$snapname}, $test_mp, $snapname);
+ }
+
+ # finally all currently used volumes
+ PVE::LXC::Config->foreach_mountpoint($conf, $test_mp);
+