From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 173821FF183 for ; Wed, 19 Nov 2025 16:16:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2E19C11030; Wed, 19 Nov 2025 16:16:32 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Wed, 19 Nov 2025 16:11:07 +0100 Message-ID: <20251119151623.168802-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1763565355842 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" As also outlined in [0], QEMU 10.1 introduced a regression here, with a fix [1] already on qemu-devel. The issue was also reported in the community forum [2], thanks to Abobakr for pointing me towards the upstream issue! [0]: https://gitlab.com/qemu-project/qemu/-/issues/3127 [1]: https://lore.kernel.org/qemu-devel/20251007141700.71891-1-stefanha@redhat.com/ [2]: https://forum.proxmox.com/threads/vm-create-move-fails-on-netapp-shared-lvm-storage-with-qcow2-disk.175785/ Signed-off-by: Fiona Ebner --- ...six-populate-pwrite_zeroes_alignment.patch | 49 +++++++++++ ..._zeroes_alignment-when-writing-first.patch | 86 +++++++++++++++++++ ...k-file-change-locking-default-to-off.patch | 2 +- ...le-posix-make-locking-optiono-on-cre.patch | 14 +-- debian/patches/series | 2 + 5 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 debian/patches/extra/0009-file-posix-populate-pwrite_zeroes_alignment.patch create mode 100644 debian/patches/extra/0010-block-use-pwrite_zeroes_alignment-when-writing-first.patch diff --git a/debian/patches/extra/0009-file-posix-populate-pwrite_zeroes_alignment.patch b/debian/patches/extra/0009-file-posix-populate-pwrite_zeroes_alignment.patch new file mode 100644 index 0000000..513a8c7 --- /dev/null +++ b/debian/patches/extra/0009-file-posix-populate-pwrite_zeroes_alignment.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stefan Hajnoczi +Date: Tue, 7 Oct 2025 10:16:58 -0400 +Subject: [PATCH] file-posix: populate pwrite_zeroes_alignment + +Linux block devices require write zeroes alignment whereas files do not. + +It may come as a surprise that block devices opened in buffered I/O mode +require the alignment for write zeroes requests although normal +read/write requests do not. + +Therefore it is necessary to populate the pwrite_zeroes_alignment field. + +Signed-off-by: Stefan Hajnoczi +Reviewed-by: Vladimir Sementsov-Ogievskiy +Link: https://lore.proxmox.com/20251007141700.71891-2-stefanha@redhat.com +[FE: picked from qemu-devel] +Signed-off-by: Fiona Ebner +--- + block/file-posix.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/block/file-posix.c b/block/file-posix.c +index 8c738674ce..827ffa77a5 100644 +--- a/block/file-posix.c ++++ b/block/file-posix.c +@@ -1602,6 +1602,22 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) + + bs->bl.pdiscard_alignment = dalign; + } ++ ++#ifdef __linux__ ++ /* ++ * Linux requires logical block size alignment for write zeroes even ++ * when normal reads/writes do not require alignment. ++ */ ++ if (!s->needs_alignment) { ++ ret = probe_logical_blocksize(s->fd, ++ &bs->bl.pwrite_zeroes_alignment); ++ if (ret < 0) { ++ error_setg_errno(errp, -ret, ++ "Failed to probe logical block size"); ++ return; ++ } ++ } ++#endif /* __linux__ */ + } + + raw_refresh_zoned_limits(bs, &st, errp); diff --git a/debian/patches/extra/0010-block-use-pwrite_zeroes_alignment-when-writing-first.patch b/debian/patches/extra/0010-block-use-pwrite_zeroes_alignment-when-writing-first.patch new file mode 100644 index 0000000..de057ae --- /dev/null +++ b/debian/patches/extra/0010-block-use-pwrite_zeroes_alignment-when-writing-first.patch @@ -0,0 +1,86 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stefan Hajnoczi +Date: Tue, 7 Oct 2025 10:16:59 -0400 +Subject: [PATCH] block: use pwrite_zeroes_alignment when writing first sector + +Since commit 5634622bcb33 ("file-posix: allow BLKZEROOUT with -t +writeback"), qemu-img create errors out on a Linux loop block device +with a 4 KB sector size: + + # dd if=/dev/zero of=blockfile bs=1M count=1024 + # losetup --sector-size 4096 /dev/loop0 blockfile + # qemu-img create -f raw /dev/loop0 1G + Formatting '/dev/loop0', fmt=raw size=1073741824 + qemu-img: /dev/loop0: Failed to clear the new image's first sector: Invalid argument + +Use the pwrite_zeroes_alignment block limit to avoid misaligned +fallocate(2) or ioctl(BLKZEROOUT) in the block/file-posix.c block +driver. + +Fixes: 5634622bcb33 ("file-posix: allow BLKZEROOUT with -t writeback") +Reported-by: Jean-Louis Dupond +Buglink: https://gitlab.com/qemu-project/qemu/-/issues/3127 +Reviewed-by: Vladimir Sementsov-Ogievskiy +Signed-off-by: Stefan Hajnoczi +Link: https://lore.proxmox.com/20251007141700.71891-3-stefanha@redhat.com +[FE: picked from qemu-devel] +Signed-off-by: Fiona Ebner +--- + block.c | 3 ++- + block/block-backend.c | 11 +++++++++++ + include/system/block-backend-io.h | 1 + + 3 files changed, 14 insertions(+), 1 deletion(-) + +diff --git a/block.c b/block.c +index 8848e9a7ed..be77e03904 100644 +--- a/block.c ++++ b/block.c +@@ -606,12 +606,13 @@ create_file_fallback_zero_first_sector(BlockBackend *blk, + int64_t current_size, + Error **errp) + { ++ uint32_t alignment = blk_get_pwrite_zeroes_alignment(blk); + int64_t bytes_to_clear; + int ret; + + GLOBAL_STATE_CODE(); + +- bytes_to_clear = MIN(current_size, BDRV_SECTOR_SIZE); ++ bytes_to_clear = MIN(current_size, MAX(BDRV_SECTOR_SIZE, alignment)); + if (bytes_to_clear) { + ret = blk_co_pwrite_zeroes(blk, 0, bytes_to_clear, BDRV_REQ_MAY_UNMAP); + if (ret < 0) { +diff --git a/block/block-backend.c b/block/block-backend.c +index f8d6ba65c1..239d6eca37 100644 +--- a/block/block-backend.c ++++ b/block/block-backend.c +@@ -2305,6 +2305,17 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) + return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE; + } + ++/* Returns the optimal write zeroes alignment, in bytes; guaranteed nonzero */ ++uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk) ++{ ++ BlockDriverState *bs = blk_bs(blk); ++ IO_CODE(); ++ if (!bs) { ++ return BDRV_SECTOR_SIZE; ++ } ++ return bs->bl.pwrite_zeroes_alignment ?: bs->bl.request_alignment; ++} ++ + /* Returns the maximum hardware transfer length, in bytes; guaranteed nonzero */ + uint64_t blk_get_max_hw_transfer(BlockBackend *blk) + { +diff --git a/include/system/block-backend-io.h b/include/system/block-backend-io.h +index ba8dfcc7d0..6d5ac476fc 100644 +--- a/include/system/block-backend-io.h ++++ b/include/system/block-backend-io.h +@@ -116,6 +116,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, + void *opaque, int ret); + + uint32_t blk_get_request_alignment(BlockBackend *blk); ++uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk); + uint32_t blk_get_max_transfer(BlockBackend *blk); + uint64_t blk_get_max_hw_transfer(BlockBackend *blk); + diff --git a/debian/patches/pve/0001-PVE-Config-block-file-change-locking-default-to-off.patch b/debian/patches/pve/0001-PVE-Config-block-file-change-locking-default-to-off.patch index 2538947..df81614 100644 --- a/debian/patches/pve/0001-PVE-Config-block-file-change-locking-default-to-off.patch +++ b/debian/patches/pve/0001-PVE-Config-block-file-change-locking-default-to-off.patch @@ -14,7 +14,7 @@ Signed-off-by: Thomas Lamprecht 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c -index 8c738674ce..6a9433c836 100644 +index 827ffa77a5..baac7653db 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -588,7 +588,7 @@ static QemuOptsList raw_runtime_opts = { diff --git a/debian/patches/pve/0022-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch b/debian/patches/pve/0022-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch index 270829f..989695e 100644 --- a/debian/patches/pve/0022-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch +++ b/debian/patches/pve/0022-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch @@ -13,10 +13,10 @@ Signed-off-by: Thomas Lamprecht 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c -index 6a9433c836..37b6d495db 100644 +index baac7653db..fc5cf223bc 100644 --- a/block/file-posix.c +++ b/block/file-posix.c -@@ -2977,6 +2977,7 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) +@@ -2993,6 +2993,7 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) int fd; uint64_t perm, shared; int result = 0; @@ -24,7 +24,7 @@ index 6a9433c836..37b6d495db 100644 /* Validate options and set default values */ assert(options->driver == BLOCKDEV_DRIVER_FILE); -@@ -3017,19 +3018,22 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) +@@ -3033,19 +3034,22 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) perm = BLK_PERM_WRITE | BLK_PERM_RESIZE; shared = BLK_PERM_ALL & ~BLK_PERM_RESIZE; @@ -59,7 +59,7 @@ index 6a9433c836..37b6d495db 100644 } /* Clear the file by truncating it to 0 */ -@@ -3083,13 +3087,15 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) +@@ -3099,13 +3103,15 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp) } out_unlock: @@ -82,7 +82,7 @@ index 6a9433c836..37b6d495db 100644 } out_close: -@@ -3113,6 +3119,7 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, +@@ -3129,6 +3135,7 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, PreallocMode prealloc; char *buf = NULL; Error *local_err = NULL; @@ -90,7 +90,7 @@ index 6a9433c836..37b6d495db 100644 /* Skip file: protocol prefix */ strstart(filename, "file:", &filename); -@@ -3135,6 +3142,18 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, +@@ -3151,6 +3158,18 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, return -EINVAL; } @@ -109,7 +109,7 @@ index 6a9433c836..37b6d495db 100644 options = (BlockdevCreateOptions) { .driver = BLOCKDEV_DRIVER_FILE, .u.file = { -@@ -3146,6 +3165,8 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, +@@ -3162,6 +3181,8 @@ raw_co_create_opts(BlockDriver *drv, const char *filename, .nocow = nocow, .has_extent_size_hint = has_extent_size_hint, .extent_size_hint = extent_size_hint, diff --git a/debian/patches/series b/debian/patches/series index 0bd9ea8..b1afcd4 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -6,6 +6,8 @@ extra/0005-hw-scsi-avoid-deadlock-upon-TMF-request-cancelling-w.patch extra/0006-vfio-rename-field-to-num_initial_regions.patch extra/0007-vfio-only-check-region-info-cache-for-initial-region.patch extra/0008-ui-vdagent-fix-windows-agent-regression.patch +extra/0009-file-posix-populate-pwrite_zeroes_alignment.patch +extra/0010-block-use-pwrite_zeroes_alignment-when-writing-first.patch bitmap-mirror/0001-drive-mirror-add-support-for-sync-bitmap-mode-never.patch bitmap-mirror/0002-drive-mirror-add-support-for-conditional-and-always-.patch bitmap-mirror/0003-mirror-add-check-for-bitmap-mode-without-bitmap.patch -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel