[PATCH v5 2/8] block-backend: Introduce blk_get_guest_block_size()

Xie Yongji posted 8 patches 3 years, 9 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Xie Yongji <xieyongji@bytedance.com>, Coiby Xu <Coiby.Xu@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH v5 2/8] block-backend: Introduce blk_get_guest_block_size()
Posted by Xie Yongji 3 years, 9 months ago
Support getting the guest block size for the block backend.
It's needed for the following commit.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
---
 block/block-backend.c             | 6 ++++++
 include/sysemu/block-backend-io.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index 35457a6a1d..1582ff81c9 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2106,6 +2106,12 @@ void blk_set_guest_block_size(BlockBackend *blk, int align)
     blk->guest_block_size = align;
 }
 
+int blk_get_guest_block_size(BlockBackend *blk)
+{
+    IO_CODE();
+    return blk->guest_block_size;
+}
+
 void *blk_try_blockalign(BlockBackend *blk, size_t size)
 {
     IO_CODE();
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 6517c39295..7600822196 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -73,6 +73,7 @@ void blk_iostatus_set_err(BlockBackend *blk, int error);
 int blk_get_max_iov(BlockBackend *blk);
 int blk_get_max_hw_iov(BlockBackend *blk);
 void blk_set_guest_block_size(BlockBackend *blk, int align);
+int blk_get_guest_block_size(BlockBackend *blk);
 
 void blk_io_plug(BlockBackend *blk);
 void blk_io_unplug(BlockBackend *blk);
-- 
2.20.1
Re: [PATCH v5 2/8] block-backend: Introduce blk_get_guest_block_size()
Posted by Stefan Hajnoczi 3 years, 8 months ago
On Wed, May 04, 2022 at 03:40:45PM +0800, Xie Yongji wrote:
> Support getting the guest block size for the block backend.
> It's needed for the following commit.
> 
> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> ---
>  block/block-backend.c             | 6 ++++++
>  include/sysemu/block-backend-io.h | 1 +
>  2 files changed, 7 insertions(+)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 35457a6a1d..1582ff81c9 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -2106,6 +2106,12 @@ void blk_set_guest_block_size(BlockBackend *blk, int align)
>      blk->guest_block_size = align;
>  }
>  
> +int blk_get_guest_block_size(BlockBackend *blk)
> +{
> +    IO_CODE();
> +    return blk->guest_block_size;

I have sent a patch to remove blk->guest_block_size because this field
is currently unused.

I think there is a cleaner way for this patch series to store the guest
logical_block_size (see next patch). Stashing it in BlockBackend was
attractive because virtio-blk-handler.c lacks a struct to store its
parameters (writable, serial, logical_block_size), but if such a struct
is introduced then there's no need to stash it in BlockBackend.

Stefan
Re: [PATCH v5 2/8] block-backend: Introduce blk_get_guest_block_size()
Posted by Yongji Xie 3 years, 8 months ago
On Wed, May 18, 2022 at 9:17 PM Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> On Wed, May 04, 2022 at 03:40:45PM +0800, Xie Yongji wrote:
> > Support getting the guest block size for the block backend.
> > It's needed for the following commit.
> >
> > Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> > ---
> >  block/block-backend.c             | 6 ++++++
> >  include/sysemu/block-backend-io.h | 1 +
> >  2 files changed, 7 insertions(+)
> >
> > diff --git a/block/block-backend.c b/block/block-backend.c
> > index 35457a6a1d..1582ff81c9 100644
> > --- a/block/block-backend.c
> > +++ b/block/block-backend.c
> > @@ -2106,6 +2106,12 @@ void blk_set_guest_block_size(BlockBackend *blk, int align)
> >      blk->guest_block_size = align;
> >  }
> >
> > +int blk_get_guest_block_size(BlockBackend *blk)
> > +{
> > +    IO_CODE();
> > +    return blk->guest_block_size;
>
> I have sent a patch to remove blk->guest_block_size because this field
> is currently unused.
>

OK.

> I think there is a cleaner way for this patch series to store the guest
> logical_block_size (see next patch). Stashing it in BlockBackend was
> attractive because virtio-blk-handler.c lacks a struct to store its
> parameters (writable, serial, logical_block_size), but if such a struct
> is introduced then there's no need to stash it in BlockBackend.
>

Looks good to me.

Thanks,
Yongji