-
Notifications
You must be signed in to change notification settings - Fork 127
install: Add reset #1389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cgwalters
wants to merge
2
commits into
bootc-dev:main
Choose a base branch
from
cgwalters:switch-stateroot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
install: Add reset #1389
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ use ostree_ext::oci_spec; | |
use ostree_ext::ostree; | ||
use ostree_ext::ostree_prepareroot::{ComposefsState, Tristate}; | ||
use ostree_ext::prelude::Cast; | ||
use ostree_ext::sysroot::SysrootLock; | ||
use ostree_ext::sysroot::{allocate_new_stateroot, list_stateroots, SysrootLock}; | ||
use ostree_ext::{container as ostree_container, ostree_prepareroot}; | ||
#[cfg(feature = "install-to-disk")] | ||
use rustix::fs::FileTypeExt; | ||
|
@@ -54,7 +54,9 @@ use serde::{Deserialize, Serialize}; | |
use self::baseline::InstallBlockDeviceOpts; | ||
use crate::boundimage::{BoundImage, ResolvedBoundImage}; | ||
use crate::containerenv::ContainerExecutionInfo; | ||
use crate::deploy::{prepare_for_pull, pull_from_prepared, PreparedImportMeta, PreparedPullResult}; | ||
use crate::deploy::{ | ||
prepare_for_pull, pull_from_prepared, MergeState, PreparedImportMeta, PreparedPullResult, | ||
}; | ||
use crate::lsm; | ||
use crate::progress_jsonl::ProgressWriter; | ||
use crate::spec::ImageReference; | ||
|
@@ -350,6 +352,50 @@ pub(crate) struct InstallToExistingRootOpts { | |
pub(crate) root_path: Utf8PathBuf, | ||
} | ||
|
||
#[derive(Debug, clap::Parser, PartialEq, Eq)] | ||
pub(crate) struct InstallResetOpts { | ||
/// Acknowledge that this command is experimental. | ||
#[clap(long)] | ||
pub(crate) experimental: bool, | ||
|
||
#[clap(flatten)] | ||
pub(crate) source_opts: InstallSourceOpts, | ||
|
||
#[clap(flatten)] | ||
pub(crate) target_opts: InstallTargetOpts, | ||
|
||
/// Name of the target stateroot. If not provided, one will be automatically | ||
/// generated of the form s<year>-<serial> where <serial> starts at zero and | ||
/// increments automatically. | ||
#[clap(long)] | ||
pub(crate) stateroot: Option<String>, | ||
|
||
/// Don't display progress | ||
#[clap(long)] | ||
pub(crate) quiet: bool, | ||
|
||
#[clap(flatten)] | ||
pub(crate) progress: crate::cli::ProgressOptions, | ||
|
||
/// Restart or reboot into the new target image. | ||
/// | ||
/// Currently, this option always reboots. In the future this command | ||
/// will detect the case where no kernel changes are queued, and perform | ||
/// a userspace-only restart. | ||
#[clap(long)] | ||
pub(crate) apply: bool, | ||
|
||
/// Skip inheriting any automatically discovered root file system kernel arguments. | ||
#[clap(long)] | ||
no_root_kargs: bool, | ||
|
||
/// Add a kernel argument. This option can be provided multiple times. | ||
/// | ||
/// Example: --karg=nosmt --karg=console=ttyS0,114800n8 | ||
#[clap(long)] | ||
karg: Option<Vec<String>>, | ||
} | ||
|
||
/// Global state captured from the container. | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct SourceInfo { | ||
|
@@ -383,6 +429,24 @@ pub(crate) struct State { | |
pub(crate) tempdir: TempDir, | ||
} | ||
|
||
impl InstallTargetOpts { | ||
pub(crate) fn imageref(&self) -> Result<Option<ostree_container::OstreeImageReference>> { | ||
let Some(target_imgname) = self.target_imgref.as_deref() else { | ||
return Ok(None); | ||
}; | ||
let target_transport = | ||
ostree_container::Transport::try_from(self.target_transport.as_str())?; | ||
let target_imgref = ostree_container::OstreeImageReference { | ||
sigverify: ostree_container::SignatureSource::ContainerPolicyAllowInsecure, | ||
imgref: ostree_container::ImageReference { | ||
transport: target_transport, | ||
name: target_imgname.to_string(), | ||
}, | ||
}; | ||
Ok(Some(target_imgref)) | ||
} | ||
} | ||
|
||
impl State { | ||
#[context("Loading SELinux policy")] | ||
pub(crate) fn load_policy(&self) -> Result<Option<ostree::SePolicy>> { | ||
|
@@ -1964,6 +2028,94 @@ pub(crate) async fn install_to_existing_root(opts: InstallToExistingRootOpts) -> | |
install_to_filesystem(opts, true, cleanup).await | ||
} | ||
|
||
pub(crate) async fn install_reset(opts: InstallResetOpts) -> Result<()> { | ||
let rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?; | ||
if !opts.experimental { | ||
anyhow::bail!("This command requires --experimental"); | ||
} | ||
|
||
let prog: ProgressWriter = opts.progress.try_into()?; | ||
|
||
let sysroot = &crate::cli::get_storage().await?; | ||
let repo = &sysroot.repo(); | ||
let (booted_deployment, _deployments, host) = | ||
crate::status::get_status_require_booted(sysroot)?; | ||
|
||
let stateroots = list_stateroots(sysroot)?; | ||
dbg!(&stateroots); | ||
let target_stateroot = if let Some(s) = opts.stateroot { | ||
s | ||
} else { | ||
let now = chrono::Utc::now(); | ||
let r = allocate_new_stateroot(&sysroot, &stateroots, now)?; | ||
r.name | ||
}; | ||
|
||
let booted_stateroot = booted_deployment.osname(); | ||
assert!(booted_stateroot.as_str() != target_stateroot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using anyhow::ensure!(
booted_stateroot.as_str() != target_stateroot,
"Target stateroot cannot be the same as the booted one"
); |
||
let (fetched, spec) = if let Some(target) = opts.target_opts.imageref()? { | ||
let mut new_spec = host.spec; | ||
new_spec.image = Some(target.into()); | ||
let fetched = crate::deploy::pull( | ||
repo, | ||
&new_spec.image.as_ref().unwrap(), | ||
None, | ||
opts.quiet, | ||
prog.clone(), | ||
) | ||
.await?; | ||
(fetched, new_spec) | ||
} else { | ||
let imgstate = host | ||
.status | ||
.booted | ||
.map(|b| b.query_image(repo)) | ||
.transpose()? | ||
.flatten() | ||
.ok_or_else(|| anyhow::anyhow!("No image source specified"))?; | ||
(Box::new((*imgstate).into()), host.spec) | ||
}; | ||
let spec = crate::deploy::RequiredHostSpec::from_spec(&spec)?; | ||
|
||
// Compute the kernel arguments to inherit. By default, that's only those involved | ||
// in the root filesystem. | ||
let root_kargs = if opts.no_root_kargs { | ||
Vec::new() | ||
} else { | ||
let bootcfg = booted_deployment | ||
.bootconfig() | ||
.ok_or_else(|| anyhow!("Missing bootcfg for booted deployment"))?; | ||
if let Some(options) = bootcfg.get("options") { | ||
let options = options.split_ascii_whitespace().collect::<Vec<_>>(); | ||
crate::kernel::root_args_from_cmdline(&options) | ||
.into_iter() | ||
.map(ToOwned::to_owned) | ||
.collect::<Vec<_>>() | ||
} else { | ||
Vec::new() | ||
} | ||
}; | ||
|
||
let kargs = crate::kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)? | ||
.into_iter() | ||
.chain(root_kargs.into_iter()) | ||
.chain(opts.karg.unwrap_or_default()) | ||
.collect::<Vec<_>>(); | ||
|
||
let from = MergeState::Reset { | ||
stateroot: target_stateroot, | ||
kargs, | ||
}; | ||
crate::deploy::stage(sysroot, from, &fetched, &spec, prog.clone()).await?; | ||
|
||
sysroot.update_mtime()?; | ||
|
||
if opts.apply { | ||
crate::reboot::reboot()?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Implementation of `bootc install finalize`. | ||
pub(crate) async fn install_finalize(target: &Utf8Path) -> Result<()> { | ||
crate::cli::require_root(false)?; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
dbg!
macro call appears to be leftover from debugging. It should be removed before merging to keep the command's output clean.