Skip to content
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

WIP: Handle ro /boot #116

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ pub(crate) enum ComponentUpdateResult {
},
}

fn ensure_writable_mount<P: AsRef<Path>>(p: P) -> Result<()> {
use nix::sys::statvfs;
let p = p.as_ref();
let stat = statvfs::statvfs(p)?;
if !stat.flags().contains(statvfs::FsFlags::ST_RDONLY) {
return Ok(());
}
let status = std::process::Command::new("mount")
.args(&["-o", "remount,rw"])
.arg(p.as_os_str())
Copy link
Member

@kelvinfan001 kelvinfan001 Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly pass p here without as_os_str() since Path implements the AsRef<OsStr> trait right?

.status()?;
if !status.success() {
anyhow::bail!("Failed to remount {:?} writable", p);
}
Ok(())
}

fn ensure_writable_boot() -> Result<()> {
ensure_writable_mount("/boot")
}

/// daemon implementation of component update
pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
let mut state = SavedState::load_from_disk("/")?.unwrap_or_default();
Expand All @@ -109,6 +130,8 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
_ => return Ok(ComponentUpdateResult::AtLatestVersion),
};

ensure_writable_boot()?;

let mut pending_container = state.pending.take().unwrap_or_default();
let interrupted = pending_container.get(component.name()).cloned();
pending_container.insert(component.name().into(), update.clone());
Expand Down Expand Up @@ -145,6 +168,8 @@ pub(crate) fn adopt_and_update(name: &str) -> Result<ContentMetadata> {
} else {
anyhow::bail!("Component {} has no available update", name);
};
ensure_writable_boot()?;

let mut state_guard =
SavedState::acquire_write_lock(sysroot).context("Failed to acquire write lock")?;

Expand Down