all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM
@ 2025-11-19 15:11 Fiona Ebner
  2025-11-19 17:13 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Fiona Ebner @ 2025-11-19 15:11 UTC (permalink / raw)
  To: 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 <f.ebner@proxmox.com>
---
 ...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 <stefanha@redhat.com>
+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 <stefanha@redhat.com>
+Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
+Link: https://lore.proxmox.com/20251007141700.71891-2-stefanha@redhat.com
+[FE: picked from qemu-devel]
+Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+---
+ 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 <stefanha@redhat.com>
+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 <jean-louis@dupond.be>
+Buglink: https://gitlab.com/qemu-project/qemu/-/issues/3127
+Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
+Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
+Link: https://lore.proxmox.com/20251007141700.71891-3-stefanha@redhat.com
+[FE: picked from qemu-devel]
+Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
+---
+ 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 <t.lamprecht@proxmox.com>
  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 <t.lamprecht@proxmox.com>
  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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH qemu] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM
  2025-11-19 15:11 [pve-devel] [PATCH qemu] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM Fiona Ebner
@ 2025-11-19 17:13 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2025-11-19 17:13 UTC (permalink / raw)
  To: pve-devel, Fiona Ebner

On Wed, 19 Nov 2025 16:11:07 +0100, Fiona Ebner wrote:
> 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/
> 
> [...]

Applied, thanks!

[1/1] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM
      commit: 8ea4414ca0e72d32b1ada4cac05bbd714a609c98


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-19 17:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-19 15:11 [pve-devel] [PATCH qemu] fix #7033: backport fixes for write zeroes request alignment to fix qcow2 creation on LVM Fiona Ebner
2025-11-19 17:13 ` Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal