[Devel] [PATCH hci-8.1 v7 3/6] dm-qcow2: extend the file in place_r2() before linking the refblock

Alexander Ivanov alexander.ivanov at virtuozzo.com
Thu Oct 22 17:50:29 MSK 2026


place_r2() links a new refblock into R1, but moves neither file_size
nor file_preallocated_area_start. The refblock stays at or above the
watermark if truncate_prealloc_safe() in allocate_cluster() fails
after place_r2(), or if a parallel mark_cluster_unused() lowers
free_cluster_search_pos before the second pass of
find_unused_cluster(). Truncation of preallocations on suspend then
cuts the file under the refblock: R1 on disk points past EOF, and
the next session gets -EIO on allocations in the range it covers.

Extend the file and raise the watermark to the end of the refblock
before linking it into R1, as allocate_cluster() does for data
clusters.

https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver

Signed-off-by: Alexander Ivanov <alexander.ivanov at virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 78ee7cf5e881..810dd22425ae 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -82,6 +82,7 @@ struct qcow2_bvec {
 static int qcow2_handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio **qio,
 	struct qcow2_map_item *r1, struct qcow2_map_item *r2, bool compressed);
 static int qcow2_punch_hole(struct file *file, loff_t pos, loff_t len);
+static int truncate_prealloc_safe(struct qcow2 *qcow2, loff_t len, const char *func);
 static void handle_cleanup_mask(struct qio *qio);
 static void process_read_qio(struct qcow2 *qcow2, struct qio *qio,
 			     struct qcow2_map *map);
@@ -2088,6 +2089,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
 		    struct qcow2_map_item *r2, loff_t r2_pos, struct qio **qio)
 {
 	struct dm_target *ti = qcow2->tgt->ti;
+	loff_t end = r2_pos + qcow2->clu_size;
 	u64 page_id = r2_pos >> PAGE_SHIFT;
 	int ret;
 
@@ -2100,6 +2102,12 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
 		return ret;
 	}
 
+	ret = truncate_prealloc_safe(qcow2, end, __func__);
+	if (ret)
+		return ret;
+	if (end > qcow2->file_preallocated_area_start)
+		qcow2->file_preallocated_area_start = end;
+
 	ret = qcow2_alloc_and_insert_md_page(qcow2, page_id, &r2->md);
 	if (ret < 0) {
 		QC_ERR(ti, "Can't alloc: ret=%d, page_id=%llu", ret, page_id);
-- 
2.53.0



More information about the Devel mailing list