0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/disk/src
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
..
qcow disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00
sys disk: windows: restrict file sharing 2024-10-07 21:30:55 +00:00
android_sparse.rs crosvm: upgrade zerocopy to 0.8 2025-02-24 11:35:51 -08:00
asynchronous.rs devices: virtio-blk: don't stop the worker thread on sleep/reset 2024-06-21 02:02:13 +00:00
composite.rs disk: composite: support fdatasync 2025-02-27 10:59:57 -08:00
disk.rs disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00
gpt.rs Update all copyright headers to match new style 2022-09-13 18:41:29 +00:00
sys.rs disk: consolidate disk file opening logic 2024-09-09 20:39:03 +00:00
zstd.rs disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00
zstd_ffi.rs disk: qcow2 zero clusters, a C zstd shim, and a refusal to open snapshots 2026-08-30 13:09:47 +08:00