All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gluster: Align block-status tail
@ 2021-08-05 14:36 Max Reitz
  2021-08-05 19:35 ` Eric Blake
  2021-09-07  8:08 ` Hanna Reitz
  0 siblings, 2 replies; 3+ messages in thread
From: Max Reitz @ 2021-08-05 14:36 UTC (permalink / raw)
  To: qemu-block; +Cc: Kevin Wolf, qemu-devel, Max Reitz

gluster's block-status implementation is basically a copy of that in
block/file-posix.c, there is only one thing missing, and that is
aligning trailing data extents to the request alignment (as added by
commit 9c3db310ff0).

Note that 9c3db310ff0 mentions that "there seems to be no other block
driver that sets request_alignment and [...]", but while block/gluster.c
does indeed not set request_alignment, block/io.c's
bdrv_refresh_limits() will still default to an alignment of 512 because
block/gluster.c does not provide a byte-aligned read function.
Therefore, unaligned tails can conceivably occur, and so we should apply
the change from 9c3db310ff0 to gluster's block-status implementation.

Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/gluster.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/block/gluster.c b/block/gluster.c
index e8ee14c8e9..48a04417cf 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1477,6 +1477,8 @@ static int coroutine_fn qemu_gluster_co_block_status(BlockDriverState *bs,
     off_t data = 0, hole = 0;
     int ret = -EINVAL;
 
+    assert(QEMU_IS_ALIGNED(offset | bytes, bs->bl.request_alignment));
+
     if (!s->fd) {
         return ret;
     }
@@ -1501,6 +1503,20 @@ static int coroutine_fn qemu_gluster_co_block_status(BlockDriverState *bs,
         /* On a data extent, compute bytes to the end of the extent,
          * possibly including a partial sector at EOF. */
         *pnum = MIN(bytes, hole - offset);
+
+        /*
+         * We are not allowed to return partial sectors, though, so
+         * round up if necessary.
+         */
+        if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) {
+            int64_t file_length = qemu_gluster_getlength(bs);
+            if (file_length > 0) {
+                /* Ignore errors, this is just a safeguard */
+                assert(hole == file_length);
+            }
+            *pnum = ROUND_UP(*pnum, bs->bl.request_alignment);
+        }
+
         ret = BDRV_BLOCK_DATA;
     } else {
         /* On a hole, compute bytes to the beginning of the next extent.  */
-- 
2.31.1



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

* Re: [PATCH] gluster: Align block-status tail
  2021-08-05 14:36 [PATCH] gluster: Align block-status tail Max Reitz
@ 2021-08-05 19:35 ` Eric Blake
  2021-09-07  8:08 ` Hanna Reitz
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2021-08-05 19:35 UTC (permalink / raw)
  To: Max Reitz; +Cc: Kevin Wolf, qemu-devel, qemu-block

On Thu, Aug 05, 2021 at 04:36:03PM +0200, Max Reitz wrote:
> gluster's block-status implementation is basically a copy of that in
> block/file-posix.c, there is only one thing missing, and that is
> aligning trailing data extents to the request alignment (as added by
> commit 9c3db310ff0).
> 
> Note that 9c3db310ff0 mentions that "there seems to be no other block
> driver that sets request_alignment and [...]", but while block/gluster.c
> does indeed not set request_alignment, block/io.c's
> bdrv_refresh_limits() will still default to an alignment of 512 because
> block/gluster.c does not provide a byte-aligned read function.
> Therefore, unaligned tails can conceivably occur, and so we should apply
> the change from 9c3db310ff0 to gluster's block-status implementation.
> 
> Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/gluster.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Probably not a show-stopper for 6.1, so I'm fine if it sits until 6.2.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



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

* Re: [PATCH] gluster: Align block-status tail
  2021-08-05 14:36 [PATCH] gluster: Align block-status tail Max Reitz
  2021-08-05 19:35 ` Eric Blake
@ 2021-09-07  8:08 ` Hanna Reitz
  1 sibling, 0 replies; 3+ messages in thread
From: Hanna Reitz @ 2021-09-07  8:08 UTC (permalink / raw)
  To: Max Reitz, qemu-block; +Cc: Kevin Wolf, qemu-devel

On 05.08.21 16:36, Max Reitz wrote:
> gluster's block-status implementation is basically a copy of that in
> block/file-posix.c, there is only one thing missing, and that is
> aligning trailing data extents to the request alignment (as added by
> commit 9c3db310ff0).
>
> Note that 9c3db310ff0 mentions that "there seems to be no other block
> driver that sets request_alignment and [...]", but while block/gluster.c
> does indeed not set request_alignment, block/io.c's
> bdrv_refresh_limits() will still default to an alignment of 512 because
> block/gluster.c does not provide a byte-aligned read function.
> Therefore, unaligned tails can conceivably occur, and so we should apply
> the change from 9c3db310ff0 to gluster's block-status implementation.
>
> Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   block/gluster.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)

Thanks for the review, applied to my block branch:

https://github.com/XanClic/qemu/commits/block

Hanna



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

end of thread, other threads:[~2021-09-07  8:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 14:36 [PATCH] gluster: Align block-status tail Max Reitz
2021-08-05 19:35 ` Eric Blake
2021-09-07  8:08 ` Hanna Reitz

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.