Skip to content

Commit 31c1ae4

Browse files
storage: Fix premature ostree booted check
There were a few checks that asserted ostree booted system even for systems booted via composefs. Move the checks in `Storage::new` Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent bfff92d commit 31c1ae4

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

crates/lib/src/cli.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ pub(crate) fn ensure_self_unshared_mount_namespace() -> Result<()> {
715715
/// Load global storage state, expecting that we're booted into a bootc system.
716716
#[context("Initializing storage")]
717717
pub(crate) async fn get_storage() -> Result<crate::store::BootedStorage> {
718-
prepare_for_write()?;
719718
BootedStorage::new().await
720719
}
721720

@@ -842,7 +841,7 @@ fn soft_reboot_rollback(booted_ostree: &BootedOstree<'_>) -> Result<()> {
842841
/// IMPORTANT: This may end up re-executing the current process,
843842
/// so anything that happens before this should be idempotent.
844843
#[context("Preparing for write")]
845-
fn prepare_for_write() -> Result<()> {
844+
pub(crate) fn prepare_for_write() -> Result<()> {
846845
use std::sync::atomic::{AtomicBool, Ordering};
847846

848847
// This is intending to give "at most once" semantics to this

crates/lib/src/status.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use fn_error_context::context;
1010
use ostree::glib;
1111
use ostree_container::OstreeImageReference;
1212
use ostree_ext::container as ostree_container;
13-
use ostree_ext::container_utils::ostree_booted;
1413
use ostree_ext::keyfileext::KeyFileExt;
1514
use ostree_ext::oci_spec;
1615
use ostree_ext::oci_spec::image::Digest;
@@ -368,19 +367,16 @@ pub(crate) fn get_status(
368367
}
369368

370369
async fn get_host() -> Result<Host> {
371-
let host = if ostree_booted()? {
372-
let storage = super::cli::get_storage().await?;
373-
match storage.kind()? {
374-
crate::store::BootedStorageKind::Ostree(booted_ostree) => {
375-
let (_deployments, host) = get_status(&booted_ostree)?;
376-
host
377-
}
378-
crate::store::BootedStorageKind::Composefs(booted_cfs) => {
379-
crate::bootc_composefs::status::get_composefs_status(&storage, &booted_cfs).await?
380-
}
370+
let storage = super::cli::get_storage().await?;
371+
372+
let host = match storage.kind()? {
373+
crate::store::BootedStorageKind::Ostree(booted_ostree) => {
374+
let (_deployments, host) = get_status(&booted_ostree)?;
375+
host
376+
}
377+
crate::store::BootedStorageKind::Composefs(booted_cfs) => {
378+
crate::bootc_composefs::status::get_composefs_status(&storage, &booted_cfs).await?
381379
}
382-
} else {
383-
Default::default()
384380
};
385381

386382
Ok(host)

crates/lib/src/store/mod.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use ostree_ext::{gio, ostree};
3131
use rustix::fs::Mode;
3232

3333
use crate::bootc_composefs::status::{composefs_booted, ComposefsCmdline};
34+
use crate::cli::prepare_for_write;
3435
use crate::lsm;
3536
use crate::podstorage::CStorage;
3637
use crate::spec::ImageStatus;
@@ -111,11 +112,12 @@ impl BootedStorage {
111112
pub(crate) async fn new() -> Result<Self> {
112113
let physical_root = Dir::open_ambient_dir("/sysroot", cap_std::ambient_authority())
113114
.context("Opening /sysroot")?;
115+
114116
let run =
115117
Dir::open_ambient_dir("/run", cap_std::ambient_authority()).context("Opening /run")?;
118+
116119
if let Some(cmdline) = composefs_booted()? {
117-
let mut composefs =
118-
ComposefsRepository::open_path(physical_root.open_dir(COMPOSEFS)?, ".")?;
120+
let mut composefs = ComposefsRepository::open_path(&physical_root, COMPOSEFS)?;
119121
if cmdline.insecure {
120122
composefs.set_insecure(true);
121123
}
@@ -128,24 +130,26 @@ impl BootedStorage {
128130
composefs: OnceCell::from(composefs),
129131
imgstore: Default::default(),
130132
};
131-
Ok(Self { storage })
132-
} else {
133-
let sysroot = ostree::Sysroot::new_default();
134-
sysroot.set_mount_namespace_in_use();
135-
let sysroot = ostree_ext::sysroot::SysrootLock::new_from_sysroot(&sysroot).await?;
136-
sysroot.load(gio::Cancellable::NONE)?;
137-
// Verify this is a booted system
138-
let _ = sysroot.require_booted_deployment()?;
139133

140-
let storage = Storage {
141-
physical_root,
142-
run,
143-
ostree: OnceCell::from(sysroot),
144-
composefs: Default::default(),
145-
imgstore: Default::default(),
146-
};
147-
Ok(Self { storage })
134+
return Ok(Self { storage });
148135
}
136+
137+
prepare_for_write()?;
138+
139+
let sysroot = ostree::Sysroot::new_default();
140+
sysroot.set_mount_namespace_in_use();
141+
let sysroot = ostree_ext::sysroot::SysrootLock::new_from_sysroot(&sysroot).await?;
142+
sysroot.load(gio::Cancellable::NONE)?;
143+
144+
let storage = Storage {
145+
physical_root,
146+
run,
147+
ostree: OnceCell::from(sysroot),
148+
composefs: Default::default(),
149+
imgstore: Default::default(),
150+
};
151+
152+
Ok(Self { storage })
149153
}
150154

151155
/// Determine the boot storage backend kind.

0 commit comments

Comments
 (0)