Skip to contentSkip to conversation

block/gluster: correctly set max_pdiscard

PATCH Applied Fabian Ebner 5 participants 5 messages May 20, 2022 – May 30, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 block/gluster: correctly set max_pdiscard

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard results in a negative value, and the following assertion would trigger down the line (it's not the same max_pdiscard, but computed from the other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion `max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value of 'bytes' can safely be passed to glfs_discard_async(), which takes a size_t for the argument in question, so it is kept as is. And since max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still fine.

Fixes 0c8022876f ("block: use int64_t instead of int in driver discard handlers")

---

v2 -> v3:
* Keep assertion in qemu_gluster_co_pdiscard() as is.
* Improve commit message.

v1 -> v2:
* Use an expression that works for both 64-bit and 32-bit platforms.

 block/gluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/gluster.c +1 -1
index 398976bc66..b60213ab80 100644
@@ -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 = MIN(SIZE_MAX, INT64_MAX);
 }
 
 static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
Signature · 1 line
2.30.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 15 lines · Fabian Ebner

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard results in a negative value, and the following assertion would trigger down the line (it's not the same max_pdiscard, but computed from the other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion `max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value of 'bytes' can safely be passed to glfs_discard_async(), which takes a size_t for the argument in question, so it is kept as is. And since max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still fine.

Quoted 4 lines
Fixes 0c8022876f ("block: use int64_t instead of int in driver discard handlers")

---

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v3 1/1
#2 lore raw
In reply to Fabian Ebner
Quoted 24 lines · Fabian Ebner

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard results in a negative value, and the following assertion would trigger down the line (it's not the same max_pdiscard, but computed from the other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion `max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value of 'bytes' can safely be passed to glfs_discard_async(), which takes a size_t for the argument in question, so it is kept as is. And since max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still fine.

Fixes 0c8022876f ("block: use int64_t instead of int in driver discard handlers")

---

v2 -> v3:
* Keep assertion in qemu_gluster_co_pdiscard() as is.
* Improve commit message.

Quoted 5 lines

v1 -> v2:
* Use an expression that works for both 64-bit and 32-bit platforms.

block/gluster.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 18 lines
block/gluster.c +1 -1
index 398976bc66..b60213ab80 100644
@@ -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 = MIN(SIZE_MAX, INT64_MAX);
 }
 
 static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
Signature · 1 line
2.30.2
Reviewed-by on v3 1/1
#3 lore raw
In reply to Fabian Ebner
Quoted 2 lines · Fabian Ebner

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard results in a negative value, and the following assertion would trigger

Oops. Good catch!

Quoted 13 lines

down the line (it's not the same max_pdiscard, but computed from the other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion `max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value of 'bytes' can safely be passed to glfs_discard_async(), which takes a size_t for the argument in question, so it is kept as is. And since max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still fine.

Quoted 3 lines
Fixes 0c8022876f ("block: use int64_t instead of int in driver discard handlers")
Signature · 2 lines
Best regards,
Vladimir
Applied
#4 lore raw
In reply to Fabian Ebner

Am 20.05.2022 um 09:59 hat Fabian Ebner geschrieben:

Quoted 15 lines

On 64-bit platforms, assigning SIZE_MAX to the int64_t max_pdiscard results in a negative value, and the following assertion would trigger down the line (it's not the same max_pdiscard, but computed from the other one):
qemu-system-x86_64: ../block/io.c:3166: bdrv_co_pdiscard: Assertion `max_pdiscard >= bs->bl.request_alignment' failed.

On 32-bit platforms, it's fine to keep using SIZE_MAX.

The assertion in qemu_gluster_co_pdiscard() is checking that the value of 'bytes' can safely be passed to glfs_discard_async(), which takes a size_t for the argument in question, so it is kept as is. And since max_pdiscard is still <= SIZE_MAX, relying on max_pdiscard is still fine.

Quoted 3 lines
Fixes 0c8022876f ("block: use int64_t instead of int in driver discard handlers")

Thanks, applied to the block branch.

Kevin