qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block: Drop @child_class from bdrv_child_perm()

Implementations should decide the necessary permissions based on @role.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200513110544.176672-35-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

authored by

Max Reitz and committed by
Kevin Wolf
e5d8a406 1f38f04e

+22 -59
+16 -23
block.c
··· 1947 1947 } 1948 1948 1949 1949 static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, 1950 - BdrvChild *c, const BdrvChildClass *child_class, 1951 - BdrvChildRole role, BlockReopenQueue *reopen_queue, 1950 + BdrvChild *c, BdrvChildRole role, 1951 + BlockReopenQueue *reopen_queue, 1952 1952 uint64_t parent_perm, uint64_t parent_shared, 1953 1953 uint64_t *nperm, uint64_t *nshared) 1954 1954 { 1955 1955 assert(bs->drv && bs->drv->bdrv_child_perm); 1956 - bs->drv->bdrv_child_perm(bs, c, child_class, role, reopen_queue, 1956 + bs->drv->bdrv_child_perm(bs, c, role, reopen_queue, 1957 1957 parent_perm, parent_shared, 1958 1958 nperm, nshared); 1959 1959 /* TODO Take force_share from reopen_queue */ ··· 2047 2047 uint64_t cur_perm, cur_shared; 2048 2048 bool child_tighten_restr; 2049 2049 2050 - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, q, 2050 + bdrv_child_perm(bs, c->bs, c, c->role, q, 2051 2051 cumulative_perms, cumulative_shared_perms, 2052 2052 &cur_perm, &cur_shared); 2053 2053 ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, ··· 2114 2114 /* Update all children */ 2115 2115 QLIST_FOREACH(c, &bs->children, next) { 2116 2116 uint64_t cur_perm, cur_shared; 2117 - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, 2117 + bdrv_child_perm(bs, c->bs, c, c->role, NULL, 2118 2118 cumulative_perms, cumulative_shared_perms, 2119 2119 &cur_perm, &cur_shared); 2120 2120 bdrv_child_set_perm(c, cur_perm, cur_shared); ··· 2342 2342 uint64_t perms, shared; 2343 2343 2344 2344 bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); 2345 - bdrv_child_perm(bs, c->bs, c, c->klass, c->role, NULL, 2345 + bdrv_child_perm(bs, c->bs, c, c->role, NULL, 2346 2346 parent_perms, parent_shared, &perms, &shared); 2347 2347 2348 2348 return bdrv_child_try_set_perm(c, perms, shared, errp); ··· 2354 2354 * filtered child. 2355 2355 */ 2356 2356 static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, 2357 - const BdrvChildClass *child_class, 2358 2357 BdrvChildRole role, 2359 2358 BlockReopenQueue *reopen_queue, 2360 2359 uint64_t perm, uint64_t shared, ··· 2365 2364 } 2366 2365 2367 2366 static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, 2368 - const BdrvChildClass *child_class, 2369 2367 BdrvChildRole role, 2370 2368 BlockReopenQueue *reopen_queue, 2371 2369 uint64_t perm, uint64_t shared, 2372 2370 uint64_t *nperm, uint64_t *nshared) 2373 2371 { 2374 - assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW)); 2372 + assert(role & BDRV_CHILD_COW); 2375 2373 2376 2374 /* 2377 2375 * We want consistent read from backing files if the parent needs it. ··· 2402 2400 } 2403 2401 2404 2402 static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, 2405 - const BdrvChildClass *child_class, 2406 2403 BdrvChildRole role, 2407 2404 BlockReopenQueue *reopen_queue, 2408 2405 uint64_t perm, uint64_t shared, ··· 2410 2407 { 2411 2408 int flags; 2412 2409 2413 - assert(child_class == &child_of_bds && 2414 - (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA))); 2410 + assert(role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)); 2415 2411 2416 2412 flags = bdrv_reopen_get_flags(reopen_queue, bs); 2417 2413 ··· 2419 2415 * Apart from the modifications below, the same permissions are 2420 2416 * forwarded and left alone as for filters 2421 2417 */ 2422 - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, 2418 + bdrv_filter_default_perms(bs, c, role, reopen_queue, 2423 2419 perm, shared, &perm, &shared); 2424 2420 2425 2421 if (role & BDRV_CHILD_METADATA) { ··· 2483 2479 } 2484 2480 2485 2481 void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, 2486 - const BdrvChildClass *child_class, BdrvChildRole role, 2487 - BlockReopenQueue *reopen_queue, 2482 + BdrvChildRole role, BlockReopenQueue *reopen_queue, 2488 2483 uint64_t perm, uint64_t shared, 2489 2484 uint64_t *nperm, uint64_t *nshared) 2490 2485 { 2491 - assert(child_class == &child_of_bds); 2492 - 2493 2486 if (role & BDRV_CHILD_FILTERED) { 2494 2487 assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | 2495 2488 BDRV_CHILD_COW))); 2496 - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, 2489 + bdrv_filter_default_perms(bs, c, role, reopen_queue, 2497 2490 perm, shared, nperm, nshared); 2498 2491 } else if (role & BDRV_CHILD_COW) { 2499 2492 assert(!(role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA))); 2500 - bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue, 2493 + bdrv_default_perms_for_cow(bs, c, role, reopen_queue, 2501 2494 perm, shared, nperm, nshared); 2502 2495 } else if (role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA)) { 2503 - bdrv_default_perms_for_storage(bs, c, child_class, role, reopen_queue, 2496 + bdrv_default_perms_for_storage(bs, c, role, reopen_queue, 2504 2497 perm, shared, nperm, nshared); 2505 2498 } else { 2506 2499 g_assert_not_reached(); ··· 2744 2737 bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm); 2745 2738 2746 2739 assert(parent_bs->drv); 2747 - bdrv_child_perm(parent_bs, child_bs, NULL, child_class, child_role, NULL, 2740 + bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL, 2748 2741 perm, shared_perm, &perm, &shared_perm); 2749 2742 2750 2743 child = bdrv_root_attach_child(child_bs, child_name, child_class, ··· 3807 3800 if (state->replace_backing_bs && state->new_backing_bs) { 3808 3801 uint64_t nperm, nshared; 3809 3802 bdrv_child_perm(state->bs, state->new_backing_bs, 3810 - NULL, &child_of_bds, bdrv_backing_role(state->bs), 3803 + NULL, bdrv_backing_role(state->bs), 3811 3804 bs_queue, state->perm, state->shared_perm, 3812 3805 &nperm, &nshared); 3813 3806 ret = bdrv_check_update_perm(state->new_backing_bs, NULL, ··· 3930 3923 } else { 3931 3924 uint64_t nperm, nshared; 3932 3925 3933 - bdrv_child_perm(parent->state.bs, bs, c, c->klass, c->role, q, 3926 + bdrv_child_perm(parent->state.bs, bs, c, c->role, q, 3934 3927 parent->state.perm, parent->state.shared_perm, 3935 3928 &nperm, &nshared); 3936 3929
+1 -2
block/backup-top.c
··· 122 122 } 123 123 124 124 static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, 125 - const BdrvChildClass *child_class, 126 125 BdrvChildRole role, 127 126 BlockReopenQueue *reopen_queue, 128 127 uint64_t perm, uint64_t shared, ··· 156 155 *nperm = BLK_PERM_WRITE; 157 156 } else { 158 157 /* Source child */ 159 - bdrv_default_perms(bs, c, child_class, role, reopen_queue, 158 + bdrv_default_perms(bs, c, role, reopen_queue, 160 159 perm, shared, nperm, nshared); 161 160 162 161 if (perm & BLK_PERM_WRITE) {
+1 -2
block/blkdebug.c
··· 995 995 } 996 996 997 997 static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, 998 - const BdrvChildClass *child_class, 999 998 BdrvChildRole role, 1000 999 BlockReopenQueue *reopen_queue, 1001 1000 uint64_t perm, uint64_t shared, ··· 1003 1002 { 1004 1003 BDRVBlkdebugState *s = bs->opaque; 1005 1004 1006 - bdrv_default_perms(bs, c, child_class, role, reopen_queue, 1005 + bdrv_default_perms(bs, c, role, reopen_queue, 1007 1006 perm, shared, nperm, nshared); 1008 1007 1009 1008 *nperm |= s->take_child_perms;
+1 -2
block/blklogwrites.c
··· 283 283 } 284 284 285 285 static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, 286 - const BdrvChildClass *child_class, 287 286 BdrvChildRole role, 288 287 BlockReopenQueue *ro_q, 289 288 uint64_t perm, uint64_t shrd, ··· 295 294 return; 296 295 } 297 296 298 - bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, 297 + bdrv_default_perms(bs, c, role, ro_q, perm, shrd, 299 298 nperm, nshrd); 300 299 } 301 300
-1
block/commit.c
··· 223 223 } 224 224 225 225 static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, 226 - const BdrvChildClass *child_class, 227 226 BdrvChildRole role, 228 227 BlockReopenQueue *reopen_queue, 229 228 uint64_t perm, uint64_t shared,
-1
block/copy-on-read.c
··· 52 52 #define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) 53 53 54 54 static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, 55 - const BdrvChildClass *child_class, 56 55 BdrvChildRole role, 57 56 BlockReopenQueue *reopen_queue, 58 57 uint64_t perm, uint64_t shared,
-1
block/mirror.c
··· 1492 1492 } 1493 1493 1494 1494 static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, 1495 - const BdrvChildClass *child_class, 1496 1495 BdrvChildRole role, 1497 1496 BlockReopenQueue *reopen_queue, 1498 1497 uint64_t perm, uint64_t shared,
-1
block/quorum.c
··· 1153 1153 } 1154 1154 1155 1155 static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, 1156 - const BdrvChildClass *child_class, 1157 1156 BdrvChildRole role, 1158 1157 BlockReopenQueue *reopen_queue, 1159 1158 uint64_t perm, uint64_t shared,
-1
block/replication.c
··· 164 164 } 165 165 166 166 static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, 167 - const BdrvChildClass *child_class, 168 167 BdrvChildRole role, 169 168 BlockReopenQueue *reopen_queue, 170 169 uint64_t perm, uint64_t shared,
+1 -3
block/vvfat.c
··· 3213 3213 } 3214 3214 3215 3215 static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, 3216 - const BdrvChildClass *child_class, 3217 3216 BdrvChildRole role, 3218 3217 BlockReopenQueue *reopen_queue, 3219 3218 uint64_t perm, uint64_t shared, ··· 3221 3220 { 3222 3221 BDRVVVFATState *s = bs->opaque; 3223 3222 3224 - assert(c == s->qcow || 3225 - (child_class == &child_of_bds && (role & BDRV_CHILD_COW))); 3223 + assert(c == s->qcow || (role & BDRV_CHILD_COW)); 3226 3224 3227 3225 if (c == s->qcow) { 3228 3226 /* This is a private node, nobody should try to attach to it */
+1 -3
include/block/block_int.h
··· 563 563 * @reopen_queue. 564 564 */ 565 565 void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, 566 - const BdrvChildClass *child_class, 567 566 BdrvChildRole role, 568 567 BlockReopenQueue *reopen_queue, 569 568 uint64_t parent_perm, uint64_t parent_shared, ··· 1270 1269 * child_of_bds child class and set an appropriate BdrvChildRole. 1271 1270 */ 1272 1271 void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, 1273 - const BdrvChildClass *child_class, BdrvChildRole role, 1274 - BlockReopenQueue *reopen_queue, 1272 + BdrvChildRole role, BlockReopenQueue *reopen_queue, 1275 1273 uint64_t perm, uint64_t shared, 1276 1274 uint64_t *nperm, uint64_t *nshared); 1277 1275
+1 -18
tests/test-bdrv-drain.c
··· 85 85 return 0; 86 86 } 87 87 88 - static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, 89 - const BdrvChildClass *child_class, 90 - BdrvChildRole role, 91 - BlockReopenQueue *reopen_queue, 92 - uint64_t perm, uint64_t shared, 93 - uint64_t *nperm, uint64_t *nshared) 94 - { 95 - /* 96 - * bdrv_default_perms() accepts nothing else, so disguise 97 - * detach_by_driver_cb_parent. 98 - */ 99 - child_class = &child_of_bds; 100 - 101 - bdrv_default_perms(bs, c, child_class, role, reopen_queue, 102 - perm, shared, nperm, nshared); 103 - } 104 - 105 88 static int bdrv_test_change_backing_file(BlockDriverState *bs, 106 89 const char *backing_file, 107 90 const char *backing_fmt) ··· 119 102 .bdrv_co_drain_begin = bdrv_test_co_drain_begin, 120 103 .bdrv_co_drain_end = bdrv_test_co_drain_end, 121 104 122 - .bdrv_child_perm = bdrv_test_child_perm, 105 + .bdrv_child_perm = bdrv_default_perms, 123 106 124 107 .bdrv_change_backing_file = bdrv_test_change_backing_file, 125 108 };
-1
tests/test-bdrv-graph-mod.c
··· 30 30 }; 31 31 32 32 static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, 33 - const BdrvChildClass *child_class, 34 33 BdrvChildRole role, 35 34 BlockReopenQueue *reopen_queue, 36 35 uint64_t perm, uint64_t shared,