+sub get_replicatable_volumes {
+ my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
+
+ my $volhash = {};
+
+ my $test_volid = sub {
+ my ($volid, $attr) = @_;
+
+ return if $attr->{cdrom};
+
+ return if !$cleanup && !$attr->{replicate};
+
+ if ($volid =~ m|^/|) {
+ return if !$attr->{replicate};
+ return if $cleanup || $noerr;
+ die "unable to replicate local file/device '$volid'\n";
+ }
+
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, $noerr);
+ return if !$storeid;
+
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ return if $scfg->{shared};
+
+ my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid);
+ return if !$owner || ($owner != $vmid);
+
+ if ($vtype ne 'images') {
+ return if $cleanup || $noerr;
+ die "unable to replicate volume '$volid', type '$vtype'\n";
+ }
+
+ if (!PVE::Storage::volume_has_feature($storecfg, 'replicate', $volid)) {
+ return if $cleanup || $noerr;
+ die "missing replicate feature on volume '$volid'\n";
+ }
+
+ $volhash->{$volid} = 1;
+ };
+
+ PVE::QemuServer::foreach_volid($conf, $test_volid);
+
+ # add 'unusedX' volumes to volhash
+ foreach my $key (keys %$conf) {
+ if ($key =~ m/^unused/) {
+ $test_volid->($conf->{$key}, { replicate => 1 });
+ }
+ }
+
+ return $volhash;
+}
+