diff mbox series

[v6,1/4] block: Add zoned device model property

Message ID 20190904210100.10501-2-dmitry.fomichev@wdc.com (mailing list archive)
State New, archived
Headers show
Series virtio/block: handle zoned backing devices | expand

Commit Message

Dmitry Fomichev Sept. 4, 2019, 9 p.m. UTC
This commit adds Zoned Device Model (as defined in T10 ZBC and
T13 ZAC standards) as a block driver property, along with some
useful access functions.

A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also
introduced. Only the drivers having this permission will be allowed
to open host managed zoned block devices.

No code is added yet to initialize or check the value of this new
property, therefore this commit doesn't change any functionality.

Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
---
 block.c                   | 15 +++++++++++++++
 include/block/block.h     | 19 ++++++++++++++++++-
 include/block/block_int.h |  3 +++
 3 files changed, 36 insertions(+), 1 deletion(-)

Comments

Stefano Garzarella Sept. 6, 2019, 8:11 a.m. UTC | #1
On Wed, Sep 04, 2019 at 05:00:57PM -0400, Dmitry Fomichev wrote:
> This commit adds Zoned Device Model (as defined in T10 ZBC and
> T13 ZAC standards) as a block driver property, along with some
> useful access functions.
> 
> A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also
> introduced. Only the drivers having this permission will be allowed
> to open host managed zoned block devices.
> 
> No code is added yet to initialize or check the value of this new
> property, therefore this commit doesn't change any functionality.
> 
> Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> ---
>  block.c                   | 15 +++++++++++++++
>  include/block/block.h     | 19 ++++++++++++++++++-
>  include/block/block_int.h |  3 +++
>  3 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 874a29a983..69f565e1e9 100644
> --- a/block.c
> +++ b/block.c
> @@ -4679,6 +4679,21 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
>      *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
>  }
>  
> +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs)
> +{
> +    return bs->bl.zoned_model;
> +}
> +
> +bool bdrv_is_hm_zoned(BlockDriverState *bs)
> +{
> +    /*
> +     * Host Aware zone devices are supposed to be able to work
> +     * just like regular block devices. Thus, we only consider
> +     * Host Managed devices to be zoned here.
> +     */
> +    return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM;
> +}
> +
>  bool bdrv_is_sg(BlockDriverState *bs)
>  {
>      return bs->sg;
> diff --git a/include/block/block.h b/include/block/block.h
> index 124ad40809..28d065ed80 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -271,18 +271,33 @@ enum {
>       */
>      BLK_PERM_GRAPH_MOD          = 0x10,
>  
> +    /**
> +     * This permission is required to open host-managed zoned block devices.
> +     */
> +    BLK_PERM_SUPPORT_HM_ZONED   = 0x20,
> +
>      BLK_PERM_ALL                = 0x1f,

Should we update BLK_PERM_ALL to 0x3f?

Thanks,
Stefano
Dmitry Fomichev Sept. 6, 2019, 4:17 p.m. UTC | #2
On Fri, 2019-09-06 at 10:11 +0200, Stefano Garzarella wrote:
> On Wed, Sep 04, 2019 at 05:00:57PM -0400, Dmitry Fomichev wrote:
> > This commit adds Zoned Device Model (as defined in T10 ZBC and
> > T13 ZAC standards) as a block driver property, along with some
> > useful access functions.
> > 
> > A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also
> > introduced. Only the drivers having this permission will be allowed
> > to open host managed zoned block devices.
> > 
> > No code is added yet to initialize or check the value of this new
> > property, therefore this commit doesn't change any functionality.
> > 
> > Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> > ---
> >  block.c                   | 15 +++++++++++++++
> >  include/block/block.h     | 19 ++++++++++++++++++-
> >  include/block/block_int.h |  3 +++
> >  3 files changed, 36 insertions(+), 1 deletion(-)
> > 
> > diff --git a/block.c b/block.c
> > index 874a29a983..69f565e1e9 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -4679,6 +4679,21 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
> >      *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
> >  }
> >  
> > +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs)
> > +{
> > +    return bs->bl.zoned_model;
> > +}
> > +
> > +bool bdrv_is_hm_zoned(BlockDriverState *bs)
> > +{
> > +    /*
> > +     * Host Aware zone devices are supposed to be able to work
> > +     * just like regular block devices. Thus, we only consider
> > +     * Host Managed devices to be zoned here.
> > +     */
> > +    return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM;
> > +}
> > +
> >  bool bdrv_is_sg(BlockDriverState *bs)
> >  {
> >      return bs->sg;
> > diff --git a/include/block/block.h b/include/block/block.h
> > index 124ad40809..28d065ed80 100644
> > --- a/include/block/block.h
> > +++ b/include/block/block.h
> > @@ -271,18 +271,33 @@ enum {
> >       */
> >      BLK_PERM_GRAPH_MOD          = 0x10,
> >  
> > +    /**
> > +     * This permission is required to open host-managed zoned block devices.
> > +     */
> > +    BLK_PERM_SUPPORT_HM_ZONED   = 0x20,
> > +
> >      BLK_PERM_ALL                = 0x1f,
> 
> Should we update BLK_PERM_ALL to 0x3f?
> 
Stefano, good catch! Will update and resend...

> Thanks,
> Stefano
>
Stefano Garzarella Sept. 6, 2019, 9:10 p.m. UTC | #3
On Fri, Sep 06, 2019 at 04:17:12PM +0000, Dmitry Fomichev wrote:
> On Fri, 2019-09-06 at 10:11 +0200, Stefano Garzarella wrote:
> > On Wed, Sep 04, 2019 at 05:00:57PM -0400, Dmitry Fomichev wrote:
> > > This commit adds Zoned Device Model (as defined in T10 ZBC and
> > > T13 ZAC standards) as a block driver property, along with some
> > > useful access functions.
> > > 
> > > A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also
> > > introduced. Only the drivers having this permission will be allowed
> > > to open host managed zoned block devices.
> > > 
> > > No code is added yet to initialize or check the value of this new
> > > property, therefore this commit doesn't change any functionality.
> > > 
> > > Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> > > ---
> > >  block.c                   | 15 +++++++++++++++
> > >  include/block/block.h     | 19 ++++++++++++++++++-
> > >  include/block/block_int.h |  3 +++
> > >  3 files changed, 36 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/block.c b/block.c
> > > index 874a29a983..69f565e1e9 100644
> > > --- a/block.c
> > > +++ b/block.c
> > > @@ -4679,6 +4679,21 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
> > >      *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
> > >  }
> > >  
> > > +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs)
> > > +{
> > > +    return bs->bl.zoned_model;
> > > +}
> > > +
> > > +bool bdrv_is_hm_zoned(BlockDriverState *bs)
> > > +{
> > > +    /*
> > > +     * Host Aware zone devices are supposed to be able to work
> > > +     * just like regular block devices. Thus, we only consider
> > > +     * Host Managed devices to be zoned here.
> > > +     */
> > > +    return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM;
> > > +}
> > > +
> > >  bool bdrv_is_sg(BlockDriverState *bs)
> > >  {
> > >      return bs->sg;
> > > diff --git a/include/block/block.h b/include/block/block.h
> > > index 124ad40809..28d065ed80 100644
> > > --- a/include/block/block.h
> > > +++ b/include/block/block.h
> > > @@ -271,18 +271,33 @@ enum {
> > >       */
> > >      BLK_PERM_GRAPH_MOD          = 0x10,
> > >  
> > > +    /**
> > > +     * This permission is required to open host-managed zoned block devices.
> > > +     */
> > > +    BLK_PERM_SUPPORT_HM_ZONED   = 0x20,
> > > +
> > >      BLK_PERM_ALL                = 0x1f,
> > 
> > Should we update BLK_PERM_ALL to 0x3f?
> > 
> Stefano, good catch! Will update and resend...
> 

Good!

Looking better, if we update it, maybe we should also change something in
xdbg_graph_add_edge() since there is this line:

    QEMU_BUILD_BUG_ON(1UL << (ARRAY_SIZE(permissions) - 1) != BLK_PERM_ALL + 1);

We should extend the permissions array or change this check.

Thanks,
Stefano
Dmitry Fomichev Sept. 6, 2019, 9:21 p.m. UTC | #4
On Fri, 2019-09-06 at 23:10 +0200, Stefano Garzarella wrote:
> On Fri, Sep 06, 2019 at 04:17:12PM +0000, Dmitry Fomichev wrote:
> > On Fri, 2019-09-06 at 10:11 +0200, Stefano Garzarella wrote:
> > > On Wed, Sep 04, 2019 at 05:00:57PM -0400, Dmitry Fomichev wrote:
> > > > This commit adds Zoned Device Model (as defined in T10 ZBC and
> > > > T13 ZAC standards) as a block driver property, along with some
> > > > useful access functions.
> > > > 
> > > > A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also
> > > > introduced. Only the drivers having this permission will be allowed
> > > > to open host managed zoned block devices.
> > > > 
> > > > No code is added yet to initialize or check the value of this new
> > > > property, therefore this commit doesn't change any functionality.
> > > > 
> > > > Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> > > > ---
> > > >  block.c                   | 15 +++++++++++++++
> > > >  include/block/block.h     | 19 ++++++++++++++++++-
> > > >  include/block/block_int.h |  3 +++
> > > >  3 files changed, 36 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/block.c b/block.c
> > > > index 874a29a983..69f565e1e9 100644
> > > > --- a/block.c
> > > > +++ b/block.c
> > > > @@ -4679,6 +4679,21 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
> > > >      *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
> > > >  }
> > > >  
> > > > +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs)
> > > > +{
> > > > +    return bs->bl.zoned_model;
> > > > +}
> > > > +
> > > > +bool bdrv_is_hm_zoned(BlockDriverState *bs)
> > > > +{
> > > > +    /*
> > > > +     * Host Aware zone devices are supposed to be able to work
> > > > +     * just like regular block devices. Thus, we only consider
> > > > +     * Host Managed devices to be zoned here.
> > > > +     */
> > > > +    return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM;
> > > > +}
> > > > +
> > > >  bool bdrv_is_sg(BlockDriverState *bs)
> > > >  {
> > > >      return bs->sg;
> > > > diff --git a/include/block/block.h b/include/block/block.h
> > > > index 124ad40809..28d065ed80 100644
> > > > --- a/include/block/block.h
> > > > +++ b/include/block/block.h
> > > > @@ -271,18 +271,33 @@ enum {
> > > >       */
> > > >      BLK_PERM_GRAPH_MOD          = 0x10,
> > > >  
> > > > +    /**
> > > > +     * This permission is required to open host-managed zoned block devices.
> > > > +     */
> > > > +    BLK_PERM_SUPPORT_HM_ZONED   = 0x20,
> > > > +
> > > >      BLK_PERM_ALL                = 0x1f,
> > > 
> > > Should we update BLK_PERM_ALL to 0x3f?
> > > 
> > Stefano, good catch! Will update and resend...
> > 
> 
> Good!
> 
> Looking better, if we update it, maybe we should also change something in
> xdbg_graph_add_edge() since there is this line:
> 
>     QEMU_BUILD_BUG_ON(1UL << (ARRAY_SIZE(permissions) - 1) != BLK_PERM_ALL + 1);
> 
> We should extend the permissions array or change this check.
> 
Yes, I've noticed that the mask change triggers this BUG_ON.
I am adding BLK_PERM_SUPPORT_HM_ZONED permission into "permissions" array and this
also requires adding the permission to qapi schema. I think that would be the right
thing to do rather than to modify this check.

Dmitry

> Thanks,
> Stefano
diff mbox series

Patch

diff --git a/block.c b/block.c
index 874a29a983..69f565e1e9 100644
--- a/block.c
+++ b/block.c
@@ -4679,6 +4679,21 @@  void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
     *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
 }
 
+BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs)
+{
+    return bs->bl.zoned_model;
+}
+
+bool bdrv_is_hm_zoned(BlockDriverState *bs)
+{
+    /*
+     * Host Aware zone devices are supposed to be able to work
+     * just like regular block devices. Thus, we only consider
+     * Host Managed devices to be zoned here.
+     */
+    return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM;
+}
+
 bool bdrv_is_sg(BlockDriverState *bs)
 {
     return bs->sg;
diff --git a/include/block/block.h b/include/block/block.h
index 124ad40809..28d065ed80 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -271,18 +271,33 @@  enum {
      */
     BLK_PERM_GRAPH_MOD          = 0x10,
 
+    /**
+     * This permission is required to open host-managed zoned block devices.
+     */
+    BLK_PERM_SUPPORT_HM_ZONED   = 0x20,
+
     BLK_PERM_ALL                = 0x1f,
 
     DEFAULT_PERM_PASSTHROUGH    = BLK_PERM_CONSISTENT_READ
                                  | BLK_PERM_WRITE
                                  | BLK_PERM_WRITE_UNCHANGED
-                                 | BLK_PERM_RESIZE,
+                                 | BLK_PERM_RESIZE
+                                 | BLK_PERM_SUPPORT_HM_ZONED,
 
     DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH,
 };
 
 char *bdrv_perm_names(uint64_t perm);
 
+/*
+ * Known zoned device models.
+ */
+typedef enum {
+    BDRV_ZONED_MODEL_NONE, /* Regular block device */
+    BDRV_ZONED_MODEL_HA,   /* Host-aware zoned block device */
+    BDRV_ZONED_MODEL_HM,   /* Host-managed zoned block device */
+} BdrvZonedModel;
+
 /* disk I/O throttling */
 void bdrv_init(void);
 void bdrv_init_with_whitelist(void);
@@ -359,6 +374,8 @@  int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
 BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts,
                                BlockDriverState *in_bs, Error **errp);
 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
+BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs);
+bool bdrv_is_hm_zoned(BlockDriverState *bs);
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
 int bdrv_commit(BlockDriverState *bs);
 int bdrv_change_backing_file(BlockDriverState *bs,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 0422acdf1c..928cbae9a5 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -635,6 +635,9 @@  typedef struct BlockLimits {
 
     /* maximum number of iovec elements */
     int max_iov;
+
+    /* Zoned device model. Zero value indicates a regular block device */
+    BdrvZonedModel zoned_model;
 } BlockLimits;
 
 typedef struct BdrvOpBlocker BdrvOpBlocker;