Skip to content

More work on ostree - #338

Merged
alexlarsson merged 9 commits into
mainfrom
ostree-fixes
Jul 1, 2026
Merged

alexlarsson merged 9 commits into
mainfrom
ostree-fixes

Conversation

@alexlarsson

Copy link
Copy Markdown
Contributor

This adds some fixes and cleanups to the ostree support, adds a list-refs command, and then adds support for ostree summaries and static deltas.

Also, there is a fix to FsVerityHasher that may be important to non-ostree users as well.

Comment thread crates/composefs/src/fsverity/digest.rs Resolved
Comment thread crates/composefs/src/fsverity/digest.rs Outdated
layers: vec![],
value: None,
n_bytes: 0,
partial: Vec::new(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure how you meant it to be used.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A BytesMut is a special cased more powerful version of Vec<u8> basically that is designed specifically for "buffer" use cases, but anyways not blocking

Comment thread crates/composefs/src/fsverity/digest.rs Resolved
FsVerityHasher::add_block() requires block-aligned input (exactly
BLOCK_SIZE bytes, except for the final block). Both
ensure_object_from_reader() and compute_verity_digest() fed it
variable-sized chunks directly from BufReader::fill_buf(), which
can return less than a full block at any time. This caused incorrect
Merkle tree computation, producing different fs-verity digests for
the same file content depending on how the reader chunked the data.

Fix by adding FsVerityHasher::write() which accepts arbitrary-sized
input and handles block buffering internally. Any partial block is
flushed when digest() is called. Both callers now use write()
instead of add_block().

Assisted-by: Claude Code (Opus 4.6)
Signed-off-by: Alexander Larsson <[email protected]>
Ostree canonicalizes symlinks to size 0, not the size of the symlink.

Assisted-by: Claude Code (Opus 4.6)
Signed-off-by: Alexander Larsson <[email protected]>
We're gonna use some of the these in the public API, and these are anyway
very stable formats.

Signed-off-by: Alexander Larsson <[email protected]>
Various cleanups to the pull CLI operation:
 * We now use a shared progress reported, no eprint!
 * There is only one pull(), and it takes either a LocalRepo or a RemoteRepo
 * Pull options are passed via an extensible options struct

Signed-off-by: Alexander Larsson <[email protected]>
This downloads and caches ostree summaries and flatpak-style
subsummaries and uses them to resolve refs. Summaries
are cached by ETAG or last modified, while subsummaries are
cached by the checksum (which is in the index).

Signed-off-by: Alexander Larsson <[email protected]>
Add support for applying ostree static deltas to the composefs
repository via a new `cfsctl ostree apply-delta` CLI command.

The implementation includes:
- Custom GVariant framing parser for the delta superblock that avoids
  loading the entire file into memory (important for large inline
  deltas). Only the offset table and key strings are cached; inline
  part payloads are read on demand via pread.
- Delta part executor supporting all 7 ostree opcodes:
  OPEN_SPLICE_AND_CLOSE, OPEN, WRITE, SET_READ_SOURCE,
  UNSET_READ_SOURCE, CLOSE, and BSPATCH.
- Base commit object inheritance: walks the new commit's DAG and
  copies unchanged objects from the base commit's splitstream,
  since composefs-rs requires each commit splitstream to be
  self-contained.
- Proper symlink handling (size includes NUL terminator, content
  not duplicated in the file header).

Tested with a real ostree delta (gedit flatpak update) and verified
that the resulting commit splitstream and EROFS image are
byte-identical to a direct pull of the same commit.

Assisted-by: Claude Code (Opus 4.6)
Signed-off-by: Alexander Larsson <[email protected]>
When pulling from a remote ostree repository, check for available
static deltas before falling back to object-by-object fetching.
This is significantly faster for large commits.

Delta discovery checks two sources:
- The summary metadata's `ostree.static-deltas` key
- Per-commit delta indexes at `delta-indexes/{b64}.index`

When a usable delta is found (scratch or differential from a locally
available commit), the superblock and parts are fetched from the
remote. Parts are pipelined: the next part is fetched while the
current one is decompressed and applied via spawn_blocking.
Fallback objects (large files not included in delta parts) are
fetched using the existing fetch_file/fetch_object methods.

Also adds `PullStats::delta_parts_applied` to track delta usage,
and a `print_pull_stats` helper in the CLI that shows "via N delta
parts" when deltas were used.

Assisted-by: Claude Code (Opus 4.6)
Signed-off-by: Alexander Larsson <[email protected]>
Add three new tests:
- test_ostree_pull_remote_scratch_delta: generates a from-scratch
  delta, serves over HTTP, pulls via delta, verifies image matches
  a direct local pull
- test_ostree_pull_remote_diff_delta: generates a differential delta
  between two commits, pulls the base first, then the target via
  delta, verifies image matches
- test_ostree_apply_delta_offline: generates an inline delta file,
  applies it via apply_delta_offline, verifies image matches

Also refactors the existing test_ostree_pull_remote_archive to use
a shared HttpServer helper (RAII cleanup via Drop).

Assisted-by: Claude Code (Opus 4.6)
Signed-off-by: Alexander Larsson <[email protected]>
#[cfg(any(feature = "oci", feature = "ostree"))]
use comfy_table::{Table, presets::UTF8_FULL};
#[cfg(any(feature = "oci", feature = "http"))]
#[cfg(any(feature = "oci", feature = "http", feature = "ostree"))]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we can consolidate to a single #[cfg(content_fetching)] or so

Comment thread crates/composefs-ostree/src/repo.rs Resolved
Comment on lines +224 to +229
let mut ss = repo.create_stream(OSTREE_SUMMARY_CONTENT_TYPE)?;
ss.write_inline(header.as_bytes());
ss.write_inline(etag_bytes);
ss.write_inline(lm_bytes);
ss.write_inline(summary_data);
repo.write_stream(ss, stream_id, None)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nonblocking but just thinking: I'd like to make it feel nice again to store externally defined content without touching composefs core. I could imagine for example this use case is basically "store summary as OCI artifact" for example.

(Of course we could make that even more formal outside of this project)

It is basically arguing for composefs-ostree to depend on composefs-oci in a way, or at least parts of it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case (ostree) we need the data file (the summary) in the repo for internal use, but is there really any particular reason for a user facing store arbitrary single file blobs in the composefs repo? You're unlikely to put it into a composefs image or otherwise get dedup from this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Like, I imagine storing random directories of content in the repo is useful, like builds or what have you, but single file artifacts? What is the point?

Comment thread crates/composefs-ostree/src/delta.rs Resolved
Comment thread crates/composefs-ostree/src/delta.rs Resolved
Comment thread crates/composefs-ostree/src/delta.rs Resolved

[dependencies]
anyhow = { version = "1.0.87", default-features = false }
bsdiff = { version = "0.2.1", default-features = false }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have you looked that this is equivalent to the C code vendored in libostree? I suspect There Be 🐉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would think that if bsdiff apply produced a different result thatn the C code we would detect this as it would produce a different checksum for the new ostree object. However, I see we're not actually validating the produced checksums in the delta apply case, will fix that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(added the checksum check)

Comment thread crates/composefs-ostree/src/ostree.rs Resolved
///
/// `base` is needed to resolve `SET_READ_SOURCE` opcodes that reference
/// objects from the previous commit.
pub(crate) fn execute_delta_part<ObjectID: FsVerityHashValue>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Likely worth wiring up to the fuzzing infra we have

@alexlarsson

Copy link
Copy Markdown
Contributor Author

I'll merge this and do later followups separately.

@alexlarsson
alexlarsson added this pull request to the merge queue Jul 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 1, 2026
@alexlarsson
alexlarsson added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit 5ebda42 Jul 1, 2026
18 checks passed
@alexlarsson

Copy link
Copy Markdown
Contributor Author

I resolved all comments fixed in #340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants