From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v4 3/9] add helpers for VirtIO RNG command line arguments
Date: Tue, 18 Feb 2025 12:10:56 +0100 [thread overview]
Message-ID: <20250218111102.40055-4-f.schauer@proxmox.com> (raw)
In-Reply-To: <20250218111102.40055-1-f.schauer@proxmox.com>
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
PVE/QemuServer.pm | 18 +++++-------------
PVE/QemuServer/RNG.pm | 30 ++++++++++++++++++++++++++++++
2 files changed, 35 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..23b6cd15 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,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;
--
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-18 11:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 11:10 [pve-devel] [PATCH manager/qemu-server v4 0/9] fix #5657: allow configuring RNG device as non-root user Filip Schauer
2025-02-18 11:10 ` [pve-devel] [PATCH qemu-server v4 1/9] remove outdated /dev/random entropy-starvation warnings Filip Schauer
2025-02-18 11:10 ` [pve-devel] [PATCH qemu-server v4 2/9] refactor: move rng related code into its own module Filip Schauer
2025-02-18 11:10 ` Filip Schauer [this message]
2025-02-18 11:10 ` [pve-devel] [PATCH qemu-server v4 4/9] refactor: check_mapping_access: move root user check to the top Filip Schauer
2025-02-18 11:10 ` [pve-devel] [PATCH qemu-server v4 5/9] allow non-root users to set /dev/u?random as an RNG source Filip Schauer
2025-02-18 11:10 ` [pve-devel] [PATCH qemu-server v4 6/9] allow non-root users to set /dev/hwrng " Filip Schauer
2025-02-18 11:11 ` [pve-devel] [PATCH manager v4 7/9] ui: remove warning about entropy starvation of /dev/random Filip Schauer
2025-02-18 11:11 ` [pve-devel] [PATCH manager v4 8/9] ui: permissions: add ACL path for hardware RNG Filip Schauer
2025-02-18 11:11 ` [pve-devel] [PATCH manager v4 9/9] ui: let non-root users configure VirtIO RNG devices Filip Schauer
2025-04-04 9:21 ` [pve-devel] applied-series: [PATCH manager/qemu-server v4 0/9] fix #5657: allow configuring RNG device as non-root user Fabian Grünbichler
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=20250218111102.40055-4-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.