[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 24/46] block: Include details on permission errors in
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 24/46] block: Include details on permission errors in message |
Date: |
Tue, 28 Feb 2017 21:36:23 +0100 |
Instead of just telling that there was some conflict, we can be specific
and tell which permissions were in conflict and which way the conflict
is.
Signed-off-by: Kevin Wolf <address@hidden>
Acked-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 56 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index e03cc5d..f72a67f 100644
--- a/block.c
+++ b/block.c
@@ -1462,6 +1462,43 @@ static void bdrv_get_cumulative_perm(BlockDriverState
*bs, uint64_t *perm,
*shared_perm = cumulative_shared_perms;
}
+static char *bdrv_child_user_desc(BdrvChild *c)
+{
+ if (c->role->get_parent_desc) {
+ return c->role->get_parent_desc(c);
+ }
+
+ return g_strdup("another user");
+}
+
+static char *bdrv_perm_names(uint64_t perm)
+{
+ struct perm_name {
+ uint64_t perm;
+ const char *name;
+ } permissions[] = {
+ { BLK_PERM_CONSISTENT_READ, "consistent read" },
+ { BLK_PERM_WRITE, "write" },
+ { BLK_PERM_WRITE_UNCHANGED, "write unchanged" },
+ { BLK_PERM_RESIZE, "resize" },
+ { BLK_PERM_GRAPH_MOD, "change children" },
+ { 0, NULL }
+ };
+
+ char *result = g_strdup("");
+ struct perm_name *p;
+
+ for (p = permissions; p->name; p++) {
+ if (perm & p->perm) {
+ char *old = result;
+ result = g_strdup_printf("%s%s%s", old, *old ? ", " : "", p->name);
+ g_free(old);
+ }
+ }
+
+ return result;
+}
+
/*
* Checks whether a new reference to @bs can be added if the new user requires
* @new_used_perm/@new_shared_perm as its permissions. If @ignore_child is set,
@@ -1486,17 +1523,25 @@ static int bdrv_check_update_perm(BlockDriverState *bs,
uint64_t new_used_perm,
continue;
}
- if ((new_used_perm & c->shared_perm) != new_used_perm ||
- (c->perm & new_shared_perm) != c->perm)
- {
- const char *user = NULL;
- if (c->role->get_name) {
- user = c->role->get_name(c);
- if (user && !*user) {
- user = NULL;
- }
- }
- error_setg(errp, "Conflicts with %s", user ?: "another operation");
+ if ((new_used_perm & c->shared_perm) != new_used_perm) {
+ char *user = bdrv_child_user_desc(c);
+ char *perm_names = bdrv_perm_names(new_used_perm &
~c->shared_perm);
+ error_setg(errp, "Conflicts with use by %s as '%s', which does not
"
+ "allow '%s' on %s",
+ user, c->name, perm_names, bdrv_get_node_name(c->bs));
+ g_free(user);
+ g_free(perm_names);
+ return -EPERM;
+ }
+
+ if ((c->perm & new_shared_perm) != c->perm) {
+ char *user = bdrv_child_user_desc(c);
+ char *perm_names = bdrv_perm_names(c->perm & ~new_shared_perm);
+ error_setg(errp, "Conflicts with use by %s as '%s', which uses "
+ "'%s' on %s",
+ user, c->name, perm_names, bdrv_get_node_name(c->bs));
+ g_free(user);
+ g_free(perm_names);
return -EPERM;
}
--
1.8.3.1
- [Qemu-block] [PULL 15/46] block: Add permissions to blk_new(), (continued)
- [Qemu-block] [PULL 15/46] block: Add permissions to blk_new(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 16/46] block: Add error parameter to blk_insert_bs(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 17/46] block: Add BDRV_O_RESIZE for blk_new_open(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 18/46] block: Request real permissions in blk_new_open(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 19/46] block: Allow error return in BlockDevOps.change_media_cb(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 20/46] hw/block: Request permissions, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 21/46] hw/block: Introduce share-rw qdev property, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 22/46] blockjob: Add permissions to block_job_create(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 23/46] block: Add BdrvChildRole.get_parent_desc(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 25/46] block: Add BdrvChildRole.stay_at_node, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 24/46] block: Include details on permission errors in message,
Kevin Wolf <=
- [Qemu-block] [PULL 30/46] block: Fix pending requests check in bdrv_append(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 28/46] commit: Use real permissions for HMP 'commit', Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 27/46] commit: Use real permissions in commit block job, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 29/46] backup: Use real permissions in backup block job, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 26/46] blockjob: Add permissions to block_job_add_bdrv(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 31/46] block: BdrvChildRole.attach/detach() callbacks, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 33/46] blockjob: Factor out block_job_remove_all_bdrv(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 32/46] block: Allow backing file links in change_parent_backing_link(), Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 35/46] stream: Use real permissions in streaming block job, Kevin Wolf, 2017/02/28
- [Qemu-block] [PULL 34/46] mirror: Use real permissions in mirror/active commit block job, Kevin Wolf, 2017/02/28