[Devel] [PATCH hci-8.2 v2 2/2] dm-qcow2: fix a read livelock at EOF of a read-only image

Denis V. Lunev den at virtuozzo.com
Thu Nov 19 17:44:06 MSK 2026


On 11/19/26 14:35, Alexander Ivanov wrote:
> On 11/19/26 13:51, Denis V. Lunev wrote:
>> From: Denis V. Lunev <den at openvz.org>
>>
>> submit_read_compressed() reads a compressed cluster up to a page
>> boundary, and qcow2_parse_header() pads the file to a page only when
>> the image is writable. On a read-only image whose file ends mid-page
>> on a sector boundary, as qemu-img convert -c leaves a lower image, that
>> read runs past EOF and comes back short.
>>
>> data_rw_complete() takes the short read for partial I/O and resubmits
>> the rest. The resubmit starts at EOF, reads 0 bytes, trips
>> WARN_ON_ONCE(qio->ret == 0) in data_rw_complete() and is resubmitted
>> forever.
>>
>> The worker spins, and the first reader of the device, usually udev or
>> partprobe at mount, never returns.
>>
>> Accept a short read that ends at EOF of a read-only image less than a
>> page short, the padding such an image lacks, and zero the rest, as
>> md_page_read_complete() does for metadata. The zeroing runs in the I/O
>> completion, which the previous patch made safe. End a read that
>> returns 0 bytes with -EIO instead of resubmitting it, which also covers
>> an L2 entry that points at or past EOF.
>>
>> https://virtuozzo.atlassian.net/browse/VSTOR-155987
>>
>> Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>> Feature: dm-qcow2: block device over QCOW2 files driver
>> Signed-off-by: Denis V. Lunev <den at openvz.org>
>> ---
>>   drivers/md/dm-qcow2-map.c | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
>> index c7e186fa6115..cf66b9a98085 100644
>> --- a/drivers/md/dm-qcow2-map.c
>> +++ b/drivers/md/dm-qcow2-map.c
>> @@ -3012,13 +3012,21 @@ static void data_rw_complete(struct qio *qio)
>>   	unsigned long flags;
>>   
>>   	if (unlikely(qio->ret != qio->bi_iter.bi_size)) {
>> -		if (qio->ret >= 0) {
>> +		if (!write && qio->ret > 0 && !qcow2_file_is_writable(qcow2) &&
>> +		    to_bytes(qio->bi_iter.bi_sector) + qio->ret == qcow2->file_size &&
>> +		    qio->bi_iter.bi_size - qio->ret < PAGE_SIZE) {
>> +			/* Read near EOF, same as md_page_read_complete() */
>> +			zero_fill_qio(qio, qio->ret, qio->bi_iter.bi_size - qio->ret);
>> +		} else if (!write && qio->ret == 0) {
> Writes still keep WARN_ON_ONCE(qio->ret == 0) and the resubmit, so a 
> write that returns 0
> would loop the same way. Can writes actually have 0 here?
On ext4, no. When iomap fails to invalidate the page cache it turns
-ENOTBLK into 0, but ext4_dio_write_iter() then writes the rest
through the page cache and returns the full count.

On xfs, yes. xfs falls back to buffered I/O only for a reflink CoW, so
after a failed invalidation xfs_file_dio_write() returns the 0 from
iomap_dio_rw() as is. That needs someone else to have the image cached,
and it is transient: the resubmit makes progress once the pages are
gone. So resubmitting a write is right, while a read at EOF returns 0
for good, which is why the patch only changes reads.

What is wrong for writes is the WARN_ON_ONCE() in front of the
resubmit: with panic_on_warn it panics the host. That is older than
this series and not related to the EOF livelock, so I will fix it
separately rather than grow this patch.
 
Den


More information about the Devel mailing list