diff mbox

[v2,02/16] block-backend: Add blk_request_perm

Message ID 20170419094356.19826-3-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng April 19, 2017, 9:43 a.m. UTC
This function tries to request, if not granted yet, for the given
permissions.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/block-backend.c          | 12 ++++++++++++
 include/sysemu/block-backend.h |  1 +
 2 files changed, 13 insertions(+)

Comments

Stefan Hajnoczi May 11, 2017, 7:32 p.m. UTC | #1
On Wed, Apr 19, 2017 at 05:43:42PM +0800, Fam Zheng wrote:
> This function tries to request, if not granted yet, for the given
> permissions.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/block-backend.c          | 12 ++++++++++++
>  include/sysemu/block-backend.h |  1 +
>  2 files changed, 13 insertions(+)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 7405024..6bdd9ce 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -629,6 +629,18 @@ void blk_resume_after_migration(Error **errp)
>      }
>  }
>  
> +int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp)
> +{
> +    uint64_t blk_perm, shared_perm;
> +
> +    blk_get_perm(blk, &blk_perm, &shared_perm);
> +    if ((blk_perm & perm) == perm) {
> +        return 0;
> +    }
> +    blk_perm |= perm;
> +    return blk_set_perm(blk, blk_perm, shared_perm, errp);
> +}

I'm slightly confused about why this function is needed.  blk_set_perm()
doesn't do quite the right thing?
Fam Zheng May 24, 2017, 2:16 a.m. UTC | #2
On Thu, 05/11 15:32, Stefan Hajnoczi wrote:
> On Wed, Apr 19, 2017 at 05:43:42PM +0800, Fam Zheng wrote:
> > This function tries to request, if not granted yet, for the given
> > permissions.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  block/block-backend.c          | 12 ++++++++++++
> >  include/sysemu/block-backend.h |  1 +
> >  2 files changed, 13 insertions(+)
> > 
> > diff --git a/block/block-backend.c b/block/block-backend.c
> > index 7405024..6bdd9ce 100644
> > --- a/block/block-backend.c
> > +++ b/block/block-backend.c
> > @@ -629,6 +629,18 @@ void blk_resume_after_migration(Error **errp)
> >      }
> >  }
> >  
> > +int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp)
> > +{
> > +    uint64_t blk_perm, shared_perm;
> > +
> > +    blk_get_perm(blk, &blk_perm, &shared_perm);
> > +    if ((blk_perm & perm) == perm) {
> > +        return 0;
> > +    }
> > +    blk_perm |= perm;
> > +    return blk_set_perm(blk, blk_perm, shared_perm, errp);
> > +}
> 
> I'm slightly confused about why this function is needed.  blk_set_perm()
> doesn't do quite the right thing?

Sorry for the late reply!

I think blk_set_perm() always calls bs->drv->bdrv_check_perm() even when the
required perm bits are already acquired.

Fam
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 7405024..6bdd9ce 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -629,6 +629,18 @@  void blk_resume_after_migration(Error **errp)
     }
 }
 
+int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp)
+{
+    uint64_t blk_perm, shared_perm;
+
+    blk_get_perm(blk, &blk_perm, &shared_perm);
+    if ((blk_perm & perm) == perm) {
+        return 0;
+    }
+    blk_perm |= perm;
+    return blk_set_perm(blk, blk_perm, shared_perm, errp);
+}
+
 static int blk_do_attach_dev(BlockBackend *blk, void *dev)
 {
     if (blk->dev) {
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 7462228..537f92f 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -116,6 +116,7 @@  bool bdrv_is_root_node(BlockDriverState *bs);
 int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
                  Error **errp);
 void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm);
+int blk_request_perm(BlockBackend *blk, uint64_t perm, Error **errp);
 
 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
 void blk_iostatus_enable(BlockBackend *blk);