From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id D050080031 for ; Thu, 19 Nov 2026 14:32:20 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJEV8fp012579; Thu, 19 Nov 2026 17:31:09 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJEV8fp012579 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795098671; bh=8/2glOoPjNg95T8HsNfoFXOuiOxh/s6Cgi/rOzEBQtI=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=K3E+OcQ5IJR0TJDWqozdPvUqdyV4IgB+kxqrHz/jaPfrMSh8XQgATLu2P70Sw03Cd zQ6w/AVKsPE2OJG4NMJkdu+OfCxVdO3KaLRG2X1+gC/er5kU+nn6+PCtLSbM5ciZr4 MYWDn6nXPi7G0qAAUIiBDrmMZ9pIOHT0BeXnHZohCNd528xPILikQBR+8zt3huBGi/ RbfbOcFO36tW2aT1d9EF0Wo+0NW0AmWOUPuyqOPnEUu54yQc+WKeq2Q1j9J/OxZMPE Qik0gklzeSGfDjMYPb7pchLa9XsawZ/PM7a6xGrSCflgkYQuAa6Ra5x1Bad4sYb+wj Zh0ObJQ8V6PRg== Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJEV7nN012575 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 17:31:07 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJEV7nN012575 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="QAyF90g8" Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e00f3929bso621633f8f.0 for ; Thu, 19 Nov 2026 06:31:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFA3mW1ixMJo2CdqaqaaVxnWHeLHWMyhxl6z9JUJkLrK91Yu8iAMJwGpg7nXVZSbmWyKWhNUg==@openvz.org X-Gm-Message-State: APuU4Z/pvflRxnUY433hYbu8A77oCu5h30WNEI9ICeMtEuc2cK+OhGhT Rch10ovtFE36/NqCe6auKiqrUdOb0G745dkXw9LwnCDhXEDah3dRPZs0TF/eJ0bslWAvydWfM0q 3eght42m3XU9bQtLjT+XspCM40c4/RSFW4ShQN+8aL3hA5VFcW2iJUw== X-Gm-Gg: AZFdTZd48XQOomv0tSYGHHVvDMJfqcQps5DqHu3JQpGtlE92UVVgQMG/cpx9vE0cbJJ FYui+RLIBXDyjgrivZstW/mnImkse25l7/8IzRrNKDWKXR89NvAviabvf+DbmYME4otACgF+G+H Nxpv2gxps7BFdAKNkpocinPZd5jOmN8rlOSiVytlo36GOPGA9JZMEtjqRypB8JuYk2xelBQ226m Epeo5wpLiAQW6Y68hHT6lDpQsQTnaCegUzWfNWs1+HHHwPMSyKm56UM2krjg9YmmeEOJcgQ6Vdk 5M2sAPH8rA== X-Received: by 2002:a05:6000:18ac:b0:48c:585b:8825 with SMTP id ffacd0b85a97d-4aa54f83bb7mr3379134f8f.18.1795098667039; Thu, 19 Nov 2026 06:31:07 -0800 (PST) X-Received: by 2002:a05:6000:18ac:b0:48c:585b:8825 with SMTP id ffacd0b85a97d-4aa54f83bb7mr3379072f8f.18.1795098666478; Thu, 19 Nov 2026 06:31:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795098666; cv=none; d=google.com; s=arc-20260327; b=HcBrTQqCU0k9F5kCV7z0R8sr4hfByM5r72NkapWHYjYHuJytkO6VCiX6y1nnzAenbG U7MSUuWl7Hfi+XnovsUU1sChVS0eYdUhRPUMM3pgnG0/R8k/XMEb1kjC8Q5DkcEMz/5g Q1os2xt/nYiZUMJzthPVgbysDB1AhNfsdsa0/TGOVEw74b4VpCjd1Q96/mrFpU4quuIw u5q+OnLY6NStNXQ6/T/UP13Ux6eMoh00jKADsW5Mob0VU0W+TPqxdJHs/gMMyKc4W96N yRjq84LoxtfqoDx0ZxfUDgge7Na1TVziYmNBi5FiTPAkQcFlQe/1Yyg0LK9bT0D6jHOa hJ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=3l0sbEJuDQgoTHsDWToVSndRyRkX5c7mib6ZoHmY/js=; fh=+hz+ceR6Z/AMe1/QnghYvFfMlgGFEojLQf35WP9eMoA=; b=PdiTIxaANg8wEQnw6h/PPBjCwIh0fYidJYfC+sPz5AO+kDARyB8u/hH2HoVcv/J7yS f9oHZOP/4d0OD799Kd4TdSlEdCFhsRg0VXiPvhlnIDPlVKhIWUFEZ9W0iJizMSNR5BqD 7EcIbb4wB/yQHhLxme6UukqyEfYEQFtxyGW1BHbesem+KXFzv9QIwVCbhJwwW2WQ1LP3 i9fEohBRNdqdfMj0EfpwOs3hXe1OHocNdnu3aDBEwMQBiCxSZGUkwmRZDxDzPirwUeLt 6VjTsqRUYLGHJ/VcY1wl98trCY1LhyY1z+yglT9HbP5D4wIQgGXSV7nsMRREwaEdqhnJ t50g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=QAyF90g8; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-4aa083e4dcfsor174376f8f.8.2026.11.19.06.31.06 for (Google Transport Security); Thu, 19 Nov 2026 06:31:06 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) client-ip=2a06:5b06:b600:300:989f:a206:d03d:c3d5; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=QAyF90g8; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1795098666; x=1795703466; darn=openvz.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3l0sbEJuDQgoTHsDWToVSndRyRkX5c7mib6ZoHmY/js=; b=QAyF90g8ai6UJMMYCS139jevbiMuxCPvrvdm9ur+xfWyHIipiQAgHyjV1n7ZJVYyAN pqIVxLM8ojm2YsvI2K1lW5/yGvJw/uH3KJc+7wXSrMSarT6Q8XYrifNZUOnsQra5RUWr ajR6KoS6+GlTRRe1sK04uQbAA00HqbOiZtIZvrJ2OSOREBXGXtsXrOXjjnGSQK5NKeFy gqVKpSp5jin9SYWcUyG1+UJEp/XGxwq90GeW68UHFfRf4m0/gC8cjUAuyppgPsnLU2xJ pOe6Vq5foeGf4RZYxREpfs2CIQqeZW1bOcJKCcsG65a3MwEpmHztTFAdVLeTOyy6c/7y SG8Q== X-Forwarded-Encrypted: i=1; AL+hErG26kYA6S2Wo59Ot9rGvKMj60APrv6NRjATiLuXz3TGbkduceVlJ0tFPtd66O/QxnZVe1/Nrw==@openvz.org X-Received: by 2002:a05:600c:4f53:b0:4a1:c27d:e1a8 with SMTP id 5b1f17b1804b1-4bb86116162mr30209415e9.10.1795098665846; Thu, 19 Nov 2026 06:31:05 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:989f:a206:d03d:c3d5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884865a2sm1369895e9.3.2026.11.19.06.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 06:31:05 -0800 (PST) From: "Denis V. Lunev" To: alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Thu, 19 Nov 2026 15:31:03 +0100 Message-ID: <20261119143103.999720-1-den@openvz.org> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2] dm-qcow2: truncate the unused tail of an image after backward merge X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev qcow2_postsuspend() shrinks the top image to the end of its last used cluster, which drops freed clusters and the preallocated area. A backward merge detaches the merged image in qcow2_merge_backward_complete() and never shrinks it: the clusters the merge freed and up to the whole preallocation stay at the end of the file, and qemu-img check reports them as space leaked at the end of the image. Factor the truncation out of qcow2_postsuspend() into qcow2_truncate_unused_tail(tgt, qcow2) and call it for a writable merged image before its features are cleared. The device is live there, but the image is already unlinked from the stack under seek_rwsem, its qios are drained by the ref switch and its md pages written back, so qcow2_calc_used_end() sees a stable image. A failure is only logged, as the image no longer belongs to the target. The used end comes from "dm-qcow2: truncate unused tail of image on suspend"; the preallocated tail has been left behind since the driver was added. https://virtuozzo.atlassian.net/browse/VSTOR-156099 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 --- drivers/md/dm-qcow2-cmd.c | 1 + drivers/md/dm-qcow2-map.c | 5 +++-- drivers/md/dm-qcow2-target.c | 20 +++++++++----------- drivers/md/dm-qcow2.h | 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c index 3bccce090f01..d94036b94aae 100644 --- a/drivers/md/dm-qcow2-cmd.c +++ b/drivers/md/dm-qcow2-cmd.c @@ -391,6 +391,7 @@ static int qcow2_merge_backward_complete(struct qcow2_target *tgt) qcow2->lower = NULL; if (qcow2_file_is_writable(qcow2)) { + qcow2_truncate_unused_tail(tgt, qcow2); ret = qcow2_set_image_file_features(qcow2, false); if (ret < 0) QC_ERR(tgt->ti, "Can't unuse merged img (%d)", ret); diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 32373114580e..fc070c452144 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2282,8 +2282,9 @@ int qcow2_truncate_safe(struct file *file, loff_t new_len) } /* - * Return the end of the last cluster with non-zero refcount. Must be - * called on a suspended device after md writeback. + * Return the end of the last cluster with non-zero refcount. No qio may + * reach @qcow2 and its md must be written back: the device is suspended, + * or @qcow2 is unlinked from the stack and drained. */ loff_t qcow2_calc_used_end(struct qcow2 *qcow2) { diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index 4cd5f2c0ed36..cf5645423cf4 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -1072,16 +1072,12 @@ static void qcow2_dtr(struct dm_target *ti) qcow2_tgt_destroy(tgt); } -static void qcow2_truncate_unused_tail(struct dm_target *ti) +int qcow2_truncate_unused_tail(struct qcow2_target *tgt, struct qcow2 *qcow2) { - struct qcow2_target *tgt = to_qcow2_target(ti); - struct qcow2 *qcow2 = top_qcow2_protected(ti); + struct dm_target *ti = tgt->ti; loff_t used_end, end = qcow2->file_preallocated_area_start; int ret; - if (!(dm_table_get_mode(ti->table) & FMODE_WRITE)) - return; - if (tgt->md_writeback_error) { QC_INFO(ti, "Skip shrinking to used end after md writeback error"); } else if (kernel_sets_dirty_bit && qcow2->opened_dirty) { @@ -1095,17 +1091,17 @@ static void qcow2_truncate_unused_tail(struct dm_target *ti) } if (end == qcow2->file_size) - return; + return 0; ret = qcow2_truncate_safe(qcow2->file, end); if (ret) { QC_ERR(ti, "Can't truncate unused tail"); - tgt->truncate_error = true; - return; + return ret; } qcow2->file_preallocated_area_start = end; qcow2->file_size = end; + return 0; } static void qcow2_io_hints(struct dm_target *ti, struct queue_limits *limits) @@ -1177,15 +1173,17 @@ static void qcow2_presuspend_undo(struct dm_target *ti) } static void qcow2_postsuspend(struct dm_target *ti) { + struct qcow2_target *tgt = to_qcow2_target(ti); struct qcow2 *qcow2 = top_qcow2_protected(ti); unsigned int noio_flag; int ret; noio_flag = memalloc_noio_save(); - qcow2_flush_deferred_activity_all(to_qcow2_target(ti)); - qcow2_truncate_unused_tail(ti); + qcow2_flush_deferred_activity_all(tgt); if (dm_table_get_mode(ti->table) & FMODE_WRITE) { + if (qcow2_truncate_unused_tail(tgt, qcow2)) + tgt->truncate_error = true; ret = qcow2_set_image_file_features(qcow2, false); if (ret) QC_ERR(ti, "Can't set features"); diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index 3f1d5b5eef26..4acddbe7c95f 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -428,6 +428,7 @@ void qcow2_ref_dec(struct qcow2_target *tgt, u8 ref_index); int qcow2_inflight_ref_switch(struct qcow2_target *tgt); void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2); int qcow2_truncate_safe(struct file *file, loff_t new_len); +int qcow2_truncate_unused_tail(struct qcow2_target *tgt, struct qcow2 *qcow2); loff_t qcow2_calc_used_end(struct qcow2 *qcow2); void qcow2_merge_backward_work(struct work_struct *work); -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel