Skip to contentSkip to conversation

replication: Fix replication open fail

PATCH Applied Wang Guang 3 participants 3 messages Oct 25, 2017 – Oct 27, 2017 Block layer

lore
Share & tools
lore

Wang Guang

author
#0 lore raw

PATCH 1/1 replication: Fix replication open fail

replication_child_perm request write
permissions for all child which will lead bdrv_check_perm fail. replication_child_perm() should request write permissions only if it is writable itself.

---
 block/replication.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
block/replication.c +7 -4
index 3a4e682..1c95d67 100644
@@ -161,10 +161,13 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
                                    uint64_t perm, uint64_t shared,
                                    uint64_t *nperm, uint64_t *nshared)
 {
-    *nperm = *nshared = BLK_PERM_CONSISTENT_READ \
-                        | BLK_PERM_WRITE \
-                        | BLK_PERM_WRITE_UNCHANGED;
-
+    *nperm = BLK_PERM_CONSISTENT_READ;
+    if ((bs->open_flags & (BDRV_O_INACTIVE | BDRV_O_RDWR)) == BDRV_O_RDWR) {
+        *nperm |= BLK_PERM_WRITE;
+    }
+    *nshared = BLK_PERM_CONSISTENT_READ \
+               | BLK_PERM_WRITE \
+               | BLK_PERM_WRITE_UNCHANGED;
     return;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Wang Guang

replication_child_perm request write
permissions for all child which will lead bdrv_check_perm fail. replication_child_perm() should request write permissions only if it is writable itself.

Thanks, this patch fixs the problem in
http://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg03358.html.

Quoted 27 lines
---
  block/replication.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
block/replication.c +7 -4
index 3a4e682..1c95d67 100644
@@ -161,10 +161,13 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
                                     uint64_t perm, uint64_t shared,
                                     uint64_t *nperm, uint64_t *nshared)
  {
-    *nperm = *nshared = BLK_PERM_CONSISTENT_READ \
-                        | BLK_PERM_WRITE \
-                        | BLK_PERM_WRITE_UNCHANGED;
-
+    *nperm = BLK_PERM_CONSISTENT_READ;
+    if ((bs->open_flags & (BDRV_O_INACTIVE | BDRV_O_RDWR)) == BDRV_O_RDWR) {
+        *nperm |= BLK_PERM_WRITE;
+    }
+    *nshared = BLK_PERM_CONSISTENT_READ \
+               | BLK_PERM_WRITE \
+               | BLK_PERM_WRITE_UNCHANGED;
      return;
  }
 
Signature · 2 lines
Thanks
     -Xie