From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id A6712CAED
 for <pve-devel@lists.proxmox.com>; Thu,  5 May 2022 10:43:17 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 9A2CD1875
 for <pve-devel@lists.proxmox.com>; Thu,  5 May 2022 10:43:17 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id A885E186B
 for <pve-devel@lists.proxmox.com>; Thu,  5 May 2022 10:43:16 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 70B4343179
 for <pve-devel@lists.proxmox.com>; Thu,  5 May 2022 10:43:16 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu,  5 May 2022 10:43:12 +0200
Message-Id: <20220505084312.182672-1-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.083 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [proxmox.com, nongnu.org]
Subject: [pve-devel] [PATCH qemu] add patch to fix discard on GlusterFS
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 05 May 2022 08:43:17 -0000

Reported in the community forum:
https://forum.proxmox.com/threads/108875
and thanks to Mira for telling me how to reproduce it.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Mail sent upstream:
https://lists.nongnu.org/archive/html/qemu-devel/2022-05/msg00938.html

 ...rrectly-set-max_pdiscard-which-is-in.patch | 37 +++++++++++++++++++
 debian/patches/series                         |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 debian/patches/extra/0018-block-gluster-correctly-set-max_pdiscard-which-is-in.patch

diff --git a/debian/patches/extra/0018-block-gluster-correctly-set-max_pdiscard-which-is-in.patch b/debian/patches/extra/0018-block-gluster-correctly-set-max_pdiscard-which-is-in.patch
new file mode 100644
index 0000000..0fed7f5
--- /dev/null
+++ b/debian/patches/extra/0018-block-gluster-correctly-set-max_pdiscard-which-is-in.patch
@@ -0,0 +1,37 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Fabian Ebner <f.ebner@proxmox.com>
+Date: Thu, 5 May 2022 09:50:38 +0200
+Subject: [PATCH] block/gluster: correctly set max_pdiscard which is int64_t
+
+Previously, max_pdiscard would be zero in the following assertion:
+qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion
+`max_pdiscard >= bs->bl.request_alignment' failed.
+
+Fixes: 0c8022876f ("block: use int64_t instead of int in driver discard handlers")
+Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
+---
+ block/gluster.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/block/gluster.c b/block/gluster.c
+index 398976bc66..592e71b22a 100644
+--- a/block/gluster.c
++++ b/block/gluster.c
+@@ -891,7 +891,7 @@ out:
+ static void qemu_gluster_refresh_limits(BlockDriverState *bs, Error **errp)
+ {
+     bs->bl.max_transfer = GLUSTER_MAX_TRANSFER;
+-    bs->bl.max_pdiscard = SIZE_MAX;
++    bs->bl.max_pdiscard = INT64_MAX;
+ }
+ 
+ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
+@@ -1304,7 +1304,7 @@ static coroutine_fn int qemu_gluster_co_pdiscard(BlockDriverState *bs,
+     GlusterAIOCB acb;
+     BDRVGlusterState *s = bs->opaque;
+ 
+-    assert(bytes <= SIZE_MAX); /* rely on max_pdiscard */
++    assert(bytes <= INT64_MAX); /* rely on max_pdiscard */
+ 
+     acb.size = 0;
+     acb.ret = 0;
diff --git a/debian/patches/series b/debian/patches/series
index 9a75f9b..6589fe7 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -15,6 +15,7 @@ extra/0014-vhost-vsock-detach-the-virqueue-element-in-case-of-e.patch
 extra/0015-vhost-user-remove-VirtQ-notifier-restore.patch
 extra/0016-vhost-user-fix-VirtQ-notifier-cleanup.patch
 extra/0017-virtio-fix-the-condition-for-iommu_platform-not-supp.patch
+extra/0018-block-gluster-correctly-set-max_pdiscard-which-is-in.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.30.2