Skip to content

Commit 680b29f

Browse files
authored
Merge pull request #882 from cgwalters/install-not-container-kargs
install: Stop reading kargs from container root, use ostree
2 parents 34b490f + b783278 commit 680b29f

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

lib/src/install.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,6 @@ async fn install_container(
660660
let sepolicy = sepolicy.as_ref();
661661
let stateroot = state.stateroot();
662662

663-
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
664-
665663
let (src_imageref, proxy_cfg) = if !state.source.in_host_mountns {
666664
(state.source.imageref.clone(), None)
667665
} else {
@@ -703,17 +701,26 @@ async fn install_container(
703701

704702
// Pull the container image into the target root filesystem. Since this is
705703
// an install path, we don't need to fsync() individual layers.
706-
{
704+
let pulled_image = {
707705
let spec_imgref = ImageReference::from(src_imageref.clone());
708706
let repo = &sysroot.repo();
709707
repo.set_disable_fsync(true);
710-
crate::deploy::pull(repo, &spec_imgref, Some(&state.target_imgref), false).await?;
708+
let r = crate::deploy::pull(repo, &spec_imgref, Some(&state.target_imgref), false).await?;
711709
repo.set_disable_fsync(false);
712-
}
710+
r
711+
};
713712

714-
// Load the kargs from the /usr/lib/bootc/kargs.d from the running root,
715-
// which should be the same as the filesystem we'll deploy.
716-
let kargsd = crate::kargs::get_kargs_in_root(container_rootfs, std::env::consts::ARCH)?;
713+
// We need to read the kargs from the target merged ostree commit before
714+
// we do the deployment.
715+
let merged_ostree_root = sysroot
716+
.repo()
717+
.read_commit(pulled_image.ostree_commit.as_str(), gio::Cancellable::NONE)?
718+
.0;
719+
let kargsd = crate::kargs::get_kargs_from_ostree_root(
720+
&sysroot.repo(),
721+
merged_ostree_root.downcast_ref().unwrap(),
722+
std::env::consts::ARCH,
723+
)?;
717724
let kargsd = kargsd.iter().map(|s| s.as_str());
718725

719726
let install_config_kargs = state

lib/src/kargs.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use serde::Deserialize;
1515
use crate::deploy::ImageState;
1616
use crate::store::Storage;
1717

18+
const KARGS_PATH: &str = "usr/lib/bootc/kargs.d";
19+
1820
/// The kargs.d configuration file.
1921
#[derive(Deserialize)]
2022
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
@@ -37,10 +39,7 @@ impl Config {
3739
/// a combined list.
3840
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
3941
// If the directory doesn't exist, that's OK.
40-
let Some(d) = d
41-
.open_dir_optional("usr/lib/bootc/kargs.d")?
42-
.map(DirUtf8::from_cap_std)
43-
else {
42+
let Some(d) = d.open_dir_optional(KARGS_PATH)?.map(DirUtf8::from_cap_std) else {
4443
return Ok(Default::default());
4544
};
4645
let mut ret = Vec::new();
@@ -54,6 +53,18 @@ pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>>
5453
}
5554

5655
/// Load kargs.d files from the target ostree commit root
56+
#[cfg(feature = "install")]
57+
pub(crate) fn get_kargs_from_ostree_root(
58+
repo: &ostree::Repo,
59+
root: &ostree::RepoFile,
60+
sys_arch: &str,
61+
) -> Result<Vec<String>> {
62+
let kargsd = root.resolve_relative_path(KARGS_PATH);
63+
let kargsd = kargsd.downcast_ref::<ostree::RepoFile>().expect("downcast");
64+
get_kargs_from_ostree(repo, kargsd, sys_arch)
65+
}
66+
67+
/// Load kargs.d files from the target dir
5768
fn get_kargs_from_ostree(
5869
repo: &ostree::Repo,
5970
fetched_tree: &ostree::RepoFile,
@@ -119,7 +130,7 @@ pub(crate) fn get_kargs(
119130

120131
// Get the kargs in kargs.d of the pending image
121132
let (fetched_tree, _) = repo.read_commit(fetched.ostree_commit.as_str(), cancellable)?;
122-
let fetched_tree = fetched_tree.resolve_relative_path("/usr/lib/bootc/kargs.d");
133+
let fetched_tree = fetched_tree.resolve_relative_path(KARGS_PATH);
123134
let fetched_tree = fetched_tree
124135
.downcast::<ostree::RepoFile>()
125136
.expect("downcast");

0 commit comments

Comments
 (0)