Skip to content

Commit 9d3cb1e

Browse files
committed
Apply OCI deltas with the ostree backend
`bootc upgrade --from-delta` and `bootc switch --from-delta` worked only with the composefs backend. Wire them up for ostree too. A tar-diff patch reads the source image by *path*, not from the original tar byte stream, so the source does not have to be a container layer: an ostree commit holding the same filesystem works just as well. `OstreeDataSource` serves file content out of a commit, and `DeltaLayerSource` plugs that into the container importer in place of the image proxy, so nothing is fetched. ostree does not store an image's root filesystem verbatim - the tar importer moves `/etc` to `/usr/etc`, and `/var` to `/usr/share/factory/var` on ostree older than v2024.3 - so a source path is tried at each of the locations that importer could have put it. Each reconstructed layer is streamed to the importer over a pipe, with the reconstruction itself running as the driver future that `join_fetch` already polls concurrently, so a multi-GB base layer never has to be spooled to disk. The source image is looked up by config digest among the images in the repository, and an absent source is fatal: there is no guarantee of a network connection at the point a delta is applied, so falling back to the registry would defeat the purpose. Byte-level progress is not reported for delta layers: the reconstructed bytes are uncompressed, so counting them against the descriptor's compressed size would overshoot. Per-layer start/completion still is. A layer's ref is written as the layer is unpacked, i.e. before the driver future has had the chance to report a diff_id mismatch, so a failed apply can leave a ref to unverified content that a retry would reuse. Prune the unreferenced layers after a failed delta apply. Also, `switch --from-delta` no longer short-circuits when the image specification is unchanged - a delta names one specific target digest, and switching to the reference you are already tracking is exactly how it is normally used. Assisted-by: AI Signed-off-by: Alexander Larsson <alexl@redhat.com>
1 parent 654b659 commit 9d3cb1e

5 files changed

Lines changed: 594 additions & 38 deletions

File tree

