Skip to content

Commit 8ef418d

Browse files
composefs: Don't soft-reboot automatically
Aligning with ostree API, now we only initiate soft-reboot if `--apply` is passed to `bootc update`, `bootc switch`, else we only prepare the soft reboot Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 8bd27e2 commit 8ef418d

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

crates/lib/src/bootc_composefs/soft_reboot.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
bootc_composefs::{
33
service::start_finalize_stated_svc, status::composefs_deployment_status_from,
44
},
5+
cli::SoftRebootMode,
56
composefs_consts::COMPOSEFS_CMDLINE,
67
store::{BootedComposefs, Storage},
78
};
@@ -21,7 +22,7 @@ use std::{fs::create_dir_all, os::unix::process::CommandExt, path::PathBuf, proc
2122
const NEXTROOT: &str = "/run/nextroot";
2223

2324
#[context("Resetting soft reboot state")]
24-
fn reset_soft_reboot() -> Result<()> {
25+
pub(crate) fn reset_soft_reboot() -> Result<()> {
2526
let run = Utf8Path::new("/run");
2627
bind_mount_from_pidns(PID1, &run, &run, true).context("Bind mounting /run")?;
2728

@@ -61,17 +62,13 @@ pub(crate) async fn prepare_soft_reboot_composefs(
6162
storage: &Storage,
6263
booted_cfs: &BootedComposefs,
6364
deployment_id: Option<&String>,
65+
soft_reboot_mode: SoftRebootMode,
6466
reboot: bool,
65-
reset: bool,
6667
) -> Result<()> {
6768
if !systemd_has_soft_reboot() {
6869
anyhow::bail!("System does not support soft reboots")
6970
}
7071

71-
if reset {
72-
return reset_soft_reboot();
73-
}
74-
7572
let deployment_id = deployment_id.ok_or_else(|| anyhow::anyhow!("Expected deployment id"))?;
7673

7774
if *deployment_id == *booted_cfs.cmdline.digest {
@@ -89,7 +86,13 @@ pub(crate) async fn prepare_soft_reboot_composefs(
8986
.ok_or_else(|| anyhow::anyhow!("Deployment '{deployment_id}' not found"))?;
9087

9188
if !requred_deployment.soft_reboot_capable {
92-
anyhow::bail!("Cannot soft-reboot to deployment with a different kernel state");
89+
match soft_reboot_mode {
90+
SoftRebootMode::Required => {
91+
anyhow::bail!("Cannot soft-reboot to deployment with a different kernel state")
92+
}
93+
94+
SoftRebootMode::Auto => return Ok(()),
95+
}
9396
}
9497

9598
start_finalize_stated_svc()?;

crates/lib/src/bootc_composefs/update.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,21 @@ pub(crate) async fn do_upgrade(
262262
)
263263
.await?;
264264

265+
if let Some(soft_reboot_mode) = opts.soft_reboot {
266+
return prepare_soft_reboot_composefs(
267+
storage,
268+
booted_cfs,
269+
Some(&id.to_hex()),
270+
soft_reboot_mode,
271+
opts.apply,
272+
)
273+
.await;
274+
};
275+
265276
if opts.apply {
266277
return crate::reboot::reboot();
267278
}
268279

269-
if opts.soft_reboot.is_some() {
270-
prepare_soft_reboot_composefs(storage, booted_cfs, Some(&id.to_hex()), true, false).await?;
271-
}
272-
273280
Ok(())
274281
}
275282

crates/lib/src/cli.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use schemars::schema_for;
3434
use serde::{Deserialize, Serialize};
3535

3636
use crate::bootc_composefs::delete::delete_composefs_deployment;
37-
use crate::bootc_composefs::soft_reboot::prepare_soft_reboot_composefs;
37+
use crate::bootc_composefs::soft_reboot::{prepare_soft_reboot_composefs, reset_soft_reboot};
3838
use crate::bootc_composefs::{
3939
digest::{compute_composefs_digest, new_temp_composefs_repo},
4040
finalize::{composefs_backend_finalize, get_etc_diff},
@@ -624,7 +624,6 @@ pub(crate) enum InternalsOpts {
624624
reboot: bool,
625625
#[clap(long, conflicts_with = "reboot")]
626626
reset: bool,
627-
reboot: bool,
628627
},
629628
}
630629

@@ -1850,13 +1849,18 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
18501849
// TODO: Call ostree implementation?
18511850
anyhow::bail!("soft-reboot only implemented for composefs")
18521851
}
1852+
18531853
BootedStorageKind::Composefs(booted_cfs) => {
1854+
if reset {
1855+
return reset_soft_reboot();
1856+
}
1857+
18541858
prepare_soft_reboot_composefs(
18551859
&storage,
18561860
&booted_cfs,
18571861
deployment.as_ref(),
1862+
SoftRebootMode::Required,
18581863
reboot,
1859-
reset,
18601864
)
18611865
.await
18621866
}

0 commit comments

Comments
 (0)