Signed-off-by: Daniel Herzig <[email protected]>
---
src/PVE/QemuServer.pm | 54 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 09e7a19b..a7b98e01 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -6068,6 +6068,60 @@ sub get_current_vm_volumes {
return $volumes;
}
+=head3 activate_current_vm_volumes($storecfg, $conf, $vmid [,
$statefile_volume])
+Activates VM volumes (With -blockdev, it is necessary to activate the volumes
+before generating the command line).
+
+NOTE: If $drive->{dismissable} is specified for a CD-ROM, C<$conf> may change.
+If $drive->{file} is unavailable, $drive->{file} will be set to 'none', and
+the entries $drive->{size} and $drive->{format} will be deleted.
+This will be written out to C<$conf>.
+
+=cut
+sub activate_current_vm_volumes {
+ my ($storecfg, $conf, $vmid, $statefile_volume, $storage_hints) = @_;
+ my $volumes_to_be_activated = [];
+ my $activated_volumes = [];
+
+ if ($statefile_volume) {
+ push $volumes_to_be_activated->@*, $statefile_volume;
+ }
+ PVE::QemuConfig->foreach_volume_full(
+ $conf,
+ { extra_keys => ['vmstate'] },
+ sub {
+ my ($ds, $drive) = @_;
+ my $volid = $drive->{file};
+ if (PVE::Storage::parse_volume_id($volid, 1)) {
+ check_volume_storage_type($storecfg, $volid);
+ if ($drive->{dismissable}) {
+ eval { PVE::Storage::activate_volumes($storecfg, [$volid])
};
+ if ($@) {
+ log_warn($@);
+ log_warn("removing dismissable CD-ROM from VM
configuration: ". $volid);
+ $drive->{file} = "none";
+ delete $drive->{size};
+ delete $drive->{format};
+ $conf->{$ds} = print_drive($drive);
+ PVE::QemuConfig->write_config($vmid, $conf);
+ } else {
+ push $activated_volumes->@*, $volid;
+ }
+ } else {
+ push $volumes_to_be_activated->@*, $volid;
+ }
+ }
+ }
+ );
+ eval { PVE::Storage::activate_volumes($storecfg, $volumes_to_be_activated,
undef, $storage_hints) };
+ if ($@) {
+ die $@;
+ } else {
+ push $activated_volumes->@*, $volumes_to_be_activated;
+ }
+ return $activated_volumes;
+}
+
sub cleanup_pci_devices {
my ($vmid, $conf) = @_;
--
2.47.3