mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 19:20:11 +00:00
add helpers for VirtIO RNG command line arguments
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
This commit is contained in:
parent
18fc321ef3
commit
6b192cb536
@ -61,7 +61,7 @@ use PVE::QemuServer::MetaInfo;
|
||||
use PVE::QemuServer::Monitor qw(mon_cmd);
|
||||
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
|
||||
use PVE::QemuServer::QMPHelpers qw(qemu_deviceadd qemu_devicedel qemu_objectadd qemu_objectdel);
|
||||
use PVE::QemuServer::RNG qw(check_rng_source parse_rng);
|
||||
use PVE::QemuServer::RNG qw(parse_rng print_rng_device_commandline print_rng_object_commandline);
|
||||
use PVE::QemuServer::USB;
|
||||
|
||||
my $have_sdn;
|
||||
@ -3726,18 +3726,10 @@ sub config_to_command {
|
||||
|
||||
my $rng = $conf->{rng0} ? parse_rng($conf->{rng0}) : undef;
|
||||
if ($rng && $version_guard->(4, 1, 2)) {
|
||||
check_rng_source($rng->{source});
|
||||
|
||||
my $max_bytes = $rng->{max_bytes} // $rng_fmt->{max_bytes}->{default};
|
||||
my $period = $rng->{period} // $rng_fmt->{period}->{default};
|
||||
my $limiter_str = "";
|
||||
if ($max_bytes) {
|
||||
$limiter_str = ",max-bytes=$max_bytes,period=$period";
|
||||
}
|
||||
|
||||
my $rng_addr = print_pci_addr("rng0", $bridges, $arch, $machine_type);
|
||||
push @$devices, '-object', "rng-random,filename=$rng->{source},id=rng0";
|
||||
push @$devices, '-device', "virtio-rng-pci,rng=rng0$limiter_str$rng_addr";
|
||||
my $rng_object = print_rng_object_commandline('rng0', $rng);
|
||||
my $rng_device = print_rng_device_commandline('rng0', $rng, $bridges, $arch, $machine_type);
|
||||
push @$devices, '-object', $rng_object;
|
||||
push @$devices, '-device', $rng_device;
|
||||
}
|
||||
|
||||
my $spice_port;
|
||||
|
@ -13,6 +13,8 @@ use base 'Exporter';
|
||||
our @EXPORT_OK = qw(
|
||||
parse_rng
|
||||
check_rng_source
|
||||
print_rng_device_commandline
|
||||
print_rng_object_commandline
|
||||
);
|
||||
|
||||
my $rng_fmt = {
|
||||
@ -83,4 +85,32 @@ sub check_rng_source {
|
||||
}
|
||||
}
|
||||
|
||||
sub print_rng_device_commandline {
|
||||
my ($id, $rng, $bridges, $arch, $machine) = @_;
|
||||
|
||||
die "no rng device specified\n" if !$rng;
|
||||
|
||||
my $max_bytes = $rng->{max_bytes} // $rng_fmt->{max_bytes}->{default};
|
||||
my $period = $rng->{period} // $rng_fmt->{period}->{default};
|
||||
my $limiter_str = "";
|
||||
if ($max_bytes) {
|
||||
$limiter_str = ",max-bytes=$max_bytes,period=$period";
|
||||
}
|
||||
|
||||
my $rng_addr = print_pci_addr($id, $bridges, $arch, $machine);
|
||||
|
||||
return "virtio-rng-pci,rng=$id$limiter_str$rng_addr";
|
||||
}
|
||||
|
||||
sub print_rng_object_commandline {
|
||||
my ($id, $rng) = @_;
|
||||
|
||||
die "no rng device specified\n" if !$rng;
|
||||
|
||||
my $source_path = $rng->{source};
|
||||
check_rng_source($source_path);
|
||||
|
||||
return "rng-random,filename=$source_path,id=$id";
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user