block: qcow: Return zeros for reads beyond backing file size by weltling · Pull Request #7678 · cloud-hypervisor/cloud-hypervisor · GitHub
Skip to content

block: qcow: Return zeros for reads beyond backing file size#7678

Merged
rbradford merged 2 commits intocloud-hypervisor:mainfrom
weltling:qcow-backing-read-fix
Feb 10, 2026
Merged

block: qcow: Return zeros for reads beyond backing file size#7678
rbradford merged 2 commits intocloud-hypervisor:mainfrom
weltling:qcow-backing-read-fix

Conversation

@weltling
Copy link
Copy Markdown
Member

@weltling weltling commented Feb 8, 2026

When an overlay QCOW2 image is larger than its backing file, reads from offsets beyond the backing file virtual size previously failed with I/O error.

This PR fixes the issue by returning zeros for such reads. This is matching QEMU that treats unallocated regions beyond the backing file as implicitly zero-filled.

Example:

qemu-img create -f qcow2 backing.qcow2 1G
qemu-img create -f qcow2 -b backing.qcow2 -F qcow2 overlay.qcow2 2G
  • Cache backing file virtual size at open time
  • Return zeros for reads beyond backing, including partial boundary reads

Added unit test covering reads within, beyond, and spanning the backing boundary.

When an overlay QCOW2 image is larger than its backing file, reads
from offsets beyond the backing file virtual size would previously
fail with an I/O error.

The backing file virtual size is determined at open time and stored
for bounds checking during read operations:

- If the entire read is beyond the backing size, return all zeros
- If the read spans the boundary, read available data from backing and
  fill the remainder with zeros

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
@weltling weltling requested a review from a team as a code owner February 8, 2026 18:43
@weltling weltling force-pushed the qcow-backing-read-fix branch 2 times, most recently from 3964de5 to ce37ad0 Compare February 8, 2026 19:06
Copy link
Copy Markdown
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

LGTM! Left one remark

Comment thread block/src/qcow/mod.rs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't you also assert here that boundary_buf[0..512] is not all zero?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Absolutely. I've extended it to write some bytes at the end and check both 512 byte chunks. Thanks!

Test reading from overlay at offsets beyond backing file returns
zeros. Covers reads within backing range, beyond backing, and
boundary spanning.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
@weltling weltling force-pushed the qcow-backing-read-fix branch from ce37ad0 to b786cd4 Compare February 9, 2026 09:30
@rbradford rbradford added this pull request to the merge queue Feb 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 9, 2026
@rbradford rbradford added this pull request to the merge queue Feb 10, 2026
Merged via the queue into cloud-hypervisor:main with commit 2793448 Feb 10, 2026
43 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

5 participants