Skip to content

Commit d1b02a4

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 0b513f8 commit d1b02a4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

crates/lib/src/bootc_composefs/status.rs

Lines changed: 24 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::run_findmnt;
56
use fn_error_context::context;
67

78
use crate::{
@@ -76,7 +77,29 @@ 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 findmnt = run_findmnt(&[], None, None)?;
83+
84+
let root_mnt = findmnt
85+
.filesystems
86+
.iter()
87+
.find(|fs| fs.target == "/")
88+
.ok_or_else(|| anyhow::anyhow!("Failed to get root mountpoint"))?;
89+
90+
// This is of the format composefs:<composefs_hash>
91+
let verity_from_mount_src = root_mnt
92+
.source
93+
.strip_prefix("composefs:")
94+
.ok_or_else(|| anyhow::anyhow!("Root not mounted using composefs"))?;
95+
96+
let r = if *verity_from_mount_src != *v.digest {
97+
// soft rebooted into another deployment
98+
CACHED_DIGEST_VALUE.get_or_init(|| Some(ComposefsCmdline::new(verity_from_mount_src)))
99+
} else {
100+
CACHED_DIGEST_VALUE.get_or_init(|| Some(v))
101+
};
102+
80103
Ok(r.as_ref())
81104
}
82105

0 commit comments

Comments
 (0)