Skip to content

Commit 689692d

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 <[email protected]>
1 parent 7a5dce0 commit 689692d

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

78
use crate::{
@@ -76,7 +77,23 @@ pub(crate) fn composefs_booted() -> Result<Option<&'static ComposefsCmdline>> {
7677
};
7778
let Some(v) = kv.value() else { return Ok(None) };
7879
let v = ComposefsCmdline::new(v);
79-
let r = CACHED_DIGEST_VALUE.get_or_init(|| Some(v));
80+
81+
// Find the source of / mountpoint as the cmdline doesn't change on soft-reboot
82+
let root_mnt = inspect_filesystem("/".into())?;
83+
84+
// This is of the format composefs:<composefs_hash>
85+
let verity_from_mount_src = root_mnt
86+
.source
87+
.strip_prefix("composefs:")
88+
.ok_or_else(|| anyhow::anyhow!("Root not mounted using composefs"))?;
89+
90+
let r = if *verity_from_mount_src != *v.digest {
91+
// soft rebooted into another deployment
92+
CACHED_DIGEST_VALUE.get_or_init(|| Some(ComposefsCmdline::new(verity_from_mount_src)))
93+
} else {
94+
CACHED_DIGEST_VALUE.get_or_init(|| Some(v))
95+
};
96+
8097
Ok(r.as_ref())
8198
}
8299

0 commit comments

Comments
 (0)