0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/disk
HuJK 5efff66cf2 disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots
Three things a phone-hosted qcow2 overlay needs and did not have.

A discard over a backing file has to make a ZERO CLUSTER, not zeroes. Without
QCOW_OFLAG_ZERO the only way to say "this cluster reads as zeroes even though
the backing file has data here" is to allocate a cluster and write zeroes into
it, so a guest fstrim over a 32 GB image grows the overlay by 32 GB -- measured,
and the reason this exists. With the flag the same fstrim leaves the overlay at
327 MiB. COMPRESSED is tested before ZERO everywhere the pair is matched: a
compressed L2 descriptor keeps a byte offset in its low bits, so bit 0 is set
for about half of all compressed clusters, and testing ZERO first hands back a
freshly zeroed cluster instead of decompressing -- silent data loss.

The zstd feature is backed by a C libzstd through an FFI shim rather than the
zstd crate. The crate wants a vendored C build of its own; the platform already
ships the library, and linking it directly is what lets the compressed-qcow2
path exist in a device build at all.

An image with internal snapshots is refused for writing. It is not merely
unimplemented: writes never copy a cluster a snapshot still shares, because
`file_offset_write` reuses any already-mapped cluster without consulting its
refcount, and a refcount rebuild only walks the active L1 table, so clusters
reachable only from a snapshot are counted free and handed out again. Reading is
unaffected -- the active L1 table is complete on its own -- so such an image
still works as a backing file.
History 2026-08-30 13:09:47 +08:00
..
patches Merge remote-tracking branch 'aosp/upstream-main' 2024-11-25 11:22:10 -08:00
src disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00
Android.bp disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00
Cargo.toml feat(disk/qcow): support compressed qcow2 clusters (zlib + zstd) with COW writes 2026-07-06 06:43:20 -07:00