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

install: Only switch to loopback after re-exec #278

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl LoopbackDevice {
.quiet()
.read()?;
let dev = Utf8PathBuf::from(dev.trim());
tracing::debug!("Allocated loopback {dev}");
Ok(Self { dev: Some(dev) })
}

Expand All @@ -104,6 +105,7 @@ impl LoopbackDevice {
let dev = if let Some(dev) = self.dev.take() {
dev
} else {
tracing::trace!("loopback device already deallocated");
return Ok(());
};
Task::new("losetup", "losetup")
Expand Down
22 changes: 15 additions & 7 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,27 +1088,35 @@ pub(crate) async fn install_to_disk(opts: InstallToDiskOpts) -> Result<()> {
.device
.metadata()
.with_context(|| format!("Querying {}", &block_opts.device))?;
let mut loopback = None;
if opts.via_loopback {
if !target_blockdev_meta.file_type().is_file() {
anyhow::bail!(
"Not a regular file (to be used via loopback): {}",
block_opts.device
);
}
let loopback_dev = crate::blockdev::LoopbackDevice::new(block_opts.device.as_std_path())?;
block_opts.device = loopback_dev.path().into();
loopback = Some(loopback_dev);
} else if !target_blockdev_meta.file_type().is_block_device() {
anyhow::bail!("Not a block device: {}", block_opts.device);
}
let state = prepare_install(opts.config_opts, opts.source_opts, opts.target_opts).await?;

// This is all blocking stuff
let mut rootfs = {
let (mut rootfs, loopback) = {
let loopback_dev = if opts.via_loopback {
let loopback_dev =
crate::blockdev::LoopbackDevice::new(block_opts.device.as_std_path())?;
block_opts.device = loopback_dev.path().into();
Some(loopback_dev)
} else {
None
};

let state = state.clone();
tokio::task::spawn_blocking(move || baseline::install_create_rootfs(&state, block_opts))
.await??
let rootfs = tokio::task::spawn_blocking(move || {
baseline::install_create_rootfs(&state, block_opts)
})
.await??;
(rootfs, loopback_dev)
};

install_to_filesystem_impl(&state, &mut rootfs).await?;
Expand Down
Loading