From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id EA5BD1FF136 for ; Mon, 23 Mar 2026 14:29:19 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0E45519A64; Mon, 23 Mar 2026 14:29:11 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 2/4] move get_host_phys_address_bits() to helpers module Date: Mon, 23 Mar 2026 14:27:22 +0100 Message-ID: <20260323132857.125747-3-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260323132857.125747-1-f.ebner@proxmox.com> References: <20260323132857.125747-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774272494978 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: IPAYMZ75RQMRQO3ZBQI7AAW4TY4MNUN4 X-Message-ID-Hash: IPAYMZ75RQMRQO3ZBQI7AAW4TY4MNUN4 X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: To be re-used by a check in the CPU config module. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer/Helpers.pm | 18 ++++++++++++++++++ src/PVE/QemuServer/Memory.pm | 23 +++-------------------- src/test/run_config2command_tests.pl | 11 ++++++++--- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm index e14e9ad4..65f4ce5f 100644 --- a/src/PVE/QemuServer/Helpers.pm +++ b/src/PVE/QemuServer/Helpers.pm @@ -369,4 +369,22 @@ sub get_iscsi_initiator_name { return $initiator; } +my $_host_bits; + +sub get_host_phys_address_bits { + return $_host_bits if defined($_host_bits); + + my $fh = IO::File->new('/proc/cpuinfo', "r") or return; + while (defined(my $line = <$fh>)) { + # hopefully we never need to care about mixed (big.LITTLE) archs + if ($line =~ m/^address sizes\s*:\s*(\d+)\s*bits physical/i) { + $_host_bits = int($1); + $fh->close(); + return $_host_bits; + } + } + $fh->close(); + return; # undef, cannot really do anything.. +} + 1; diff --git a/src/PVE/QemuServer/Memory.pm b/src/PVE/QemuServer/Memory.pm index 7ebfc545..ab337bea 100644 --- a/src/PVE/QemuServer/Memory.pm +++ b/src/PVE/QemuServer/Memory.pm @@ -93,24 +93,6 @@ sub parse_memory { return $res; } -my $_host_bits; - -sub get_host_phys_address_bits { - return $_host_bits if defined($_host_bits); - - my $fh = IO::File->new('/proc/cpuinfo', "r") or return; - while (defined(my $line = <$fh>)) { - # hopefully we never need to care about mixed (big.LITTLE) archs - if ($line =~ m/^address sizes\s*:\s*(\d+)\s*bits physical/i) { - $_host_bits = int($1); - $fh->close(); - return $_host_bits; - } - } - $fh->close(); - return; # undef, cannot really do anything.. -} - my sub get_max_mem { my ($conf) = @_; @@ -122,14 +104,15 @@ my sub get_max_mem { my $bits; if (my $phys_bits = $cpu->{'phys-bits'}) { if ($phys_bits eq 'host') { - $bits = get_host_phys_address_bits(); + $bits = PVE::QemuServer::Helpers::get_host_phys_address_bits(); } elsif ($phys_bits =~ /^(\d+)$/) { $bits = int($phys_bits); } } if (!defined($bits)) { - my $host_bits = get_host_phys_address_bits() // 36; # fixme: what fallback? + # fixme: what fallback? + my $host_bits = PVE::QemuServer::Helpers::get_host_phys_address_bits() // 36; if ($cpu->{cputype} && $cpu->{cputype} =~ /^(host|max)$/) { $bits = $host_bits; } else { diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl index f7f3a2d5..3c4a695c 100755 --- a/src/test/run_config2command_tests.pl +++ b/src/test/run_config2command_tests.pl @@ -370,6 +370,14 @@ $qemu_server_config->mock( }, ); +my $qemu_server_helpers; +$qemu_server_helpers = Test::MockModule->new('PVE::QemuServer::Helpers'); +$qemu_server_helpers->mock( + get_host_phys_address_bits => sub { + return 46; + }, +); + my $qemu_server_memory; $qemu_server_memory = Test::MockModule->new('PVE::QemuServer::Memory'); $qemu_server_memory->mock( @@ -380,9 +388,6 @@ $qemu_server_memory->mock( my ($id) = @_; return 1; }, - get_host_phys_address_bits => sub { - return 46; - }, ); my $pve_common_tools; -- 2.47.3