Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/docbuilder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Context, Error};
use clap::{Args, Parser, Subcommand, ValueEnum};
use log::info;

use trident_api::constants::ESP_MOUNT_POINT_PATH;
use trident_api::constants::DEFAULT_ESP_MOUNT_POINT_PATH;

mod clap_model;
mod host_config;
Expand Down Expand Up @@ -227,9 +227,9 @@ fn build_host_config_docs(mut opts: HostConfigMarkdownOpts) -> Result<(), Error>

// Constants that we are making available to the tera context for rendering
// descriptions. They will exists as variables with the exact same name as
// the constant. For example, `ESP_MOUNT_POINT_PATH` can be used in
// descriptions as `{{ ESP_MOUNT_POINT_PATH }}`.
let variables = string_const_map!(ESP_MOUNT_POINT_PATH);
// the constant. For example, `DEFAULT_ESP_MOUNT_POINT_PATH` can be used in
// descriptions as `{{ DEFAULT_ESP_MOUNT_POINT_PATH }}`.
let variables = string_const_map!(DEFAULT_ESP_MOUNT_POINT_PATH);

host_config::docs::build(
opts.output,
Expand Down
4 changes: 2 additions & 2 deletions crates/osutils/src/tabfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ mod tests {

use tempfile::NamedTempFile;

use trident_api::constants::ESP_MOUNT_POINT_PATH;
use trident_api::constants::DEFAULT_ESP_MOUNT_POINT_PATH;

#[test]
fn test_get_device_path() {
Expand All @@ -347,7 +347,7 @@ mod tests {
tmpfile.flush().unwrap();

assert_eq!(
get_device_path(tmpfile.path(), Path::new(ESP_MOUNT_POINT_PATH)).unwrap(),
get_device_path(tmpfile.path(), Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)).unwrap(),
PathBuf::from("/dev/sda1")
);

Expand Down
4 changes: 2 additions & 2 deletions crates/trident/src/engine/boot/grub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub(crate) mod functional_test {
self, AbUpdate, AbVolumePair, Disk, FileSystem, FileSystemSource, HostConfiguration,
MountOptions, MountPoint, Partition, PartitionType, RaidLevel, SoftwareRaidArray,
},
constants::ESP_MOUNT_POINT_PATH,
constants::DEFAULT_ESP_MOUNT_POINT_PATH,
status::ServicingType,
};

Expand All @@ -304,7 +304,7 @@ pub(crate) mod functional_test {
let grub_esp = include_str!("test_files/grub_esp.cfg");
let grub_boot = include_str!("test_files/grub_boot.cfg");

let grub_esp_path = Path::new(ESP_MOUNT_POINT_PATH)
let grub_esp_path = Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)
.join(ESP_EFI_DIRECTORY)
.join(get_update_esp_dir_name(ctx).expect("Failed to get update esp dir name"))
.join(GRUB2_CONFIG_FILENAME);
Expand Down
71 changes: 49 additions & 22 deletions crates/trident/src/engine/boot/uki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use osutils::{
use trident_api::error::{
InternalError, ReportError, ServicingError, TridentError, TridentResultExt,
};
use trident_api::{
constants::{ESP_EFI_DIRECTORY, ESP_MOUNT_POINT_PATH},
status::AbVolumeSelection,
};
use trident_api::{constants::ESP_EFI_DIRECTORY, status::AbVolumeSelection};

use crate::engine::EngineContext;

Expand All @@ -42,7 +39,11 @@ pub fn is_staged(esp_dir_path: &Path) -> bool {
}

/// Copies the UKI file from the mounted image to the ESP directory.
pub fn stage_uki_on_esp(temp_mount_dir: &Path, mount_point: &Path) -> Result<(), Error> {
pub fn stage_uki_on_esp(
temp_mount_dir: &Path,
mount_point: &Path,
esp_mount_path: &Path,
) -> Result<(), Error> {
let uki_source_dir = temp_mount_dir.join(UKI_DIRECTORY);
let ukis: Vec<_> = uki_source_dir
.read_dir()
Expand All @@ -59,7 +60,7 @@ pub fn stage_uki_on_esp(temp_mount_dir: &Path, mount_point: &Path) -> Result<(),
ensure!(ukis.len() == 1, "Multiple UKI files found within the image");

// Path to stage the UKI file on the ESP, e.g. <mount_point>/EFI/Linux/vmlinuz-0.efi.staged
let staging_uki_path = join_relative(mount_point, ESP_MOUNT_POINT_PATH).join(UKI_DIRECTORY);
let staging_uki_path = join_relative(mount_point, esp_mount_path).join(UKI_DIRECTORY);

let dest_path = staging_uki_path.join(TMP_UKI_NAME);
debug!("Staging UKI file at '{}'", dest_path.display());
Expand Down Expand Up @@ -144,8 +145,8 @@ pub fn stage_uki_on_esp(temp_mount_dir: &Path, mount_point: &Path) -> Result<(),
}

/// Prepares the ESP directory structure required for UKI boot.
pub fn prepare_esp_for_uki(root_mount_point: &Path) -> Result<(), Error> {
let esp_root_path = join_relative(root_mount_point, ESP_MOUNT_POINT_PATH);
pub fn prepare_esp_for_uki(root_mount_point: &Path, esp_mount_path: &Path) -> Result<(), Error> {
let esp_root_path = join_relative(root_mount_point, esp_mount_path);
let esp_uki_directory = esp_root_path.join(UKI_DIRECTORY);

fs::create_dir_all(&esp_uki_directory)
Expand Down Expand Up @@ -415,6 +416,7 @@ mod tests {
use super::*;
use std::fs::File;
use tempfile::tempdir;
use trident_api::constants::DEFAULT_ESP_MOUNT_POINT_PATH;

/// Validates that `uki_suffix` produces the correct A/B suffix based on
/// the active volume and install index.
Expand Down Expand Up @@ -462,21 +464,31 @@ mod tests {
fs::write(src_uki_dir.join("dummy-uki.efi"), b"uki-content").unwrap();

let mount_point = tempdir().unwrap();
prepare_esp_for_uki(mount_point.path()).unwrap();
prepare_esp_for_uki(mount_point.path(), Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)).unwrap();

// Should succeed when exactly one UKI file is present
stage_uki_on_esp(temp_mount.path(), mount_point.path()).unwrap();
stage_uki_on_esp(
temp_mount.path(),
mount_point.path(),
Path::new(DEFAULT_ESP_MOUNT_POINT_PATH),
)
.unwrap();

// Check that the file was copied to the correct destination
let dest_uki_file = join_relative(mount_point.path(), ESP_MOUNT_POINT_PATH)
let dest_uki_file = join_relative(mount_point.path(), DEFAULT_ESP_MOUNT_POINT_PATH)
.join(UKI_DIRECTORY)
.join(TMP_UKI_NAME);
assert_eq!(fs::read(&dest_uki_file).unwrap(), b"uki-content");

// Should fail if there are multiple UKI files
let extra_uki_file = src_uki_dir.join("another.efi");
fs::write(&extra_uki_file, b"other").unwrap();
stage_uki_on_esp(temp_mount.path(), mount_point.path()).unwrap_err();
stage_uki_on_esp(
temp_mount.path(),
mount_point.path(),
Path::new(DEFAULT_ESP_MOUNT_POINT_PATH),
)
.unwrap_err();
}

/// Validates that `stage_uki_on_esp` copies both the UKI file and its
Expand All @@ -502,19 +514,24 @@ mod tests {
fs::write(addon_dir.join("README"), b"ignored").unwrap();

let mount_point = tempdir().unwrap();
prepare_esp_for_uki(mount_point.path()).unwrap();
prepare_esp_for_uki(mount_point.path(), Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)).unwrap();

// Should succeed when exactly one UKI file is present
stage_uki_on_esp(temp_mount.path(), mount_point.path()).unwrap();
stage_uki_on_esp(
temp_mount.path(),
mount_point.path(),
Path::new(DEFAULT_ESP_MOUNT_POINT_PATH),
)
.unwrap();

// Check that the UKI file was copied to the correct destination
let dest_uki_file = join_relative(mount_point.path(), ESP_MOUNT_POINT_PATH)
let dest_uki_file = join_relative(mount_point.path(), DEFAULT_ESP_MOUNT_POINT_PATH)
.join(UKI_DIRECTORY)
.join(TMP_UKI_NAME);
assert_eq!(fs::read(&dest_uki_file).unwrap(), b"uki-content");

// Check that the addon files were copied to the correct destination
let dest_addon_dir = join_relative(mount_point.path(), ESP_MOUNT_POINT_PATH)
let dest_addon_dir = join_relative(mount_point.path(), DEFAULT_ESP_MOUNT_POINT_PATH)
.join(UKI_DIRECTORY)
.join(TMP_UKI_ADDON_DIR_NAME);
assert_eq!(
Expand All @@ -537,9 +554,9 @@ mod tests {
#[test]
fn test_prepare_esp_for_uki() {
let root_mount = tempdir().unwrap();
prepare_esp_for_uki(root_mount.path()).unwrap();
prepare_esp_for_uki(root_mount.path(), Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)).unwrap();

let esp_root_path = join_relative(root_mount.path(), ESP_MOUNT_POINT_PATH);
let esp_root_path = join_relative(root_mount.path(), DEFAULT_ESP_MOUNT_POINT_PATH);
assert!(esp_root_path.join(UKI_DIRECTORY).exists());
assert!(esp_root_path.join("loader").exists());
assert!(esp_root_path.join("loader/entries.srel").exists());
Expand Down Expand Up @@ -693,18 +710,28 @@ mod tests {

// With no regular files present, staging should fail with "No UKI files found"
let mount_point = tempdir().unwrap();
prepare_esp_for_uki(mount_point.path()).unwrap();
let err = stage_uki_on_esp(temp_mount.path(), mount_point.path()).unwrap_err();
prepare_esp_for_uki(mount_point.path(), Path::new(DEFAULT_ESP_MOUNT_POINT_PATH)).unwrap();
let err = stage_uki_on_esp(
temp_mount.path(),
mount_point.path(),
Path::new(DEFAULT_ESP_MOUNT_POINT_PATH),
)
.unwrap_err();
assert!(
err.to_string().contains("No UKI files found"),
"Expected 'No UKI files found' error, got: {err}"
);

// Now add exactly one regular file — staging should succeed
fs::write(src_uki_dir.join("real-uki.efi"), b"uki-content").unwrap();
stage_uki_on_esp(temp_mount.path(), mount_point.path()).unwrap();
stage_uki_on_esp(
temp_mount.path(),
mount_point.path(),
Path::new(DEFAULT_ESP_MOUNT_POINT_PATH),
)
.unwrap();

let dest_uki_file = join_relative(mount_point.path(), ESP_MOUNT_POINT_PATH)
let dest_uki_file = join_relative(mount_point.path(), DEFAULT_ESP_MOUNT_POINT_PATH)
.join(UKI_DIRECTORY)
.join(TMP_UKI_NAME);
assert_eq!(fs::read(&dest_uki_file).unwrap(), b"uki-content");
Expand Down
10 changes: 5 additions & 5 deletions crates/trident/src/engine/bootentries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ mod tests {
use super::*;
use boot::get_update_esp_dir_name;

use constants::ESP_MOUNT_POINT_PATH;
use constants::DEFAULT_ESP_MOUNT_POINT_PATH;

/// Validates logic for determining which A/B volume to use for updates
#[test]
Expand Down Expand Up @@ -844,7 +844,7 @@ mod tests {
source: FileSystemSource::Image,
device_id: Some("esp".to_string()),
mount_point: Some(MountPoint {
path: ESP_MOUNT_POINT_PATH.into(),
path: DEFAULT_ESP_MOUNT_POINT_PATH.into(),
options: MountOptions::defaults(),
}),
is_esp: true,
Expand Down Expand Up @@ -900,7 +900,7 @@ mod tests {
source: FileSystemSource::Image,
device_id: Some("esp".to_string()),
mount_point: Some(MountPoint {
path: ESP_MOUNT_POINT_PATH.into(),
path: DEFAULT_ESP_MOUNT_POINT_PATH.into(),
options: MountOptions::defaults(),
}),
is_esp: true,
Expand Down Expand Up @@ -1029,7 +1029,7 @@ mod functional_test {
self, Disk, HostConfiguration, ImageSha384, MountOptions, MountPoint, OsImage,
Partition, PartitionSize, PartitionType,
},
constants::ESP_MOUNT_POINT_PATH,
constants::DEFAULT_ESP_MOUNT_POINT_PATH,
};

use crate::engine::{storage::partitioning, EngineContext};
Expand Down Expand Up @@ -1415,7 +1415,7 @@ mod functional_test {
source: config::FileSystemSource::Image,
device_id: Some("esp".to_string()),
mount_point: Some(MountPoint {
path: ESP_MOUNT_POINT_PATH.into(),
path: DEFAULT_ESP_MOUNT_POINT_PATH.into(),
options: MountOptions::defaults(),
}),
is_esp: true,
Expand Down
4 changes: 2 additions & 2 deletions crates/trident/src/engine/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ pub struct EngineContext {
#[cfg(any(test, feature = "functional-test"))]
impl Default for EngineContext {
fn default() -> Self {
use trident_api::constants::ESP_MOUNT_POINT_PATH;
use trident_api::constants::DEFAULT_ESP_MOUNT_POINT_PATH;
Self {
esp_mount_path: PathBuf::from(ESP_MOUNT_POINT_PATH),
esp_mount_path: PathBuf::from(DEFAULT_ESP_MOUNT_POINT_PATH),
spec: Default::default(),
spec_old: Default::default(),
servicing_type: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions crates/trident/src/engine/install_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ mod tests {

use tempfile::TempDir;

use trident_api::{constants::ESP_MOUNT_POINT_PATH, error::ErrorKind};
use trident_api::{constants::DEFAULT_ESP_MOUNT_POINT_PATH, error::ErrorKind};

use crate::engine::boot::make_esp_dir_name_candidates;

// Helper that constructs the ESP EFI path, creates the directories, and returns
// (full_esp_efi_path, esp_mount_path). The esp_mount_path is what next_install_index expects.
fn setup_esp_efi_path(mount_point: &Path) -> (PathBuf, PathBuf) {
let esp_mount_path = PathBuf::from(ESP_MOUNT_POINT_PATH);
let esp_mount_path = PathBuf::from(DEFAULT_ESP_MOUNT_POINT_PATH);
let esp_efi_path =
path::join_relative(mount_point, &esp_mount_path).join(ESP_EFI_DIRECTORY);
fs::create_dir_all(&esp_efi_path).unwrap();
Expand Down
13 changes: 4 additions & 9 deletions crates/trident/src/engine/manual_rollback/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use std::{
path::{Path, PathBuf},
time::Instant,
};
use std::{path::PathBuf, time::Instant};

use enumflags2::BitFlags;
use log::{debug, info, trace, warn};

use osutils::{efivar, pcrlock};
use osutils::{efivar, path, pcrlock};
use trident_api::{
config::Operations,
constants::{
internal_params::NO_TRANSITION, ESP_RELATIVE_MOUNT_POINT_PATH, ROOT_MOUNT_POINT_PATH,
},
constants::{internal_params::NO_TRANSITION, ROOT_MOUNT_POINT_PATH},
error::{InvalidInputError, ReportError, ServicingError, TridentError, TridentResultExt},
status::{ServicingState, ServicingType},
};
Expand Down Expand Up @@ -286,7 +281,7 @@ fn finalize_rollback(

let root_path = container::get_host_relative_path(PathBuf::from(ROOT_MOUNT_POINT_PATH))
.message("Failed to get host root path")?;
let esp_path = Path::join(&root_path, ESP_RELATIVE_MOUNT_POINT_PATH);
let esp_path = path::join_relative(&root_path, engine_context.esp_mount_path.as_path());

// In UKI, find the previous UKI and set it as default boot entry
if engine_context.is_uki()? {
Expand Down
4 changes: 2 additions & 2 deletions crates/trident/src/engine/newroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ mod functional_test {
self, Disk, FileSystemSource, HostConfiguration, MountOptions, MountPoint, Partition,
PartitionSize, PartitionType,
},
constants::{ESP_RELATIVE_MOUNT_POINT_PATH, MOUNT_OPTION_READ_ONLY},
constants::{DEFAULT_ESP_RELATIVE_MOUNT_POINT_PATH, MOUNT_OPTION_READ_ONLY},
error::ErrorKind,
};

Expand Down Expand Up @@ -948,7 +948,7 @@ mod functional_test {

assert!(root_mount_dir
.path()
.join(ESP_RELATIVE_MOUNT_POINT_PATH)
.join(DEFAULT_ESP_RELATIVE_MOUNT_POINT_PATH)
.join(mock_bootloader_path)
.exists());
newroot_mount2.unmount_all().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions crates/trident/src/engine/storage/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,14 @@ mod tests {
use super::*;

use trident_api::{
constants::ESP_MOUNT_POINT_PATH,
constants::DEFAULT_ESP_MOUNT_POINT_PATH,
status::{AbVolumeSelection, ServicingType},
};

#[test]
fn test_get_bootloader_paths() {
// Declare ESP path; no need to actually write anything as this func only constructs paths.
let esp_path = PathBuf::from(ESP_MOUNT_POINT_PATH);
let esp_path = PathBuf::from(DEFAULT_ESP_MOUNT_POINT_PATH);

let mut ctx = EngineContext {
ab_active_volume: None,
Expand Down Expand Up @@ -722,7 +722,7 @@ mod functional_test {
use super::*;

use pytest_gen::functional_test;
use trident_api::{constants::ESP_MOUNT_POINT_PATH, status::ServicingType};
use trident_api::{constants::DEFAULT_ESP_MOUNT_POINT_PATH, status::ServicingType};

#[functional_test(feature = "helpers")]
fn test_get_uki_paths() {
Expand All @@ -734,7 +734,7 @@ mod functional_test {
};

// Declare ESP path; no need to actually write anything as this func only constructs paths.
let esp_path = PathBuf::from(ESP_MOUNT_POINT_PATH);
let esp_path = PathBuf::from(DEFAULT_ESP_MOUNT_POINT_PATH);
let esp_uki_path = esp_path.join(UKI_DIRECTORY);

// Test case #1: No mount_path, so only one path is returned, i.e. current entry.
Expand Down Expand Up @@ -781,7 +781,7 @@ mod functional_test {

#[functional_test(feature = "helpers")]
fn test_get_binary_paths_pcrlock() {
let esp_path = PathBuf::from(ESP_MOUNT_POINT_PATH);
let esp_path = PathBuf::from(DEFAULT_ESP_MOUNT_POINT_PATH);
let esp_uki_path = esp_path.join(UKI_DIRECTORY);

let mut ctx = EngineContext {
Expand Down
Loading
Loading