Skip to content

Commit 53550fc

Browse files
committed
install: Split internal main phase into two
Split up: - Initialize empty sysroot - Install container to sysroot This makes it easier to do more things that still reference the sysroot. (The git diff for this change is...really nice IMO, very straightforward) Signed-off-by: Colin Walters <[email protected]>
1 parent d91c00a commit 53550fc

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

lib/src/install.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,9 @@ pub(crate) fn print_configuration() -> Result<()> {
542542
}
543543

544544
#[context("Creating ostree deployment")]
545-
async fn initialize_ostree_root_from_self(
546-
state: &State,
547-
root_setup: &RootSetup,
548-
) -> Result<InstallAleph> {
545+
async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result<ostree::Sysroot> {
549546
let sepolicy = state.load_policy()?;
550547
let sepolicy = sepolicy.as_ref();
551-
552-
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
553-
554548
// Load a fd for the mounted target physical root
555549
let rootfs_dir = &root_setup.rootfs_fd;
556550
let rootfs = root_setup.rootfs.as_path();
@@ -607,6 +601,20 @@ async fn initialize_ostree_root_from_self(
607601

608602
let sysroot = ostree::Sysroot::new(Some(&gio::File::for_path(rootfs)));
609603
sysroot.load(cancellable)?;
604+
Ok(sysroot)
605+
}
606+
607+
#[context("Creating ostree deployment")]
608+
async fn install_container(
609+
state: &State,
610+
root_setup: &RootSetup,
611+
sysroot: &ostree::Sysroot,
612+
) -> Result<InstallAleph> {
613+
let sepolicy = state.load_policy()?;
614+
let sepolicy = sepolicy.as_ref();
615+
let stateroot = STATEROOT_DEFAULT;
616+
617+
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
610618

611619
let (src_imageref, proxy_cfg) = if !state.source.in_host_mountns {
612620
(state.source.imageref.clone(), None)
@@ -692,15 +700,15 @@ async fn initialize_ostree_root_from_self(
692700
)
693701
.await?;
694702

695-
sysroot.load(cancellable)?;
696703
let deployment = sysroot
697704
.deployments()
698705
.into_iter()
699706
.next()
700707
.ok_or_else(|| anyhow::anyhow!("Failed to find deployment"))?;
701708
// SAFETY: There must be a path
702709
let path = sysroot.deployment_dirpath(&deployment);
703-
let root = rootfs_dir
710+
let root = root_setup
711+
.rootfs_fd
704712
.open_dir(path.as_str())
705713
.context("Opening deployment dir")?;
706714

@@ -713,7 +721,7 @@ async fn initialize_ostree_root_from_self(
713721
for d in ["ostree", "boot"] {
714722
let mut pathbuf = Utf8PathBuf::from(d);
715723
crate::lsm::ensure_dir_labeled_recurse(
716-
rootfs_dir,
724+
&root_setup.rootfs_fd,
717725
&mut pathbuf,
718726
policy,
719727
Some(deployment_root_devino),
@@ -1228,8 +1236,9 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
12281236
tracing::debug!("boot uuid={boot_uuid}");
12291237

12301238
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
1239+
let sysroot = initialize_ostree_root(state, rootfs).await?;
12311240
{
1232-
let aleph = initialize_ostree_root_from_self(state, rootfs).await?;
1241+
let aleph = install_container(state, rootfs, &sysroot).await?;
12331242
rootfs
12341243
.rootfs_fd
12351244
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {

0 commit comments

Comments
 (0)