Skip to content

Commit 46516cd

Browse files
committed
kargs: Use merge deployment
This is in general for us right now a no-op, but is closer to technically correct. In ostree the "merge deployment" concept started out as "deployment we use for the original /etc" which *may be different* from the booted deployment. For example, when one wants to do a "factory reset", we want to start from a fresh /etc. The other important case here is when we're doing a fresh install (or into a new stateroot) there may be no merge deployment at all! It wouldn't be correct to look at `/`. We only sidestep this issue right now because the install logic bypasses this to directly gather kargs...and doesn't use the same `deploy` API as inplace updates. But we want to get closer to doing things that way. Signed-off-by: Colin Walters <[email protected]>
1 parent 7d91ed9 commit 46516cd

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

lib/src/deploy.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,7 @@ async fn deploy(
335335
// is a distinct minor issue, but not super important as right now the install path
336336
// doesn't use this API).
337337
let override_kargs = if let Some(deployment) = merge_deployment {
338-
Some(crate::kargs::get_kargs(
339-
&sysroot.repo(),
340-
&deployment,
341-
image,
342-
)?)
338+
Some(crate::kargs::get_kargs(sysroot, &deployment, image)?)
343339
} else {
344340
None
345341
};

lib/src/kargs.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::{Context, Result};
22
use camino::Utf8Path;
3-
use cap_std_ext::cap_std;
43
use cap_std_ext::cap_std::fs::Dir;
54
use cap_std_ext::dirext::CapStdExtDirExt;
65
use ostree::gio;
@@ -9,6 +8,7 @@ use ostree_ext::ostree::Deployment;
98
use ostree_ext::prelude::Cast;
109
use ostree_ext::prelude::FileEnumeratorExt;
1110
use ostree_ext::prelude::FileExt;
11+
use ostree_ext::sysroot::SysrootLock;
1212
use serde::Deserialize;
1313

1414
use crate::deploy::ImageState;
@@ -101,25 +101,26 @@ fn get_kargs_from_ostree(
101101
/// karg, but applies the diff between the bootc karg files in /usr/lib/bootc/kargs.d
102102
/// between the booted deployment and the new one.
103103
pub(crate) fn get_kargs(
104-
repo: &ostree::Repo,
105-
booted_deployment: &Deployment,
104+
sysroot: &SysrootLock,
105+
merge_deployment: &Deployment,
106106
fetched: &ImageState,
107107
) -> Result<Vec<String>> {
108108
let cancellable = gio::Cancellable::NONE;
109+
let repo = &sysroot.repo();
109110
let mut kargs: Vec<String> = vec![];
110111
let sys_arch = std::env::consts::ARCH;
111112

112-
// Get the running kargs of the booted system
113-
if let Some(bootconfig) = ostree::Deployment::bootconfig(booted_deployment) {
113+
// Get the kargs used for the merge in the bootloader config
114+
if let Some(bootconfig) = ostree::Deployment::bootconfig(merge_deployment) {
114115
if let Some(options) = ostree::BootconfigParser::get(&bootconfig, "options") {
115116
let options = options.split_whitespace().map(|s| s.to_owned());
116117
kargs.extend(options);
117118
}
118119
};
119120

120-
// Get the kargs in kargs.d of the booted system
121-
let root = &cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
122-
let existing_kargs: Vec<String> = get_kargs_in_root(root, sys_arch)?;
121+
// Get the kargs in kargs.d of the merge
122+
let merge_root = &crate::utils::deployment_fd(sysroot, merge_deployment)?;
123+
let existing_kargs: Vec<String> = get_kargs_in_root(merge_root, sys_arch)?;
123124

124125
// Get the kargs in kargs.d of the pending image
125126
let (fetched_tree, _) = repo.read_commit(fetched.ostree_commit.as_str(), cancellable)?;
@@ -179,6 +180,7 @@ fn parse_kargs_toml(contents: &str, sys_arch: &str) -> Result<Vec<String>> {
179180

180181
#[cfg(test)]
181182
mod tests {
183+
use cap_std_ext::cap_std;
182184
use fn_error_context::context;
183185
use rustix::fd::{AsFd, AsRawFd};
184186

lib/src/utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::future::Future;
22
use std::io::Write;
3+
use std::os::fd::BorrowedFd;
34
use std::process::Command;
45
use std::time::Duration;
56

67
use anyhow::{Context, Result};
8+
use cap_std_ext::cap_std::fs::Dir;
79
use ostree::glib;
810
use ostree_ext::container::SignatureSource;
911
use ostree_ext::ostree;
@@ -21,6 +23,24 @@ pub(crate) fn origin_has_rpmostree_stuff(kf: &glib::KeyFile) -> bool {
2123
false
2224
}
2325

26+
// Access the file descriptor for a sysroot
27+
#[allow(unsafe_code)]
28+
pub(crate) fn sysroot_fd(sysroot: &ostree::Sysroot) -> BorrowedFd {
29+
unsafe { BorrowedFd::borrow_raw(sysroot.fd()) }
30+
}
31+
32+
// Return a cap-std `Dir` type for a deployment.
33+
// TODO: in the future this should perhaps actually mount via composefs
34+
#[allow(unsafe_code)]
35+
pub(crate) fn deployment_fd(
36+
sysroot: &ostree::Sysroot,
37+
deployment: &ostree::Deployment,
38+
) -> Result<Dir> {
39+
let sysroot_dir = &Dir::reopen_dir(&sysroot_fd(sysroot))?;
40+
let dirpath = sysroot.deployment_dirpath(deployment);
41+
sysroot_dir.open_dir(&dirpath).map_err(Into::into)
42+
}
43+
2444
/// Given an mount option string list like foo,bar=baz,something=else,ro parse it and find
2545
/// the first entry like $optname=
2646
/// This will not match a bare `optname` without an equals.

0 commit comments

Comments
 (0)