block: Introduce real BdrvChildRole
v4 cover block: Introduce real BdrvChildRole
Based-on: <[email protected]> (“block: Do not call BlockDriver.bdrv_make_empty() directly”)
Branch: https://github.com/XanClic/qemu.git child-role-v4
Branch: https://git.xanclic.moe/XanClic/qemu.git child-role-v4
v1: https://lists.nongnu.org/archive/html/qemu-block/2019-11/msg00908.html
v2: https://lists.nongnu.org/archive/html/qemu-block/2020-02/msg00108.html
v3: https://lists.nongnu.org/archive/html/qemu-block/2020-02/msg00737.html
Hi,
For the “why” and “what” regarding this series, see the cover letter of v1 (linked above).
In v4, I mostly addressed Kevin’s comments (and one permission bug for pure data children in patch 18):
- Patch 1: Pulled in from the “Deal with filters” series (and added blkreplay to the mix)
- Patch 4: More comments, and added consistent notes on how many children may get a certain role
- Patch 10:
- Move the function down below child_backing, so that we get less forward declarations of static functions, and they’ll all be temporary
- Split the (role & (DATA | METADATA | FILTERED)) == DATA condition
into (role & DATA) && !(role & (METADATA | FILTERED))
- Fixed up the comment on how backing files are opened RO only by default
- Unconditionally let @unmap default to true for children
- Patch 11: Fallout from having moved bdrv_inherited_options() down: We need a forward declaration of bdrv_open_inherit()
- Patch 12: Move bdrv_child_cb_attach() down to bdrv_inherited_options(), and add a (temporary) forward declaration for it
- Patch 13: Same as patch 12, but for bdrv_child_detach() now
- Patch 14: Drop (now unnecessary) forward declaration of bdrv_backing_update_filename()
- Patch 16: Renamed s/for_backing/for_cow/
- Patch 18: Swapped the existing patch that split bdrv_default_perms_for_storage() function into for_data() and for_metadata() for this one, which handles both cases in the existing function, but just relaxes the restrictions for pure data children
- Also, some permissions fixed: When WRITE_UNCHANGED was taken on the parent, it may need WRITE on the the data child; and if it needs WRITE, it may also need RESIZE.
- Patch 19:
- Fallout from bdrv_default_perms_for_storage() still being a single function
- Assertions that FILTERED, COW, and DATA | METADATA are mutually exclusive
- Patch 23: Use bdrv_backing_role() instead of a fixed BDRV_CHILD_COW in bdrv_open_backing_file()
- Patch 24: Fallout from bdrv_default_perms_for_storage() still being a single function
- Patch 26: blkreplay is a filter now, too
- Patch 27: Drop blkreplay (it’s now a filter, so handled in patch 26)
- Patch 31: Fallout from bdrv_default_perms_for_storage() still being a single function
- Patch 32:
- Fallout from bdrv_default_perms_for_storage() still being a single function
- Remove the temporary forward declarations added in patches 11 through 13
- Patch 33: Pass DATA | METADATA instead of just DATA for vvfat’s qcow child
- Patch 34:
- Fallout from bdrv_default_perms_for_backing() being named bdrv_default_perms_for_cow() now
- Fallout from bdrv_default_perms_for_storage() still being a single function
git-backport-diff against v3:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/34:[down] 'block: Mark commit, mirror, blkreplay as filters' 002/34:[----] [--] 'block: Add BlockDriver.is_format' 003/34:[----] [-C] 'block: Rename BdrvChildRole to BdrvChildClass' 004/34:[0030] [FC] 'block: Add BdrvChildRole and BdrvChildRoleBits' 005/34:[----] [-C] 'block: Add BdrvChildRole to BdrvChild' 006/34:[----] [--] 'block: Pass BdrvChildRole to bdrv_child_perm()' 007/34:[----] [-C] 'block: Pass BdrvChildRole to .inherit_options()' 008/34:[----] [--] 'block: Pass parent_is_format to .inherit_options()' 009/34:[----] [--] 'block: Rename bdrv_inherited_options()' 010/34:[0021] [FC] 'block: Add generic bdrv_inherited_options()' 011/34:[0015] [FC] 'block: Use bdrv_inherited_options()' 012/34:[0025] [FC] 'block: Unify bdrv_child_cb_attach()' 013/34:[0024] [FC] 'block: Unify bdrv_child_cb_detach()' 014/34:[0003] [FC] 'block: Add child_of_bds'
015/34:[----] [--] 'block: Distinguish paths in *_format_default_perms' 016/34:[0016] [FC] 'block: Pull out bdrv_default_perms_for_cow()' 017/34:[----] [-C] 'block: Pull out bdrv_default_perms_for_storage()' 018/34:[down] 'block: Relax *perms_for_storage for data children' 019/34:[0028] [FC] 'block: Add bdrv_default_perms()' 020/34:[----] [--] 'raw-format: Split raw_read_options()' 021/34:[----] [--] 'block: Switch child_format users to child_of_bds' 022/34:[----] [--] 'block: Drop child_format'
023/34:[0002] [FC] 'block: Make backing files child_of_bds children' 024/34:[0010] [FC] 'block: Drop child_backing'
025/34:[----] [--] 'block: Make format drivers use child_of_bds' 026/34:[0005] [FC] 'block: Make filter drivers use child_of_bds' 027/34:[0005] [FC] 'block: Use child_of_bds in remaining places' 028/34:[----] [--] 'tests: Use child_of_bds instead of child_file' 029/34:[----] [-C] 'block: Use bdrv_default_perms()' 030/34:[----] [--] 'block: Make bdrv_filter_default_perms() static' 031/34:[0004] [FC] 'block: Drop bdrv_format_default_perms()' 032/34:[0013] [FC] 'block: Drop child_file'
033/34:[0004] [FC] 'block: Pass BdrvChildRole in remaining cases' 034/34:[0024] [FC] 'block: Drop @child_class from bdrv_child_perm()'
Max Reitz (34):
block: Mark commit, mirror, blkreplay as filters
block: Add BlockDriver.is_format
block: Rename BdrvChildRole to BdrvChildClass
block: Add BdrvChildRole and BdrvChildRoleBits
block: Add BdrvChildRole to BdrvChild
block: Pass BdrvChildRole to bdrv_child_perm()
block: Pass BdrvChildRole to .inherit_options()
block: Pass parent_is_format to .inherit_options()
block: Rename bdrv_inherited_options()
block: Add generic bdrv_inherited_options()
block: Use bdrv_inherited_options()
block: Unify bdrv_child_cb_attach()
block: Unify bdrv_child_cb_detach()
block: Add child_of_bds
block: Distinguish paths in *_format_default_perms
block: Pull out bdrv_default_perms_for_cow()
block: Pull out bdrv_default_perms_for_storage()
block: Relax *perms_for_storage for data children
block: Add bdrv_default_perms()
raw-format: Split raw_read_options()
block: Switch child_format users to child_of_bds
block: Drop child_format
block: Make backing files child_of_bds children
block: Drop child_backing
block: Make format drivers use child_of_bds
block: Make filter drivers use child_of_bds
block: Use child_of_bds in remaining places
tests: Use child_of_bds instead of child_file
block: Use bdrv_default_perms()
block: Make bdrv_filter_default_perms() static
block: Drop bdrv_format_default_perms()
block: Drop child_file
block: Pass BdrvChildRole in remaining cases
block: Drop @child_class from bdrv_child_perm()
include/block/block.h | 64 +++- include/block/block_int.h | 57 ++-- block.c | 578 ++++++++++++++++++++++-------------- block/backup-top.c | 11 +- block/blkdebug.c | 10 +- block/blklogwrites.c | 16 +- block/blkreplay.c | 8 +- block/blkverify.c | 10 +- block/block-backend.c | 20 +- block/bochs.c | 7 +- block/cloop.c | 7 +- block/commit.c | 4 +- block/copy-on-read.c | 7 +- block/crypto.c | 8 +- block/dmg.c | 7 +- block/filter-compress.c | 7 +- block/io.c | 22 +- block/mirror.c | 4 +- block/parallels.c | 7 +- block/qcow.c | 7 +- block/qcow2.c | 20 +- block/qed.c | 7 +- block/quorum.c | 8 +- block/raw-format.c | 128 +++++--- block/replication.c | 5 +- block/throttle.c | 7 +- block/vdi.c | 7 +- block/vhdx.c | 7 +- block/vmdk.c | 23 +- block/vpc.c | 7 +- block/vvfat.c | 13 +- blockjob.c | 7 +- tests/test-bdrv-drain.c | 72 ++--- tests/test-bdrv-graph-mod.c | 10 +- tests/test-block-iothread.c | 17 +- 35 files changed, 738 insertions(+), 461 deletions(-)
Signature · 1 line
2.26.2
PATCH v4 1/34 block: Mark commit, mirror, blkreplay as filters
The commit, mirror, and blkreplay block nodes are filters, so they should be marked as such.
--- block/blkreplay.c | 1 + block/commit.c | 2 ++ block/mirror.c | 2 ++ 3 files changed, 5 insertions(+)
block/blkreplay.c +1 -0
@@ -135,6 +135,7 @@ static int blkreplay_snapshot_goto(BlockDriverState *bs,static BlockDriver bdrv_blkreplay = { .format_name ="blkreplay" , .instance_size =0 , + .is_filter = true, .bdrv_open = blkreplay_open, .bdrv_child_perm = bdrv_filter_default_perms,
block/commit.c +2 -0
@@ -240,6 +240,8 @@ static BlockDriver bdrv_commit_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_commit_top_refresh_filename, .bdrv_child_perm = bdrv_commit_top_child_perm, + + .is_filter = true, }; void commit_start(const char *job_id, BlockDriverState *bs,
block/mirror.c +2 -0
@@ -1530,6 +1530,8 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_block_status = bdrv_co_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_child_perm = bdrv_mirror_top_child_perm, + + .is_filter = true, }; static BlockJob *mirror_start_job(
Signature · 1 line
2.26.2
PATCH v4 2/34 block: Add BlockDriver.is_format
In reply to Max ReitzWe want to unify child_format and child_file at some point. One of the important things that set format drivers apart from other drivers is that they do not expect other format nodes under them (except in the backing chain), i.e. we must not probe formats inside of formats. That means we need something on which to distinguish format drivers from others, and hence this flag.
--- include/block/block_int.h | 7 +++++++ block/bochs.c | 1 + block/cloop.c | 1 + block/crypto.c | 2 ++ block/dmg.c | 1 + block/parallels.c | 1 + block/qcow.c | 1 + block/qcow2.c | 1 + block/qed.c | 1 + block/raw-format.c | 1 + block/vdi.c | 1 + block/vhdx.c | 1 + block/vmdk.c | 1 + block/vpc.c | 1 + 14 files changed, 21 insertions(+)
include/block/block_int.h +7 -0
@@ -95,6 +95,13 @@ struct BlockDriver {* must implement them and return -ENOTSUP. */ bool is_filter; +/* +* Set to true if the BlockDriver is a format driver. Format nodes +* generally do not expect their children to be other format nodes +* (except for backing files), and so format probing is disabled +* on those children. +*/ +bool is_format;/* * Return true if @to_replace can be replaced by a BDS with the * same data as @bs without it affecting @bs's behavior (that is,
block/bochs.c +1 -0
@@ -301,6 +301,7 @@ static BlockDriver bdrv_bochs = { .bdrv_refresh_limits = bochs_refresh_limits, .bdrv_co_preadv = bochs_co_preadv, .bdrv_close = bochs_close, + .is_format = true, };static void bdrv_bochs_init (void )
block/cloop.c +1 -0
@@ -297,6 +297,7 @@ static BlockDriver bdrv_cloop = { .bdrv_refresh_limits = cloop_refresh_limits, .bdrv_co_preadv = cloop_co_preadv, .bdrv_close = cloop_close, + .is_format = true, };static void bdrv_cloop_init (void )
block/crypto.c +2 -0
@@ -771,6 +771,8 @@ static BlockDriver bdrv_crypto_luks = { .bdrv_get_info = block_crypto_get_info_luks, .bdrv_get_specific_info = block_crypto_get_specific_info_luks, + .is_format = true, + .strong_runtime_opts = block_crypto_strong_runtime_opts, };
block/dmg.c +1 -0
@@ -753,6 +753,7 @@ static BlockDriver bdrv_dmg = { .bdrv_child_perm = bdrv_format_default_perms, .bdrv_co_preadv = dmg_co_preadv, .bdrv_close = dmg_close, + .is_format = true, };static void bdrv_dmg_init (void )
block/parallels.c +1 -0
@@ -918,6 +918,7 @@ static BlockDriver bdrv_parallels = { .bdrv_co_flush_to_os = parallels_co_flush_to_os, .bdrv_co_readv = parallels_co_readv, .bdrv_co_writev = parallels_co_writev, + .is_format = true, .supports_backing = true, .bdrv_co_create = parallels_co_create, .bdrv_co_create_opts = parallels_co_create_opts,
block/qcow.c +1 -0
@@ -1185,6 +1185,7 @@ static BlockDriver bdrv_qcow = { .bdrv_co_create = qcow_co_create, .bdrv_co_create_opts = qcow_co_create_opts, .bdrv_has_zero_init = bdrv_has_zero_init_1, + .is_format = true, .supports_backing = true, .bdrv_refresh_limits = qcow_refresh_limits,
block/qcow2.c +1 -0
@@ -5767,6 +5767,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_save_vmstate = qcow2_save_vmstate, .bdrv_load_vmstate = qcow2_load_vmstate, + .is_format = true, .supports_backing = true, .bdrv_change_backing_file = qcow2_change_backing_file,
block/qed.c +1 -0
@@ -1665,6 +1665,7 @@ static BlockDriver bdrv_qed = { .format_name = "qed", .instance_size = sizeof(BDRVQEDState), .create_opts = &qed_create_opts, + .is_format = true, .supports_backing = true, .bdrv_probe = bdrv_qed_probe,
block/raw-format.c +1 -0
@@ -566,6 +566,7 @@ BlockDriver bdrv_raw = { .bdrv_co_copy_range_to = &raw_co_copy_range_to, .bdrv_co_truncate = &raw_co_truncate, .bdrv_getlength = &raw_getlength, + .is_format = true, .has_variable_length = true, .bdrv_measure = &raw_measure, .bdrv_get_info = &raw_get_info,
block/vdi.c +1 -0
@@ -1053,6 +1053,7 @@ static BlockDriver bdrv_vdi = { .bdrv_get_info = vdi_get_info, + .is_format = true, .create_opts = &vdi_create_opts, .bdrv_co_check = vdi_co_check, };
block/vhdx.c +1 -0
@@ -2254,6 +2254,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_co_check = vhdx_co_check, .bdrv_has_zero_init = vhdx_has_zero_init, + .is_format = true, .create_opts = &vhdx_create_opts, };
block/vmdk.c +1 -0
@@ -3070,6 +3070,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_get_info = vmdk_get_info, .bdrv_gather_child_options = vmdk_gather_child_options, + .is_format = true, .supports_backing = true, .create_opts = &vmdk_create_opts, };
block/vpc.c +1 -0
@@ -1250,6 +1250,7 @@ static BlockDriver bdrv_vpc = { .bdrv_get_info = vpc_get_info, + .is_format = true, .create_opts = &vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, .strong_runtime_opts = vpc_strong_runtime_opts,
Signature · 1 line
2.26.2
PATCH v4 3/34 block: Rename BdrvChildRole to BdrvChildClass
In reply to Max ReitzThis structure nearly only contains parent callbacks for child state changes. It cannot really reflect a child's role, because different roles may overlap (as we will see when real roles are introduced), and because parents can have custom callbacks even when the child fulfills a standard role.
--- include/block/block.h | 6 +- include/block/block_int.h | 22 +++--- block.c | 142 ++++++++++++++++++------------------ block/backup-top.c | 8 +- block/blkdebug.c | 4 +- block/blklogwrites.c | 8 +- block/block-backend.c | 6 +- block/commit.c | 2 +- block/copy-on-read.c | 2 +- block/io.c | 22 +++--- block/mirror.c | 2 +- block/quorum.c | 2 +- block/replication.c | 2 +- block/vvfat.c | 6 +- blockjob.c | 2 +- tests/test-bdrv-drain.c | 36 ++++----- tests/test-bdrv-graph-mod.c | 2 +- 17 files changed, 141 insertions(+), 133 deletions(-)
include/block/block.h +3 -3
@@ -13,7 +13,7 @@/* block.c */ typedef struct BlockDriver BlockDriver ;typedef struct BdrvChild BdrvChild ; -typedef struct BdrvChildRole BdrvChildRole ; +typedef struct BdrvChildClass BdrvChildClass ; typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */
@@ -296,7 +296,7 @@ int bdrv_parse_discard_flags(const char *mode, int *flags);BdrvChild *bdrv_open_child (const char *filename,QDict *options,const char *bdref_key,BlockDriverState * parent, -const BdrvChildRole *child_role, +const BdrvChildClass *child_class,bool allow_none,Error **errp);BlockDriverState *bdrv_open_blockdev_ref (BlockdevRef *ref,Error **errp); void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
@@ -541,7 +541,7 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);BdrvChild *bdrv_attach_child (BlockDriverState *parent_bs,BlockDriverState *child_bs,const char *child_name, -const BdrvChildRole *child_role, +const BdrvChildClass *child_class,Error **errp);bool bdrv_op_is_blocked (BlockDriverState *bs,BlockOpType op,Error **errp);
include/block/block_int.h +11 -11
@@ -556,14 +556,14 @@ struct BlockDriver {* the parents in @parent_perm and @parent_shared. * * If @c is NULL, return the permissions for attaching a new child for the -* given @role. +* given @child_class. * * If @reopen_queue is non-NULL, don't return the currently needed * permissions, but those that will be needed after applying the * @reopen_queue. */ void (*bdrv_child_perm)(BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared);
@@ -665,7 +665,7 @@ typedef struct BdrvAioNotifier {QLIST_ENTRY (BdrvAioNotifier) list; } BdrvAioNotifier; -struct BdrvChildRole { +struct BdrvChildClass {/* If true, bdrv_replace_node() doesn't change the node this BdrvChild * points to. */ bool stay_at_node;
@@ -738,14 +738,14 @@ struct BdrvChildRole {void (*set_aio_ctx)(BdrvChild *child,AioContext *ctx,GSList **ignore); }; -extern const BdrvChildRole child_file; -extern const BdrvChildRole child_format; -extern const BdrvChildRole child_backing; +extern const BdrvChildClass child_file; +extern const BdrvChildClass child_format; +extern const BdrvChildClass child_backing;struct BdrvChild {BlockDriverState *bs;char *name; -const BdrvChildRole *role; +const BdrvChildClass *klass;void *opaque;/**
@@ -772,7 +772,7 @@ struct BdrvChild {/* * How many times the parent of this child has been drained -* (through role->drained_*). +* (through klass->drained_*). * Usually, this is equal to bs->quiesce_counter (potentially * reduced by bdrv_drain_all_count). It may differ while the * child is entering or leaving a drained section.
@@ -1232,7 +1232,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BdrvChild *bdrv_root_attach_child (BlockDriverState *child_bs,const char *child_name, -const BdrvChildRole *child_role, +const BdrvChildClass *child_class,AioContext *ctx,uint64_t perm,uint64_t shared_perm,void *opaque,Error **errp);
@@ -1263,7 +1263,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp);* block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to * all children */ void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
@@ -1273,7 +1273,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,* requires WRITE | RESIZE for read-write images, always requires * CONSISTENT_READ and doesn't share WRITE. */ void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
block.c +73 -69
429 lines not on this page · raw message
block/backup-top.c +4 -4
@@ -122,7 +122,7 @@ static void backup_top_refresh_filename(BlockDriverState *bs) }static void backup_top_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -142,7 +142,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -if (role == &child_file) { +if (child_class == &child_file) {/* * Target child *
@@ -155,8 +155,8 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm =BLK_PERM_WRITE ; }else {/* Source child */ -bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, - nperm, nshared); +bdrv_filter_default_perms (bs, c, child_class, reopen_queue, + perm, shared, nperm, nshared);if (perm &BLK_PERM_WRITE ) { *nperm = *nperm |BLK_PERM_CONSISTENT_READ ;
block/blkdebug.c +2 -2
@@ -993,14 +993,14 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, }static void blkdebug_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {BDRVBlkdebugState *s = bs->opaque; -bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, +bdrv_filter_default_perms (bs, c, child_class, reopen_queue, perm, shared, nperm, nshared); *nperm |= s->take_child_perms;
block/blklogwrites.c +5 -3
@@ -282,7 +282,7 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) }static void blk_log_writes_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *ro_q,uint64_t perm,uint64_t shrd,uint64_t *nperm,uint64_t *nshrd)
@@ -294,9 +294,11 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, }if (!strcmp (c->name,"log" )) { -bdrv_format_default_perms (bs, c, role, ro_q, perm, shrd, nperm, nshrd); +bdrv_format_default_perms (bs, c, child_class, ro_q, perm, shrd, nperm, + nshrd); }else { -bdrv_filter_default_perms (bs, c, role, ro_q, perm, shrd, nperm, nshrd); +bdrv_filter_default_perms (bs, c, child_class, ro_q, perm, shrd, nperm, + nshrd); } }
block/block-backend.c +3 -3
@@ -297,7 +297,7 @@ static void blk_root_detach(BdrvChild *child) } } -static const BdrvChildRole child_root = { +static const BdrvChildClass child_root = { .inherit_options = blk_root_inherit_options, .change_media = blk_root_change_media,
@@ -716,7 +716,7 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs) {BdrvChild *child; QLIST_FOREACH(child, &bs->parents, next_parent) { -if (child->role == &child_root) { +if (child->klass == &child_root) {return child->opaque; } }
@@ -740,7 +740,7 @@ bool bdrv_is_root_node(BlockDriverState *bs)BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c->role != &child_root) { +if (c->klass != &child_root) {return false; } }
block/commit.c +1 -1
@@ -223,7 +223,7 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) }static void bdrv_commit_top_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/copy-on-read.c +1 -1
@@ -51,7 +51,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,#define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH)static void cor_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/io.c +11 -11
@@ -50,7 +50,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore,BdrvChild *c, *next; QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { -if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { +if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {continue ; }bdrv_parent_drained_begin_single (c, false);
@@ -62,8 +62,8 @@ static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c, {assert (c->parent_quiesce_counter >0 ); c->parent_quiesce_counter--; -if (c->role->drained_end) { - c->role->drained_end (c, drained_end_counter); +if (c->klass->drained_end) { + c->klass->drained_end (c, drained_end_counter); } }
@@ -81,7 +81,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { +if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {continue ; }bdrv_parent_drained_end_single_no_poll (c, drained_end_counter);
@@ -90,8 +90,8 @@ static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,static bool bdrv_parent_drained_poll_single (BdrvChild *c) { -if (c->role->drained_poll) { -return c->role->drained_poll (c); +if (c->klass->drained_poll) { +return c->klass->drained_poll (c); }return false; }
@@ -103,7 +103,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,bool busy = false; QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { -if (c == ignore || (ignore_bds_parents && c->role->parent_is_bds)) { +if (c == ignore || (ignore_bds_parents && c->klass->parent_is_bds)) {continue ; } busy |=bdrv_parent_drained_poll_single (c);
@@ -115,8 +115,8 @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,void bdrv_parent_drained_begin_single (BdrvChild *c,bool poll) { c->parent_quiesce_counter++; -if (c->role->drained_begin) { - c->role->drained_begin (c); +if (c->klass->drained_begin) { + c->klass->drained_begin (c); }if (poll) {BDRV_POLL_WHILE (c->bs,bdrv_parent_drained_poll_single (c));
@@ -3326,8 +3326,8 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs) {BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c->role->resize) { - c->role->resize (c); +if (c->klass->resize) { + c->klass->resize (c); } } }
block/mirror.c +1 -1
@@ -1492,7 +1492,7 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) }static void bdrv_mirror_top_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/quorum.c +1 -1
@@ -1151,7 +1151,7 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) }static void quorum_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/replication.c +1 -1
@@ -163,7 +163,7 @@ static void replication_close(BlockDriverState *bs) }static void replication_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/vvfat.c +3 -3
@@ -3136,7 +3136,7 @@ static void vvfat_qcow_options(int *child_flags, QDict *child_options,qdict_set_default_str (child_options,BDRV_OPT_CACHE_NO_FLUSH ,"on" ); } -static const BdrvChildRole child_vvfat_qcow = { +static const BdrvChildClass child_vvfat_qcow = { .parent_is_bds = true, .inherit_options = vvfat_qcow_options, };
@@ -3210,14 +3210,14 @@ err: }static void vvfat_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {BDRVVVFATState *s = bs->opaque; -assert (c == s->qcow || role == &child_backing); +assert (c == s->qcow || child_class == &child_backing);if (c == s->qcow) {/* This is a private node, nobody should try to attach to it */
blockjob.c +1 -1
@@ -163,7 +163,7 @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx, job->job.aio_context = ctx; } -static const BdrvChildRole child_job = { +static const BdrvChildClass child_job = { .get_parent_desc = child_job_get_parent_desc, .drained_begin = child_job_drained_begin, .drained_poll = child_job_drained_poll,
tests/test-bdrv-drain.c +19 -17
@@ -86,18 +86,20 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, }static void bdrv_test_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) { -/* bdrv_format_default_perms() accepts only these two, so disguise -* detach_by_driver_cb_role as one of them. */ -if (role != &child_file && role != &child_backing) { - role = &child_file; +/* +* bdrv_format_default_perms() accepts only these two, so disguise +* detach_by_driver_cb_parent as one of them. +*/ +if (child_class != &child_file && child_class != &child_backing) { + child_class = &child_file; } -bdrv_format_default_perms (bs, c, role, reopen_queue, perm, shared, +bdrv_format_default_perms (bs, c, child_class, reopen_queue, perm, shared, nperm, nshared); }
@@ -1332,7 +1334,7 @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) child_file.drained_begin (child); } -static BdrvChildRole detach_by_driver_cb_role; +static BdrvChildClass detach_by_driver_cb_class;/* * Initial graph:
@@ -1349,7 +1351,7 @@ static BdrvChildRole detach_by_driver_cb_role;* * by_parent_cb == false: Test that bdrv_drain_invoke() doesn't poll * -* PA's BdrvChildRole has a .drained_begin callback that schedules a BH +* PA's BdrvChildClass has a .drained_begin callback that schedules a BH * that does the same graph change. If bdrv_drain_invoke() calls it, the * state is messed up, but if it is only polled in the single * BDRV_POLL_WHILE() at the end of the drain, this should work fine.
@@ -1364,8 +1366,8 @@ static void test_detach_indirect(bool by_parent_cb)QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov,NULL ,0 );if (!by_parent_cb) { - detach_by_driver_cb_role = child_file; - detach_by_driver_cb_role.drained_begin = + detach_by_driver_cb_class = child_file; + detach_by_driver_cb_class.drained_begin = detach_by_driver_cb_drained_begin; }
@@ -1399,7 +1401,7 @@ static void test_detach_indirect(bool by_parent_cb)bdrv_ref (a);bdrv_attach_child (parent_a, a,"PA-A" , - by_parent_cb ? &child_file : &detach_by_driver_cb_role, + by_parent_cb ? &child_file : &detach_by_driver_cb_class, &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1);
@@ -1735,7 +1737,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child,/** * Test a poll in the midst of bdrv_drop_intermediate(). * -* bdrv_drop_intermediate() calls BdrvChildRole.update_filename(), +* bdrv_drop_intermediate() calls BdrvChildClass.update_filename(), * which can yield or poll. This may lead to graph changes, unless * the whole subtree in question is drained. *
@@ -1772,7 +1774,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child,* * The solution is for bdrv_drop_intermediate() to drain top's * subtree. This prevents graph changes from happening just because -* BdrvChildRole.update_filename() yields or polls. Thus, the block +* BdrvChildClass.update_filename() yields or polls. Thus, the block * job is paused during that drained section and must finish before or * after. *
@@ -1780,7 +1782,7 @@ static int drop_intermediate_poll_update_filename(BdrvChild *child,*/ static void test_drop_intermediate_poll (void ) { -static BdrvChildRole chain_child_role; +static BdrvChildClass chain_child_class;BlockDriverState *chain[3 ];TestSimpleBlockJob *job;BlockDriverState *job_node;
@@ -1788,8 +1790,8 @@ static void test_drop_intermediate_poll(void)int i;int ret; - chain_child_role = child_backing; - chain_child_role.update_filename = drop_intermediate_poll_update_filename; + chain_child_class = child_backing; + chain_child_class.update_filename = drop_intermediate_poll_update_filename;for (i =0 ; i <3 ; i++) {char name[32 ];
@@ -1810,7 +1812,7 @@ static void test_drop_intermediate_poll(void)if (i) {/* Takes the reference to chain[i - 1] */ chain[i]->backing =bdrv_attach_child (chain[i], chain[i -1 ], -"chain" , &chain_child_role, +"chain" , &chain_child_class, &error_abort); } }
tests/test-bdrv-graph-mod.c +1 -1
@@ -30,7 +30,7 @@ static BlockDriver bdrv_pass_through = { };static void no_perm_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
Signature · 1 line
2.26.2
PATCH v4 4/34 block: Add BdrvChildRole and BdrvChildRoleBits
In reply to Max ReitzThis mask will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent. It consists of BdrvChildRoleBits values (which is an enum).
Because empty enums are not allowed, let us just start with it filled.
--- include/block/block.h | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
include/block/block.h +56 -0
@@ -268,6 +268,62 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +/* +* Flags parent nodes give for the child nodes to specify what kind of +* role(s) they take. +* +* At least one of DATA, METADATA, FILTERED, or COW must be set for +* every child. +*/ +enum BdrvChildRoleBits { +/* +* This child stores data. +* Any node may have an arbitrary number of such children. +*/ +BDRV_CHILD_DATA = (1 <<0 ), + +/* +* This child stores metadata. +* Any node may have an arbitrary number of metadata-storing +* children. +*/ +BDRV_CHILD_METADATA = (1 <<1 ), + +/* +* A child that always presents exactly the same visible data as +* the parent, e.g. by virtue of the parent forwarding all reads +* and writes. +* This flag is mutually exclusive with DATA, METADATA, and COW. +* Any node may have at most one filtered child at a time. +*/ +BDRV_CHILD_FILTERED = (1 <<2 ), + +/* +* Child from which to read all data that isn’t allocated in the +* parent (i.e., the backing child); such data is copied to the +* parent through COW (and optionally COR). +* This field is mutually exclusive with DATA, METADATA, and +* FILTERED. +* Any node may have at most one such backing child at a time. +*/ +BDRV_CHILD_COW = (1 <<3 ), + +/* +* The primary child. For most drivers, this is the child whose +* filename applies best to the parent node. +* Any node may have at most one primary child at a time. +*/ +BDRV_CHILD_PRIMARY = (1 <<4 ), + +/* Useful combination of flags */ +BDRV_CHILD_IMAGE =BDRV_CHILD_DATA + |BDRV_CHILD_METADATA + |BDRV_CHILD_PRIMARY , +}; + +/* Mask of BdrvChildRoleBits values */ +typedef unsigned int BdrvChildRole ; +char *bdrv_perm_names (uint64_t perm);uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm);
Signature · 1 line
2.26.2
Re: [PATCH v4 04/34] block: Add BdrvChildRole and BdrvChildRoleBits
Quoted 16 lines · Max Reitz
This mask will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent. It consists of BdrvChildRoleBits values (which is an enum).
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)include/block/block.h +0
-0
include/block/block.h enum { · line 273
Quoted 6 lines
include/block/block.h +3
-0@@ -268,6 +268,62 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +/* +* Flags parent nodes give for the child nodes to specify what kind of +* role(s) they take.
Reads a bit awkwardly. Maybe:
Flags that parent nodes assign to child nodes to specify what kind of role(s) they take.
Touching up grammar doesn't affect code correctness, so:
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 5/34 block: Add BdrvChildRole to BdrvChild
In reply to Max ReitzFor now, it is always set to 0. Later patches in this series will ensure that all callers pass an appropriate combination of flags.
--- include/block/block.h | 2 ++ include/block/block_int.h | 2 ++ block.c | 11 ++++++++--- block/backup-top.c | 3 ++- block/blkdebug.c | 2 +- block/blklogwrites.c | 6 +++--- block/blkreplay.c | 2 +- block/blkverify.c | 4 ++-- block/block-backend.c | 4 ++-- block/bochs.c | 2 +- block/cloop.c | 2 +- block/copy-on-read.c | 2 +- block/crypto.c | 2 +- block/dmg.c | 2 +- block/filter-compress.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 6 +++--- block/qed.c | 2 +- block/quorum.c | 4 ++-- block/raw-format.c | 2 +- block/replication.c | 2 +- block/throttle.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 ++-- block/vpc.c | 2 +- block/vvfat.c | 2 +- blockjob.c | 5 +++-- tests/test-bdrv-drain.c | 20 +++++++++++--------- tests/test-bdrv-graph-mod.c | 4 ++-- 31 files changed, 62 insertions(+), 49 deletions(-)
include/block/block.h +2 -0
@@ -353,6 +353,7 @@ BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState* parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, bool allow_none, Error **errp);BlockDriverState *bdrv_open_blockdev_ref (BlockdevRef *ref,Error **errp); void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
@@ -598,6 +599,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp);bool bdrv_op_is_blocked (BlockDriverState *bs,BlockOpType op,Error **errp);
include/block/block_int.h +2 -0
@@ -746,6 +746,7 @@ struct BdrvChild {BlockDriverState *bs;char *name;const BdrvChildClass *klass; +BdrvChildRole role;void *opaque;/**
@@ -1233,6 +1234,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BdrvChild *bdrv_root_attach_child (BlockDriverState *child_bs,const char *child_name,const BdrvChildClass *child_class, +BdrvChildRole child_role,AioContext *ctx,uint64_t perm,uint64_t shared_perm,void *opaque,Error **errp);
block.c +8 -3
@@ -2571,6 +2571,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)BdrvChild *bdrv_root_attach_child (BlockDriverState *child_bs,const char *child_name,const BdrvChildClass *child_class, +BdrvChildRole child_role,AioContext *ctx,uint64_t perm,uint64_t shared_perm,void *opaque,Error **errp)
@@ -2592,6 +2593,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, .bs = NULL, .name = g_strdup(child_name), .klass = child_class, + .role = child_role, .perm = perm, .shared_perm = shared_perm, .opaque = opaque,
@@ -2644,6 +2646,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,BlockDriverState *child_bs, const char *child_name, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp) { BdrvChild *child;
@@ -2656,7 +2659,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, perm, shared_perm, &perm, &shared_perm); child =bdrv_root_attach_child (child_bs, child_name, child_class, -bdrv_get_aio_context (parent_bs), + child_role,bdrv_get_aio_context (parent_bs), perm, shared_perm, parent_bs, errp);if (child ==NULL ) {return NULL ;
@@ -2774,7 +2777,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, } bs->backing =bdrv_attach_child (bs, backing_hd,"backing" , &child_backing, - errp); +0 , errp);/* If backing_hd was already part of bs's backing chain, and * inherits_from pointed recursively to bs then let's update it to * point directly to bs (else it will become NULL). */
@@ -2965,6 +2968,7 @@ BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, bool allow_none, Error **errp) { BlockDriverState *bs;
@@ -2975,7 +2979,8 @@ BdrvChild *bdrv_open_child(const char *filename,return NULL ; } -return bdrv_attach_child (parent, bs, bdref_key, child_class, errp); +return bdrv_attach_child (parent, bs, bdref_key, child_class, child_role, + errp); }/*
block/backup-top.c +2 -1
@@ -214,7 +214,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, source->supported_zero_flags);bdrv_ref (target); - state->target =bdrv_attach_child (top, target,"target" , &child_file, errp); + state->target =bdrv_attach_child (top, target,"target" , &child_file,0 , + errp);if (!state->target) {bdrv_unref (target);bdrv_unref (top);
block/blkdebug.c +1 -1
@@ -497,7 +497,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,/* Open the image file */ bs->file =bdrv_open_child (qemu_opt_get (opts,"x-image" ), options,"image" , - bs, &child_file, false, &local_err); + bs, &child_file,0 , false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/blklogwrites.c +3 -3
@@ -157,7 +157,7 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, }/* Open the file */ - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, &local_err);if (local_err) { ret = -EINVAL ;
@@ -166,8 +166,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, }/* Open the log file */ - s->log_file =bdrv_open_child (NULL , options,"log" , bs, &child_file, false, - &local_err); + s->log_file =bdrv_open_child (NULL , options,"log" , bs, &child_file,0 , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/blkreplay.c +1 -1
@@ -28,7 +28,7 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,/* Open the image file */ bs->file =bdrv_open_child (NULL , options,"image" , - bs, &child_file, false, &local_err); + bs, &child_file,0 , false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/blkverify.c +2 -2
@@ -125,7 +125,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,/* Open the raw file */ bs->file =bdrv_open_child (qemu_opt_get (opts,"x-raw" ), options,"raw" , - bs, &child_file, false, &local_err); + bs, &child_file,0 , false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
@@ -134,7 +134,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,/* Open the test file */ s->test_file =bdrv_open_child (qemu_opt_get (opts,"x-image" ), options, -"test" , bs, &child_format, false, +"test" , bs, &child_format,0 , false, &local_err);if (local_err) { ret = -EINVAL ;
block/block-backend.c +2 -2
@@ -423,7 +423,7 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,return NULL ; } - blk->root =bdrv_root_attach_child (bs,"root" , &child_root, blk->ctx, + blk->root =bdrv_root_attach_child (bs,"root" , &child_root,0 , blk->ctx, perm,BLK_PERM_ALL , blk, errp);if (!blk->root) {blk_unref (blk);
@@ -834,7 +834,7 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) {ThrottleGroupMember *tgm = &blk->public.throttle_group_member;bdrv_ref (bs); - blk->root =bdrv_root_attach_child (bs,"root" , &child_root, blk->ctx, + blk->root =bdrv_root_attach_child (bs,"root" , &child_root,0 , blk->ctx, blk->perm, blk->shared_perm, blk, errp);if (blk->root ==NULL ) {return -EPERM ;
block/bochs.c +1 -1
@@ -110,7 +110,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/cloop.c +1 -1
@@ -71,7 +71,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/copy-on-read.c +1 -1
@@ -28,7 +28,7 @@static int cor_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/crypto.c +1 -1
@@ -218,7 +218,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,unsigned int cflags =0 ;QDict *cryptoopts =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/dmg.c +1 -1
@@ -439,7 +439,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/filter-compress.c +1 -1
@@ -30,7 +30,7 @@static int compress_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/parallels.c +1 -1
@@ -739,7 +739,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,Error *local_err =NULL ;char *buf; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/qcow.c +1 -1
@@ -130,7 +130,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,qdict_extract_subqdict (options, &encryptopts,"encrypt." ); encryptfmt =qdict_get_try_str (encryptopts,"format" ); - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) { ret = -EINVAL ;
block/qcow2.c +3 -3
@@ -1591,7 +1591,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,/* Open external data file */ s->data_file =bdrv_open_child (NULL , options,"data-file" , bs, &child_file, - true, &local_err); +0 , true, &local_err);if (local_err) {error_propagate (errp, local_err); ret = -EINVAL ;
@@ -1601,7 +1601,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,if (s->incompatible_features &QCOW2_INCOMPAT_DATA_FILE ) {if (!s->data_file && s->image_data_file) { s->data_file =bdrv_open_child (s->image_data_file, options, -"data-file" , bs, &child_file, +"data-file" , bs, &child_file,0 , false, errp);if (!s->data_file) { ret = -EINVAL ;
@@ -1863,7 +1863,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/qed.c +1 -1
@@ -547,7 +547,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/quorum.c +2 -2
@@ -977,7 +977,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,assert (ret <32 ); s->children[i] =bdrv_open_child (NULL , options, indexstr, bs, - &child_format, false, &local_err); + &child_format,0 , false, &local_err);if (local_err) { ret = -EINVAL ; goto close_exit;
@@ -1053,7 +1053,7 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs,/* We can safely add the child now */ bdrv_ref (child_bs); - child =bdrv_attach_child (bs, child_bs, indexstr, &child_format, errp); + child =bdrv_attach_child (bs, child_bs, indexstr, &child_format,0 , errp);if (child ==NULL ) { s->next_child_index--; goto out;
block/raw-format.c +1 -1
@@ -428,7 +428,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,BDRVRawState *s = bs->opaque;int ret; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/replication.c +1 -1
@@ -90,7 +90,7 @@ static int replication_open(BlockDriverState *bs, QDict *options,const char *mode;const char *top_id; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/throttle.c +1 -1
@@ -82,7 +82,7 @@ static int throttle_open(BlockDriverState *bs, QDict *options,int ret; bs->file =bdrv_open_child (NULL , options,"file" , bs, - &child_file, false, errp); + &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ; }
block/vdi.c +1 -1
@@ -378,7 +378,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,Error *local_err =NULL ;QemuUUID uuid_link, uuid_parent; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/vhdx.c +1 -1
@@ -996,7 +996,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,uint64_t signature;Error *local_err =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/vmdk.c +2 -2
@@ -1152,7 +1152,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,assert (ret <32 ); extent_file =bdrv_open_child (extent_path, options, extent_opt_prefix, - bs, &child_file, false, &local_err); + bs, &child_file,0 , false, &local_err);g_free (extent_path);if (local_err) {error_propagate (errp, local_err);
@@ -1257,7 +1257,7 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,uint32_t magic;Error *local_err =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/vpc.c +1 -1
@@ -228,7 +228,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,int ret;int64_t bs_size; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {return -EINVAL ;
block/vvfat.c +1 -1
@@ -3183,7 +3183,7 @@ static int enable_write_target(BlockDriverState *bs, Error **errp) options =qdict_new ();qdict_put_str (options,"write-target.driver" ,"qcow" ); s->qcow =bdrv_open_child (s->qcow_filename, options,"write-target" , bs, - &child_vvfat_qcow, false, errp); + &child_vvfat_qcow,0 , false, errp);qobject_unref (options);if (!s->qcow) { ret = -EINVAL ;
blockjob.c +3 -2
@@ -217,8 +217,9 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,if (job->job.aio_context !=qemu_get_aio_context ()) {aio_context_release (job->job.aio_context); } - c =bdrv_root_attach_child (bs, name, &child_job, job->job.aio_context, - perm, shared_perm, job, errp); + c =bdrv_root_attach_child (bs, name, &child_job,0 , + job->job.aio_context, perm, shared_perm, job, + errp);if (job->job.aio_context !=qemu_get_aio_context ()) {aio_context_acquire (job->job.aio_context); }
tests/test-bdrv-drain.c +11 -9
@@ -1202,7 +1202,7 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_attach_child (bs, null_bs,"null-child" , &child_file, &error_abort); +bdrv_attach_child (bs, null_bs,"null-child" , &child_file,0 , &error_abort);/* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */
@@ -1211,13 +1211,13 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, child_bs->total_sectors =65536 >>BDRV_SECTOR_BITS ;/* Takes our reference to child_bs */ tts->wait_child =bdrv_attach_child (bs, child_bs,"wait-child" , &child_file, - &error_abort); +0 , &error_abort);/* This child is just there to be deleted * (for detach_instead_of_delete == true) */ null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_attach_child (bs, null_bs,"null-child" , &child_file, &error_abort); +bdrv_attach_child (bs, null_bs,"null-child" , &child_file,0 , &error_abort); blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL ,BLK_PERM_ALL );blk_insert_bs (blk, bs, &error_abort);
@@ -1314,7 +1314,7 @@ static void detach_indirect_bh(void *opaque)bdrv_ref (data->c); data->child_c =bdrv_attach_child (data->parent_b, data->c,"PB-C" , - &child_file, &error_abort); + &child_file,0 , &error_abort); }static void detach_by_parent_aio_cb (void *opaque,int ret)
@@ -1396,13 +1396,15 @@ static void test_detach_indirect(bool by_parent_cb)/* Set child relationships */ bdrv_ref (b);bdrv_ref (a); - child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_file, &error_abort); - child_a =bdrv_attach_child (parent_b, a,"PB-A" , &child_backing, &error_abort); + child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_file,0 , + &error_abort); + child_a =bdrv_attach_child (parent_b, a,"PB-A" , &child_backing,0 , + &error_abort);bdrv_ref (a);bdrv_attach_child (parent_a, a,"PA-A" , by_parent_cb ? &child_file : &detach_by_driver_cb_class, - &error_abort); +0 , &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1); g_assert_cmpint(parent_b->refcnt, ==, 1);
@@ -1813,7 +1815,7 @@ static void test_drop_intermediate_poll(void)/* Takes the reference to chain[i - 1] */ chain[i]->backing =bdrv_attach_child (chain[i], chain[i -1 ],"chain" , &chain_child_class, - &error_abort); +0 , &error_abort); } }
@@ -2031,7 +2033,7 @@ static void do_test_replace_child_mid_drain(int old_drain_count,bdrv_ref (old_child_bs); parent_bs->backing =bdrv_attach_child (parent_bs, old_child_bs,"child" , - &child_backing, &error_abort); + &child_backing,0 , &error_abort);for (i =0 ; i < old_drain_count; i++) {bdrv_drained_begin (old_child_bs);
tests/test-bdrv-graph-mod.c +2 -2
@@ -111,7 +111,7 @@ static void test_update_perm_tree(void)blk_insert_bs (root, bs, &error_abort); -bdrv_attach_child (filter, bs,"child" , &child_file, &error_abort); +bdrv_attach_child (filter, bs,"child" , &child_file,0 , &error_abort);bdrv_append (filter, bs, &local_err);
@@ -177,7 +177,7 @@ static void test_should_update_child(void)bdrv_set_backing_hd (target, bs, &error_abort);g_assert (target->backing->bs == bs); -bdrv_attach_child (filter, target,"target" , &child_file, &error_abort); +bdrv_attach_child (filter, target,"target" , &child_file,0 , &error_abort);bdrv_append (filter, bs, &error_abort);g_assert (target->backing->bs == bs);
Signature · 1 line
2.26.2
PATCH v4 6/34 block: Pass BdrvChildRole to bdrv_child_perm()
In reply to Max ReitzFor now, all callers pass 0 and no callee evaluates this value. Later patches will change both.
--- include/block/block_int.h | 5 ++++- block.c | 22 ++++++++++++---------- block/backup-top.c | 3 ++- block/blkdebug.c | 5 +++-- block/blklogwrites.c | 9 +++++---- block/commit.c | 1 + block/copy-on-read.c | 1 + block/mirror.c | 1 + block/quorum.c | 1 + block/replication.c | 1 + block/vvfat.c | 1 + tests/test-bdrv-drain.c | 5 +++-- tests/test-bdrv-graph-mod.c | 1 + 13 files changed, 36 insertions(+), 20 deletions(-)
include/block/block_int.h +4 -1
@@ -556,7 +556,7 @@ struct BlockDriver {* the parents in @parent_perm and @parent_shared. * * If @c is NULL, return the permissions for attaching a new child for the -* given @child_class. +* given @child_class and @role. * * If @reopen_queue is non-NULL, don't return the currently needed * permissions, but those that will be needed after applying the
@@ -564,6 +564,7 @@ struct BlockDriver {*/ void (*bdrv_child_perm)(BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared);
@@ -1266,6 +1267,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp);* all children */ void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole child_role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
@@ -1276,6 +1278,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,* CONSISTENT_READ and doesn't share WRITE. */ void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole child_role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
block.c +12 -10
@@ -1954,12 +1954,12 @@ bool bdrv_is_writable(BlockDriverState *bs)static void bdrv_child_perm (BlockDriverState *bs,BlockDriverState *child_bs,BdrvChild *c,const BdrvChildClass *child_class, -BlockReopenQueue *reopen_queue, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared) {assert (bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm (bs, c, child_class, reopen_queue, + bs->drv->bdrv_child_perm (bs, c, child_class, role, reopen_queue, parent_perm, parent_shared, nperm, nshared);/* TODO Take force_share from reopen_queue */
@@ -2053,7 +2053,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,uint64_t cur_perm, cur_shared;bool child_tighten_restr; -bdrv_child_perm (bs, c->bs, c, c->klass, q, +bdrv_child_perm (bs, c->bs, c, c->klass, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children,
@@ -2120,7 +2120,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Update all children */ QLIST_FOREACH(c, &bs->children, next) {uint64_t cur_perm, cur_shared; -bdrv_child_perm (bs, c->bs, c, c->klass,NULL , +bdrv_child_perm (bs, c->bs, c, c->klass, c->role,NULL , cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared);bdrv_child_set_perm (c, cur_perm, cur_shared);
@@ -2348,14 +2348,15 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp)uint64_t perms, shared;bdrv_get_cumulative_perm (bs, &parent_perms, &parent_shared); -bdrv_child_perm (bs, c->bs, c, c->klass,NULL , parent_perms, parent_shared, - &perms, &shared); +bdrv_child_perm (bs, c->bs, c, c->klass, c->role,NULL , + parent_perms, parent_shared, &perms, &shared);return bdrv_child_try_set_perm (c, perms, shared, errp); }void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -2366,6 +2367,7 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -2378,7 +2380,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,/* Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ -bdrv_filter_default_perms (bs, c, child_class, reopen_queue, +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, perm, shared, &perm, &shared);/* Format drivers may touch metadata even if the guest doesn't write */
@@ -2655,7 +2657,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,bdrv_get_cumulative_perm (parent_bs, &perm, &shared_perm);assert (parent_bs->drv); -bdrv_child_perm (parent_bs, child_bs,NULL , child_class,NULL , +bdrv_child_perm (parent_bs, child_bs,NULL , child_class, child_role,NULL , perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_class,
@@ -3683,7 +3685,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)if (state->replace_backing_bs && state->new_backing_bs) {uint64_t nperm, nshared;bdrv_child_perm (state->bs, state->new_backing_bs, -NULL , &child_backing, bs_queue, +NULL , &child_backing,0 , bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL,
@@ -3806,7 +3808,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, }else {uint64_t nperm, nshared; -bdrv_child_perm (parent->state.bs, bs, c, c->klass, q, +bdrv_child_perm (parent->state.bs, bs, c, c->klass, c->role, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared);
block/backup-top.c +2 -1
@@ -123,6 +123,7 @@ static void backup_top_refresh_filename(BlockDriverState *bs)static void backup_top_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -155,7 +156,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm =BLK_PERM_WRITE ; }else {/* Source child */ -bdrv_filter_default_perms (bs, c, child_class, reopen_queue, +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared);if (perm &BLK_PERM_WRITE ) {
block/blkdebug.c +3 -2
@@ -994,14 +994,15 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,static void blkdebug_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) {BDRVBlkdebugState *s = bs->opaque; -bdrv_filter_default_perms (bs, c, child_class, reopen_queue, perm, shared, - nperm, nshared); +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); *nperm |= s->take_child_perms; *nshared &= ~s->unshare_child_perms;
block/blklogwrites.c +5 -4
@@ -283,6 +283,7 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs)static void blk_log_writes_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *ro_q,uint64_t perm,uint64_t shrd,uint64_t *nperm,uint64_t *nshrd)
@@ -294,11 +295,11 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, }if (!strcmp (c->name,"log" )) { -bdrv_format_default_perms (bs, c, child_class, ro_q, perm, shrd, nperm, - nshrd); +bdrv_format_default_perms (bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); }else { -bdrv_filter_default_perms (bs, c, child_class, ro_q, perm, shrd, nperm, - nshrd); +bdrv_filter_default_perms (bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); } }
block/commit.c +1 -0
@@ -224,6 +224,7 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs)static void bdrv_commit_top_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/copy-on-read.c +1 -0
@@ -52,6 +52,7 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,static void cor_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/mirror.c +1 -0
@@ -1493,6 +1493,7 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs)static void bdrv_mirror_top_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/quorum.c +1 -0
@@ -1152,6 +1152,7 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp)static void quorum_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/replication.c +1 -0
@@ -164,6 +164,7 @@ static void replication_close(BlockDriverState *bs)static void replication_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
block/vvfat.c +1 -0
@@ -3211,6 +3211,7 @@ err:static void vvfat_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
tests/test-bdrv-drain.c +3 -2
@@ -87,6 +87,7 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs,static void bdrv_test_child_perm (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -99,8 +100,8 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, child_class = &child_file; } -bdrv_format_default_perms (bs, c, child_class, reopen_queue, perm, shared, - nperm, nshared); +bdrv_format_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } static int bdrv_test_change_backing_file(BlockDriverState *bs,
tests/test-bdrv-graph-mod.c +1 -0
@@ -31,6 +31,7 @@ static BlockDriver bdrv_pass_through = {static void no_perm_default_perms (BlockDriverState *bs,BdrvChild *c,const BdrvChildClass *child_class, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
Signature · 1 line
2.26.2
PATCH v4 7/34 block: Pass BdrvChildRole to .inherit_options()
In reply to Max ReitzFor now, all callers (effectively) pass 0 and no callee evaluates thie value. Later patches will change both.
--- include/block/block_int.h | 3 ++- block.c | 40 +++++++++++++++++++++++---------------- block/block-backend.c | 3 ++- block/vvfat.c | 3 ++- 4 files changed, 30 insertions(+), 19 deletions(-)
include/block/block_int.h +2 -1
@@ -677,7 +677,8 @@ struct BdrvChildClass {* non-BDS parents. */ bool parent_is_bds; -void (*inherit_options)(int *child_flags,QDict *child_options, +void (*inherit_options)(BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options);void (*change_media)(BdrvChild *child,bool load);
block.c +24 -16
@@ -77,6 +77,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, QDict *options, int flags, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp);/* If non-zero, use only whitelisted block drivers */
@@ -1153,7 +1154,8 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,* Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options (int *child_flags,QDict *child_options, +static void bdrv_inherited_options (BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {int flags = parent_flags;
@@ -1202,10 +1204,11 @@ const BdrvChildClass child_file = {* (and not only protocols) is permitted for it, based on the given options and * flags for the parent BDS */ -static void bdrv_inherited_fmt_options (int *child_flags,QDict *child_options, +static void bdrv_inherited_fmt_options (BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) { - child_file.inherit_options (child_flags, child_options, + child_file.inherit_options (role, child_flags, child_options, parent_flags, parent_options); *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO );
@@ -1286,7 +1289,8 @@ static void bdrv_backing_detach(BdrvChild *c)* Returns the options and flags that bs->backing should get, based on the * given options and flags for the parent BDS */ -static void bdrv_backing_options (int *child_flags,QDict *child_options, +static void bdrv_backing_options (BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {int flags = parent_flags;
@@ -2876,7 +2880,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, } backing_hd =bdrv_open_inherit (backing_filename, reference, options,0 , bs, - &child_backing, errp); + &child_backing,0 , errp);if (!backing_hd) { bs->open_flags |=BDRV_O_NO_BACKING ;error_prepend (errp,"Could not open backing file: " );
@@ -2911,7 +2915,7 @@ free_exit:static BlockDriverState *bdrv_open_child_bs (const char *filename,QDict *options,const char *bdref_key,BlockDriverState *parent,const BdrvChildClass *child_class, -bool allow_none,Error **errp) +BdrvChildRole child_role,bool allow_none,Error **errp) {BlockDriverState *bs =NULL ;QDict *image_options;
@@ -2942,7 +2946,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key, } bs =bdrv_open_inherit (filename, reference, image_options,0 , - parent, child_class, errp); + parent, child_class, child_role, errp);if (!bs) { goto done; }
@@ -2976,7 +2980,7 @@ BdrvChild *bdrv_open_child(const char *filename,BlockDriverState *bs; bs =bdrv_open_child_bs (filename, options, bdref_key, parent, child_class, - allow_none, errp); + child_role, allow_none, errp);if (bs ==NULL ) {return NULL ; }
@@ -3020,7 +3024,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) } - bs =bdrv_open_inherit (NULL , reference, qdict,0 ,NULL ,NULL , errp); + bs =bdrv_open_inherit (NULL , reference, qdict,0 ,NULL ,NULL ,0 , errp); obj =NULL ;qobject_unref (obj);visit_free (v);
@@ -3117,6 +3121,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, QDict *options, int flags, BlockDriverState *parent, const BdrvChildClass *child_class, + BdrvChildRole child_role, Error **errp) { int ret;
@@ -3169,7 +3174,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,if (child_class) { bs->inherits_from = parent; - child_class->inherit_options (&flags, options, + child_class->inherit_options (child_role, &flags, options, parent->open_flags, parent->options); }
@@ -3198,7 +3203,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options);/* Let bdrv_backing_options() override "read-only" */ qdict_del (options,BDRV_OPT_READ_ONLY ); -bdrv_backing_options (&flags, options, flags, options); +bdrv_backing_options (0 , &flags, options, flags, options); } bs->open_flags = flags;
@@ -3240,7 +3245,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,BlockDriverState *file_bs; file_bs =bdrv_open_child_bs (filename, options,"file" , bs, - &child_file, true, &local_err); + &child_file,0 , true, &local_err);if (local_err) { goto fail; }
@@ -3385,7 +3390,7 @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp) { return bdrv_open_inherit(filename, reference, options, flags, NULL, -NULL ,errp ); + NULL, 0, errp); }/* Return true if the NULL-terminated @list contains @str */
@@ -3482,6 +3487,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, const BdrvChildClass *klass, + BdrvChildRole role, QDict *parent_options, int parent_flags, bool keep_old_opts)
@@ -3537,7 +3543,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,/* Inherit from parent node */ if (parent_options) { flags =0 ; - klass->inherit_options (&flags, options, parent_flags, parent_options); + klass->inherit_options (role, &flags, options, + parent_flags, parent_options); }else { flags =bdrv_get_flags (bs); }
@@ -3628,7 +3635,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, }bdrv_reopen_queue_child (bs_queue, child->bs, new_child_options, - child->klass, options, flags, child_keep_old); + child->klass, child->role, options, flags, + child_keep_old); }return bs_queue;
@@ -3638,7 +3646,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, bool keep_old_opts) { -return bdrv_reopen_queue_child (bs_queue, bs, options,NULL ,NULL ,0 , +return bdrv_reopen_queue_child (bs_queue, bs, options,NULL ,0 ,NULL ,0 , keep_old_opts); }
block/block-backend.c +2 -1
@@ -120,7 +120,8 @@ static QTAILQ_HEAD(, BlockBackend) block_backends = static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =QTAILQ_HEAD_INITIALIZER (monitor_block_backends); -static void blk_root_inherit_options (int *child_flags,QDict *child_options, +static void blk_root_inherit_options (BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {/* We're not supposed to call this function for root nodes */
block/vvfat.c +2 -1
@@ -3128,7 +3128,8 @@ static BlockDriver vvfat_write_target = { .bdrv_co_pwritev = write_target_commit, }; -static void vvfat_qcow_options (int *child_flags,QDict *child_options, +static void vvfat_qcow_options (BdrvChildRole role, +int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {qdict_set_default_str (child_options,BDRV_OPT_READ_ONLY ,"off" );
Signature · 1 line
2.26.2
PATCH v4 8/34 block: Pass parent_is_format to .inherit_options()
In reply to Max ReitzWe plan to unify the generic .inherit_options() functions. The resulting common function will need to decide whether to force-enable format probing, force-disable it, or leave it as-is. To make this decision, it will need to know whether the parent node is a format node or not (because we never want format probing if the parent is a format node already (except for the backing chain)).
--- include/block/block_int.h | 2 +- block.c | 37 +++++++++++++++++++++++++++---------- block/block-backend.c | 2 +- block/vvfat.c | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-)
include/block/block_int.h +1 -1
@@ -677,7 +677,7 @@ struct BdrvChildClass {* non-BDS parents. */ bool parent_is_bds; -void (*inherit_options)(BdrvChildRole role, +void (*inherit_options)(BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options);
block.c +27 -10
@@ -1154,7 +1154,7 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,* Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options (BdrvChildRole role, +static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {
@@ -1205,10 +1205,12 @@ const BdrvChildClass child_file = {* flags for the parent BDS */ static void bdrv_inherited_fmt_options (BdrvChildRole role, +bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) { - child_file.inherit_options (role, child_flags, child_options, + child_file.inherit_options (role, parent_is_format, + child_flags, child_options, parent_flags, parent_options); *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO );
@@ -1289,7 +1291,7 @@ static void bdrv_backing_detach(BdrvChild *c)* Returns the options and flags that bs->backing should get, based on the * given options and flags for the parent BDS */ -static void bdrv_backing_options (BdrvChildRole role, +static void bdrv_backing_options (BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {
@@ -3173,8 +3175,22 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, bs->explicit_options =qdict_clone_shallow (options);if (child_class) { +bool parent_is_format; + +if (parent->drv) { + parent_is_format = parent->drv->is_format; + }else { +/* +* parent->drv is not set yet because this node is opened for +* (potential) format probing. That means that @parent is going +* to be a format node. +*/ + parent_is_format = true; + } + bs->inherits_from = parent; - child_class->inherit_options (child_role, &flags, options, + child_class->inherit_options (child_role, parent_is_format, + &flags, options, parent->open_flags, parent->options); }
@@ -3203,7 +3219,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options);/* Let bdrv_backing_options() override "read-only" */ qdict_del (options,BDRV_OPT_READ_ONLY ); -bdrv_backing_options (0 , &flags, options, flags, options); +bdrv_backing_options (0 , true, &flags, options, flags, options); } bs->open_flags = flags;
@@ -3488,6 +3504,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,QDict *options, const BdrvChildClass *klass, BdrvChildRole role, + bool parent_is_format, QDict *parent_options, int parent_flags, bool keep_old_opts)
@@ -3543,7 +3560,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,/* Inherit from parent node */ if (parent_options) { flags =0 ; - klass->inherit_options (role, &flags, options, + klass->inherit_options (role, parent_is_format, &flags, options, parent_flags, parent_options); }else { flags =bdrv_get_flags (bs);
@@ -3635,8 +3652,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, }bdrv_reopen_queue_child (bs_queue, child->bs, new_child_options, - child->klass, child->role, options, flags, - child_keep_old); + child->klass, child->role, bs->drv->is_format, + options, flags, child_keep_old); }return bs_queue;
@@ -3646,8 +3663,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, bool keep_old_opts) { -return bdrv_reopen_queue_child (bs_queue, bs, options,NULL ,0 ,NULL ,0 , - keep_old_opts); +return bdrv_reopen_queue_child (bs_queue, bs, options,NULL ,0 , false, +NULL ,0 , keep_old_opts); }/*
block/block-backend.c +1 -1
@@ -120,7 +120,7 @@ static QTAILQ_HEAD(, BlockBackend) block_backends = static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =QTAILQ_HEAD_INITIALIZER (monitor_block_backends); -static void blk_root_inherit_options (BdrvChildRole role, +static void blk_root_inherit_options (BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {
block/vvfat.c +1 -1
@@ -3128,7 +3128,7 @@ static BlockDriver vvfat_write_target = { .bdrv_co_pwritev = write_target_commit, }; -static void vvfat_qcow_options (BdrvChildRole role, +static void vvfat_qcow_options (BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options) {
Signature · 1 line
2.26.2
PATCH v4 9/34 block: Rename bdrv_inherited_options()
In reply to Max ReitzThe other two .inherit_options implementations specify exactly for what case they are used in their name, so do it for this one as well.
(The actual intention behind this patch is to follow it up with a generic bdrv_inherited_options() that works for all three cases.)
--- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
block.c +4 -4
@@ -1154,9 +1154,9 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,* Returns the options and flags that bs->file should get if a protocol driver * is expected, based on the given options and flags for the parent BDS */ -static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) +static void bdrv_protocol_options (BdrvChildRole role,bool parent_is_format, +int *child_flags,QDict *child_options, +int parent_flags,QDict *parent_options) {int flags = parent_flags;
@@ -1188,7 +1188,7 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,const BdrvChildClass child_file = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_inherited_options, + .inherit_options = bdrv_protocol_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_poll = bdrv_child_cb_drained_poll, .drained_end = bdrv_child_cb_drained_end,
Signature · 1 line
2.26.2
PATCH v4 10/34 block: Add generic bdrv_inherited_options()
In reply to Max ReitzAfter the series this patch belongs to, we want to have a common BdrvChildClass that encompasses all of child_file, child_format, and child_backing. Such a single class needs a single .inherit_options() implementation, and this patch introduces it.
The next patch will show how the existing implementations can fall back to it just by passing appropriate BdrvChildRole and parent_is_format values.
--- block.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
block.c +81 -0
@@ -1356,6 +1356,87 @@ const BdrvChildClass child_backing = { .set_aio_ctx = bdrv_child_cb_set_aio_ctx, }; +/* +* Returns the options and flags that a generic child of a BDS should +* get, based on the given options and flags for the parent BDS. +*/ +static void __attribute__((unused)) +bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, +int *child_flags,QDict *child_options, +int parent_flags,QDict *parent_options) +{ +int flags = parent_flags; + +/* +* First, decide whether to set, clear, or leave BDRV_O_PROTOCOL. +* Generally, the question to answer is: Should this child be +* format-probed by default? +*/ + +/* +* Pure and non-filtered data children of non-format nodes should +* be probed by default (even when the node itself has BDRV_O_PROTOCOL +* set). This only affects a very limited set of drivers (namely +* quorum and blkverify when this comment was written). +* Force-clear BDRV_O_PROTOCOL then. +*/ +if (!parent_is_format && + (role &BDRV_CHILD_DATA ) && + !(role & (BDRV_CHILD_METADATA |BDRV_CHILD_FILTERED ))) + { + flags &= ~BDRV_O_PROTOCOL ; + } + +/* +* All children of format nodes (except for COW children) and all +* metadata children in general should never be format-probed. +* Force-set BDRV_O_PROTOCOL then. +*/ +if ((parent_is_format && !(role &BDRV_CHILD_COW )) || + (role &BDRV_CHILD_METADATA )) + { + flags |=BDRV_O_PROTOCOL ; + } + +/* +* If the cache mode isn't explicitly set, inherit direct and no-flush from +* the parent. +*/ +qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_DIRECT ); +qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_NO_FLUSH ); +qdict_copy_default (child_options, parent_options,BDRV_OPT_FORCE_SHARE ); + +if (role &BDRV_CHILD_COW ) { +/* backing files are opened read-only by default */ +qdict_set_default_str (child_options,BDRV_OPT_READ_ONLY ,"on" ); +qdict_set_default_str (child_options,BDRV_OPT_AUTO_READ_ONLY ,"off" ); + }else { +/* Inherit the read-only option from the parent if it's not set */ +qdict_copy_default (child_options, parent_options,BDRV_OPT_READ_ONLY ); +qdict_copy_default (child_options, parent_options, +BDRV_OPT_AUTO_READ_ONLY ); + } + +/* +* bdrv_co_pdiscard() respects unmap policy for the parent, so we +* can default to enable it on lower layers regardless of the +* parent option. +*/ +qdict_set_default_str (child_options,BDRV_OPT_DISCARD ,"unmap" ); + +/* Clear flags that only apply to the top layer */ + flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_COPY_ON_READ ); + +if (role &BDRV_CHILD_METADATA ) { + flags &= ~BDRV_O_NO_IO ; + } +if (role &BDRV_CHILD_COW ) { + flags &= ~BDRV_O_TEMPORARY ; + } + + *child_flags = flags; +} +static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags;
Signature · 1 line
2.26.2
Re: [PATCH v4 10/34] block: Add generic bdrv_inherited_options()
Quoted 5 lines · Max Reitz
After the series this patch belongs to, we want to have a common BdrvChildClass that encompasses all of
child_file,child_format, andchild_backing. Such a single class needs a single .inherit_options() implementation, and this patch introduces it.
Quoted 9 lines
The next patch will show how the existing implementations can fall back to it just by passing appropriate BdrvChildRole and
parent_is_formatvalues.Signed-off-by Max Reitz <[email protected]>--- block.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 11/34 block: Use bdrv_inherited_options()
In reply to Max ReitzLet child_file's, child_format's, and child_backing's .inherit_options() implementations fall back to bdrv_inherited_options() to show that it would really work for all of these cases, if only the parents passed the appropriate BdrvChildRole and parent_is_format values.
(Also, make bdrv_open_inherit(), the only place to explicitly call bdrv_backing_options(), call bdrv_inherited_options() instead.)
This patch should incur only two visible changes, both for child_format children, both of which are effectively bug fixes:
First, they no longer have discard=unmap set by default. This reason it was set is because bdrv_inherited_fmt_options() fell through to bdrv_protocol_options(), and that set it because "format drivers take care to send flushes and respect unmap policy". None of the drivers that use child_format for their children (quorum and blkverify) are format drivers, though, so this reasoning does not apply here.
Second, they no longer have BDRV_O_NO_IO force-cleared. child_format was used solely for children that do not store any metadata and as such will not be accessed by their parents as long as those parents do not receive I/O themselves. Thus, such children should inherit BDRV_O_NO_IO.
--- block.c | 71 +++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 52 deletions(-)
block.c +19 -52
@@ -80,6 +80,11 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,BdrvChildRole child_role, Error **errp); +/* TODO: Remove when no longer needed */ +static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, +int *child_flags,QDict *child_options, +int parent_flags,QDict *parent_options); +/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist;
@@ -1158,31 +1163,9 @@ static void bdrv_protocol_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - int flags = parent_flags; - -/* Enable protocol handling, disable format probing for bs->file */ - flags |=BDRV_O_PROTOCOL ; - -/* If the cache mode isn't explicitly set, inherit direct and no-flush from -* the parent. */ -qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_DIRECT ); -qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_NO_FLUSH ); -qdict_copy_default (child_options, parent_options,BDRV_OPT_FORCE_SHARE ); - -/* Inherit the read-only option from the parent if it's not set */ -qdict_copy_default (child_options, parent_options,BDRV_OPT_READ_ONLY ); -qdict_copy_default (child_options, parent_options,BDRV_OPT_AUTO_READ_ONLY ); - -/* Our block drivers take care to send flushes and respect unmap policy, -* so we can default to enable both on lower layers regardless of the -* corresponding parent options. */ -qdict_set_default_str (child_options,BDRV_OPT_DISCARD ,"unmap" ); - -/* Clear flags that only apply to the top layer */ - flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_NO_BACKING |BDRV_O_COPY_ON_READ | -BDRV_O_NO_IO ); - - *child_flags = flags; +bdrv_inherited_options (BDRV_CHILD_IMAGE ,true , +child_flags ,child_options , +parent_flags ,parent_options ); } const BdrvChildClass child_file = {
@@ -1209,11 +1192,9 @@ static void bdrv_inherited_fmt_options(BdrvChildRole role, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - child_file.inherit_options(role, parent_is_format, -child_flags ,child_options , -parent_flags ,parent_options ); - - *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO ); +bdrv_inherited_options (BDRV_CHILD_DATA ,false , +child_flags ,child_options , +parent_flags ,parent_options ); } const BdrvChildClass child_format = {
@@ -1295,23 +1276,9 @@ static void bdrv_backing_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options) { - int flags = parent_flags; - -/* The cache mode is inherited unmodified for backing files; except WCE, -* which is only applied on the top level (BlockBackend) */ -qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_DIRECT ); -qdict_copy_default (child_options, parent_options,BDRV_OPT_CACHE_NO_FLUSH ); -qdict_copy_default (child_options, parent_options,BDRV_OPT_FORCE_SHARE ); - -/* backing files always opened read-only */ -qdict_set_default_str (child_options,BDRV_OPT_READ_ONLY ,"on" ); -qdict_set_default_str (child_options,BDRV_OPT_AUTO_READ_ONLY ,"off" ); - flags &= ~BDRV_O_COPY_ON_READ ; - -/* snapshot=on is handled on the top layer */ - flags &= ~(BDRV_O_SNAPSHOT |BDRV_O_TEMPORARY ); - - *child_flags = flags; +bdrv_inherited_options (BDRV_CHILD_COW ,true , +child_flags ,child_options , +parent_flags ,parent_options ); } static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
@@ -1360,10 +1327,9 @@ const BdrvChildClass child_backing = {* Returns the options and flags that a generic child of a BDS should * get, based on the given options and flags for the parent BDS. */ -static void __attribute__((unused)) -bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) +static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, +int *child_flags,QDict *child_options, +int parent_flags,QDict *parent_options) {int flags = parent_flags;
@@ -3300,7 +3266,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, flags, options);/* Let bdrv_backing_options() override "read-only" */ qdict_del (options,BDRV_OPT_READ_ONLY ); -bdrv_backing_options (0 , true, &flags, options, flags, options); +bdrv_inherited_options (BDRV_CHILD_COW , true, + &flags, options, flags, options); } bs->open_flags = flags;
Signature · 1 line
2.26.2
Re: [PATCH v4 11/34] block: Use bdrv_inherited_options()
Quoted 24 lines · Max Reitz
Let child_file's, child_format's, and child_backing's .inherit_options() implementations fall back to
bdrv_inherited_options()to show that it would really work for all of these cases, if only the parents passed the appropriate BdrvChildRole andparent_is_formatvalues.(Also, make
bdrv_open_inherit(), the only place to explicitly callbdrv_backing_options(), callbdrv_inherited_options()instead.)This patch should incur only two visible changes, both for
child_formatchildren, both of which are effectively bug fixes:First, they no longer have discard=unmap set by default. This reason it was set is because
bdrv_inherited_fmt_options()fell through tobdrv_protocol_options(), and that set it because "format drivers take care to send flushes and respect unmap policy". None of the drivers that usechild_formatfor their children (quorum and blkverify) are format drivers, though, so this reasoning does not apply here.Second, they no longer have
BDRV_O_NO_IOforce-cleared.child_formatwas used solely for children that do not store any metadata and as such will not be accessed by their parents as long as those parents do not receive I/O themselves. Thus, such children should inheritBDRV_O_NO_IO.
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- block.c | 71 +++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 52 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 12/34 block: Unify bdrv_child_cb_attach()
In reply to Max ReitzMake bdrv_child_cb_attach() call bdrv_backing_attach() for children with a COW role (and drop the reverse call from bdrv_backing_attach()), so it can be used for any child (with a proper role set).
Because so far no child has a proper role set, we need a temporary new callback for child_backing.attach that ensures bdrv_backing_attach() is called for all COW children that do not have their role set yet.
(Also, move bdrv_child_cb_attach() down to group it with bdrv_inherited_options().)
--- block.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
block.c +20 -7
@@ -84,6 +84,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format,int *child_flags,QDict *child_options,int parent_flags,QDict *parent_options); +static void bdrv_child_cb_attach (BdrvChild *child);/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist;
@@ -1099,12 +1100,6 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,bdrv_drained_end_no_poll (bs, drained_end_counter); } -static void bdrv_child_cb_attach (BdrvChild *child) -{ -BlockDriverState *bs = child->opaque; -bdrv_apply_subtree_drain (child, bs); -} -static void bdrv_child_cb_detach (BdrvChild *child) {BlockDriverState *bs = child->opaque;
@@ -1252,7 +1247,14 @@ static void bdrv_backing_attach(BdrvChild *c) parent->backing_blocker);bdrv_op_unblock (backing_hd,BLOCK_OP_TYPE_BACKUP_TARGET , parent->backing_blocker); +} +/* XXX: Will be removed along with child_backing */ +static void bdrv_child_cb_attach_backing (BdrvChild *c) +{ +if (!(c->role &BDRV_CHILD_COW )) { +bdrv_backing_attach (c); + }bdrv_child_cb_attach (c); }
@@ -1311,7 +1313,7 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, - .attach = bdrv_backing_attach, + .attach = bdrv_child_cb_attach_backing, .detach = bdrv_backing_detach, .inherit_options = bdrv_backing_options, .drained_begin = bdrv_child_cb_drained_begin,
@@ -1403,6 +1405,17 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, *child_flags = flags; } +static void bdrv_child_cb_attach (BdrvChild *child) +{ +BlockDriverState *bs = child->opaque; + +if (child->role &BDRV_CHILD_COW ) { +bdrv_backing_attach (child); + } + +bdrv_apply_subtree_drain (child, bs); +} +static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags;
Signature · 1 line
2.26.2
Re: [PATCH v4 12/34] block: Unify bdrv_child_cb_attach()
Quoted 8 lines · Max Reitz
Make
bdrv_child_cb_attach()callbdrv_backing_attach()for children with a COW role (and drop the reverse call frombdrv_backing_attach()), so it can be used for any child (with a proper role set).Because so far no child has a proper role set, we need a temporary new callback for child_backing.attach that ensures
bdrv_backing_attach()is called for all COW children that do not have their role set yet.
Quoted 8 lines
(Also, move
bdrv_child_cb_attach()down to group it withbdrv_inherited_options().)Signed-off-by Max Reitz <[email protected]>--- block.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 13/34 block: Unify bdrv_child_cb_detach()
In reply to Max ReitzMake bdrv_child_cb_detach() call bdrv_backing_detach() for children with a COW role (and drop the reverse call from bdrv_backing_detach()), so it can be used for any child (with a proper role set).
Because so far no child has a proper role set, we need a temporary new callback for child_backing.detach that ensures bdrv_backing_detach() is called for all COW children that do not have their role set yet.
(Also, move bdrv_child_cb_detach() down to group it with bdrv_inherited_options() and bdrv_child_cb_attach().)
--- block.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
block.c +20 -7
@@ -85,6 +85,7 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format, int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options);static void bdrv_child_cb_attach (BdrvChild *child); +static void bdrv_child_cb_detach (BdrvChild *child);/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist;
@@ -1100,12 +1101,6 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,bdrv_drained_end_no_poll (bs, drained_end_counter); } -static void bdrv_child_cb_detach (BdrvChild *child) -{ -BlockDriverState *bs = child->opaque; -bdrv_unapply_subtree_drain (child, bs); -} -static int bdrv_child_cb_inactivate (BdrvChild *child) {BlockDriverState *bs = child->opaque;
@@ -1266,7 +1261,14 @@ static void bdrv_backing_detach(BdrvChild *c)bdrv_op_unblock_all (c->bs, parent->backing_blocker);error_free (parent->backing_blocker); parent->backing_blocker =NULL ; +} +/* XXX: Will be removed along with child_backing */ +static void bdrv_child_cb_detach_backing (BdrvChild *c) +{ +if (!(c->role &BDRV_CHILD_COW )) { +bdrv_backing_detach (c); + }bdrv_child_cb_detach (c); }
@@ -1314,7 +1316,7 @@ const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .attach = bdrv_child_cb_attach_backing, - .detach = bdrv_backing_detach, + .detach = bdrv_child_cb_detach_backing, .inherit_options = bdrv_backing_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_poll = bdrv_child_cb_drained_poll,
@@ -1416,6 +1418,17 @@ static void bdrv_child_cb_attach(BdrvChild *child)bdrv_apply_subtree_drain (child, bs); } +static void bdrv_child_cb_detach (BdrvChild *child) +{ +BlockDriverState *bs = child->opaque; + +if (child->role &BDRV_CHILD_COW ) { +bdrv_backing_detach (child); + } + +bdrv_unapply_subtree_drain (child, bs); +} +static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags;
Signature · 1 line
2.26.2
Re: [PATCH v4 13/34] block: Unify bdrv_child_cb_detach()
Quoted 8 lines · Max Reitz
Make
bdrv_child_cb_detach()callbdrv_backing_detach()for children with a COW role (and drop the reverse call frombdrv_backing_detach()), so it can be used for any child (with a proper role set).Because so far no child has a proper role set, we need a temporary new callback for child_backing.detach that ensures
bdrv_backing_detach()is called for all COW children that do not have their role set yet.
Quoted 8 lines
(Also, move
bdrv_child_cb_detach()down to group it withbdrv_inherited_options()andbdrv_child_cb_attach().)Signed-off-by Max Reitz <[email protected]>--- block.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 14/34 block: Add child_of_bds
In reply to Max ReitzAny current user of child_file, child_format, and child_backing can and should use this generic BdrvChildClass instead, as it can handle all of these cases. However, to be able to do so, the users must pass the appropriate BdrvChildRole when the child is created/attached. (The following commits will take care of that.)
--- include/block/block_int.h | 1 + block.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
include/block/block_int.h +1 -0
@@ -740,6 +740,7 @@ struct BdrvChildClass {void (*set_aio_ctx)(BdrvChild *child,AioContext *ctx,GSList **ignore); }; +extern const BdrvChildClass child_of_bds;extern const BdrvChildClass child_file;extern const BdrvChildClass child_format;extern const BdrvChildClass child_backing;
block.c +24 -0
@@ -1429,6 +1429,30 @@ static void bdrv_child_cb_detach(BdrvChild *child)bdrv_unapply_subtree_drain (child, bs); } +static int bdrv_child_cb_update_filename (BdrvChild *c,BlockDriverState *base, +const char *filename,Error **errp) +{ +if (c->role &BDRV_CHILD_COW ) { +return bdrv_backing_update_filename (c, base, filename, errp); + } +return 0 ; +} + +const BdrvChildClass child_of_bds = { + .parent_is_bds = true, + .get_parent_desc = bdrv_child_get_parent_desc, + .inherit_options = bdrv_inherited_options, + .drained_begin = bdrv_child_cb_drained_begin, + .drained_poll = bdrv_child_cb_drained_poll, + .drained_end = bdrv_child_cb_drained_end, + .attach = bdrv_child_cb_attach, + .detach = bdrv_child_cb_detach, + .inactivate = bdrv_child_cb_inactivate, + .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, + .set_aio_ctx = bdrv_child_cb_set_aio_ctx, + .update_filename = bdrv_child_cb_update_filename, +}; +static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags;
Signature · 1 line
2.26.2
Re: [PATCH v4 14/34] block: Add child_of_bds
Quoted 6 lines · Max Reitz
Any current user of
child_file,child_format, andchild_backingcan and should use this generic BdrvChildClass instead, as it can handle all of these cases. However, to be able to do so, the users must pass the appropriate BdrvChildRole when the child is created/attached. (The following commits will take care of that.)
Quoted 6 lines
Signed-off-by Max Reitz <[email protected]>--- include/block/block_int.h | 1 + block.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 15/34 block: Distinguish paths in *_format_default_perms
In reply to Max Reitzbdrv_format_default_perms() has one code path for backing files, and one for storage files. We want to pull them out into own functions, so make sure they are completely distinct before so the next patches will be a bit cleaner.
--- block.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
block.c +13 -6
@@ -2497,6 +2497,13 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, perm |=BLK_PERM_CONSISTENT_READ ; } shared &= ~(BLK_PERM_WRITE |BLK_PERM_RESIZE ); + +if (bs->open_flags &BDRV_O_INACTIVE ) { + shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + + *nperm = perm; + *nshared = shared; }else {/* We want consistent read from backing files if the parent needs it. * No other operations are performed on backing files. */
@@ -2513,14 +2520,14 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, shared |=BLK_PERM_CONSISTENT_READ |BLK_PERM_GRAPH_MOD |BLK_PERM_WRITE_UNCHANGED ; - } -if (bs->open_flags &BDRV_O_INACTIVE ) { - shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; - } +if (bs->open_flags &BDRV_O_INACTIVE ) { + shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } - *nperm = perm; - *nshared = shared; + *nperm = perm; + *nshared = shared; + } }uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm)
Signature · 1 line
2.26.2
Re: [PATCH v4 15/34] block: Distinguish paths in *_format_default_perms
Quoted 2 lines · Max Reitz
bdrv_format_default_perms()has one code path for backing files, and one for storage files. We want to pull them out into own functions, so
Grammar suggestion: s/into own/into their own/
Quoted 5 lines
make sure they are completely distinct before so the next patches will be a bit cleaner.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>
R-b still stands.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 16/34 block: Pull out bdrv_default_perms_for_cow()
In reply to Max ReitzRight now, bdrv_format_default_perms() is used by format parents (generally). We want to switch to a model where most parents use a single BdrvChildClass, which then decides the permissions based on the child role. To do so, we have to split bdrv_format_default_perms() into separate functions for each such role.
--- block.c | 62 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 22 deletions(-)
block.c +40 -22
@@ -2468,6 +2468,44 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, *nshared = (shared &DEFAULT_PERM_PASSTHROUGH ) |DEFAULT_PERM_UNCHANGED ; } +static void bdrv_default_perms_for_cow (BlockDriverState *bs,BdrvChild *c, +const BdrvChildClass *child_class, +BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) +{ +assert (child_class == &child_backing || + (child_class == &child_of_bds && (role &BDRV_CHILD_COW ))); + +/* +* We want consistent read from backing files if the parent needs it. +* No other operations are performed on backing files. +*/ + perm &=BLK_PERM_CONSISTENT_READ ; + +/* +* If the parent can deal with changing data, we're okay with a +* writable and resizable backing file. +* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? +*/ +if (shared &BLK_PERM_WRITE ) { + shared =BLK_PERM_WRITE |BLK_PERM_RESIZE ; + }else { + shared =0 ; + } + + shared |=BLK_PERM_CONSISTENT_READ |BLK_PERM_GRAPH_MOD | +BLK_PERM_WRITE_UNCHANGED ; + +if (bs->open_flags &BDRV_O_INACTIVE ) { + shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + + *nperm = perm; + *nshared = shared; +} + void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role,
@@ -2505,28 +2543,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, *nperm = perm; *nshared = shared; }else { -/* We want consistent read from backing files if the parent needs it. -* No other operations are performed on backing files. */ - perm &=BLK_PERM_CONSISTENT_READ ; - -/* If the parent can deal with changing data, we're okay with a -* writable and resizable backing file. */ -/* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? */ -if (shared &BLK_PERM_WRITE ) { - shared =BLK_PERM_WRITE |BLK_PERM_RESIZE ; - }else { - shared =0 ; - } - - shared |=BLK_PERM_CONSISTENT_READ |BLK_PERM_GRAPH_MOD | -BLK_PERM_WRITE_UNCHANGED ; - -if (bs->open_flags &BDRV_O_INACTIVE ) { - shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; - } - - *nperm = perm; - *nshared = shared; +bdrv_default_perms_for_cow (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } }
Signature · 1 line
2.26.2
Re: [PATCH v4 16/34] block: Pull out bdrv_default_perms_for_cow()
Quoted 11 lines · Max Reitz
Right now,
bdrv_format_default_perms()is used by format parents (generally). We want to switch to a model where most parents use a single BdrvChildClass, which then decides the permissions based on the child role. To do so, we have to splitbdrv_format_default_perms()into separate functions for each such role.Signed-off-by Max Reitz <[email protected]>--- block.c | 62 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 22 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 17/34 block: Pull out bdrv_default_perms_for_storage()
In reply to Max ReitzRight now, bdrv_format_default_perms() is used by format parents (generally). We want to switch to a model where most parents use a single BdrvChildClass, which then decides the permissions based on the child role. To do so, we have to split bdrv_format_default_perms() into separate functions for each such role.
Note that bdrv_default_perms_for_storage() currently handles all DATA | METADATA children. A follow-up patch is going to split it further into one function for each case.
--- block.c | 71 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 25 deletions(-)
block.c +46 -25
@@ -2506,6 +2506,50 @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } +static void bdrv_default_perms_for_storage (BlockDriverState *bs,BdrvChild *c, +const BdrvChildClass *child_class, +BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) +{ +int flags; + +assert (child_class == &child_file || + (child_class == &child_of_bds && + (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA )))); + + flags =bdrv_reopen_get_flags (reopen_queue, bs); + +/* +* Apart from the modifications below, the same permissions are +* forwarded and left alone as for filters +*/ +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, &perm, &shared); + +/* Format drivers may touch metadata even if the guest doesn't write */ +if (bdrv_is_writable_after_reopen (bs, reopen_queue)) { + perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + +/* +* bs->file always needs to be consistent because of the metadata. We +* can never allow other users to resize or write to it. +*/ +if (!(flags &BDRV_O_NO_IO )) { + perm |=BLK_PERM_CONSISTENT_READ ; + } + shared &= ~(BLK_PERM_WRITE |BLK_PERM_RESIZE ); + +if (bs->open_flags &BDRV_O_INACTIVE ) { + shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + + *nperm = perm; + *nshared = shared; +} + void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role,
@@ -2517,31 +2561,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,assert (child_class == &child_backing || child_class == &child_file);if (!backing) { -int flags =bdrv_reopen_get_flags (reopen_queue, bs); - -/* Apart from the modifications below, the same permissions are -* forwarded and left alone as for filters */ -bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, &perm, &shared); - -/* Format drivers may touch metadata even if the guest doesn't write */ -if (bdrv_is_writable_after_reopen (bs, reopen_queue)) { - perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; - } - -/* bs->file always needs to be consistent because of the metadata. We -* can never allow other users to resize or write to it. */ -if (!(flags &BDRV_O_NO_IO )) { - perm |=BLK_PERM_CONSISTENT_READ ; - } - shared &= ~(BLK_PERM_WRITE |BLK_PERM_RESIZE ); - -if (bs->open_flags &BDRV_O_INACTIVE ) { - shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; - } - - *nperm = perm; - *nshared = shared; +bdrv_default_perms_for_storage (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); }else {bdrv_default_perms_for_cow (bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared);
Signature · 1 line
2.26.2
PATCH v4 18/34 block: Relax *perms_for_storage for data children
In reply to Max ReitzWe can be less restrictive about pure data children than those with metadata on them, so let bdrv_default_perms_for_storage() handle metadata children differently from pure data children.
As explained in the code, the restrictions on metadata children are strictly stricter than those for pure data children, so in theory we just have to distinguish between pure-data and all other storage children (pure metadata or data+metadata). In practice, that is not obvious, though, so we have two independent code paths for metadata and for data children, and data+metadata children will go through both (without the path for data children doing anything meaningful).
--- block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-)
block.c +48 -10
@@ -2528,19 +2528,57 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, perm, shared, &perm, &shared); -/* Format drivers may touch metadata even if the guest doesn't write */ -if (bdrv_is_writable_after_reopen (bs, reopen_queue)) { - perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; +if (role &BDRV_CHILD_METADATA ) { +/* Format drivers may touch metadata even if the guest doesn't write */ +if (bdrv_is_writable_after_reopen (bs, reopen_queue)) { + perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + +/* +* bs->file always needs to be consistent because of the +* metadata. We can never allow other users to resize or write +* to it. +*/ +if (!(flags &BDRV_O_NO_IO )) { + perm |=BLK_PERM_CONSISTENT_READ ; + } + shared &= ~(BLK_PERM_WRITE |BLK_PERM_RESIZE ); } -/* -* bs->file always needs to be consistent because of the metadata. We -* can never allow other users to resize or write to it. -*/ -if (!(flags &BDRV_O_NO_IO )) { - perm |=BLK_PERM_CONSISTENT_READ ; +if (role &BDRV_CHILD_DATA ) { +/* +* Technically, everything in this block is a subset of the +* BDRV_CHILD_METADATA path taken above, and so this could +* be an "else if" branch. However, that is not obvious, and +* this function is not performance critical, therefore we let +* this be an independent "if". +*/ + +/* +* We cannot allow other users to resize the file because the +* format driver might have some assumptions about the size +* (e.g. because it is stored in metadata, or because the file +* is split into fixed-size data files). +*/ + shared &= ~BLK_PERM_RESIZE ; + +/* +* WRITE_UNCHANGED often cannot be performed as such on the +* data file. For example, the qcow2 driver may still need to +* write copied clusters on copy-on-read. +*/ +if (perm &BLK_PERM_WRITE_UNCHANGED ) { + perm |=BLK_PERM_WRITE ; + } + +/* +* If the data file is written to, the format driver may +* expect to be able to resize it by writing beyond the EOF. +*/ +if (perm &BLK_PERM_WRITE ) { + perm |=BLK_PERM_RESIZE ; + } } - shared &= ~(BLK_PERM_WRITE |BLK_PERM_RESIZE );if (bs->open_flags &BDRV_O_INACTIVE ) { shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ;
Signature · 1 line
2.26.2
Re: [PATCH v4 18/34] block: Relax *perms_for_storage for data children
Quoted 12 lines · Max Reitz
We can be less restrictive about pure data children than those with metadata on them, so let
bdrv_default_perms_for_storage()handle metadata children differently from pure data children.As explained in the code, the restrictions on metadata children are strictly stricter than those for pure data children, so in theory we just have to distinguish between pure-data and all other storage children (pure metadata or data+metadata). In practice, that is not obvious, though, so we have two independent code paths for metadata and for data children, and data+metadata children will go through both (without the path for data children doing anything meaningful).
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 19/34 block: Add bdrv_default_perms()
In reply to Max ReitzThis callback can be used by BDSs that use child_of_bds with the appropriate BdrvChildRole for their children.
Also, make bdrv_format_default_perms() use it for child_of_bds children (just a temporary solution until we can drop bdrv_format_default_perms() altogether).
--- include/block/block_int.h | 11 +++++++++++ block.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
include/block/block_int.h +11 -0
@@ -1288,6 +1288,17 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,bool bdrv_recurse_can_replace (BlockDriverState *bs,BlockDriverState *to_replace); +/* +* Default implementation for BlockDriver.bdrv_child_perm() that can +* be used by block filters and image formats, as long as they use the +* child_of_bds child class and set an appropriate BdrvChildRole. +*/ +void bdrv_default_perms (BlockDriverState *bs,BdrvChild *c, +const BdrvChildClass *child_class,BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared); +/* * Default implementation for drivers to pass bdrv_co_block_status() to * their file.
block.c +32 -0
@@ -2596,6 +2596,13 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) { bool backing = (child_class == &child_backing); + +if (child_class == &child_of_bds) { +bdrv_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); +return ; + } +assert (child_class == &child_backing || child_class == &child_file);if (!backing) {
@@ -2607,6 +2614,31 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, } } +void bdrv_default_perms (BlockDriverState *bs,BdrvChild *c, +const BdrvChildClass *child_class,BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) +{ +assert (child_class == &child_of_bds); + +if (role &BDRV_CHILD_FILTERED ) { +assert (!(role & (BDRV_CHILD_DATA |BDRV_CHILD_METADATA | +BDRV_CHILD_COW ))); +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else if (role &BDRV_CHILD_COW ) { +assert (!(role & (BDRV_CHILD_DATA |BDRV_CHILD_METADATA ))); +bdrv_default_perms_for_cow (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else if (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA )) { +bdrv_default_perms_for_storage (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else { +g_assert_not_reached (); + } +} +uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm) {static const uint64_t permissions[] = {
Signature · 1 line
2.26.2
Re: [PATCH v4 19/34] block: Add bdrv_default_perms()
Quoted 7 lines · Max Reitz
This callback can be used by BDSs that use
child_of_bdswith the appropriate BdrvChildRole for their children.Also, make
bdrv_format_default_perms()use it forchild_of_bdschildren (just a temporary solution until we can dropbdrv_format_default_perms()altogether).
Quoted 6 lines
Signed-off-by Max Reitz <[email protected]>--- include/block/block_int.h | 11 +++++++++++ block.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 20/34 raw-format: Split raw_read_options()
In reply to Max ReitzSplit raw_read_options() into one function that actually just reads the options, and another that applies them. This will allow us to detect whether the user has specified any options before attaching the file child (so we can decide on its role based on the options).
--- block/raw-format.c | 110 ++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 45 deletions(-)
block/raw-format.c +65 -45
@@ -71,20 +71,13 @@ static QemuOptsList raw_create_opts = { } }; -static int raw_read_options (QDict *options,BlockDriverState *bs, -BDRVRawState *s,Error **errp) +static int raw_read_options (QDict *options,uint64_t *offset,bool *has_size, +uint64_t *size,Error **errp) {Error *local_err =NULL ;QemuOpts *opts =NULL ; -int64_t real_size =0 ;int ret; - real_size =bdrv_getlength (bs->file->bs); -if (real_size <0 ) { -error_setg_errno (errp, -real_size,"Could not get image size" ); -return real_size; - } - opts =qemu_opts_create (&raw_runtime_opts,NULL ,0 , &error_abort);qemu_opts_absorb_qdict (opts, options, &local_err);if (local_err) {
@@ -93,64 +86,84 @@ static int raw_read_options(QDict *options, BlockDriverState *bs, goto end; } - s->offset =qemu_opt_get_size (opts,"offset" ,0 ); -if (s->offset > real_size) { -error_setg (errp,"Offset (%" PRIu64") cannot be greater than " -"size of the containing file (%" PRId64")" , - s->offset, real_size); - ret = -EINVAL ; - goto end; - } + *offset =qemu_opt_get_size (opts,"offset" ,0 ); + *has_size =qemu_opt_find (opts,"size" ); + *size =qemu_opt_get_size (opts,"size" ,0 ); -if (qemu_opt_find (opts,"size" ) !=NULL ) { - s->size =qemu_opt_get_size (opts,"size" ,0 ); - s->has_size = true; - }else { - s->has_size = false; - s->size = real_size - s->offset; + ret =0 ; +end: +qemu_opts_del (opts); +return ret; +} + +static int raw_apply_options (BlockDriverState *bs,BDRVRawState *s, +uint64_t offset,bool has_size,uint64_t size, +Error **errp) +{ +int64_t real_size =0 ; + + real_size =bdrv_getlength (bs->file->bs); +if (real_size <0 ) { +error_setg_errno (errp, -real_size,"Could not get image size" ); +return real_size; }/* Check size and offset */ -if ((real_size - s->offset) < s->size) { +if (offset > real_size) { +error_setg (errp,"Offset (%" PRIu64") cannot be greater than " +"size of the containing file (%" PRId64")" , + s->offset, real_size); +return -EINVAL ; + } + +if (has_size && (real_size - offset) < size) {error_setg (errp,"The sum of offset (%" PRIu64") and size " -"(%" PRIu64") has to be smaller or equal to the " -" actual size of the containing file (%" PRId64")" , - s->offset, s->size, real_size); - ret = -EINVAL ; - goto end; +"(%" PRIu64") has to be smaller or equal to the " +" actual size of the containing file (%" PRId64")" , + s->offset, s->size, real_size); +return -EINVAL ; }/* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding * up and leaking out of the specified area. */ -if (s->has_size && !QEMU_IS_ALIGNED (s->size,BDRV_SECTOR_SIZE )) { +if (has_size && !QEMU_IS_ALIGNED (size,BDRV_SECTOR_SIZE )) {error_setg (errp,"Specified size is not multiple of %llu" , -BDRV_SECTOR_SIZE ); - ret = -EINVAL ; - goto end; +BDRV_SECTOR_SIZE ); +return -EINVAL ; } - ret =0 ; - -end: + s->offset = offset; + s->has_size = has_size; + s->size = has_size ? size : real_size - offset; -qemu_opts_del (opts); - -return ret; +return 0 ; }static int raw_reopen_prepare (BDRVReopenState *reopen_state,BlockReopenQueue *queue,Error **errp) { +bool has_size; +uint64_t offset, size; +int ret; +assert (reopen_state !=NULL );assert (reopen_state->bs !=NULL ); reopen_state->opaque =g_new0 (BDRVRawState,1 ); -return raw_read_options ( - reopen_state->options, - reopen_state->bs, - reopen_state->opaque, - errp); + ret =raw_read_options (reopen_state->options, &offset, &has_size, &size, + errp); +if (ret <0 ) { +return ret; + } + + ret =raw_apply_options (reopen_state->bs, reopen_state->opaque, + offset, has_size, size, errp); +if (ret <0 ) { +return ret; + } + +return 0 ; }static void raw_reopen_commit (BDRVReopenState *state)
@@ -426,8 +439,15 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) {BDRVRawState *s = bs->opaque; +bool has_size; +uint64_t offset, size;int ret; + ret =raw_read_options (options, &offset, &has_size, &size, errp); +if (ret <0 ) { +return ret; + } + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, errp);if (!bs->file) {
@@ -455,7 +475,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, bs->file->bs->filename); } - ret =raw_read_options (options, bs, s, errp); + ret =raw_apply_options (bs, s, offset, has_size, size, errp);if (ret <0 ) {return ret; }
Signature · 1 line
2.26.2
PATCH v4 21/34 block: Switch child_format users to child_of_bds
In reply to Max ReitzBoth users (quorum and blkverify) use child_format for not-really-filtered children, so the appropriate BdrvChildRole in both cases is DATA. (Note that this will cause bdrv_inherited_options() to force-allow format probing.)
--- block/blkverify.c | 4 ++-- block/quorum.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
block/blkverify.c +2 -2
@@ -134,8 +134,8 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,/* Open the test file */ s->test_file =bdrv_open_child (qemu_opt_get (opts,"x-image" ), options, -"test" , bs, &child_format,0 , false, - &local_err); +"test" , bs, &child_of_bds,BDRV_CHILD_DATA , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/quorum.c +4 -2
@@ -977,7 +977,8 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,assert (ret <32 ); s->children[i] =bdrv_open_child (NULL , options, indexstr, bs, - &child_format,0 , false, &local_err); + &child_of_bds,BDRV_CHILD_DATA , false, + &local_err);if (local_err) { ret = -EINVAL ; goto close_exit;
@@ -1053,7 +1054,8 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs,/* We can safely add the child now */ bdrv_ref (child_bs); - child =bdrv_attach_child (bs, child_bs, indexstr, &child_format,0 , errp); + child =bdrv_attach_child (bs, child_bs, indexstr, &child_of_bds, +BDRV_CHILD_DATA , errp);if (child ==NULL ) { s->next_child_index--; goto out;
Signature · 1 line
2.26.2
PATCH v4 22/34 block: Drop child_format
In reply to Max Reitz--- include/block/block_int.h | 1 - block.c | 29 ----------------------------- 2 files changed, 30 deletions(-)
include/block/block_int.h +0 -1
@@ -742,7 +742,6 @@ struct BdrvChildClass {extern const BdrvChildClass child_of_bds;extern const BdrvChildClass child_file; -extern const BdrvChildClass child_format;extern const BdrvChildClass child_backing;struct BdrvChild {
block.c +0 -29
@@ -1172,35 +1172,6 @@ const BdrvChildClass child_file = { .set_aio_ctx = bdrv_child_cb_set_aio_ctx, }; -/* -* Returns the options and flags that bs->file should get if the use of formats -* (and not only protocols) is permitted for it, based on the given options and -* flags for the parent BDS -*/ -static void bdrv_inherited_fmt_options (BdrvChildRole role, -bool parent_is_format, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) -{ -bdrv_inherited_options (BDRV_CHILD_DATA , false, - child_flags, child_options, - parent_flags, parent_options); -} - -const BdrvChildClass child_format = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_inherited_fmt_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_poll = bdrv_child_cb_drained_poll, - .drained_end = bdrv_child_cb_drained_end, - .attach = bdrv_child_cb_attach, - .detach = bdrv_child_cb_detach, - .inactivate = bdrv_child_cb_inactivate, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; -static void bdrv_backing_attach (BdrvChild *c) {BlockDriverState *parent = c->opaque;
Signature · 1 line
2.26.2
PATCH v4 23/34 block: Make backing files child_of_bds children
In reply to Max ReitzMake all parents of backing files pass the appropriate BdrvChildRole. By doing so, we can switch their BdrvChildClass over to the generic child_of_bds, which will do the right thing when given a correct BdrvChildRole.
--- block.c | 26 ++++++++++++++++++++------ block/backup-top.c | 2 +- block/vvfat.c | 3 ++- tests/test-bdrv-drain.c | 13 +++++++------ 4 files changed, 30 insertions(+), 14 deletions(-)
block.c +20 -6
@@ -2941,6 +2941,20 @@ static bool bdrv_inherits_from_recursive(BlockDriverState *child,return child !=NULL ; } +/* +* Return the BdrvChildRole for @bs's backing child. bs->backing is +* mostly used for COW backing children (role = COW), but also for +* filtered children (role = FILTERED | PRIMARY). +*/ +static BdrvChildRole bdrv_backing_role (BlockDriverState *bs) +{ +if (bs->drv && bs->drv->is_filter) { +return BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY ; + }else { +return BDRV_CHILD_COW ; + } +} +/* * Sets the backing file link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref().
@@ -2968,8 +2982,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, goto out; } - bs->backing =bdrv_attach_child (bs, backing_hd,"backing" , &child_backing, -0 , errp); + bs->backing =bdrv_attach_child (bs, backing_hd,"backing" , &child_of_bds, +bdrv_backing_role (bs), errp);/* If backing_hd was already part of bs's backing chain, and * inherits_from pointed recursively to bs then let's update it to * point directly to bs (else it will become NULL). */
@@ -3066,7 +3080,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, } backing_hd =bdrv_open_inherit (backing_filename, reference, options,0 , bs, - &child_backing,0 , errp); + &child_of_bds,bdrv_backing_role (bs), errp);if (!backing_hd) { bs->open_flags |=BDRV_O_NO_BACKING ;error_prepend (errp,"Could not open backing file: " );
@@ -3895,8 +3909,8 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)if (state->replace_backing_bs && state->new_backing_bs) {uint64_t nperm, nshared;bdrv_child_perm (state->bs, state->new_backing_bs, -NULL , &child_backing,0 , bs_queue, - state->perm, state->shared_perm, +NULL , &child_of_bds,bdrv_backing_role (state->bs), + bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret =bdrv_check_update_perm (state->new_backing_bs,NULL , nperm, nshared,NULL ,NULL , errp);
@@ -6852,7 +6866,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) drv->bdrv_gather_child_options (bs, opts, backing_overridden); }else { QLIST_FOREACH(child, &bs->children, next) { -if (child->klass == &child_backing && !backing_overridden) { +if (child == bs->backing && !backing_overridden) {/* We can skip the backing BDS if it has not been overridden */ continue ; }
block/backup-top.c +1 -1
@@ -143,7 +143,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -if (child_class == &child_file) { +if (!(role &BDRV_CHILD_FILTERED )) {/* * Target child *
block/vvfat.c +2 -1
@@ -3219,7 +3219,8 @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, {BDRVVVFATState *s = bs->opaque; -assert (c == s->qcow || child_class == &child_backing); +assert (c == s->qcow || + (child_class == &child_of_bds && (role &BDRV_CHILD_COW )));if (c == s->qcow) {/* This is a private node, nobody should try to attach to it */
tests/test-bdrv-drain.c +7 -6
@@ -96,7 +96,7 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c,* bdrv_format_default_perms() accepts only these two, so disguise * detach_by_driver_cb_parent as one of them. */ -if (child_class != &child_file && child_class != &child_backing) { +if (child_class != &child_file && child_class != &child_of_bds) { child_class = &child_file; }
@@ -1399,8 +1399,8 @@ static void test_detach_indirect(bool by_parent_cb)bdrv_ref (a); child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_file,0 , &error_abort); - child_a =bdrv_attach_child (parent_b, a,"PB-A" , &child_backing,0 , - &error_abort); + child_a =bdrv_attach_child (parent_b, a,"PB-A" , &child_of_bds, +BDRV_CHILD_COW , &error_abort);bdrv_ref (a); bdrv_attach_child(parent_a, a, "PA-A",
@@ -1793,7 +1793,7 @@ static void test_drop_intermediate_poll(void)int i;int ret; - chain_child_class = child_backing; + chain_child_class = child_of_bds; chain_child_class.update_filename = drop_intermediate_poll_update_filename;for (i =0 ; i <3 ; i++) {
@@ -1816,7 +1816,7 @@ static void test_drop_intermediate_poll(void)/* Takes the reference to chain[i - 1] */ chain[i]->backing =bdrv_attach_child (chain[i], chain[i -1 ],"chain" , &chain_child_class, -0 , &error_abort); +BDRV_CHILD_COW , &error_abort); } }
@@ -2034,7 +2034,8 @@ static void do_test_replace_child_mid_drain(int old_drain_count,bdrv_ref (old_child_bs); parent_bs->backing =bdrv_attach_child (parent_bs, old_child_bs,"child" , - &child_backing,0 , &error_abort); + &child_of_bds,BDRV_CHILD_COW , + &error_abort);for (i =0 ; i < old_drain_count; i++) {bdrv_drained_begin (old_child_bs);
Signature · 1 line
2.26.2
Re: [PATCH v4 23/34] block: Make backing files child_of_bds children
Quoted 5 lines · Max Reitz
Make all parents of backing files pass the appropriate BdrvChildRole. By doing so, we can switch their BdrvChildClass over to the generic
child_of_bds, which will do the right thing when given a correct BdrvChildRole.
Quoted 8 lines
Signed-off-by Max Reitz <[email protected]>--- block.c | 26 ++++++++++++++++++++------ block/backup-top.c | 2 +- block/vvfat.c | 3 ++- tests/test-bdrv-drain.c | 13 +++++++------ 4 files changed, 30 insertions(+), 14 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 24/34 block: Drop child_backing
In reply to Max Reitz--- include/block/block_int.h | 1 - block.c | 60 ++------------------------------------- 2 files changed, 3 insertions(+), 58 deletions(-)
include/block/block_int.h +0 -1
@@ -742,7 +742,6 @@ struct BdrvChildClass {extern const BdrvChildClass child_of_bds;extern const BdrvChildClass child_file; -extern const BdrvChildClass child_backing;struct BdrvChild {BlockDriverState *bs;
block.c +3 -57
98 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v4 24/34] block: Drop child_backing
Quoted 6 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- include/block/block_int.h | 1 - block.c | 60 ++------------------------------------- 2 files changed, 3 insertions(+), 58 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 25/34 block: Make format drivers use child_of_bds
In reply to Max ReitzCommonly, they need to pass the BDRV_CHILD_IMAGE set as the BdrvChildRole; but there are exceptions for drivers with external data files (qcow2 and vmdk).
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/crypto.c | 4 ++-- block/dmg.c | 4 ++-- block/parallels.c | 4 ++-- block/qcow.c | 4 ++-- block/qcow2.c | 19 +++++++++++++------ block/qed.c | 4 ++-- block/vdi.c | 4 ++-- block/vhdx.c | 4 ++-- block/vmdk.c | 20 +++++++++++++++++--- block/vpc.c | 4 ++-- 12 files changed, 50 insertions(+), 29 deletions(-)
block/bochs.c +2 -2
@@ -110,8 +110,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/cloop.c +2 -2
@@ -71,8 +71,8 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/crypto.c +2 -2
@@ -218,8 +218,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,unsigned int cflags =0 ;QDict *cryptoopts =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/dmg.c +2 -2
@@ -439,8 +439,8 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/parallels.c +2 -2
@@ -739,8 +739,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,Error *local_err =NULL ;char *buf; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/qcow.c +2 -2
@@ -130,8 +130,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,qdict_extract_subqdict (options, &encryptopts,"encrypt." ); encryptfmt =qdict_get_try_str (encryptopts,"format" ); - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) { ret = -EINVAL ; goto fail;
block/qcow2.c +13 -6
@@ -1590,8 +1590,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, }/* Open external data file */ - s->data_file =bdrv_open_child (NULL , options,"data-file" , bs, &child_file, -0 , true, &local_err); + s->data_file =bdrv_open_child (NULL , options,"data-file" , bs, + &child_of_bds,BDRV_CHILD_DATA , + true, &local_err);if (local_err) {error_propagate (errp, local_err); ret = -EINVAL ;
@@ -1601,8 +1602,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,if (s->incompatible_features &QCOW2_INCOMPAT_DATA_FILE ) {if (!s->data_file && s->image_data_file) { s->data_file =bdrv_open_child (s->image_data_file, options, -"data-file" , bs, &child_file,0 , - false, errp); +"data-file" , bs, &child_of_bds, +BDRV_CHILD_DATA , false, errp);if (!s->data_file) { ret = -EINVAL ; goto fail;
@@ -1613,6 +1614,12 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, ret = -EINVAL ; goto fail; } + +/* No data here */ + bs->file->role &= ~BDRV_CHILD_DATA ; + +/* Must succeed because we have given up permissions if anything */ +bdrv_child_refresh_perms (bs, bs->file, &error_abort); }else {if (s->data_file) { error_setg(errp, "'data-file' can only be set for images with an "
@@ -1863,8 +1870,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/qed.c +2 -2
@@ -547,8 +547,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, .ret = -EINPROGRESS }; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/vdi.c +2 -2
@@ -378,8 +378,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,Error *local_err =NULL ;QemuUUID uuid_link, uuid_parent; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/vhdx.c +2 -2
@@ -996,8 +996,8 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,uint64_t signature;Error *local_err =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
block/vmdk.c +17 -3
@@ -1089,6 +1089,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,char *desc_file_dir =NULL ;char *extent_path;BdrvChild *extent_file; +BdrvChildRole extent_role;BDRVVmdkState *s = bs->opaque;VmdkExtent *extent;char extent_opt_prefix[32 ];
@@ -1151,8 +1152,15 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, ret =snprintf (extent_opt_prefix,32 ,"extents.%d" , s->num_extents);assert (ret <32 ); + extent_role =BDRV_CHILD_DATA ; +if (strcmp (type,"FLAT" ) !=0 &&strcmp (type,"VMFS" ) !=0 ) { +/* non-flat extents have metadata */ + extent_role |=BDRV_CHILD_METADATA ; + } + extent_file =bdrv_open_child (extent_path, options, extent_opt_prefix, - bs, &child_file,0 , false, &local_err); + bs, &child_of_bds, extent_role, false, + &local_err);g_free (extent_path);if (local_err) {error_propagate (errp, local_err);
@@ -1257,8 +1265,8 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,uint32_t magic;Error *local_err =NULL ; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
@@ -1277,6 +1285,12 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags, s->desc_offset =0x200 ;break ;default : +/* No data in the descriptor file */ + bs->file->role &= ~BDRV_CHILD_DATA ; + +/* Must succeed because we have given up permissions if anything */ +bdrv_child_refresh_perms (bs, bs->file, &error_abort); + ret =vmdk_open_desc_file (bs, flags, buf, options, errp);break ; }
block/vpc.c +2 -2
@@ -228,8 +228,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,int ret;int64_t bs_size; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_IMAGE , false, errp);if (!bs->file) {return -EINVAL ; }
Signature · 1 line
2.26.2
PATCH v4 26/34 block: Make filter drivers use child_of_bds
In reply to Max ReitzNote that some filters have secondary children, namely blkverify (the image to be verified) and blklogwrites (the log). This patch does not touch those children.
Note that for blkverify, the filtered child should not be format-probed. While there is nothing enforcing this here, in practice, it will not be:
blkverify implements .bdrv_file_open. The block layer ensures (and in fact, asserts) that BDRV_O_PROTOCOL is set for every BDS whose driver implements .bdrv_file_open. This flag will then be bequeathed to blkverify's children, and they will thus (by default) not be probed either.
("By default" refers to the fact that blkverify's other child (the non-filtered one) will have BDRV_O_PROTOCOL force-unset, because that is what happens for all non-filtered children of non-format drivers.)
--- block/blkdebug.c | 4 +++- block/blklogwrites.c | 3 ++- block/blkreplay.c | 5 +++-- block/blkverify.c | 4 +++- block/copy-on-read.c | 5 +++-- block/filter-compress.c | 5 +++-- block/replication.c | 3 ++- block/throttle.c | 5 +++-- 8 files changed, 22 insertions(+), 12 deletions(-)
block/blkdebug.c +3 -1
@@ -497,7 +497,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,/* Open the image file */ bs->file =bdrv_open_child (qemu_opt_get (opts,"x-image" ), options,"image" , - bs, &child_file,0 , false, &local_err); + bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/blklogwrites.c +2 -1
@@ -157,7 +157,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, }/* Open the file */ - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , false, &local_err);if (local_err) { ret = -EINVAL ;
block/blkreplay.c +3 -2
@@ -27,8 +27,9 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,int ret;/* Open the image file */ - bs->file =bdrv_open_child (NULL , options,"image" , - bs, &child_file,0 , false, &local_err); + bs->file =bdrv_open_child (NULL , options,"image" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/blkverify.c +3 -1
@@ -125,7 +125,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,/* Open the raw file */ bs->file =bdrv_open_child (qemu_opt_get (opts,"x-raw" ), options,"raw" , - bs, &child_file,0 , false, &local_err); + bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/copy-on-read.c +3 -2
@@ -28,8 +28,9 @@static int cor_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, - errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, errp);if (!bs->file) {return -EINVAL ; }
block/filter-compress.c +3 -2
@@ -30,8 +30,9 @@static int compress_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , false, - errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, errp);if (!bs->file) {return -EINVAL ; }
block/replication.c +2 -1
@@ -90,7 +90,8 @@ static int replication_open(BlockDriverState *bs, QDict *options,const char *mode;const char *top_id; - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , false, errp);if (!bs->file) {return -EINVAL ;
block/throttle.c +3 -2
@@ -81,8 +81,9 @@ static int throttle_open(BlockDriverState *bs, QDict *options,char *group;int ret; - bs->file =bdrv_open_child (NULL , options,"file" , bs, - &child_file,0 , false, errp); + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + false, errp);if (!bs->file) {return -EINVAL ; }
Signature · 1 line
2.26.2
Re: [PATCH v4 26/34] block: Make filter drivers use child_of_bds
Quoted 12 lines · Max Reitz
Note that some filters have secondary children, namely blkverify (the image to be verified) and blklogwrites (the log). This patch does not touch those children.
Note that for blkverify, the filtered child should not be format-probed. While there is nothing enforcing this here, in practice, it will not be:
blkverify implements .bdrv_file_open. The block layer ensures (and in fact, asserts) thatBDRV_O_PROTOCOLis set for every BDS whose driver implements .bdrv_file_open. This flag will then be bequeathed to blkverify's children, and they will thus (by default) not be probed either.
Quoted 6 lines
("By default" refers to the fact that blkverify's other child (the non-filtered one) will have
BDRV_O_PROTOCOLforce-unset, because that is what happens for all non-filtered children of non-format drivers.)Signed-off-by Max Reitz <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 27/34 block: Use child_of_bds in remaining places
In reply to Max ReitzReplace child_file by child_of_bds in all remaining places (excluding tests).
--- block.c | 3 ++- block/backup-top.c | 4 ++-- block/blklogwrites.c | 4 ++-- block/raw-format.c | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-)
block.c +2 -1
@@ -3406,7 +3406,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,BlockDriverState *file_bs; file_bs =bdrv_open_child_bs (filename, options,"file" , bs, - &child_file,0 , true, &local_err); + &child_of_bds,BDRV_CHILD_IMAGE , + true, &local_err);if (local_err) { goto fail; }
block/backup-top.c +2 -2
@@ -215,8 +215,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, source->supported_zero_flags);bdrv_ref (target); - state->target =bdrv_attach_child (top, target,"target" , &child_file,0 , - errp); + state->target =bdrv_attach_child (top, target,"target" , &child_of_bds, +BDRV_CHILD_DATA , errp);if (!state->target) {bdrv_unref (target);bdrv_unref (top);
block/blklogwrites.c +2 -2
@@ -167,8 +167,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, }/* Open the log file */ - s->log_file =bdrv_open_child (NULL , options,"log" , bs, &child_file,0 , - false, &local_err); + s->log_file =bdrv_open_child (NULL , options,"log" , bs, &child_of_bds, +BDRV_CHILD_METADATA , false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/raw-format.c +13 -2
@@ -441,6 +441,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,BDRVRawState *s = bs->opaque;bool has_size;uint64_t offset, size; +BdrvChildRole file_role;int ret; ret =raw_read_options (options, &offset, &has_size, &size, errp);
@@ -448,8 +449,18 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file,0 , - false, errp); +/* +* Without offset and a size limit, this driver behaves very much +* like a filter. With any such limit, it does not. +*/ +if (offset || has_size) { + file_role =BDRV_CHILD_DATA |BDRV_CHILD_PRIMARY ; + }else { + file_role =BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY ; + } + + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, + file_role, false, errp);if (!bs->file) {return -EINVAL ; }
Signature · 1 line
2.26.2
Re: [PATCH v4 27/34] block: Use child_of_bds in remaining places
Quoted 17 lines · Max Reitz
Replace
child_filebychild_of_bdsin all remaining places (excluding tests).Signed-off-by Max Reitz <[email protected]>--- block.c | 3 ++- block/backup-top.c | 4 ++-- block/blklogwrites.c | 4 ++-- block/raw-format.c | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-)block/raw-format.c +0
-1@@ -448,8 +449,18 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,return ret; } - bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, 0,
block/raw-format.c static int raw_open(BlockDriverState *bs, QDict *options, int flags, · line 460
Quoted 10 lines
block/raw-format.c +9
-1- false, errp); +/* +* Without offset and a size limit, this driver behaves very much +* like a filter. With any such limit, it does not. +*/ +if (offset || has_size) { + file_role =BDRV_CHILD_DATA |BDRV_CHILD_PRIMARY ; + }else { + file_role =BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY ; + }
I wonder if we'll hit subtle bugs where one but not the other use of raw breaks because of the difference in roles. I know we have _some_ iotest coverage of raw with offsets, but wonder if we might need more (or a way to add it on top of existing images, similar to how we can easily toggle qcow2 options like refcount size for interesting non-default test runs).
block/raw-format.c static int raw_open(BlockDriverState *bs, QDict *options, int flags, · line 466
Quoted 7 lines
block/raw-format.c +3
-0+ + bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_of_bds, + file_role, false, errp);if (!bs->file) {return -EINVAL ; }
At any rate, if we have corner-case bugs, I don't think this is making them worse.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 28/34 tests: Use child_of_bds instead of child_file
In reply to Max Reitz--- tests/test-bdrv-drain.c | 29 +++++++++++++++++------------ tests/test-bdrv-graph-mod.c | 6 ++++-- 2 files changed, 21 insertions(+), 14 deletions(-)
tests/test-bdrv-drain.c +17 -12
@@ -97,7 +97,7 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c,* detach_by_driver_cb_parent as one of them. */ if (child_class != &child_file && child_class != &child_of_bds) { - child_class = &child_file; + child_class = &child_of_bds; } bdrv_format_default_perms(bs, c, child_class, role, reopen_queue,
@@ -1203,7 +1203,8 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_attach_child (bs, null_bs,"null-child" , &child_file,0 , &error_abort); +bdrv_attach_child (bs, null_bs,"null-child" , &child_of_bds, +BDRV_CHILD_DATA , &error_abort);/* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */
@@ -1211,14 +1212,17 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete, &error_abort); child_bs->total_sectors =65536 >>BDRV_SECTOR_BITS ;/* Takes our reference to child_bs */ - tts->wait_child =bdrv_attach_child (bs, child_bs,"wait-child" , &child_file, -0 , &error_abort); + tts->wait_child =bdrv_attach_child (bs, child_bs,"wait-child" , + &child_of_bds, +BDRV_CHILD_DATA |BDRV_CHILD_PRIMARY , + &error_abort);/* This child is just there to be deleted * (for detach_instead_of_delete == true) */ null_bs =bdrv_open ("null-co://" ,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , &error_abort); -bdrv_attach_child (bs, null_bs,"null-child" , &child_file,0 , &error_abort); +bdrv_attach_child (bs, null_bs,"null-child" , &child_of_bds,BDRV_CHILD_DATA , + &error_abort); blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL ,BLK_PERM_ALL );blk_insert_bs (blk, bs, &error_abort);
@@ -1315,7 +1319,8 @@ static void detach_indirect_bh(void *opaque)bdrv_ref (data->c); data->child_c =bdrv_attach_child (data->parent_b, data->c,"PB-C" , - &child_file,0 , &error_abort); + &child_of_bds,BDRV_CHILD_DATA , + &error_abort); }static void detach_by_parent_aio_cb (void *opaque,int ret)
@@ -1332,7 +1337,7 @@ static void detach_by_driver_cb_drained_begin(BdrvChild *child) {aio_bh_schedule_oneshot (qemu_get_current_aio_context (), detach_indirect_bh, &detach_by_parent_data); - child_file.drained_begin (child); + child_of_bds.drained_begin (child); }static BdrvChildClass detach_by_driver_cb_class;
@@ -1367,7 +1372,7 @@ static void test_detach_indirect(bool by_parent_cb)QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov,NULL ,0 );if (!by_parent_cb) { - detach_by_driver_cb_class = child_file; + detach_by_driver_cb_class = child_of_bds; detach_by_driver_cb_class.drained_begin = detach_by_driver_cb_drained_begin; }
@@ -1397,15 +1402,15 @@ static void test_detach_indirect(bool by_parent_cb)/* Set child relationships */ bdrv_ref (b);bdrv_ref (a); - child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_file,0 , - &error_abort); + child_b =bdrv_attach_child (parent_b, b,"PB-B" , &child_of_bds, +BDRV_CHILD_DATA , &error_abort); child_a =bdrv_attach_child (parent_b, a,"PB-A" , &child_of_bds,BDRV_CHILD_COW , &error_abort);bdrv_ref (a);bdrv_attach_child (parent_a, a,"PA-A" , - by_parent_cb ? &child_file : &detach_by_driver_cb_class, -0 , &error_abort); + by_parent_cb ? &child_of_bds : &detach_by_driver_cb_class, +BDRV_CHILD_DATA , &error_abort); g_assert_cmpint(parent_a->refcnt, ==, 1); g_assert_cmpint(parent_b->refcnt, ==, 1);
tests/test-bdrv-graph-mod.c +4 -2
@@ -112,7 +112,8 @@ static void test_update_perm_tree(void)blk_insert_bs (root, bs, &error_abort); -bdrv_attach_child (filter, bs,"child" , &child_file,0 , &error_abort); +bdrv_attach_child (filter, bs,"child" , &child_of_bds, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , &error_abort);bdrv_append (filter, bs, &local_err);
@@ -178,7 +179,8 @@ static void test_should_update_child(void)bdrv_set_backing_hd (target, bs, &error_abort);g_assert (target->backing->bs == bs); -bdrv_attach_child (filter, target,"target" , &child_file,0 , &error_abort); +bdrv_attach_child (filter, target,"target" , &child_of_bds, +BDRV_CHILD_DATA , &error_abort);bdrv_append (filter, bs, &error_abort);g_assert (target->backing->bs == bs);
Signature · 1 line
2.26.2
PATCH v4 29/34 block: Use bdrv_default_perms()
In reply to Max Reitzbdrv_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.)
--- block/backup-top.c | 4 ++-- block/blkdebug.c | 4 ++-- block/blklogwrites.c | 9 ++------- block/blkreplay.c | 2 +- block/blkverify.c | 2 +- block/bochs.c | 2 +- block/cloop.c | 2 +- block/crypto.c | 2 +- block/dmg.c | 2 +- block/filter-compress.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- block/raw-format.c | 2 +- block/throttle.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 2 +- block/vpc.c | 2 +- tests/test-bdrv-drain.c | 10 +++++----- tests/test-bdrv-graph-mod.c | 2 +- tests/test-block-iothread.c | 17 ++++++++++++++--- 23 files changed, 43 insertions(+), 37 deletions(-)
block/backup-top.c +2 -2
@@ -156,8 +156,8 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm =BLK_PERM_WRITE ; }else {/* Source child */ -bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); +bdrv_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared);if (perm &BLK_PERM_WRITE ) { *nperm = *nperm |BLK_PERM_CONSISTENT_READ ;
block/blkdebug.c +2 -2
@@ -1003,8 +1003,8 @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, {BDRVBlkdebugState *s = bs->opaque; -bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); +bdrv_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); *nperm |= s->take_child_perms; *nshared &= ~s->unshare_child_perms;
block/blklogwrites.c +2 -7
@@ -295,13 +295,8 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -if (!strcmp (c->name,"log" )) { -bdrv_format_default_perms (bs, c, child_class, role, ro_q, perm, shrd, - nperm, nshrd); - }else { -bdrv_filter_default_perms (bs, c, child_class, role, ro_q, perm, shrd, - nperm, nshrd); - } +bdrv_default_perms (bs, c, child_class, role, ro_q, perm, shrd, + nperm, nshrd); }static void blk_log_writes_refresh_limits (BlockDriverState *bs,Error **errp)
block/blkreplay.c +1 -1
@@ -139,7 +139,7 @@ static BlockDriver bdrv_blkreplay = { .is_filter = true, .bdrv_open = blkreplay_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = blkreplay_getlength, .bdrv_co_preadv = blkreplay_co_preadv,
block/blkverify.c +1 -1
@@ -319,7 +319,7 @@ static BlockDriver bdrv_blkverify = { .bdrv_parse_filename = blkverify_parse_filename, .bdrv_file_open = blkverify_open, .bdrv_close = blkverify_close, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = blkverify_getlength, .bdrv_refresh_filename = blkverify_refresh_filename, .bdrv_dirname = blkverify_dirname,
block/bochs.c +1 -1
@@ -297,7 +297,7 @@ static BlockDriver bdrv_bochs = { .instance_size = sizeof(BDRVBochsState), .bdrv_probe = bochs_probe, .bdrv_open = bochs_open, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_refresh_limits = bochs_refresh_limits, .bdrv_co_preadv = bochs_co_preadv, .bdrv_close = bochs_close,
block/cloop.c +1 -1
@@ -293,7 +293,7 @@ static BlockDriver bdrv_cloop = { .instance_size = sizeof(BDRVCloopState), .bdrv_probe = cloop_probe, .bdrv_open = cloop_open, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_refresh_limits = cloop_refresh_limits, .bdrv_co_preadv = cloop_co_preadv, .bdrv_close = cloop_close,
block/crypto.c +1 -1
@@ -756,7 +756,7 @@ static BlockDriver bdrv_crypto_luks = { .bdrv_close = block_crypto_close,/* This driver doesn't modify LUKS metadata except when creating image. * Allow share-rw=on as a special case. */ - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = block_crypto_co_create_luks, .bdrv_co_create_opts = block_crypto_co_create_opts_luks, .bdrv_co_truncate = block_crypto_co_truncate,
block/dmg.c +1 -1
@@ -750,7 +750,7 @@ static BlockDriver bdrv_dmg = { .bdrv_probe = dmg_probe, .bdrv_open = dmg_open, .bdrv_refresh_limits = dmg_refresh_limits, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_preadv = dmg_co_preadv, .bdrv_close = dmg_close, .is_format = true,
block/filter-compress.c +1 -1
@@ -133,7 +133,7 @@ static BlockDriver bdrv_compress = { .format_name = "compress", .bdrv_open = compress_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = compress_getlength,
block/parallels.c +1 -1
@@ -912,7 +912,7 @@ static BlockDriver bdrv_parallels = { .bdrv_probe = parallels_probe, .bdrv_open = parallels_open, .bdrv_close = parallels_close, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_block_status = parallels_co_block_status, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_flush_to_os = parallels_co_flush_to_os,
block/qcow.c +1 -1
@@ -1180,7 +1180,7 @@ static BlockDriver bdrv_qcow = { .bdrv_probe = qcow_probe, .bdrv_open = qcow_open, .bdrv_close = qcow_close, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_reopen_prepare = qcow_reopen_prepare, .bdrv_co_create = qcow_co_create, .bdrv_co_create_opts = qcow_co_create_opts,
block/qcow2.c +1 -1
@@ -5744,7 +5744,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_reopen_commit_post = qcow2_reopen_commit_post, .bdrv_reopen_abort = qcow2_reopen_abort, .bdrv_join_options = qcow2_join_options, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create_opts = qcow2_co_create_opts, .bdrv_co_create = qcow2_co_create, .bdrv_has_zero_init = qcow2_has_zero_init,
block/qed.c +1 -1
@@ -1672,7 +1672,7 @@ static BlockDriver bdrv_qed = { .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = bdrv_qed_co_create, .bdrv_co_create_opts = bdrv_qed_co_create_opts, .bdrv_has_zero_init = bdrv_has_zero_init_1,
block/raw-format.c +1 -1
@@ -586,7 +586,7 @@ BlockDriver bdrv_raw = { .bdrv_reopen_commit = &raw_reopen_commit, .bdrv_reopen_abort = &raw_reopen_abort, .bdrv_open = &raw_open, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create_opts = &raw_co_create_opts, .bdrv_co_preadv = &raw_co_preadv, .bdrv_co_pwritev = &raw_co_pwritev,
block/throttle.c +1 -1
@@ -237,7 +237,7 @@ static BlockDriver bdrv_throttle = { .bdrv_close = throttle_close, .bdrv_co_flush = throttle_co_flush, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_getlength = throttle_getlength,
block/vdi.c +1 -1
@@ -1039,7 +1039,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = vdi_co_create, .bdrv_co_create_opts = vdi_co_create_opts, .bdrv_has_zero_init = vdi_has_zero_init,
block/vhdx.c +1 -1
@@ -2245,7 +2245,7 @@ static BlockDriver bdrv_vhdx = { .bdrv_open = vhdx_open, .bdrv_close = vhdx_close, .bdrv_reopen_prepare = vhdx_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, .bdrv_co_create = vhdx_co_create,
block/vmdk.c +1 -1
@@ -3067,7 +3067,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_open = vmdk_open, .bdrv_co_check = vmdk_co_check, .bdrv_reopen_prepare = vmdk_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_preadv = vmdk_co_preadv, .bdrv_co_pwritev = vmdk_co_pwritev, .bdrv_co_pwritev_compressed = vmdk_co_pwritev_compressed,
block/vpc.c +1 -1
@@ -1240,7 +1240,7 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, .bdrv_co_create = vpc_co_create, .bdrv_co_create_opts = vpc_co_create_opts,
tests/test-bdrv-drain.c +5 -5
@@ -93,15 +93,15 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) {/* -* bdrv_format_default_perms() accepts only these two, so disguise +* bdrv_default_perms() accepts only these two, so disguise * detach_by_driver_cb_parent as one of them. */ if (child_class != &child_file && child_class != &child_of_bds) { child_class = &child_of_bds; } -bdrv_format_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); +bdrv_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } static int bdrv_test_change_backing_file(BlockDriverState *bs,
@@ -1137,7 +1137,7 @@ static BlockDriver bdrv_test_top_driver = { .bdrv_close = bdrv_test_top_close, .bdrv_co_preadv = bdrv_test_top_co_preadv, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; typedef struct TestCoDeleteByDrainData {
@@ -1966,7 +1966,7 @@ static BlockDriver bdrv_replace_test = { .bdrv_co_drain_begin = bdrv_replace_test_co_drain_begin, .bdrv_co_drain_end = bdrv_replace_test_co_drain_end, - .bdrv_child_perm = bdrv_format_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; static void coroutine_fn test_replace_child_mid_drain_read_co(void *opaque)
tests/test-bdrv-graph-mod.c +1 -1
@@ -26,7 +26,7 @@static BlockDriver bdrv_pass_through = { .format_name ="pass-through" , - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = bdrv_default_perms, }; static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c,
tests/test-block-iothread.c +14 -3
@@ -482,8 +482,13 @@ static void test_propagate_basic(void)BlockDriverState *bs_a, *bs_b, *bs_verify;QDict *options; -/* Create bs_a and its BlockBackend */ - blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL ,BLK_PERM_ALL ); +/* +* Create bs_a and its BlockBackend. We cannot take the RESIZE +* permission because blkverify will not share it on the test +* image. +*/ + blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL & ~BLK_PERM_RESIZE , +BLK_PERM_ALL ); bs_a =bdrv_new_open_driver (&bdrv_test,"bs_a" ,BDRV_O_RDWR , &error_abort);blk_insert_bs (blk, bs_a, &error_abort);
@@ -566,7 +571,13 @@ static void test_propagate_diamond(void)qdict_put_str (options,"raw" ,"bs_c" ); bs_verify =bdrv_open (NULL ,NULL , options,BDRV_O_RDWR , &error_abort); - blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL ,BLK_PERM_ALL ); +/* +* Do not take the RESIZE permission: This would require the same +* from bs_c and thus from bs_a; however, blkverify will not share +* it on bs_b, and thus it will not be available for bs_a. +*/ + blk =blk_new (qemu_get_aio_context (),BLK_PERM_ALL & ~BLK_PERM_RESIZE , +BLK_PERM_ALL );blk_insert_bs (blk, bs_verify, &error_abort);/* Switch the AioContext */
Signature · 1 line
2.26.2
PATCH v4 30/34 block: Make bdrv_filter_default_perms() static
In reply to Max Reitz--- include/block/block_int.h | 10 ---------- block.c | 17 +++++++++++------ 2 files changed, 11 insertions(+), 16 deletions(-)
include/block/block_int.h +0 -10
@@ -1262,16 +1262,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,*/ int bdrv_child_refresh_perms (BlockDriverState *bs,BdrvChild *c,Error **errp); -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by -* block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to -* all children */ -void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class, -BdrvChildRole child_role, -BlockReopenQueue *reopen_queue, -uint64_t perm,uint64_t shared, -uint64_t *nperm,uint64_t *nshared); -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by * (non-raw) image formats: Like above for bs->backing, but for bs->file it * requires WRITE | RESIZE for read-write images, always requires
block.c +11 -6
@@ -2382,12 +2382,17 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp)return bdrv_child_try_set_perm (c, perms, shared, errp); } -void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class, -BdrvChildRole role, -BlockReopenQueue *reopen_queue, -uint64_t perm,uint64_t shared, -uint64_t *nperm,uint64_t *nshared) +/* +* Default implementation for .bdrv_child_perm() for block filters: +* Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED, and RESIZE to the +* filtered child. +*/ +static void bdrv_filter_default_perms (BlockDriverState *bs,BdrvChild *c, +const BdrvChildClass *child_class, +BdrvChildRole role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) { *nperm = perm &DEFAULT_PERM_PASSTHROUGH ; *nshared = (shared &DEFAULT_PERM_PASSTHROUGH ) |DEFAULT_PERM_UNCHANGED ;
Signature · 1 line
2.26.2
PATCH v4 31/34 block: Drop bdrv_format_default_perms()
In reply to Max Reitz--- include/block/block_int.h | 11 ----------- block.c | 19 ------------------- 2 files changed, 30 deletions(-)
include/block/block_int.h +0 -11
@@ -1262,17 +1262,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,*/ int bdrv_child_refresh_perms (BlockDriverState *bs,BdrvChild *c,Error **errp); -/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by -* (non-raw) image formats: Like above for bs->backing, but for bs->file it -* requires WRITE | RESIZE for read-write images, always requires -* CONSISTENT_READ and doesn't share WRITE. */ -void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class, -BdrvChildRole child_role, -BlockReopenQueue *reopen_queue, -uint64_t perm,uint64_t shared, -uint64_t *nperm,uint64_t *nshared); -bool bdrv_recurse_can_replace (BlockDriverState *bs,BlockDriverState *to_replace);
block.c +0 -19
@@ -2517,25 +2517,6 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } -void bdrv_format_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class, -BdrvChildRole role, -BlockReopenQueue *reopen_queue, -uint64_t perm,uint64_t shared, -uint64_t *nperm,uint64_t *nshared) -{ -if (child_class == &child_of_bds) { -bdrv_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); -return ; - } - -assert (child_class == &child_file); - -bdrv_default_perms_for_storage (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); -} - void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue,
Signature · 1 line
2.26.2
PATCH v4 32/34 block: Drop child_file
In reply to Max Reitz--- include/block/block_int.h | 1 - block.c | 39 ++------------------------------------- tests/test-bdrv-drain.c | 8 +++----- 3 files changed, 5 insertions(+), 43 deletions(-)
include/block/block_int.h +0 -1
@@ -741,7 +741,6 @@ struct BdrvChildClass { };extern const BdrvChildClass child_of_bds; -extern const BdrvChildClass child_file;struct BdrvChild {BlockDriverState *bs;
block.c +2 -37
@@ -80,13 +80,6 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,BdrvChildRole child_role, Error **errp); -/* TODO: Remove when no longer needed */ -static void bdrv_inherited_options (BdrvChildRole role,bool parent_is_format, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options); -static void bdrv_child_cb_attach (BdrvChild *child); -static void bdrv_child_cb_detach (BdrvChild *child); -/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist;
@@ -1145,33 +1138,6 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options, *child_flags &= ~BDRV_O_NATIVE_AIO ; } -/* -* Returns the options and flags that bs->file should get if a protocol driver -* is expected, based on the given options and flags for the parent BDS -*/ -static void bdrv_protocol_options (BdrvChildRole role,bool parent_is_format, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) -{ -bdrv_inherited_options (BDRV_CHILD_IMAGE , true, - child_flags, child_options, - parent_flags, parent_options); -} - -const BdrvChildClass child_file = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .inherit_options = bdrv_protocol_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_poll = bdrv_child_cb_drained_poll, - .drained_end = bdrv_child_cb_drained_end, - .attach = bdrv_child_cb_attach, - .detach = bdrv_child_cb_detach, - .inactivate = bdrv_child_cb_inactivate, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; -static void bdrv_backing_attach (BdrvChild *c) {BlockDriverState *parent = c->opaque;
@@ -2444,9 +2410,8 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, {int flags; -assert (child_class == &child_file || - (child_class == &child_of_bds && - (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA )))); +assert (child_class == &child_of_bds && + (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA ))); flags =bdrv_reopen_get_flags (reopen_queue, bs);
tests/test-bdrv-drain.c +3 -5
@@ -93,12 +93,10 @@ static void bdrv_test_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t *nperm, uint64_t *nshared) {/* -* bdrv_default_perms() accepts only these two, so disguise -* detach_by_driver_cb_parent as one of them. +* bdrv_default_perms() accepts nothing else, so disguise +* detach_by_driver_cb_parent. */ -if (child_class != &child_file && child_class != &child_of_bds) { - child_class = &child_of_bds; - } + child_class = &child_of_bds;bdrv_default_perms (bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared);
Signature · 1 line
2.26.2
Re: [PATCH v4 32/34] block: Drop child_file
Quoted 7 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- include/block/block_int.h | 1 - block.c | 39 ++------------------------------------- tests/test-bdrv-drain.c | 8 +++----- 3 files changed, 5 insertions(+), 43 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 33/34 block: Pass BdrvChildRole in remaining cases
In reply to Max ReitzThese calls have no real use for the child role yet, but it will not harm to give one.
Notably, the bdrv_root_attach_child() call in blockjob.c is left unmodified because there is not much the generic BlockJob object wants from its children.
--- block/block-backend.c | 11 +++++++---- block/vvfat.c | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-)
block/block-backend.c +7 -4
@@ -424,8 +424,9 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,return NULL ; } - blk->root =bdrv_root_attach_child (bs,"root" , &child_root,0 , blk->ctx, - perm,BLK_PERM_ALL , blk, errp); + blk->root =bdrv_root_attach_child (bs,"root" , &child_root, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + blk->ctx, perm,BLK_PERM_ALL , blk, errp);if (!blk->root) {blk_unref (blk);return NULL ;
@@ -835,8 +836,10 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) {ThrottleGroupMember *tgm = &blk->public.throttle_group_member;bdrv_ref (bs); - blk->root =bdrv_root_attach_child (bs,"root" , &child_root,0 , blk->ctx, - blk->perm, blk->shared_perm, blk, errp); + blk->root =bdrv_root_attach_child (bs,"root" , &child_root, +BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , + blk->ctx, blk->perm, blk->shared_perm, + blk, errp);if (blk->root ==NULL ) {return -EPERM ; }
block/vvfat.c +3 -1
@@ -3184,7 +3184,9 @@ static int enable_write_target(BlockDriverState *bs, Error **errp) options =qdict_new ();qdict_put_str (options,"write-target.driver" ,"qcow" ); s->qcow =bdrv_open_child (s->qcow_filename, options,"write-target" , bs, - &child_vvfat_qcow,0 , false, errp); + &child_vvfat_qcow, +BDRV_CHILD_DATA |BDRV_CHILD_METADATA , + false, errp);qobject_unref (options);if (!s->qcow) { ret = -EINVAL ;
Signature · 1 line
2.26.2
Re: [PATCH v4 33/34] block: Pass BdrvChildRole in remaining cases
Quoted 7 lines · Max Reitz
These calls have no real use for the child role yet, but it will not harm to give one.
Notably, the
bdrv_root_attach_child()call inblockjob.cis left unmodified because there is not much the generic BlockJob object wants from its children.
Quoted 6 lines
Signed-off-by Max Reitz <[email protected]>--- block/block-backend.c | 11 +++++++---- block/vvfat.c | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH v4 34/34 block: Drop @child_class from bdrv_child_perm()
In reply to Max ReitzImplementations should decide the necessary permissions based on @role.
--- include/block/block_int.h | 4 +--- block.c | 39 +++++++++++++++---------------------- block/backup-top.c | 3 +-- block/blkdebug.c | 3 +-- block/blklogwrites.c | 3 +-- block/commit.c | 1 - block/copy-on-read.c | 1 - block/mirror.c | 1 - block/quorum.c | 1 - block/replication.c | 1 - block/vvfat.c | 4 +--- tests/test-bdrv-drain.c | 19 +----------------- tests/test-bdrv-graph-mod.c | 1 - 13 files changed, 22 insertions(+), 59 deletions(-)
include/block/block_int.h +1 -3
@@ -563,7 +563,6 @@ struct BlockDriver {* @reopen_queue. */ void (*bdrv_child_perm)(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared,
@@ -1270,8 +1269,7 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs,* child_of_bds child class and set an appropriate BdrvChildRole. */ void bdrv_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class,BdrvChildRole role, -BlockReopenQueue *reopen_queue, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared);
block.c +16 -23
@@ -1947,13 +1947,13 @@ bool bdrv_is_writable(BlockDriverState *bs) }static void bdrv_child_perm (BlockDriverState *bs,BlockDriverState *child_bs, -BdrvChild *c,const BdrvChildClass *child_class, -BdrvChildRole role,BlockReopenQueue *reopen_queue, +BdrvChild *c,BdrvChildRole role, +BlockReopenQueue *reopen_queue,uint64_t parent_perm,uint64_t parent_shared,uint64_t *nperm,uint64_t *nshared) {assert (bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm (bs, c, child_class, role, reopen_queue, + bs->drv->bdrv_child_perm (bs, c, role, reopen_queue, parent_perm, parent_shared, nperm, nshared);/* TODO Take force_share from reopen_queue */
@@ -2047,7 +2047,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,uint64_t cur_perm, cur_shared;bool child_tighten_restr; -bdrv_child_perm (bs, c->bs, c, c->klass, c->role, q, +bdrv_child_perm (bs, c->bs, c, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children,
@@ -2114,7 +2114,7 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Update all children */ QLIST_FOREACH(c, &bs->children, next) {uint64_t cur_perm, cur_shared; -bdrv_child_perm (bs, c->bs, c, c->klass, c->role,NULL , +bdrv_child_perm (bs, c->bs, c, c->role,NULL , cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared);bdrv_child_set_perm (c, cur_perm, cur_shared);
@@ -2342,7 +2342,7 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp)uint64_t perms, shared;bdrv_get_cumulative_perm (bs, &parent_perms, &parent_shared); -bdrv_child_perm (bs, c->bs, c, c->klass, c->role,NULL , +bdrv_child_perm (bs, c->bs, c, c->role,NULL , parent_perms, parent_shared, &perms, &shared);return bdrv_child_try_set_perm (c, perms, shared, errp);
@@ -2354,7 +2354,6 @@ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp)* filtered child. */ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -2365,13 +2364,12 @@ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, }static void bdrv_default_perms_for_cow (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class,BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) { -assert (child_class == &child_of_bds && (role &BDRV_CHILD_COW )); +assert (role &BDRV_CHILD_COW );/* * We want consistent read from backing files if the parent needs it.
@@ -2402,7 +2400,6 @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c, } static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -2410,8 +2407,7 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, {int flags; -assert (child_class == &child_of_bds && - (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA ))); +assert (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA )); flags =bdrv_reopen_get_flags (reopen_queue, bs);
@@ -2419,7 +2415,7 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,* Apart from the modifications below, the same permissions are * forwarded and left alone as for filters */ -bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, +bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, &perm, &shared);if (role &BDRV_CHILD_METADATA ) {
@@ -2483,24 +2479,21 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, }void bdrv_default_perms (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class,BdrvChildRole role, -BlockReopenQueue *reopen_queue, +BdrvChildRole role,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared) { -assert (child_class == &child_of_bds); -if (role &BDRV_CHILD_FILTERED ) {assert (!(role & (BDRV_CHILD_DATA |BDRV_CHILD_METADATA |BDRV_CHILD_COW ))); -bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, +bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else if (role &BDRV_CHILD_COW ) {assert (!(role & (BDRV_CHILD_DATA |BDRV_CHILD_METADATA ))); -bdrv_default_perms_for_cow (bs, c, child_class, role, reopen_queue, +bdrv_default_perms_for_cow (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else if (role & (BDRV_CHILD_METADATA |BDRV_CHILD_DATA )) { -bdrv_default_perms_for_storage (bs, c, child_class, role, reopen_queue, +bdrv_default_perms_for_storage (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else {g_assert_not_reached ();
@@ -2744,7 +2737,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,bdrv_get_cumulative_perm (parent_bs, &perm, &shared_perm);assert (parent_bs->drv); -bdrv_child_perm (parent_bs, child_bs,NULL , child_class, child_role,NULL , +bdrv_child_perm (parent_bs, child_bs,NULL , child_role,NULL , perm, shared_perm, &perm, &shared_perm); child = bdrv_root_attach_child(child_bs, child_name, child_class,
@@ -3807,7 +3800,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)if (state->replace_backing_bs && state->new_backing_bs) {uint64_t nperm, nshared;bdrv_child_perm (state->bs, state->new_backing_bs, -NULL , &child_of_bds,bdrv_backing_role (state->bs), +NULL ,bdrv_backing_role (state->bs), bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL,
@@ -3930,7 +3923,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, }else {uint64_t nperm, nshared; -bdrv_child_perm (parent->state.bs, bs, c, c->klass, c->role, q, +bdrv_child_perm (parent->state.bs, bs, c, c->role, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared);
block/backup-top.c +1 -2
@@ -122,7 +122,6 @@ static void backup_top_refresh_filename(BlockDriverState *bs) } static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -156,7 +155,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c, *nperm =BLK_PERM_WRITE ; }else {/* Source child */ -bdrv_default_perms (bs, c, child_class, role, reopen_queue, +bdrv_default_perms (bs, c, role, reopen_queue, perm, shared, nperm, nshared);if (perm &BLK_PERM_WRITE ) {
block/blkdebug.c +1 -2
@@ -995,7 +995,6 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, } static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -1003,7 +1002,7 @@ static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, {BDRVBlkdebugState *s = bs->opaque; -bdrv_default_perms (bs, c, child_class, role, reopen_queue, +bdrv_default_perms (bs, c, role, reopen_queue, perm, shared, nperm, nshared); *nperm |= s->take_child_perms;
block/blklogwrites.c +1 -2
@@ -283,7 +283,6 @@ static int64_t blk_log_writes_getlength(BlockDriverState *bs) } static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *ro_q, uint64_t perm, uint64_t shrd,
@@ -295,7 +294,7 @@ static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -bdrv_default_perms (bs, c, child_class, role, ro_q, perm, shrd, +bdrv_default_perms (bs, c, role, ro_q, perm, shrd, nperm, nshrd); }
block/commit.c +0 -1
@@ -223,7 +223,6 @@ static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) } static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
block/copy-on-read.c +0 -1
@@ -52,7 +52,6 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,#define PERM_UNCHANGED (BLK_PERM_ALL & ~PERM_PASSTHROUGH) static void cor_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
block/mirror.c +0 -1
@@ -1492,7 +1492,6 @@ static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) } static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
block/quorum.c +0 -1
@@ -1153,7 +1153,6 @@ static char *quorum_dirname(BlockDriverState *bs, Error **errp) } static void quorum_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
block/replication.c +0 -1
@@ -164,7 +164,6 @@ static void replication_close(BlockDriverState *bs) } static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
block/vvfat.c +1 -3
@@ -3213,7 +3213,6 @@ err: } static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -3221,8 +3220,7 @@ static void vvfat_child_perm(BlockDriverState *bs, BdrvChild *c, {BDRVVVFATState *s = bs->opaque; -assert (c == s->qcow || - (child_class == &child_of_bds && (role &BDRV_CHILD_COW ))); +assert (c == s->qcow || (role &BDRV_CHILD_COW ));if (c == s->qcow) {/* This is a private node, nobody should try to attach to it */
tests/test-bdrv-drain.c +1 -18
@@ -85,23 +85,6 @@ static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs,return 0 ; } -static void bdrv_test_child_perm (BlockDriverState *bs,BdrvChild *c, -const BdrvChildClass *child_class, -BdrvChildRole role, -BlockReopenQueue *reopen_queue, -uint64_t perm,uint64_t shared, -uint64_t *nperm,uint64_t *nshared) -{ -/* -* bdrv_default_perms() accepts nothing else, so disguise -* detach_by_driver_cb_parent. -*/ - child_class = &child_of_bds; - -bdrv_default_perms (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); -} -static int bdrv_test_change_backing_file (BlockDriverState *bs,const char *backing_file,const char *backing_fmt)
@@ -119,7 +102,7 @@ static BlockDriver bdrv_test = { .bdrv_co_drain_begin = bdrv_test_co_drain_begin, .bdrv_co_drain_end = bdrv_test_co_drain_end, - .bdrv_child_perm = bdrv_test_child_perm, + .bdrv_child_perm = bdrv_default_perms, .bdrv_change_backing_file = bdrv_test_change_backing_file, };
tests/test-bdrv-graph-mod.c +0 -1
@@ -30,7 +30,6 @@ static BlockDriver bdrv_pass_through = { }; static void no_perm_default_perms(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
Signature · 1 line
2.26.2
Re: [PATCH v4 34/34] block: Drop @child_class from bdrv_child_perm()
Quoted 12 lines · Max Reitz
Implementations should decide the necessary permissions based on @role.
Signed-off-by Max Reitz <[email protected]>---
+++
b/block.cblock.c +0
-2@@ -1947,13 +1947,13 @@ bool bdrv_is_writable(BlockDriverState *bs) } static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, - BdrvChild *c, const BdrvChildClass *child_class, - BdrvChildRole role, BlockReopenQueue *reopen_queue,
block.c bool bdrv_is_writable(BlockDriverState *bs) · line 1958
Quoted 10 lines
block.c +3
-1+ BdrvChild *c, BdrvChildRole role, + BlockReopenQueue *reopen_queue, uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared) { assert(bs->drv && bs->drv->bdrv_child_perm); - bs->drv->bdrv_child_perm (bs, c, child_class, role, reopen_queue, + bs->drv->bdrv_child_perm (bs, c, role, reopen_queue, parent_perm, parent_shared, nperm, nshared);
Is it worth reflowing this call into two lines rather than three? But that's cosmetic.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Am 13.05.2020 um 13:05 hat Max Reitz geschrieben:
Quoted 2 lines
Based-on: <[email protected]> (“block: Do not call
BlockDriver.bdrv_make_empty()directly”)
I was just ready to apply the series, but alas, then I saw this notice...
So for now, you'll have to make do with:
Kevin Wolf
AppliedAm 13.05.2020 um 13:05 hat Max Reitz geschrieben:
Quoted 5 lines
Based-on: <[email protected]> (“block: Do not call
BlockDriver.bdrv_make_empty()directly”)Branch: https://github.com/XanClic/qemu.git child-role-v4
Branch: https://git.xanclic.moe/XanClic/qemu.git child-role-v4
Thanks, applied to the block branch (and squashed in Eric's English corrections).
Kevin