mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 11:39:53 +00:00
block: Use bdrv_qapi_perm_to_blk_perm()
We can save some LoC in xdbg_graph_add_edge() by using bdrv_qapi_perm_to_blk_perm(). Signed-off-by: Max Reitz <mreitz@redhat.com> Message-id: 20191108123455.39445-3-mreitz@redhat.com Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
7b1d9c4df0
commit
cdb1cec89e
29
block.c
29
block.c
@ -4872,36 +4872,23 @@ static void xdbg_graph_add_node(XDbgBlockGraphConstructor *gr, void *node,
|
||||
static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *parent,
|
||||
const BdrvChild *child)
|
||||
{
|
||||
typedef struct {
|
||||
unsigned int flag;
|
||||
BlockPermission num;
|
||||
} PermissionMap;
|
||||
|
||||
static const PermissionMap permissions[] = {
|
||||
{ BLK_PERM_CONSISTENT_READ, BLOCK_PERMISSION_CONSISTENT_READ },
|
||||
{ BLK_PERM_WRITE, BLOCK_PERMISSION_WRITE },
|
||||
{ BLK_PERM_WRITE_UNCHANGED, BLOCK_PERMISSION_WRITE_UNCHANGED },
|
||||
{ BLK_PERM_RESIZE, BLOCK_PERMISSION_RESIZE },
|
||||
{ BLK_PERM_GRAPH_MOD, BLOCK_PERMISSION_GRAPH_MOD },
|
||||
{ 0, 0 }
|
||||
};
|
||||
const PermissionMap *p;
|
||||
BlockPermission qapi_perm;
|
||||
XDbgBlockGraphEdge *edge;
|
||||
|
||||
QEMU_BUILD_BUG_ON(1UL << (ARRAY_SIZE(permissions) - 1) != BLK_PERM_ALL + 1);
|
||||
|
||||
edge = g_new0(XDbgBlockGraphEdge, 1);
|
||||
|
||||
edge->parent = xdbg_graph_node_num(gr, parent);
|
||||
edge->child = xdbg_graph_node_num(gr, child->bs);
|
||||
edge->name = g_strdup(child->name);
|
||||
|
||||
for (p = permissions; p->flag; p++) {
|
||||
if (p->flag & child->perm) {
|
||||
QAPI_LIST_ADD(edge->perm, p->num);
|
||||
for (qapi_perm = 0; qapi_perm < BLOCK_PERMISSION__MAX; qapi_perm++) {
|
||||
uint64_t flag = bdrv_qapi_perm_to_blk_perm(qapi_perm);
|
||||
|
||||
if (flag & child->perm) {
|
||||
QAPI_LIST_ADD(edge->perm, qapi_perm);
|
||||
}
|
||||
if (p->flag & child->shared_perm) {
|
||||
QAPI_LIST_ADD(edge->shared_perm, p->num);
|
||||
if (flag & child->shared_perm) {
|
||||
QAPI_LIST_ADD(edge->shared_perm, qapi_perm);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user