From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v3 09/11] add helpers for VirtIO RNG command line arguments
Date: Mon, 10 Feb 2025 16:37:32 +0100 [thread overview]
Message-ID: <20250210153734.103381-10-f.schauer@proxmox.com> (raw)
In-Reply-To: <20250210153734.103381-1-f.schauer@proxmox.com>
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
PVE/QemuServer.pm | 18 +++++-------------
PVE/QemuServer/RNG.pm | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 09d2b3a8..70518924 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -60,7 +60,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;
@@ -3685,18 +3685,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;
diff --git a/PVE/QemuServer/RNG.pm b/PVE/QemuServer/RNG.pm
index 22d1e9cc..ae5b2530 100644
--- a/PVE/QemuServer/RNG.pm
+++ b/PVE/QemuServer/RNG.pm
@@ -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,44 @@ sub check_rng_source {
}
}
+sub get_rng_source_path {
+ my ($rng) = @_;
+
+ my $source = $rng->{source};
+
+ if (defined($source)) {
+ return $source;
+ }
+
+ return;
+}
+
+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 = get_rng_source_path($rng);
+ check_rng_source($source_path);
+
+ return "rng-random,filename=$source_path,id=$id";
+}
+
1;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-02-10 15:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 15:37 [pve-devel] [PATCH cluster/guest-common/manager/qemu-server v3 00/11] fix #5657: allow configuring RNG device as non-root user Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH guest-common v3 01/11] mapping: add a hardware RNG mapping config Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH cluster v3 02/11] cfs: add 'mapping/hwrng.cfg' to observed files Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH manager v3 03/11] introduce hardware rng mapping api Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH manager v3 04/11] introduce hardware rng scanning api Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH manager v3 05/11] ui: add hardware RNG resource mapping Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH manager v3 06/11] ui: allow use of mapped hardware RNGs as entropy sources for VMs Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH manager v3 07/11] ui: split resource mapping types into tabbed views Filip Schauer
2025-02-10 15:37 ` [pve-devel] [PATCH qemu-server v3 08/11] refactor: move rng related code into its own module Filip Schauer
2025-02-10 15:37 ` Filip Schauer [this message]
2025-02-10 15:37 ` [pve-devel] [PATCH qemu-server v3 10/11] allow non-root users to set /dev/u?random as an RNG source Filip Schauer
2025-02-11 12:34 ` Fabian Grünbichler
2025-02-10 15:37 ` [pve-devel] [PATCH qemu-server v3 11/11] let VirtIO RNG devices source entropy from mapped HWRNGs Filip Schauer
2025-02-11 12:34 ` Fabian Grünbichler
2025-02-11 12:34 ` [pve-devel] [PATCH cluster/guest-common/manager/qemu-server v3 00/11] fix #5657: allow configuring RNG device as non-root user Fabian Grünbichler
2025-02-18 11:17 ` Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250210153734.103381-10-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.