[pve-devel] [PATCH installer 3/3] tui: check hvm support through runtime env info instead of open-coding

Christoph Heiss c.heiss at proxmox.com
Mon Jul 3 09:35:00 CEST 2023


As the runtime environment now exports that info, use it. In turn, this
allows us to drop the dependency on `proxmox-sys`, as that check was its
only user.

The dependency graph drops from 107 to 88 crates from this, which
definitively is a nice change.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 proxmox-tui-installer/Cargo.toml   |  2 --
 proxmox-tui-installer/src/main.rs  | 25 ++++++++++---------------
 proxmox-tui-installer/src/setup.rs |  4 ++++
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
index 5a50c69..8a6eba8 100644
--- a/proxmox-tui-installer/Cargo.toml
+++ b/proxmox-tui-installer/Cargo.toml
@@ -12,5 +12,3 @@ cursive = { version = "0.20.0", default-features = false, features = ["termion-b
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 regex = "1.7"
-
-proxmox-sys = "0.5.0"
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 64f21fa..109def3 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -25,13 +25,11 @@ use cursive::{

 use regex::Regex;

-use proxmox_sys::linux::procfs;
-
 mod options;
 use options::*;

 mod setup;
-use setup::{InstallConfig, LocaleInfo, RuntimeInfo, SetupInfo};
+use setup::{InstallConfig, LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo};

 mod system;

@@ -255,7 +253,7 @@ fn installer_setup(in_test_mode: bool) -> Result<(LocaleInfo, RuntimeInfo), Stri

 /// Anything that can be done late in the setup and will not result in fatal errors.
 fn installer_setup_late(siv: &mut Cursive) {
-    let state = siv.user_data::<InstallerState>().unwrap();
+    let state = siv.user_data::<InstallerState>().cloned().unwrap();

     if !state.in_test_mode {
         let kmap_id = &state.options.timezone.kb_layout;
@@ -266,17 +264,14 @@ fn installer_setup_late(siv: &mut Cursive) {
         }
     }

-    if setup_info().config.product == setup::ProxmoxProduct::PVE {
-        let cpu_hvm = procfs::read_cpuinfo().map(|info| info.hvm).unwrap_or(false);
-        if !cpu_hvm {
-            display_setup_warning(
-                siv,
-                concat!(
-                    "No support for hardware-accelerated KVM virtualization detected.\n\n",
-                    "Check BIOS settings for Intel VT / AMD-V / SVM."
-                ),
-            );
-        }
+    if state.setup_info.config.product == ProxmoxProduct::PVE && !state.runtime_info.hvm_supported {
+        display_setup_warning(
+            siv,
+            concat!(
+                "No support for hardware-accelerated KVM virtualization detected.\n\n",
+                "Check BIOS settings for Intel VT / AMD-V / SVM."
+            ),
+        );
     }
 }

diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs
index 68207c8..9d14cf8 100644
--- a/proxmox-tui-installer/src/setup.rs
+++ b/proxmox-tui-installer/src/setup.rs
@@ -367,6 +367,10 @@ pub struct RuntimeInfo {

     /// Total memory of the system in MiB.
     pub total_memory: usize,
+
+    /// Whether the CPU supports hardware-accelerated virtualization
+    #[serde(deserialize_with = "deserialize_bool_from_int")]
+    pub hvm_supported: bool,
 }

 #[derive(Clone, Deserialize)]
--
2.40.1






More information about the pve-devel mailing list