Skip to content

Commit 9c15854

Browse files
committed
store: Drop deref for ostree repo
The goal here is to make all three types of storage effectively equal peers. Signed-off-by: Colin Walters <[email protected]>
1 parent f4c8d94 commit 9c15854

File tree

9 files changed

+73
-48
lines changed

9 files changed

+73
-48
lines changed

crates/lib/src/bootc_kargs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ pub(crate) fn get_kargs(
116116
fetched: &ImageState,
117117
) -> Result<Vec<String>> {
118118
let cancellable = gio::Cancellable::NONE;
119-
let repo = &sysroot.repo();
119+
let ostree = sysroot.get_ostree()?;
120+
let repo = &ostree.repo();
120121
let mut kargs = vec![];
121122
let sys_arch = std::env::consts::ARCH;
122123

@@ -129,7 +130,7 @@ pub(crate) fn get_kargs(
129130
};
130131

131132
// Get the kargs in kargs.d of the merge
132-
let merge_root = &crate::utils::deployment_fd(sysroot, merge_deployment)?;
133+
let merge_root = &crate::utils::deployment_fd(ostree, merge_deployment)?;
133134
let existing_kargs = get_kargs_in_root(merge_root, sys_arch)?;
134135

135136
// Get the kargs in kargs.d of the pending image

crates/lib/src/boundimage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) struct ResolvedBoundImage {
3939

4040
/// Given a deployment, pull all container images it references.
4141
pub(crate) async fn pull_bound_images(sysroot: &Storage, deployment: &Deployment) -> Result<()> {
42-
let bound_images = query_bound_images_for_deployment(sysroot, deployment)?;
42+
let bound_images = query_bound_images_for_deployment(sysroot.get_ostree()?, deployment)?;
4343
pull_images(sysroot, bound_images).await
4444
}
4545

crates/lib/src/cli.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ fn prepare_for_write() -> Result<()> {
782782
#[context("Upgrading")]
783783
async fn upgrade(opts: UpgradeOpts) -> Result<()> {
784784
let sysroot = &get_storage().await?;
785-
let repo = &sysroot.repo();
786-
let (booted_deployment, _deployments, host) =
787-
crate::status::get_status_require_booted(sysroot)?;
785+
let ostree = sysroot.get_ostree()?;
786+
let repo = &ostree.repo();
787+
let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(ostree)?;
788788
let imgref = host.spec.image.as_ref();
789789
let prog: ProgressWriter = opts.progress.try_into()?;
790790

@@ -922,9 +922,9 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
922922
let cancellable = gio::Cancellable::NONE;
923923

924924
let sysroot = &get_storage().await?;
925-
let repo = &sysroot.repo();
926-
let (booted_deployment, _deployments, host) =
927-
crate::status::get_status_require_booted(sysroot)?;
925+
let ostree = sysroot.get_ostree()?;
926+
let repo = &ostree.repo();
927+
let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(ostree)?;
928928

929929
let new_spec = {
930930
let mut new_spec = host.spec.clone();
@@ -980,10 +980,10 @@ async fn rollback(opts: RollbackOpts) -> Result<()> {
980980
#[context("Editing spec")]
981981
async fn edit(opts: EditOpts) -> Result<()> {
982982
let sysroot = &get_storage().await?;
983-
let repo = &sysroot.repo();
983+
let ostree = sysroot.get_ostree()?;
984+
let repo = &ostree.repo();
984985

985-
let (booted_deployment, _deployments, host) =
986-
crate::status::get_status_require_booted(sysroot)?;
986+
let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(ostree)?;
987987
let new_host: Host = if let Some(filename) = opts.filename {
988988
let mut r = std::io::BufReader::new(std::fs::File::open(filename)?);
989989
serde_yaml::from_reader(&mut r)?

crates/lib/src/deploy.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ async fn handle_layer_progress_print(
304304
/// Gather all bound images in all deployments, then prune the image store,
305305
/// using the gathered images as the roots (that will not be GC'd).
306306
pub(crate) async fn prune_container_store(sysroot: &Storage) -> Result<()> {
307-
let deployments = sysroot.deployments();
307+
let ostree = sysroot.get_ostree()?;
308+
let deployments = ostree.deployments();
308309
let mut all_bound_images = Vec::new();
309310
for deployment in deployments {
310-
let bound = crate::boundimage::query_bound_images_for_deployment(sysroot, &deployment)?;
311+
let bound = crate::boundimage::query_bound_images_for_deployment(ostree, &deployment)?;
311312
all_bound_images.extend(bound.into_iter());
312313
}
313314
// Convert to a hashset of just the image names
@@ -463,11 +464,11 @@ pub(crate) async fn cleanup(sysroot: &Storage) -> Result<()> {
463464
let bound_prune = prune_container_store(sysroot);
464465

465466
// We create clones (just atomic reference bumps) here to move to the thread.
466-
let repo = sysroot.repo();
467-
let sysroot = sysroot.get_ostree_cloned()?;
467+
let ostree = sysroot.get_ostree_cloned()?;
468+
let repo = ostree.repo();
468469
let repo_prune =
469470
ostree_ext::tokio_util::spawn_blocking_cancellable_flatten(move |cancellable| {
470-
let locked_sysroot = &SysrootLock::from_assumed_locked(&sysroot);
471+
let locked_sysroot = &SysrootLock::from_assumed_locked(&ostree);
471472
let cancellable = Some(cancellable);
472473
let repo = &repo;
473474
let txn = repo.auto_transaction(cancellable)?;
@@ -488,7 +489,7 @@ pub(crate) async fn cleanup(sysroot: &Storage) -> Result<()> {
488489

489490
// Then, for each deployment which is derived (e.g. has configmaps) we synthesize
490491
// a base ref to ensure that it's not GC'd.
491-
for (i, deployment) in sysroot.deployments().into_iter().enumerate() {
492+
for (i, deployment) in ostree.deployments().into_iter().enumerate() {
492493
let commit = deployment.csum();
493494
if let Some(base) = get_base_commit(repo, &commit)? {
494495
repo.transaction_set_refspec(&format!("{BASE_IMAGE_PREFIX}/{i}"), Some(&base));
@@ -582,7 +583,8 @@ async fn deploy(
582583
)
583584
.await?;
584585
// SAFETY: We must have a staged deployment
585-
let staged = sysroot.staged_deployment().unwrap();
586+
let ostree = sysroot.get_ostree()?;
587+
let staged = ostree.staged_deployment().unwrap();
586588
assert_eq!(staged.index(), r);
587589
Ok(staged)
588590
}
@@ -608,6 +610,7 @@ pub(crate) async fn stage(
608610
spec: &RequiredHostSpec<'_>,
609611
prog: ProgressWriter,
610612
) -> Result<()> {
613+
let ostree = sysroot.get_ostree()?;
611614
let mut subtask = SubTaskStep {
612615
subtask: "merging".into(),
613616
description: "Merging Image".into(),
@@ -629,7 +632,7 @@ pub(crate) async fn stage(
629632
.collect(),
630633
})
631634
.await;
632-
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
635+
let merge_deployment = ostree.merge_deployment(Some(stateroot));
633636

634637
subtask.completed = true;
635638
subtasks.push(subtask.clone());
@@ -740,15 +743,18 @@ pub(crate) async fn stage(
740743
/// Implementation of rollback functionality
741744
pub(crate) async fn rollback(sysroot: &Storage) -> Result<()> {
742745
const ROLLBACK_JOURNAL_ID: &str = "26f3b1eb24464d12aa5e7b544a6b5468";
743-
let repo = &sysroot.repo();
744-
let (booted_deployment, deployments, host) = crate::status::get_status_require_booted(sysroot)?;
746+
let ostree = sysroot.get_ostree()?;
747+
let (booted_deployment, deployments, host) = crate::status::get_status_require_booted(ostree)?;
745748

746749
let new_spec = {
747750
let mut new_spec = host.spec.clone();
748751
new_spec.boot_order = new_spec.boot_order.swap();
749752
new_spec
750753
};
751754

755+
let ostree = sysroot.get_ostree()?;
756+
let repo = &ostree.repo();
757+
752758
// Just to be sure
753759
host.spec.verify_transition(&new_spec)?;
754760

@@ -788,7 +794,7 @@ pub(crate) async fn rollback(sysroot: &Storage) -> Result<()> {
788794
.chain(deployments.other)
789795
.collect::<Vec<_>>();
790796
tracing::debug!("Writing new deployments: {new_deployments:?}");
791-
sysroot.write_deployments(&new_deployments, gio::Cancellable::NONE)?;
797+
ostree.write_deployments(&new_deployments, gio::Cancellable::NONE)?;
792798
if reverting {
793799
println!("Next boot: current deployment");
794800
} else {

crates/lib/src/fsck.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ static CHECK_RESOLVCONF: FsckCheck =
106106
/// But at the current time fsck is an experimental feature that we should only be running
107107
/// in our CI.
108108
fn check_resolvconf(storage: &Storage) -> FsckResult {
109+
let ostree = storage.get_ostree()?;
109110
// For now we only check the booted deployment.
110-
if storage.booted_deployment().is_none() {
111+
if ostree.booted_deployment().is_none() {
111112
return fsck_ok();
112113
}
113114
// Read usr/etc/resolv.conf directly.
@@ -240,7 +241,8 @@ fn check_fsverity(storage: &Storage) -> Pin<Box<dyn Future<Output = FsckResult>
240241
}
241242

242243
async fn check_fsverity_inner(storage: &Storage) -> FsckResult {
243-
let repo = &storage.repo();
244+
let ostree = storage.get_ostree()?;
245+
let repo = &ostree.repo();
244246
let verity_state = ostree_ext::fsverity::is_verity_enabled(repo)?;
245247
tracing::debug!(
246248
"verity: expected={:?} found={:?}",
@@ -249,7 +251,7 @@ async fn check_fsverity_inner(storage: &Storage) -> FsckResult {
249251
);
250252

251253
let verity_found_state =
252-
verity_state_of_all_objects(&storage.repo(), verity_state.desired == Tristate::Enabled)
254+
verity_state_of_all_objects(&ostree.repo(), verity_state.desired == Tristate::Enabled)
253255
.await?;
254256
let Some((missing, rest)) = collect_until(
255257
verity_found_state.missing.iter(),

crates/lib/src/image.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct ImageOutput {
4242

4343
#[context("Listing host images")]
4444
fn list_host_images(sysroot: &crate::store::Storage) -> Result<Vec<ImageOutput>> {
45-
let repo = sysroot.repo();
45+
let ostree = sysroot.get_ostree()?;
46+
let repo = ostree.repo();
4647
let images = ostree_ext::container::store::list_images(&repo).context("Querying images")?;
4748

4849
Ok(images
@@ -129,8 +130,8 @@ pub(crate) async fn list_entrypoint(
129130
pub(crate) async fn push_entrypoint(source: Option<&str>, target: Option<&str>) -> Result<()> {
130131
let transport = Transport::ContainerStorage;
131132
let sysroot = crate::cli::get_storage().await?;
132-
133-
let repo = &sysroot.repo();
133+
let ostree = sysroot.get_ostree()?;
134+
let repo = &ostree.repo();
134135

135136
// If the target isn't specified, push to containers-storage + our default image
136137
let target = if let Some(target) = target {
@@ -150,7 +151,7 @@ pub(crate) async fn push_entrypoint(source: Option<&str>, target: Option<&str>)
150151
let source = if let Some(source) = source {
151152
ImageReference::try_from(source).context("Parsing source image")?
152153
} else {
153-
let status = crate::status::get_status_require_booted(&sysroot)?;
154+
let status = crate::status::get_status_require_booted(&ostree)?;
154155
// SAFETY: We know it's booted
155156
let booted = status.2.status.booted.unwrap();
156157
let booted_image = booted.image.unwrap().image;

crates/lib/src/install.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,10 @@ async fn install_with_sysroot(
13421342
has_ostree: bool,
13431343
imgstore: &crate::imgstorage::Storage,
13441344
) -> Result<()> {
1345+
let ostree = sysroot.get_ostree()?;
13451346
// And actually set up the container in that root, returning a deployment and
13461347
// the aleph state (see below).
1347-
let (deployment, aleph) = install_container(state, rootfs, &sysroot, has_ostree).await?;
1348+
let (deployment, aleph) = install_container(state, rootfs, ostree, has_ostree).await?;
13481349
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
13491350
rootfs
13501351
.physical_root
@@ -1353,7 +1354,7 @@ async fn install_with_sysroot(
13531354
})
13541355
.context("Writing aleph version")?;
13551356

1356-
let deployment_path = sysroot.deployment_dirpath(&deployment);
1357+
let deployment_path = ostree.deployment_dirpath(&deployment);
13571358

13581359
if cfg!(target_arch = "s390x") {
13591360
// TODO: Integrate s390x support into install_via_bootupd
@@ -1472,9 +1473,10 @@ async fn install_to_filesystem_impl(
14721473
&imgstore,
14731474
)
14741475
.await?;
1476+
let ostree = sysroot.get_ostree()?;
14751477

14761478
if matches!(cleanup, Cleanup::TriggerOnNextBoot) {
1477-
let sysroot_dir = crate::utils::sysroot_dir(&sysroot)?;
1479+
let sysroot_dir = crate::utils::sysroot_dir(ostree)?;
14781480
tracing::debug!("Writing {DESTRUCTIVE_CLEANUP}");
14791481
sysroot_dir.atomic_write(format!("etc/{}", DESTRUCTIVE_CLEANUP), b"")?;
14801482
}

crates/lib/src/status.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::cli::OutputFormat;
2222
use crate::spec::ImageStatus;
2323
use crate::spec::{BootEntry, BootOrder, Host, HostSpec, HostStatus, HostType};
2424
use crate::spec::{ImageReference, ImageSignature};
25-
use crate::store::{CachedImageStatus, Storage};
25+
use crate::store::CachedImageStatus;
2626

2727
impl From<ostree_container::SignatureSource> for ImageSignature {
2828
fn from(sig: ostree_container::SignatureSource) -> Self {
@@ -161,7 +161,7 @@ fn imagestatus(
161161
/// Given an OSTree deployment, parse out metadata into our spec.
162162
#[context("Reading deployment metadata")]
163163
fn boot_entry_from_deployment(
164-
sysroot: &Storage,
164+
sysroot: &SysrootLock,
165165
deployment: &ostree::Deployment,
166166
) -> Result<BootEntry> {
167167
let (
@@ -223,7 +223,7 @@ impl BootEntry {
223223

224224
/// A variant of [`get_status`] that requires a booted deployment.
225225
pub(crate) fn get_status_require_booted(
226-
sysroot: &Storage,
226+
sysroot: &SysrootLock,
227227
) -> Result<(ostree::Deployment, Deployments, Host)> {
228228
let booted_deployment = sysroot.require_booted_deployment()?;
229229
let (deployments, host) = get_status(sysroot, Some(&booted_deployment))?;
@@ -234,7 +234,7 @@ pub(crate) fn get_status_require_booted(
234234
/// a more native Rust structure.
235235
#[context("Computing status")]
236236
pub(crate) fn get_status(
237-
sysroot: &Storage,
237+
sysroot: &SysrootLock,
238238
booted_deployment: Option<&ostree::Deployment>,
239239
) -> Result<(Deployments, Host)> {
240240
let stateroot = booted_deployment.as_ref().map(|d| d.osname());
@@ -340,8 +340,9 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
340340
Default::default()
341341
} else {
342342
let sysroot = super::cli::get_storage().await?;
343-
let booted_deployment = sysroot.booted_deployment();
344-
let (_deployments, host) = get_status(&sysroot, booted_deployment.as_ref())?;
343+
let ostree = sysroot.get_ostree()?;
344+
let booted_deployment = ostree.booted_deployment();
345+
let (_deployments, host) = get_status(&ostree, booted_deployment.as_ref())?;
345346
host
346347
};
347348

crates/lib/src/store/mod.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
//! The [`Store`] holds references to three different types of
2+
//! storage:
3+
//!
4+
//! # OSTree
5+
//!
6+
//! The default backend for the bootable container store; this
7+
//! lives in `/ostree` in the physical root.
8+
//!
9+
//! # containers-storage:
10+
//!
11+
//! Later, bootc gained support for Logically Bound Images.
12+
//! This is a `containers-storage:` instance that lives
13+
//! in `/ostree/bootc/storage`
14+
//!
15+
//! # composefs
16+
//!
17+
//! This lives in `/composefs` in the physical root.
18+
119
use std::cell::OnceCell;
2-
use std::ops::Deref;
320
use std::sync::Arc;
421

522
use anyhow::{Context, Result};
@@ -9,6 +26,7 @@ use cap_std_ext::dirext::CapStdExtDirExt;
926
use fn_error_context::context;
1027

1128
use composefs;
29+
use ostree_ext::ostree;
1230
use ostree_ext::sysroot::SysrootLock;
1331
use rustix::fs::Mode;
1432

@@ -31,6 +49,8 @@ pub const COMPOSEFS_MODE: Mode = Mode::from_raw_mode(0o700);
3149
/// system root
3250
pub(crate) const BOOTC_ROOT: &str = "ostree/bootc";
3351

52+
/// A reference to a physical filesystem root, plus
53+
/// accessors for the different types of container storage.
3454
pub(crate) struct Storage {
3555
/// Directory holding the physical root
3656
pub physical_root: Dir,
@@ -52,14 +72,6 @@ pub(crate) struct CachedImageStatus {
5272
pub cached_update: Option<ImageStatus>,
5373
}
5474

55-
impl Deref for Storage {
56-
type Target = SysrootLock;
57-
58-
fn deref(&self) -> &Self::Target {
59-
&self.ostree
60-
}
61-
}
62-
6375
impl Storage {
6476
pub fn new(sysroot: SysrootLock, run: &Dir) -> Result<Self> {
6577
let run = run.try_clone()?;

0 commit comments

Comments
 (0)