‎crates/lib/src/cli.rs‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,9 @@ async fn upgrade(
12841284
storage: &Storage,
12851285
booted_ostree: &BootedOstree<'_>,
12861286
) -> Result<()> {
1287-
crate::delta::reject_unsupported(opts.from_delta.as_deref())?;
1287+
let delta = crate::delta::open_opt(opts.from_delta.as_deref())
1288+
.await?
1289+
.map(std::sync::Arc::new);
12881290

12891291
let repo = &booted_ostree.repo();
12901292

@@ -1349,6 +1351,9 @@ async fn upgrade(
13491351
// needs this for update_mtime() and the non-check path needs it for
13501352
// unified pull detection.
13511353
let use_unified = crate::deploy::image_exists_in_unified_storage(storage, imgref).await?;
1354+
if let Some(delta) = delta.as_deref() {
1355+
crate::delta::reject_unified_storage(delta, use_unified)?;
1356+
}
13521357

13531358
if opts.check {
13541359
let ostree_imgref = imgref.clone().into();
@@ -1375,7 +1380,17 @@ async fn upgrade(
13751380
}
13761381
}
13771382
} else {
1378-
let fetched = if use_unified {
1383+
let fetched = if let Some(delta) = delta.clone() {
1384+
crate::deploy::pull_delta(
1385+
repo,
1386+
imgref,
1387+
delta,
1388+
opts.quiet,
1389+
prog.clone(),
1390+
Some(&booted_ostree.deployment),
1391+
)
1392+
.await?
1393+
} else if use_unified {
13791394
crate::deploy::pull_unified(
13801395
repo,
13811396
imgref,
@@ -1512,7 +1527,9 @@ async fn switch_ostree(
15121527
storage: &Storage,
15131528
booted_ostree: &BootedOstree<'_>,
15141529
) -> Result<()> {
1515-
crate::delta::reject_unsupported(opts.from_delta.as_deref())?;
1530+
let delta = crate::delta::open_opt(opts.from_delta.as_deref())
1531+
.await?
1532+
.map(std::sync::Arc::new);
15161533

15171534
let (_, host) = crate::status::get_status(booted_ostree)?;
15181535

@@ -1577,8 +1594,21 @@ async fn switch_ostree(
15771594
} else {
15781595
crate::deploy::image_exists_in_unified_storage(storage, &target).await?
15791596
};
1597+
if let Some(delta) = delta.as_deref() {
1598+
crate::delta::reject_unified_storage(delta, use_unified)?;
1599+
}
15801600

1581-
let fetched = if use_unified {
1601+
let fetched = if let Some(delta) = delta.clone() {
1602+
crate::deploy::pull_delta(
1603+
repo,
1604+
&target,
1605+
delta,
1606+
opts.quiet,
1607+
prog.clone(),
1608+
Some(&booted_ostree.deployment),
1609+
)
1610+
.await?
1611+
} else if use_unified {
15821612
crate::deploy::pull_unified(
15831613
repo,
15841614
&target,

‎crates/lib/src/delta.rs‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub(crate) struct Delta {
9797
pub(crate) path: Utf8PathBuf,
9898
/// Parsed information about the delta.
9999
pub(crate) parsed: ParsedDelta,
100+
config: ImageConfiguration,
101+
layout: Layout,
100102
}
101103

102104
impl Delta {
@@ -107,13 +109,22 @@ impl Delta {
107109
let layout = Layout::open(path)?;
108110
let parsed = parse(&layout).await?;
109111

110-
validate(&parsed)?;
112+
let config = validate(&parsed)?;
111113
Ok(Self {
112114
path: path.to_owned(),
113115
parsed,
116+
config,
117+
layout,
114118
})
115119
}
116120

121+
/// Open the patch blob `desc`
122+
pub(crate) fn read_patch(&self, desc: &Descriptor) -> Result<Box<dyn BlobStream>> {
123+
self.layout
124+
.read_blob(desc)
125+
.with_context(|| format!("Reading delta patch {}", desc.digest()))
126+
}
127+
117128
/// The digest of the target image's manifest, as recorded in the delta.
118129
pub(crate) fn target_manifest_digest(&self) -> &Digest {
119130
self.parsed.target_manifest_descriptor.digest()
@@ -148,6 +159,11 @@ impl Delta {
148159
&self.parsed.target_manifest
149160
}
150161

162+
/// The target image's config.
163+
pub(crate) fn target_config(&self) -> &ImageConfiguration {
164+
&self.config
165+
}
166+
151167
/// The config digest of the image this delta was built against.
152168
pub(crate) fn source_config_digest(&self) -> &Digest {
153169
&self.parsed.source_config_digest
@@ -196,14 +212,6 @@ pub(crate) async fn open_opt(path: Option<&Utf8Path>) -> Result<Option<Delta>> {
196212
}
197213
}
198214

199-
/// Reject `--from-delta` on a storage backend that cannot apply one yet.
200-
pub(crate) fn reject_unsupported(path: Option<&Utf8Path>) -> Result<()> {
201-
match path {
202-
Some(path) => bail!("--from-delta ({path}) is not supported by the ostree backend yet"),
203-
None => Ok(()),
204-
}
205-
}
206-
207215
/// Reject `--from-delta` for an image that also has to be in containers-storage.
208216
pub(crate) fn reject_unified_storage(delta: &Delta, use_unified: bool) -> Result<()> {
209217
ensure!(
@@ -215,7 +223,7 @@ pub(crate) fn reject_unified_storage(delta: &Delta, use_unified: bool) -> Result
215223
}
216224

217225
/// Check the delta's internal consistency, to fail early
218-
fn validate(p: &ParsedDelta) -> Result<()> {
226+
fn validate(p: &ParsedDelta) -> Result<ImageConfiguration> {
219227
verify_digest(
220228
"Embedded target manifest",
221229
&p.target_manifest_raw,
@@ -253,7 +261,7 @@ fn validate(p: &ParsedDelta) -> Result<()> {
253261
);
254262
}
255263

256-
Ok(())
264+
Ok(config)
257265
}
258266

259267
/// Read the single manifest out of an OCI layout and parse it as a delta.
@@ -637,13 +645,6 @@ pub(crate) mod tests {
637645
}
638646
}
639647

640-
#[test]
641-
fn test_reject_unsupported() {
642-
reject_unsupported(None).unwrap();
643-
let err = reject_unsupported(Some(Utf8Path::new("/d"))).unwrap_err();
644-
assert!(format!("{err:#}").contains("ostree backend"));
645-
}
646-
647648
#[test]
648649
fn test_verify_digest() {
649650
let expected: Digest =

0 commit comments

Comments
 (0)