Browse Source

block: Improve "Block node is read-only" message

This message does not make any sense when it appears as the response to
making an R/W node read-only.  We should detect that case and emit a
different message, then.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
master
Max Reitz 1 month ago
parent
commit
481e0eeef4
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      block.c

+ 16
- 1
block.c View File

@@ -1709,6 +1709,8 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q,
1709 1709
                                  GSList *ignore_children, Error **errp);
1710 1710
 static void bdrv_child_abort_perm_update(BdrvChild *c);
1711 1711
 static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
1712
+static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
1713
+                                     uint64_t *shared_perm);
1712 1714
 
1713 1715
 typedef struct BlockReopenQueueEntry {
1714 1716
      bool prepared;
@@ -1795,7 +1797,20 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,
1795 1797
     if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) &&
1796 1798
         !bdrv_is_writable_after_reopen(bs, q))
1797 1799
     {
1798
-        error_setg(errp, "Block node is read-only");
1800
+        if (!bdrv_is_writable_after_reopen(bs, NULL)) {
1801
+            error_setg(errp, "Block node is read-only");
1802
+        } else {
1803
+            uint64_t current_perms, current_shared;
1804
+            bdrv_get_cumulative_perm(bs, &current_perms, &current_shared);
1805
+            if (current_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) {
1806
+                error_setg(errp, "Cannot make block node read-only, there is "
1807
+                           "a writer on it");
1808
+            } else {
1809
+                error_setg(errp, "Cannot make block node read-only and create "
1810
+                           "a writer on it");
1811
+            }
1812
+        }
1813
+
1799 1814
         return -EPERM;
1800 1815
     }
1801 1816
 

Loading…
Cancel
Save