Skip to content

Commit

Permalink
install: Rename rootfs -> physical_root
Browse files Browse the repository at this point in the history
In the install flow we juggle *three* file systems in general:

- The container/host root
- The physical root
- The deployment root

"rootfs" in theory could be any of those three. In the install code
it's the physical (target) root, so rename the variable
to clarify.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 19, 2024
1 parent 2c7aa26 commit f6d3436
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
25 changes: 14 additions & 11 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
let sepolicy = state.load_policy()?;
let sepolicy = sepolicy.as_ref();
// Load a fd for the mounted target physical root
let rootfs_dir = &root_setup.rootfs_fd;
let rootfs_dir = &root_setup.physical_root;
let cancellable = gio::Cancellable::NONE;

let stateroot = state.stateroot();
Expand Down Expand Up @@ -779,7 +779,7 @@ async fn install_container(
// SAFETY: There must be a path
let path = sysroot.deployment_dirpath(&deployment);
let root = root_setup
.rootfs_fd
.physical_root
.open_dir(path.as_str())
.context("Opening deployment dir")?;

Expand All @@ -792,7 +792,7 @@ async fn install_container(
for d in ["ostree", "boot"] {
let mut pathbuf = Utf8PathBuf::from(d);
crate::lsm::ensure_dir_labeled_recurse(
&root_setup.rootfs_fd,
&root_setup.physical_root,
&mut pathbuf,
policy,
Some(deployment_root_devino),
Expand Down Expand Up @@ -902,8 +902,11 @@ fn require_skopeo_with_containers_storage() -> Result<()> {
pub(crate) struct RootSetup {
luks_device: Option<String>,
device_info: crate::blockdev::PartitionTable,
rootfs: Utf8PathBuf,
rootfs_fd: Dir,
/// Absolute path to the location where we've mounted the physical
/// root filesystem for the system we're installing.
physical_root_path: Utf8PathBuf,
/// Directory file descriptor for the above physical root.
physical_root: Dir,
rootfs_uuid: Option<String>,
/// True if we should skip finalizing
skip_finalize: bool,
Expand All @@ -925,7 +928,7 @@ impl RootSetup {

// Drop any open file descriptors and return just the mount path and backing luks device, if any
fn into_storage(self) -> (Utf8PathBuf, Option<String>) {
(self.rootfs, self.luks_device)
(self.physical_root_path, self.luks_device)
}
}

Expand Down Expand Up @@ -1323,7 +1326,7 @@ async fn install_with_sysroot(
let (_deployment, aleph) = install_container(state, rootfs, &sysroot, has_ostree).await?;
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
rootfs
.rootfs_fd
.physical_root
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
serde_json::to_writer(f, &aleph)?;
anyhow::Ok(())
Expand All @@ -1336,7 +1339,7 @@ async fn install_with_sysroot(
} else {
crate::bootloader::install_via_bootupd(
&rootfs.device_info,
&rootfs.rootfs,
&rootfs.physical_root_path,
&state.config_opts,
)?;
}
Expand Down Expand Up @@ -1425,7 +1428,7 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
if !rootfs.skip_finalize {
let bootfs = rootfs.boot.as_ref().map(|_| ("boot", "boot"));
for (fsname, fs) in std::iter::once(("root", ".")).chain(bootfs) {
finalize_filesystem(fsname, &rootfs.rootfs_fd, fs)?;
finalize_filesystem(fsname, &rootfs.physical_root, fs)?;
}
}

Expand Down Expand Up @@ -1819,8 +1822,8 @@ pub(crate) async fn install_to_filesystem(
let mut rootfs = RootSetup {
luks_device: None,
device_info,
rootfs: fsopts.root_path,
rootfs_fd,
physical_root_path: fsopts.root_path,
physical_root: rootfs_fd,
rootfs_uuid: inspect.uuid.clone(),
boot,
kargs,
Expand Down
16 changes: 8 additions & 8 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ pub(crate) fn install_create_rootfs(

// Create a temporary directory to use for mount points. Note that we're
// in a mount namespace, so these should not be visible on the host.
let rootfs = mntdir.join("rootfs");
std::fs::create_dir_all(&rootfs)?;
let physical_root_path = mntdir.join("rootfs");
std::fs::create_dir_all(&physical_root_path)?;
let bootfs = mntdir.join("boot");
std::fs::create_dir_all(bootfs)?;

Expand Down Expand Up @@ -389,11 +389,11 @@ pub(crate) fn install_create_rootfs(
.chain(bootarg)
.collect::<Vec<_>>();

mount::mount(&rootdev, &rootfs)?;
let target_rootfs = Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
mount::mount(&rootdev, &physical_root_path)?;
let target_rootfs = Dir::open_ambient_dir(&physical_root_path, cap_std::ambient_authority())?;
crate::lsm::ensure_dir_labeled(&target_rootfs, "", Some("/".into()), 0o755.into(), sepolicy)?;
let rootfs_fd = Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
let bootfs = rootfs.join("boot");
let physical_root = Dir::open_ambient_dir(&physical_root_path, cap_std::ambient_authority())?;
let bootfs = physical_root_path.join("boot");
// Create the underlying mount point directory, which should be labeled
crate::lsm::ensure_dir_labeled(&target_rootfs, "boot", None, 0o755.into(), sepolicy)?;
if let Some(bootdev) = bootdev {
Expand Down Expand Up @@ -422,8 +422,8 @@ pub(crate) fn install_create_rootfs(
Ok(RootSetup {
luks_device,
device_info,
rootfs,
rootfs_fd,
physical_root_path,
physical_root,
rootfs_uuid: Some(root_uuid.to_string()),
boot,
kargs,
Expand Down

0 comments on commit f6d3436

Please sign in to comment.