Skip to content

Commit c83639d

Browse files
copy-to-storage: Fix deadlock in ostree path
The sysroot lock was being taken by `get_host` before it was released by the caller. Move the `get_host` function up the stack of calls Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 4b7c12d commit c83639d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

crates/lib/src/bootc_composefs/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn export_repo_to_image(
2626
) -> Result<()> {
2727
let host = get_composefs_status(storage, booted_cfs).await?;
2828

29-
let (source, dest_imgref) = get_imgrefs_for_copy(source, target).await?;
29+
let (source, dest_imgref) = get_imgrefs_for_copy(&host, source, target).await?;
3030

3131
let mut depl_verity = None;
3232

crates/lib/src/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::podstorage::set_additional_image_store;
4747
use crate::progress_jsonl::{ProgressWriter, RawProgressFd};
4848
use crate::spec::Host;
4949
use crate::spec::ImageReference;
50+
use crate::status::get_host;
5051
use crate::store::{BootedOstree, Storage};
5152
use crate::store::{BootedStorage, BootedStorageKind};
5253
use crate::utils::sigpolicy_from_opt;
@@ -1588,12 +1589,16 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
15881589
} => crate::image::list_entrypoint(list_type, list_format).await,
15891590

15901591
ImageOpts::CopyToStorage { source, target } => {
1592+
// We get "host" here to avoid deadlock in the ostree path
1593+
let host = get_host().await?;
1594+
15911595
let storage = get_storage().await?;
15921596

15931597
match storage.kind()? {
15941598
BootedStorageKind::Ostree(..) => {
15951599
crate::image::push_entrypoint(
15961600
&storage,
1601+
&host,
15971602
source.as_deref(),
15981603
target.as_deref(),
15991604
)

crates/lib/src/image.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
boundimage::query_bound_images,
1616
cli::{ImageListFormat, ImageListType},
1717
podstorage::CStorage,
18-
status::get_host,
18+
spec::Host,
1919
store::Storage,
2020
utils::async_task_with_spinner,
2121
};
@@ -145,6 +145,7 @@ pub(crate) async fn list_entrypoint(
145145
/// If the source isn't specified, we use booted image
146146
/// If the target isn't specified, we push to containers-storage with our default image
147147
pub(crate) async fn get_imgrefs_for_copy(
148+
host: &Host,
148149
source: Option<&str>,
149150
target: Option<&str>,
150151
) -> Result<(ImageReference, ImageReference)> {
@@ -169,18 +170,17 @@ pub(crate) async fn get_imgrefs_for_copy(
169170
.context("Parsing source image")?,
170171

171172
None => {
172-
let host = get_host().await?;
173-
174173
let booted = host
175174
.status
176175
.booted
176+
.as_ref()
177177
.ok_or_else(|| anyhow::anyhow!("Booted deployment not found"))?;
178178

179-
let booted_image = booted.image.unwrap().image;
179+
let booted_image = &booted.image.as_ref().unwrap().image;
180180

181181
ImageReference {
182182
transport: Transport::try_from(booted_image.transport.as_str()).unwrap(),
183-
name: booted_image.image,
183+
name: booted_image.image.clone(),
184184
}
185185
}
186186
};
@@ -192,10 +192,11 @@ pub(crate) async fn get_imgrefs_for_copy(
192192
#[context("Pushing image")]
193193
pub(crate) async fn push_entrypoint(
194194
storage: &Storage,
195+
host: &Host,
195196
source: Option<&str>,
196197
target: Option<&str>,
197198
) -> Result<()> {
198-
let (source, target) = get_imgrefs_for_copy(source, target).await?;
199+
let (source, target) = get_imgrefs_for_copy(host, source, target).await?;
199200

200201
let ostree = storage.get_ostree()?;
201202
let repo = &ostree.repo();

0 commit comments

Comments
 (0)