diff mbox series

[4/5] vduse-blk: Add vduse-blk resize support

Message ID 20220125131800.91-5-xieyongji@bytedance.com (mailing list archive)
State New, archived
Headers show
Series Support exporting BDSs via VDUSE | expand

Commit Message

Yongji Xie Jan. 25, 2022, 1:17 p.m. UTC
To support block resize, this uses vduse_dev_update_config()
to update the capacity field in configuration space and inject
config interrupt on the block resize callback.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
---
 block/export/vduse-blk.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Stefan Hajnoczi Feb. 7, 2022, 2:18 p.m. UTC | #1
On Tue, Jan 25, 2022 at 09:17:59PM +0800, Xie Yongji wrote:
> To support block resize, this uses vduse_dev_update_config()
> to update the capacity field in configuration space and inject
> config interrupt on the block resize callback.
> 
> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> ---
>  block/export/vduse-blk.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
> index 5a8d289685..83845e9a9a 100644
> --- a/block/export/vduse-blk.c
> +++ b/block/export/vduse-blk.c
> @@ -297,6 +297,23 @@ static void blk_aio_detach(void *opaque)
>      vblk_exp->export.ctx = NULL;
>  }
>  
> +static void vduse_blk_resize(void *opaque)
> +{
> +    BlockExport *exp = opaque;
> +    VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export);
> +    struct virtio_blk_config config;
> +
> +    config.capacity =
> +            cpu_to_le64(blk_getlength(exp->blk) >> VIRTIO_BLK_SECTOR_BITS);
> +    vduse_dev_update_config(vblk_exp->dev, sizeof(config.capacity),
> +                            offsetof(struct virtio_blk_config, capacity),
> +                            (char *)&config.capacity);
> +}
> +
> +static const BlockDevOps vduse_block_ops = {
> +    .resize_cb = vduse_blk_resize,
> +};
> +
>  static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
>                                  Error **errp)
>  {
> @@ -387,6 +404,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
>      blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach,
>                                   vblk_exp);
>  
> +    blk_set_dev_ops(exp->blk, &vduse_block_ops, exp);

Detach is missing, so BlockBackend->dev_ops will become stale after the
export is deleted. Please add code to detach when the export is deleted.
Yongji Xie Feb. 8, 2022, 7:12 a.m. UTC | #2
On Mon, Feb 7, 2022 at 10:18 PM Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> On Tue, Jan 25, 2022 at 09:17:59PM +0800, Xie Yongji wrote:
> > To support block resize, this uses vduse_dev_update_config()
> > to update the capacity field in configuration space and inject
> > config interrupt on the block resize callback.
> >
> > Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> > ---
> >  block/export/vduse-blk.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
> > index 5a8d289685..83845e9a9a 100644
> > --- a/block/export/vduse-blk.c
> > +++ b/block/export/vduse-blk.c
> > @@ -297,6 +297,23 @@ static void blk_aio_detach(void *opaque)
> >      vblk_exp->export.ctx = NULL;
> >  }
> >
> > +static void vduse_blk_resize(void *opaque)
> > +{
> > +    BlockExport *exp = opaque;
> > +    VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export);
> > +    struct virtio_blk_config config;
> > +
> > +    config.capacity =
> > +            cpu_to_le64(blk_getlength(exp->blk) >> VIRTIO_BLK_SECTOR_BITS);
> > +    vduse_dev_update_config(vblk_exp->dev, sizeof(config.capacity),
> > +                            offsetof(struct virtio_blk_config, capacity),
> > +                            (char *)&config.capacity);
> > +}
> > +
> > +static const BlockDevOps vduse_block_ops = {
> > +    .resize_cb = vduse_blk_resize,
> > +};
> > +
> >  static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
> >                                  Error **errp)
> >  {
> > @@ -387,6 +404,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
> >      blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach,
> >                                   vblk_exp);
> >
> > +    blk_set_dev_ops(exp->blk, &vduse_block_ops, exp);
>
> Detach is missing, so BlockBackend->dev_ops will become stale after the
> export is deleted. Please add code to detach when the export is deleted.

OK.

Thanks,
Yongji
diff mbox series

Patch

diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
index 5a8d289685..83845e9a9a 100644
--- a/block/export/vduse-blk.c
+++ b/block/export/vduse-blk.c
@@ -297,6 +297,23 @@  static void blk_aio_detach(void *opaque)
     vblk_exp->export.ctx = NULL;
 }
 
+static void vduse_blk_resize(void *opaque)
+{
+    BlockExport *exp = opaque;
+    VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export);
+    struct virtio_blk_config config;
+
+    config.capacity =
+            cpu_to_le64(blk_getlength(exp->blk) >> VIRTIO_BLK_SECTOR_BITS);
+    vduse_dev_update_config(vblk_exp->dev, sizeof(config.capacity),
+                            offsetof(struct virtio_blk_config, capacity),
+                            (char *)&config.capacity);
+}
+
+static const BlockDevOps vduse_block_ops = {
+    .resize_cb = vduse_blk_resize,
+};
+
 static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
                                 Error **errp)
 {
@@ -387,6 +404,8 @@  static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
     blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach,
                                  vblk_exp);
 
+    blk_set_dev_ops(exp->blk, &vduse_block_ops, exp);
+
     return 0;
 }