Skip to content

Commit 06f9082

Browse files
composefs: Handle bootc status after a soft reboot
After a soft reboot the kernel cmdline doesn't change so we can't rely on the `composefs=` parameter in the cmdline. Instead, we check the source of the root mount point Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 80b9332 commit 06f9082

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

crates/lib/src/bootc_composefs/status.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{io::Read, sync::OnceLock};
22

33
use anyhow::{Context, Result};
44
use bootc_kernel_cmdline::utf8::Cmdline;
5+
use bootc_mount::inspect_filesystem;
56
use fn_error_context::context;
67
use serde::{Deserialize, Serialize};
78

@@ -86,7 +87,23 @@ pub(crate) fn composefs_booted() -> Result<Option<&'static ComposefsCmdline>> {
8687
};
8788
let Some(v) = kv.value() else { return Ok(None) };
8889
let v = ComposefsCmdline::new(v);
89-
let r = CACHED_DIGEST_VALUE.get_or_init(|| Some(v));
90+
91+
// Find the source of / mountpoint as the cmdline doesn't change on soft-reboot
92+
let root_mnt = inspect_filesystem("/".into())?;
93+
94+
// This is of the format composefs:<composefs_hash>
95+
let verity_from_mount_src = root_mnt
96+
.source
97+
.strip_prefix("composefs:")
98+
.ok_or_else(|| anyhow::anyhow!("Root not mounted using composefs"))?;
99+
100+
let r = if *verity_from_mount_src != *v.digest {
101+
// soft rebooted into another deployment
102+
CACHED_DIGEST_VALUE.get_or_init(|| Some(ComposefsCmdline::new(verity_from_mount_src)))
103+
} else {
104+
CACHED_DIGEST_VALUE.get_or_init(|| Some(v))
105+
};
106+
90107
Ok(r.as_ref())
91108
}
92109

0 commit comments

Comments
 (0)