From 74c011cc54f99d4e08be5e607f66c8e203d78afe Mon Sep 17 00:00:00 2001 From: "Panagiotis \"Ivory\" Vasilopoulos" Date: Fri, 10 Oct 2025 23:04:39 +0200 Subject: [PATCH] refactor(fs): move uhyve check outside of init This is effectively a style-related change that suppresses an info! Apart from reducing unused code when running Hermit kernels in bare metal or under QEMU, this change additionally moves the "is_uhyve" checks to the caller function instead of the callee for reasons of consistency. Fixes https://github.com/hermit-os/kernel/issues/1969 --- src/fs/mod.rs | 4 +++- src/fs/uhyve.rs | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/fs/mod.rs b/src/fs/mod.rs index ac5dc44e10..78eb630ed4 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -365,7 +365,9 @@ pub(crate) fn init() { #[cfg(all(feature = "fuse", feature = "pci"))] fuse::init(); - uhyve::init(); + if crate::env::is_uhyve() { + uhyve::init(); + } } pub fn create_file(name: &str, data: &'static [u8], mode: AccessPermission) -> io::Result<()> { diff --git a/src/fs/uhyve.rs b/src/fs/uhyve.rs index d180497f65..58c0afe607 100644 --- a/src/fs/uhyve.rs +++ b/src/fs/uhyve.rs @@ -14,7 +14,6 @@ use uhyve_interface::parameters::{ use uhyve_interface::{GuestPhysAddr, GuestVirtAddr, Hypercall}; use crate::arch::mm::paging; -use crate::env::is_uhyve; use crate::errno::Errno; use crate::fs::{ self, AccessPermission, FileAttr, NodeKind, ObjectInterface, OpenOption, SeekWhence, VfsNode, @@ -230,16 +229,14 @@ impl VfsNode for UhyveDirectory { pub(crate) fn init() { info!("Try to initialize uhyve filesystem"); - if is_uhyve() { - let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string(); - info!("Mounting uhyve filesystem at {mount_point}"); - fs::FILESYSTEM - .get() - .unwrap() - .mount( - &mount_point, - Box::new(UhyveDirectory::new(Some(mount_point.clone()))), - ) - .expect("Mount failed. Duplicate mount_point?"); - } + let mount_point = hermit_var_or!("UHYVE_MOUNT", "/root").to_string(); + info!("Mounting uhyve filesystem at {mount_point}"); + fs::FILESYSTEM + .get() + .unwrap() + .mount( + &mount_point, + Box::new(UhyveDirectory::new(Some(mount_point.clone()))), + ) + .expect("Mount failed. Duplicate mount_point?"); }