[PATCH] block/gluster: correctly set max_pdiscard which is int64_t

Fabian Ebner posted 1 patch 2 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220505083124.163404-1-f.ebner@proxmox.com
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
block/gluster.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] block/gluster: correctly set max_pdiscard which is int64_t
Posted by Fabian Ebner 2 years ago
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")
Cc: qemu-stable@nongnu.org
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;
-- 
2.30.2
Re: [PATCH] block/gluster: correctly set max_pdiscard which is int64_t
Posted by Eric Blake 2 years ago
On Thu, May 05, 2022 at 10:31:24AM +0200, Fabian Ebner wrote:
> 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")
> Cc: qemu-stable@nongnu.org
> 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;

SIZE_MAX is unsigned, but can differ between 32- and 64-bit platforms.
Blindly setting max_pdiscard to a signed 64-bit value seems wrong if
glfs_discard_async() takes a size_t and you are on a 32-bit platform.

Is the real issue that SIZE_MAX on a 64-bit platform is too large,
where we want min(SIZE_MAX,INT_MAX) as our real cap?

>  }
>  
>  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;
> -- 
> 2.30.2
> 
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Re: [PATCH] block/gluster: correctly set max_pdiscard which is int64_t
Posted by Fabian Ebner 1 year, 12 months ago
Am 06.05.22 um 17:39 schrieb Eric Blake:
> On Thu, May 05, 2022 at 10:31:24AM +0200, Fabian Ebner wrote:
>> 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")
>> Cc: qemu-stable@nongnu.org
>> 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;
> 
> SIZE_MAX is unsigned, but can differ between 32- and 64-bit platforms.
> Blindly setting max_pdiscard to a signed 64-bit value seems wrong if
> glfs_discard_async() takes a size_t and you are on a 32-bit platform.
> 

Sorry, I did not consider this.

> Is the real issue that SIZE_MAX on a 64-bit platform is too large,

Yes, there it's too big for max_pdiscard which is int64_t.

> where we want min(SIZE_MAX,INT_MAX) as our real cap?
> 

Why not min(SIZE_MAX,INT64_MAX)? Since the constraint is to fit in both
size_t and int64_t. That would also preserve the current value on 32-bit
platforms.

>>  }
>>  
>>  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;
>> -- 
>> 2.30.2
>>
>>
>>
>