[Qemu-devel] [PATCH v14 03/20] block: Respect "force-shared-write" in perm propagating

Fam Zheng posted 20 patches 8 years, 9 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v14 03/20] block: Respect "force-shared-write" in perm propagating
Posted by Fam Zheng 8 years, 9 months ago
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/block.c b/block.c
index f5c4e97..6acf618 100644
--- a/block.c
+++ b/block.c
@@ -1422,6 +1422,21 @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
 static void bdrv_child_abort_perm_update(BdrvChild *c);
 static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
 
+static void bdrv_child_perm(BlockDriverState *bs, BdrvChild *c,
+                            const BdrvChildRole *role,
+                            uint64_t parent_perm, uint64_t parent_shared,
+                            uint64_t *nperm, uint64_t *nshared)
+{
+    if (bs->drv && bs->drv->bdrv_child_perm) {
+        bs->drv->bdrv_child_perm(bs, c, role,
+                                 parent_perm, parent_shared,
+                                 nperm, nshared);
+    }
+    if (bs->force_shared_write) {
+        *nshared |= BLK_PERM_WRITE;
+    }
+}
+
 /*
  * Check whether permissions on this node can be changed in a way that
  * @cumulative_perms and @cumulative_shared_perms are the new cumulative
@@ -1466,9 +1481,9 @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
     /* Check all children */
     QLIST_FOREACH(c, &bs->children, next) {
         uint64_t cur_perm, cur_shared;
-        drv->bdrv_child_perm(bs, c, c->role,
-                             cumulative_perms, cumulative_shared_perms,
-                             &cur_perm, &cur_shared);
+        bdrv_child_perm(bs, c, c->role,
+                        cumulative_perms, cumulative_shared_perms,
+                        &cur_perm, &cur_shared);
         ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
                                     errp);
         if (ret < 0) {
@@ -1528,9 +1543,9 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
     /* Update all children */
     QLIST_FOREACH(c, &bs->children, next) {
         uint64_t cur_perm, cur_shared;
-        drv->bdrv_child_perm(bs, c, c->role,
-                             cumulative_perms, cumulative_shared_perms,
-                             &cur_perm, &cur_shared);
+        bdrv_child_perm(bs, c, c->role,
+                        cumulative_perms, cumulative_shared_perms,
+                        &cur_perm, &cur_shared);
         bdrv_child_set_perm(c, cur_perm, cur_shared);
     }
 }
@@ -1865,8 +1880,8 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
 
     assert(parent_bs->drv);
     assert(bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs));
-    parent_bs->drv->bdrv_child_perm(parent_bs, NULL, child_role,
-                                    perm, shared_perm, &perm, &shared_perm);
+    bdrv_child_perm(parent_bs, NULL, child_role,
+                    perm, shared_perm, &perm, &shared_perm);
 
     child = bdrv_root_attach_child(child_bs, child_name, child_role,
                                    perm, shared_perm, parent_bs, errp);
-- 
2.9.3


Re: [Qemu-devel] [PATCH v14 03/20] block: Respect "force-shared-write" in perm propagating
Posted by Kevin Wolf 8 years, 9 months ago
Am 21.04.2017 um 05:55 hat Fam Zheng geschrieben:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block.c | 31 +++++++++++++++++++++++--------
>  1 file changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/block.c b/block.c
> index f5c4e97..6acf618 100644
> --- a/block.c
> +++ b/block.c
> @@ -1422,6 +1422,21 @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
>  static void bdrv_child_abort_perm_update(BdrvChild *c);
>  static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
>  
> +static void bdrv_child_perm(BlockDriverState *bs, BdrvChild *c,
> +                            const BdrvChildRole *role,
> +                            uint64_t parent_perm, uint64_t parent_shared,
> +                            uint64_t *nperm, uint64_t *nshared)
> +{
> +    if (bs->drv && bs->drv->bdrv_child_perm) {
> +        bs->drv->bdrv_child_perm(bs, c, role,
> +                                 parent_perm, parent_shared,
> +                                 nperm, nshared);
> +    }
> +    if (bs->force_shared_write) {

As discussed on IRC, this should be c->bs->force_shared_write, so that
the option set for a given node refers to all BdrvChild objects pointing
to that node, not to all children of the node.

This means that if you configure this manually and you just want to get
rid of the file locking, setting force-shared-write = true for the
file-posix node is enough (without the change you would have to set it
for all parents of the file-posix node).

> +        *nshared |= BLK_PERM_WRITE;
> +    }
> +}

Kevin