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

block: Use bdrv_default_perms()

bdrv_default_perms() can decide which permission profile to use based on
the BdrvChildRole, so block drivers do not need to select it explicitly.

The blkverify driver now no longer shares the WRITE permission for the
image to verify. We thus have to adjust two places in
test-block-iothread not to take it. (Note that in theory, blkverify
should behave like quorum in this regard and share neither WRITE nor
RESIZE for both of its children. In practice, it does not really
matter, because blkverify is used only for debugging, so we might as
well keep its permissions rather liberal.)

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

authored by

Max Reitz and committed by
Kevin Wolf
69dca43d a16be3cd

+43 -37
+2 -2
block/backup-top.c
··· 156 156 *nperm = BLK_PERM_WRITE; 157 157 } else { 158 158 /* Source child */ 159 - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, 160 - perm, shared, nperm, nshared); 159 + bdrv_default_perms(bs, c, child_class, role, reopen_queue, 160 + perm, shared, nperm, nshared); 161 161 162 162 if (perm & BLK_PERM_WRITE) { 163 163 *nperm = *nperm | BLK_PERM_CONSISTENT_READ;
+2 -2
block/blkdebug.c
··· 1003 1003 { 1004 1004 BDRVBlkdebugState *s = bs->opaque; 1005 1005 1006 - bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue, 1007 - perm, shared, nperm, nshared); 1006 + bdrv_default_perms(bs, c, child_class, role, reopen_queue, 1007 + perm, shared, nperm, nshared); 1008 1008 1009 1009 *nperm |= s->take_child_perms; 1010 1010 *nshared &= ~s->unshare_child_perms;
+2 -7
block/blklogwrites.c
··· 295 295 return; 296 296 } 297 297 298 - if (!strcmp(c->name, "log")) { 299 - bdrv_format_default_perms(bs, c, child_class, role, ro_q, perm, shrd, 300 - nperm, nshrd); 301 - } else { 302 - bdrv_filter_default_perms(bs, c, child_class, role, ro_q, perm, shrd, 303 - nperm, nshrd); 304 - } 298 + bdrv_default_perms(bs, c, child_class, role, ro_q, perm, shrd, 299 + nperm, nshrd); 305 300 } 306 301 307 302 static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp)
+1 -1
block/blkreplay.c
··· 139 139 .is_filter = true, 140 140 141 141 .bdrv_open = blkreplay_open, 142 - .bdrv_child_perm = bdrv_filter_default_perms, 142 + .bdrv_child_perm = bdrv_default_perms, 143 143 .bdrv_getlength = blkreplay_getlength, 144 144 145 145 .bdrv_co_preadv = blkreplay_co_preadv,
+1 -1
block/blkverify.c
··· 319 319 .bdrv_parse_filename = blkverify_parse_filename, 320 320 .bdrv_file_open = blkverify_open, 321 321 .bdrv_close = blkverify_close, 322 - .bdrv_child_perm = bdrv_filter_default_perms, 322 + .bdrv_child_perm = bdrv_default_perms, 323 323 .bdrv_getlength = blkverify_getlength, 324 324 .bdrv_refresh_filename = blkverify_refresh_filename, 325 325 .bdrv_dirname = blkverify_dirname,
+1 -1
block/bochs.c
··· 297 297 .instance_size = sizeof(BDRVBochsState), 298 298 .bdrv_probe = bochs_probe, 299 299 .bdrv_open = bochs_open, 300 - .bdrv_child_perm = bdrv_format_default_perms, 300 + .bdrv_child_perm = bdrv_default_perms, 301 301 .bdrv_refresh_limits = bochs_refresh_limits, 302 302 .bdrv_co_preadv = bochs_co_preadv, 303 303 .bdrv_close = bochs_close,
+1 -1
block/cloop.c
··· 293 293 .instance_size = sizeof(BDRVCloopState), 294 294 .bdrv_probe = cloop_probe, 295 295 .bdrv_open = cloop_open, 296 - .bdrv_child_perm = bdrv_format_default_perms, 296 + .bdrv_child_perm = bdrv_default_perms, 297 297 .bdrv_refresh_limits = cloop_refresh_limits, 298 298 .bdrv_co_preadv = cloop_co_preadv, 299 299 .bdrv_close = cloop_close,
+1 -1
block/crypto.c
··· 756 756 .bdrv_close = block_crypto_close, 757 757 /* This driver doesn't modify LUKS metadata except when creating image. 758 758 * Allow share-rw=on as a special case. */ 759 - .bdrv_child_perm = bdrv_filter_default_perms, 759 + .bdrv_child_perm = bdrv_default_perms, 760 760 .bdrv_co_create = block_crypto_co_create_luks, 761 761 .bdrv_co_create_opts = block_crypto_co_create_opts_luks, 762 762 .bdrv_co_truncate = block_crypto_co_truncate,
+1 -1
block/dmg.c
··· 750 750 .bdrv_probe = dmg_probe, 751 751 .bdrv_open = dmg_open, 752 752 .bdrv_refresh_limits = dmg_refresh_limits, 753 - .bdrv_child_perm = bdrv_format_default_perms, 753 + .bdrv_child_perm = bdrv_default_perms, 754 754 .bdrv_co_preadv = dmg_co_preadv, 755 755 .bdrv_close = dmg_close, 756 756 .is_format = true,
+1 -1
block/filter-compress.c
··· 133 133 .format_name = "compress", 134 134 135 135 .bdrv_open = compress_open, 136 - .bdrv_child_perm = bdrv_filter_default_perms, 136 + .bdrv_child_perm = bdrv_default_perms, 137 137 138 138 .bdrv_getlength = compress_getlength, 139 139
+1 -1
block/parallels.c
··· 912 912 .bdrv_probe = parallels_probe, 913 913 .bdrv_open = parallels_open, 914 914 .bdrv_close = parallels_close, 915 - .bdrv_child_perm = bdrv_format_default_perms, 915 + .bdrv_child_perm = bdrv_default_perms, 916 916 .bdrv_co_block_status = parallels_co_block_status, 917 917 .bdrv_has_zero_init = bdrv_has_zero_init_1, 918 918 .bdrv_co_flush_to_os = parallels_co_flush_to_os,
+1 -1
block/qcow.c
··· 1180 1180 .bdrv_probe = qcow_probe, 1181 1181 .bdrv_open = qcow_open, 1182 1182 .bdrv_close = qcow_close, 1183 - .bdrv_child_perm = bdrv_format_default_perms, 1183 + .bdrv_child_perm = bdrv_default_perms, 1184 1184 .bdrv_reopen_prepare = qcow_reopen_prepare, 1185 1185 .bdrv_co_create = qcow_co_create, 1186 1186 .bdrv_co_create_opts = qcow_co_create_opts,
+1 -1
block/qcow2.c
··· 5744 5744 .bdrv_reopen_commit_post = qcow2_reopen_commit_post, 5745 5745 .bdrv_reopen_abort = qcow2_reopen_abort, 5746 5746 .bdrv_join_options = qcow2_join_options, 5747 - .bdrv_child_perm = bdrv_format_default_perms, 5747 + .bdrv_child_perm = bdrv_default_perms, 5748 5748 .bdrv_co_create_opts = qcow2_co_create_opts, 5749 5749 .bdrv_co_create = qcow2_co_create, 5750 5750 .bdrv_has_zero_init = qcow2_has_zero_init,
+1 -1
block/qed.c
··· 1672 1672 .bdrv_open = bdrv_qed_open, 1673 1673 .bdrv_close = bdrv_qed_close, 1674 1674 .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, 1675 - .bdrv_child_perm = bdrv_format_default_perms, 1675 + .bdrv_child_perm = bdrv_default_perms, 1676 1676 .bdrv_co_create = bdrv_qed_co_create, 1677 1677 .bdrv_co_create_opts = bdrv_qed_co_create_opts, 1678 1678 .bdrv_has_zero_init = bdrv_has_zero_init_1,
+1 -1
block/raw-format.c
··· 586 586 .bdrv_reopen_commit = &raw_reopen_commit, 587 587 .bdrv_reopen_abort = &raw_reopen_abort, 588 588 .bdrv_open = &raw_open, 589 - .bdrv_child_perm = bdrv_filter_default_perms, 589 + .bdrv_child_perm = bdrv_default_perms, 590 590 .bdrv_co_create_opts = &raw_co_create_opts, 591 591 .bdrv_co_preadv = &raw_co_preadv, 592 592 .bdrv_co_pwritev = &raw_co_pwritev,
+1 -1
block/throttle.c
··· 237 237 .bdrv_close = throttle_close, 238 238 .bdrv_co_flush = throttle_co_flush, 239 239 240 - .bdrv_child_perm = bdrv_filter_default_perms, 240 + .bdrv_child_perm = bdrv_default_perms, 241 241 242 242 .bdrv_getlength = throttle_getlength, 243 243
+1 -1
block/vdi.c
··· 1039 1039 .bdrv_open = vdi_open, 1040 1040 .bdrv_close = vdi_close, 1041 1041 .bdrv_reopen_prepare = vdi_reopen_prepare, 1042 - .bdrv_child_perm = bdrv_format_default_perms, 1042 + .bdrv_child_perm = bdrv_default_perms, 1043 1043 .bdrv_co_create = vdi_co_create, 1044 1044 .bdrv_co_create_opts = vdi_co_create_opts, 1045 1045 .bdrv_has_zero_init = vdi_has_zero_init,
+1 -1
block/vhdx.c
··· 2245 2245 .bdrv_open = vhdx_open, 2246 2246 .bdrv_close = vhdx_close, 2247 2247 .bdrv_reopen_prepare = vhdx_reopen_prepare, 2248 - .bdrv_child_perm = bdrv_format_default_perms, 2248 + .bdrv_child_perm = bdrv_default_perms, 2249 2249 .bdrv_co_readv = vhdx_co_readv, 2250 2250 .bdrv_co_writev = vhdx_co_writev, 2251 2251 .bdrv_co_create = vhdx_co_create,
+1 -1
block/vmdk.c
··· 3067 3067 .bdrv_open = vmdk_open, 3068 3068 .bdrv_co_check = vmdk_co_check, 3069 3069 .bdrv_reopen_prepare = vmdk_reopen_prepare, 3070 - .bdrv_child_perm = bdrv_format_default_perms, 3070 + .bdrv_child_perm = bdrv_default_perms, 3071 3071 .bdrv_co_preadv = vmdk_co_preadv, 3072 3072 .bdrv_co_pwritev = vmdk_co_pwritev, 3073 3073 .bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed,
+1 -1
block/vpc.c
··· 1240 1240 .bdrv_open = vpc_open, 1241 1241 .bdrv_close = vpc_close, 1242 1242 .bdrv_reopen_prepare = vpc_reopen_prepare, 1243 - .bdrv_child_perm = bdrv_format_default_perms, 1243 + .bdrv_child_perm = bdrv_default_perms, 1244 1244 .bdrv_co_create = vpc_co_create, 1245 1245 .bdrv_co_create_opts = vpc_co_create_opts, 1246 1246
+5 -5
tests/test-bdrv-drain.c
··· 93 93 uint64_t *nperm, uint64_t *nshared) 94 94 { 95 95 /* 96 - * bdrv_format_default_perms() accepts only these two, so disguise 96 + * bdrv_default_perms() accepts only these two, so disguise 97 97 * detach_by_driver_cb_parent as one of them. 98 98 */ 99 99 if (child_class != &child_file && child_class != &child_of_bds) { 100 100 child_class = &child_of_bds; 101 101 } 102 102 103 - bdrv_format_default_perms(bs, c, child_class, role, reopen_queue, 104 - perm, shared, nperm, nshared); 103 + bdrv_default_perms(bs, c, child_class, role, reopen_queue, 104 + perm, shared, nperm, nshared); 105 105 } 106 106 107 107 static int bdrv_test_change_backing_file(BlockDriverState *bs, ··· 1137 1137 .bdrv_close = bdrv_test_top_close, 1138 1138 .bdrv_co_preadv = bdrv_test_top_co_preadv, 1139 1139 1140 - .bdrv_child_perm = bdrv_format_default_perms, 1140 + .bdrv_child_perm = bdrv_default_perms, 1141 1141 }; 1142 1142 1143 1143 typedef struct TestCoDeleteByDrainData { ··· 1966 1966 .bdrv_co_drain_begin = bdrv_replace_test_co_drain_begin, 1967 1967 .bdrv_co_drain_end = bdrv_replace_test_co_drain_end, 1968 1968 1969 - .bdrv_child_perm = bdrv_format_default_perms, 1969 + .bdrv_child_perm = bdrv_default_perms, 1970 1970 }; 1971 1971 1972 1972 static void coroutine_fn test_replace_child_mid_drain_read_co(void *opaque)
+1 -1
tests/test-bdrv-graph-mod.c
··· 26 26 27 27 static BlockDriver bdrv_pass_through = { 28 28 .format_name = "pass-through", 29 - .bdrv_child_perm = bdrv_filter_default_perms, 29 + .bdrv_child_perm = bdrv_default_perms, 30 30 }; 31 31 32 32 static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c,
+14 -3
tests/test-block-iothread.c
··· 482 482 BlockDriverState *bs_a, *bs_b, *bs_verify; 483 483 QDict *options; 484 484 485 - /* Create bs_a and its BlockBackend */ 486 - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); 485 + /* 486 + * Create bs_a and its BlockBackend. We cannot take the RESIZE 487 + * permission because blkverify will not share it on the test 488 + * image. 489 + */ 490 + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, 491 + BLK_PERM_ALL); 487 492 bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort); 488 493 blk_insert_bs(blk, bs_a, &error_abort); 489 494 ··· 566 571 qdict_put_str(options, "raw", "bs_c"); 567 572 568 573 bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); 569 - blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); 574 + /* 575 + * Do not take the RESIZE permission: This would require the same 576 + * from bs_c and thus from bs_a; however, blkverify will not share 577 + * it on bs_b, and thus it will not be available for bs_a. 578 + */ 579 + blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE, 580 + BLK_PERM_ALL); 570 581 blk_insert_bs(blk, bs_verify, &error_abort); 571 582 572 583 /* Switch the AioContext */