all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20260323132857.125747-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260323132857.125747-1-f.ebner@proxmox.com>

To be re-used by a check in the CPU config module.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 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





  parent reply	other threads:[~2026-03-23 13:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 13:27 [PATCH-SERIES qemu-server 0/4] cpu config: warn that OVMF might limit phys-bits to 40 without pdpe1gb CPU flag Fiona Ebner
2026-03-23 13:27 ` [PATCH qemu-server 1/4] cpu config: split resolve_cpu_flags() function Fiona Ebner
2026-03-23 13:27 ` Fiona Ebner [this message]
2026-03-23 13:27 ` [PATCH qemu-server 3/4] cpu config: get cpu options: avoid shadowing $conf variable Fiona Ebner
2026-03-23 13:27 ` [PATCH qemu-server 4/4] cpu config: warn that OVMF might limit phys-bits to 40 without pdpe1gb CPU flag Fiona Ebner

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=20260323132857.125747-3-f.ebner@proxmox.com \
    --to=f.ebner@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal