diff mbox series

[v7,6/8] config: add check to block layer

Message ID 20220816062522.85714-7-faithilikerun@gmail.com
State New
Headers show
Series Add support for zoned device | expand

Commit Message

Sam Li Aug. 16, 2022, 6:25 a.m. UTC
Putting zoned/non-zoned BlockDrivers on top of each other is not
allowed.

Signed-off-by: Sam Li <faithilikerun@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c                          | 14 ++++++++++++++
 block/raw-format.c               |  1 +
 include/block/block_int-common.h |  5 +++++
 3 files changed, 20 insertions(+)

Comments

Stefan Hajnoczi Aug. 23, 2022, 12:54 a.m. UTC | #1
On Tue, Aug 16, 2022 at 02:25:20PM +0800, Sam Li wrote:
> Putting zoned/non-zoned BlockDrivers on top of each other is not
> allowed.
> 
> Signed-off-by: Sam Li <faithilikerun@gmail.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block.c                          | 14 ++++++++++++++
>  block/raw-format.c               |  1 +
>  include/block/block_int-common.h |  5 +++++
>  3 files changed, 20 insertions(+)
> 
> diff --git a/block.c b/block.c
> index bc85f46eed..affe6c597e 100644
> --- a/block.c
> +++ b/block.c
> @@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
>          return;
>      }
>  
> +    /*
> +     * Non-zoned block drivers do not follow zoned storage constraints
> +     * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned
> +     * drivers in a graph.
> +     */
> +    if (!parent_bs->drv->supports_zoned_children &&
> +        child_bs->bl.zoned != BLK_Z_HM) {

Is this logical expression correct:

  If the parent does not support zoned children and the child is not
  zoned, fail with an error.

?

> +        error_setg(errp, "Cannot add a %s child to a %s parent",
> +                   child_bs->bl.zoned == BLK_Z_HM ? "zoned" : "non-zoned",
> +                   parent_bs->drv->supports_zoned_children ?
> +                   "support zoned children" : "not support zoned children");
> +        return;
> +    }
> +
>      if (!QLIST_EMPTY(&child_bs->parents)) {
>          error_setg(errp, "The node %s already has a parent",
>                     child_bs->node_name);
> diff --git a/block/raw-format.c b/block/raw-format.c
> index 6b20bd22ef..9441536819 100644
> --- a/block/raw-format.c
> +++ b/block/raw-format.c
> @@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,
>  BlockDriver bdrv_raw = {
>      .format_name          = "raw",
>      .instance_size        = sizeof(BDRVRawState),
> +    .supports_zoned_children = true,
>      .bdrv_probe           = &raw_probe,
>      .bdrv_reopen_prepare  = &raw_reopen_prepare,
>      .bdrv_reopen_commit   = &raw_reopen_commit,
> diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
> index de44c7b6f4..4c44592b59 100644
> --- a/include/block/block_int-common.h
> +++ b/include/block/block_int-common.h
> @@ -126,6 +126,11 @@ struct BlockDriver {
>       */
>      bool is_format;
>  
> +    /*
> +     * Set to true if the BlockDriver supports zoned children.
> +     */
> +    bool supports_zoned_children;
> +
>      /*
>       * Drivers not implementing bdrv_parse_filename nor bdrv_open should have
>       * this field set to true, except ones that are defined only by their
> -- 
> 2.37.1
>
Sam Li Aug. 23, 2022, 4:25 a.m. UTC | #2
Stefan Hajnoczi <stefanha@redhat.com> 于2022年8月23日周二 08:54写道:
>
> On Tue, Aug 16, 2022 at 02:25:20PM +0800, Sam Li wrote:
> > Putting zoned/non-zoned BlockDrivers on top of each other is not
> > allowed.
> >
> > Signed-off-by: Sam Li <faithilikerun@gmail.com>
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  block.c                          | 14 ++++++++++++++
> >  block/raw-format.c               |  1 +
> >  include/block/block_int-common.h |  5 +++++
> >  3 files changed, 20 insertions(+)
> >
> > diff --git a/block.c b/block.c
> > index bc85f46eed..affe6c597e 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
> >          return;
> >      }
> >
> > +    /*
> > +     * Non-zoned block drivers do not follow zoned storage constraints
> > +     * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned
> > +     * drivers in a graph.
> > +     */
> > +    if (!parent_bs->drv->supports_zoned_children &&
> > +        child_bs->bl.zoned != BLK_Z_HM) {
>

Should be:
+if (!parent_bs->drv->supports_zoned_children &&
+        child_bs->bl.zoned == BLK_Z_HM)

> Is this logical expression correct:
>
>   If the parent does not support zoned children and the child is not
>   zoned, fail with an error.
>
> ?

No. It should be:

If the parent does not support zoned children and the child is zoned,
fail with an error.  It should handle the case where a filter node is
inserted above a raw block driver with a zoned_host_device child.

There are some QEMU command-line constraints for the zoned devices. I
was wondering where to add such support so that it can print an error
message for users:
1. cache.direct= setting
2. mix zoned/non-zoned drivers

>
> > +        error_setg(errp, "Cannot add a %s child to a %s parent",
> > +                   child_bs->bl.zoned == BLK_Z_HM ? "zoned" : "non-zoned",
> > +                   parent_bs->drv->supports_zoned_children ?
> > +                   "support zoned children" : "not support zoned children");
> > +        return;
> > +    }
> > +
> >      if (!QLIST_EMPTY(&child_bs->parents)) {
> >          error_setg(errp, "The node %s already has a parent",
> >                     child_bs->node_name);
> > diff --git a/block/raw-format.c b/block/raw-format.c
> > index 6b20bd22ef..9441536819 100644
> > --- a/block/raw-format.c
> > +++ b/block/raw-format.c
> > @@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,
> >  BlockDriver bdrv_raw = {
> >      .format_name          = "raw",
> >      .instance_size        = sizeof(BDRVRawState),
> > +    .supports_zoned_children = true,
> >      .bdrv_probe           = &raw_probe,
> >      .bdrv_reopen_prepare  = &raw_reopen_prepare,
> >      .bdrv_reopen_commit   = &raw_reopen_commit,
> > diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
> > index de44c7b6f4..4c44592b59 100644
> > --- a/include/block/block_int-common.h
> > +++ b/include/block/block_int-common.h
> > @@ -126,6 +126,11 @@ struct BlockDriver {
> >       */
> >      bool is_format;
> >
> > +    /*
> > +     * Set to true if the BlockDriver supports zoned children.
> > +     */
> > +    bool supports_zoned_children;
> > +
> >      /*
> >       * Drivers not implementing bdrv_parse_filename nor bdrv_open should have
> >       * this field set to true, except ones that are defined only by their
> > --
> > 2.37.1
> >
Stefan Hajnoczi Aug. 23, 2022, 12:36 p.m. UTC | #3
On Tue, Aug 23, 2022 at 12:25:23PM +0800, Sam Li wrote:
> Stefan Hajnoczi <stefanha@redhat.com> 于2022年8月23日周二 08:54写道:
> >
> > On Tue, Aug 16, 2022 at 02:25:20PM +0800, Sam Li wrote:
> > > Putting zoned/non-zoned BlockDrivers on top of each other is not
> > > allowed.
> > >
> > > Signed-off-by: Sam Li <faithilikerun@gmail.com>
> > > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > > ---
> > >  block.c                          | 14 ++++++++++++++
> > >  block/raw-format.c               |  1 +
> > >  include/block/block_int-common.h |  5 +++++
> > >  3 files changed, 20 insertions(+)
> > >
> > > diff --git a/block.c b/block.c
> > > index bc85f46eed..affe6c597e 100644
> > > --- a/block.c
> > > +++ b/block.c
> > > @@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
> > >          return;
> > >      }
> > >
> > > +    /*
> > > +     * Non-zoned block drivers do not follow zoned storage constraints
> > > +     * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned
> > > +     * drivers in a graph.
> > > +     */
> > > +    if (!parent_bs->drv->supports_zoned_children &&
> > > +        child_bs->bl.zoned != BLK_Z_HM) {
> >
> 
> Should be:
> +if (!parent_bs->drv->supports_zoned_children &&
> +        child_bs->bl.zoned == BLK_Z_HM)
> 
> > Is this logical expression correct:
> >
> >   If the parent does not support zoned children and the child is not
> >   zoned, fail with an error.
> >
> > ?
> 
> No. It should be:
> 
> If the parent does not support zoned children and the child is zoned,
> fail with an error.  It should handle the case where a filter node is
> inserted above a raw block driver with a zoned_host_device child.
> 
> There are some QEMU command-line constraints for the zoned devices. I
> was wondering where to add such support so that it can print an error
> message for users:
> 1. cache.direct= setting

The O_DIRECT requirement is specific to file-posix and Linux's zoned
block device implementation, so it belongs in file-posix.c's
zoned_host_device .bdrv_file_open() function.

> 2. mix zoned/non-zoned drivers

This is generic and I think bdrv_add_child() is the right place for
parent-child compatibility checks.
diff mbox series

Patch

diff --git a/block.c b/block.c
index bc85f46eed..affe6c597e 100644
--- a/block.c
+++ b/block.c
@@ -7947,6 +7947,20 @@  void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,
         return;
     }
 
+    /*
+     * Non-zoned block drivers do not follow zoned storage constraints
+     * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned
+     * drivers in a graph.
+     */
+    if (!parent_bs->drv->supports_zoned_children &&
+        child_bs->bl.zoned != BLK_Z_HM) {
+        error_setg(errp, "Cannot add a %s child to a %s parent",
+                   child_bs->bl.zoned == BLK_Z_HM ? "zoned" : "non-zoned",
+                   parent_bs->drv->supports_zoned_children ?
+                   "support zoned children" : "not support zoned children");
+        return;
+    }
+
     if (!QLIST_EMPTY(&child_bs->parents)) {
         error_setg(errp, "The node %s already has a parent",
                    child_bs->node_name);
diff --git a/block/raw-format.c b/block/raw-format.c
index 6b20bd22ef..9441536819 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -614,6 +614,7 @@  static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,
 BlockDriver bdrv_raw = {
     .format_name          = "raw",
     .instance_size        = sizeof(BDRVRawState),
+    .supports_zoned_children = true,
     .bdrv_probe           = &raw_probe,
     .bdrv_reopen_prepare  = &raw_reopen_prepare,
     .bdrv_reopen_commit   = &raw_reopen_commit,
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index de44c7b6f4..4c44592b59 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -126,6 +126,11 @@  struct BlockDriver {
      */
     bool is_format;
 
+    /*
+     * Set to true if the BlockDriver supports zoned children.
+     */
+    bool supports_zoned_children;
+
     /*
      * Drivers not implementing bdrv_parse_filename nor bdrv_open should have
      * this field set to true, except ones that are defined only by their