block: Introduce real BdrvChildRole
cover block: Introduce real BdrvChildRole
Based-on: <[email protected]> (“block: Fix check_to_replace_node()”)
This is preliminary work for v7 of “Deal with filters”. As Kevin has noted, there may be e.g. multiple storage children, and there should probably be some way for drivers to signal what they use each child for.
Before this series, this is done in a way with the child_* BdrvChildRole objects (i.e., child_file, child_format, child_backing). However, they don’t really suit that task, for multiple reasons:
(1) They don’t formally mean anything.
(2) Drivers may or may not use them. We have tests that just copy child_backing and overwrite a single callback to suit their need.
(3) You can’t combine them (e.g. for children that store both data and metadata).
The current BdrvChildRole structure is really just a way to contact the parent about any changes regarding the child, so it doesn’t describe a role but a class. Hence this series renames it to BdrvChildClass.
Then we can introduce a real BdrvChildRole, which is an enum that captures the roles a child can have in a bit field, so they can be combined.
It turns out that we can use this role to unify child_file, child_format, and child_backing into a generic child_of_bds class that can decide what to do for each child (e.g. when it comes to flag inheritance) based on the BdrvChildRole.
This also applies to bdrv_format_default_perms() and bdrv_filter_default_perms(): We can unify them in a generic bdrv_filter_perms() that has different paths for filtered, backing, metadata, and pure-data children.
Max Reitz (31):
block: Rename BdrvChildRole to BdrvChildClass
block: Add BdrvChildRole
block: Add BdrvChildRole to BdrvChild
block: Pass BdrvChildRole to bdrv_child_perm()
block: Drop BdrvChildClass.stay_at_node
block: Keep BDRV_O_NO_IO in *inherited_fmt_options
block: Pass BdrvChildRole to .inherit_options()
block: Unify 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_backing()
block: Pull out bdrv_default_perms_for_storage()
block: Split bdrv_default_perms_for_storage()
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()
block.c | 477 +++++++++++++++++++++--------------- block/backup-top.c | 11 +- block/blkdebug.c | 10 +- block/blklogwrites.c | 17 +- block/blkreplay.c | 7 +- block/blkverify.c | 12 +- block/block-backend.c | 20 +- block/bochs.c | 6 +- block/cloop.c | 6 +- block/commit.c | 2 +- block/copy-on-read.c | 7 +- block/crypto.c | 6 +- block/dmg.c | 6 +- block/io.c | 22 +- block/mirror.c | 2 +- block/parallels.c | 6 +- block/qcow.c | 6 +- block/qcow2.c | 20 +- block/qed.c | 6 +- block/quorum.c | 11 +- block/raw-format.c | 128 ++++++---- block/replication.c | 5 +- block/throttle.c | 7 +- block/vdi.c | 6 +- block/vhdx.c | 6 +- block/vmdk.c | 22 +- block/vpc.c | 6 +- block/vvfat.c | 11 +- blockjob.c | 8 +- include/block/block.h | 46 +++- include/block/block_int.h | 54 ++-- tests/test-bdrv-drain.c | 72 +++--- tests/test-bdrv-graph-mod.c | 10 +- tests/test-block-iothread.c | 17 +- 34 files changed, 625 insertions(+), 433 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/31 block: Rename BdrvChildRole to BdrvChildClass
This 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.
--- 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 +- include/block/block.h | 6 +- include/block/block_int.h | 22 +++--- tests/test-bdrv-drain.c | 36 ++++----- tests/test-bdrv-graph-mod.c | 2 +- 17 files changed, 141 insertions(+), 133 deletions(-)
block.c +73 -69
@@ -76,7 +76,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,const char *reference, QDict *options, int flags, BlockDriverState *parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp);/* If non-zero, use only whitelisted block drivers */
@@ -1009,7 +1009,7 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options, *child_flags = flags; } -const BdrvChildRole child_file = { +const BdrvChildClass child_file = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_options,
@@ -1037,7 +1037,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO ); } -const BdrvChildRole child_format = { +const BdrvChildClass child_format = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_fmt_options,
@@ -1161,7 +1161,7 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,return ret; } -const BdrvChildRole child_backing = { +const BdrvChildClass child_backing = { .parent_is_bds = true, .get_parent_desc = bdrv_child_get_parent_desc, .attach = bdrv_backing_attach,
@@ -1763,13 +1763,13 @@ bool bdrv_is_writable(BlockDriverState *bs) }static void bdrv_child_perm (BlockDriverState *bs,BlockDriverState *child_bs, -BdrvChild *c,const BdrvChildRole *role, +BdrvChild *c,const BdrvChildClass *child_class,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, role, reopen_queue, + bs->drv->bdrv_child_perm (bs, c, child_class, reopen_queue, parent_perm, parent_shared, nperm, nshared);/* TODO Take force_share from reopen_queue */
@@ -1863,7 +1863,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->role, q, +bdrv_child_perm (bs, c->bs, c, c->klass, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children,
@@ -1930,7 +1930,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->role,NULL , +bdrv_child_perm (bs, c->bs, c, c->klass,NULL , cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared);bdrv_child_set_perm (c, cur_perm, cur_shared);
@@ -1955,8 +1955,8 @@ static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,static char *bdrv_child_user_desc (BdrvChild *c) { -if (c->role->get_parent_desc) { -return c->role->get_parent_desc (c); +if (c->klass->get_parent_desc) { +return c->klass->get_parent_desc (c); }return g_strdup ("another user" );
@@ -2157,14 +2157,14 @@ 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->role,NULL , parent_perms, parent_shared, +bdrv_child_perm (bs, c->bs, c, c->klass,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 BdrvChildRole *role, +const BdrvChildClass *child_class,BlockReopenQueue *reopen_queue,uint64_t perm,uint64_t shared,uint64_t *nperm,uint64_t *nshared)
@@ -2174,21 +2174,21 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, }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) { -bool backing = (role == &child_backing); -assert (role == &child_backing || role == &child_file); +bool backing = (child_class == &child_backing); +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, role, reopen_queue, perm, shared, - &perm, &shared); +bdrv_filter_default_perms (bs, c, child_class, 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)) {
@@ -2265,7 +2265,7 @@ static void bdrv_replace_child_noperm(BdrvChild *child,* If the new child node is drained but the old one was not, flush * all outstanding requests to the old child node. */ -while (drain_saldo >0 && child->role->drained_begin) { +while (drain_saldo >0 && child->klass->drained_begin) {bdrv_parent_drained_begin_single (child, true); drain_saldo--; }
@@ -2274,8 +2274,8 @@ static void bdrv_replace_child_noperm(BdrvChild *child,/* Detach first so that the recursive drain sections coming from @child * are already gone and we only end the drain sections that came from * elsewhere. */ -if (child->role->detach) { - child->role->detach (child); +if (child->klass->detach) { + child->klass->detach (child); }QLIST_REMOVE (child, next_parent); }
@@ -2297,8 +2297,8 @@ static void bdrv_replace_child_noperm(BdrvChild *child,/* Attach only after starting new drained sections, so that recursive * drain sections coming from @child don't get an extra .drained_begin * callback. */ -if (child->role->attach) { - child->role->attach (child); +if (child->klass->attach) { + child->klass->attach (child); } }
@@ -2306,7 +2306,7 @@ static void bdrv_replace_child_noperm(BdrvChild *child,* If the old child node was drained but the new one is not, allow * requests to come in only after the new node has been attached. */ -while (drain_saldo <0 && child->role->drained_end) { +while (drain_saldo <0 && child->klass->drained_end) {bdrv_parent_drained_end_single (child); drain_saldo++; }
@@ -2379,7 +2379,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_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)
@@ -2400,7 +2400,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, *child = (BdrvChild ) { .bs =NULL , .name =g_strdup (child_name), - .role = child_role, + .klass = child_class, .perm = perm, .shared_perm = shared_perm, .opaque = opaque,
@@ -2411,15 +2411,15 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,* try moving the parent into the AioContext of child_bs instead. */ if (bdrv_get_aio_context (child_bs) != ctx) { ret =bdrv_try_set_aio_context (child_bs, ctx, &local_err); -if (ret <0 && child_role->can_set_aio_ctx) { +if (ret <0 && child_class->can_set_aio_ctx) {GSList *ignore =g_slist_prepend (NULL , child);; ctx =bdrv_get_aio_context (child_bs); -if (child_role->can_set_aio_ctx (child, ctx, &ignore,NULL )) { +if (child_class->can_set_aio_ctx (child, ctx, &ignore,NULL )) {error_free (local_err); ret =0 ;g_slist_free (ignore); ignore =g_slist_prepend (NULL , child);; - child_role->set_aio_ctx (child, ctx, &ignore); + child_class->set_aio_ctx (child, ctx, &ignore); }g_slist_free (ignore); }
@@ -2451,7 +2451,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,BdrvChild *bdrv_attach_child (BlockDriverState *parent_bs,BlockDriverState *child_bs,const char *child_name, -const BdrvChildRole *child_role, +const BdrvChildClass *child_class,Error **errp) {BdrvChild *child;
@@ -2460,10 +2460,10 @@ 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_role,NULL , +bdrv_child_perm (parent_bs, child_bs,NULL , child_class,NULL , perm, shared_perm, &perm, &shared_perm); - child =bdrv_root_attach_child (child_bs, child_name, child_role, + child =bdrv_root_attach_child (child_bs, child_name, child_class,bdrv_get_aio_context (parent_bs), perm, shared_perm, parent_bs, errp);if (child ==NULL ) {
@@ -2539,8 +2539,8 @@ static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load) {BdrvChild *c; QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c->role->change_media) { - c->role->change_media (c, load); +if (c->klass->change_media) { + c->klass->change_media (c, load); } } }
@@ -2716,7 +2716,7 @@ free_exit:static BlockDriverState *bdrv_open_child_bs (const char *filename,QDict *options,const char *bdref_key, -BlockDriverState *parent,const BdrvChildRole *child_role, +BlockDriverState *parent,const BdrvChildClass *child_class,bool allow_none,Error **errp) {BlockDriverState *bs =NULL ;
@@ -2724,7 +2724,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key,char *bdref_key_dot;const char *reference; -assert (child_role !=NULL ); +assert (child_class !=NULL ); bdref_key_dot =g_strdup_printf ("%s." , bdref_key);qdict_extract_subqdict (options, &image_options, bdref_key_dot);
@@ -2748,7 +2748,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_role, errp); + parent, child_class, errp);if (!bs) { goto done; }
@@ -2775,22 +2775,24 @@ done: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 *bs; - bs =bdrv_open_child_bs (filename, options, bdref_key, parent, child_role, + bs =bdrv_open_child_bs (filename, options, bdref_key, parent, child_class, allow_none, errp);if (bs ==NULL ) {return NULL ; } -return bdrv_attach_child (parent, bs, bdref_key, child_role, errp); +return bdrv_attach_child (parent, bs, bdref_key, child_class, errp); } -/* TODO Future callers may need to specify parent/child_role in order for -* option inheritance to work. Existing callers use it for the root node. */ +/* +* TODO Future callers may need to specify parent/child_class in order for +* option inheritance to work. Existing callers use it for the root node. +*/ BlockDriverState *bdrv_open_blockdev_ref (BlockdevRef *ref,Error **errp) {BlockDriverState *bs =NULL ;
@@ -2925,7 +2927,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,const char *reference, QDict *options, int flags, BlockDriverState *parent, - const BdrvChildRole *child_role, + const BdrvChildClass *child_class, Error **errp) { int ret;
@@ -2939,8 +2941,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,QDict *snapshot_options =NULL ;int snapshot_flags =0 ; -assert (!child_role || !flags); -assert (!child_role == !parent); +assert (!child_class || !flags); +assert (!child_class == !parent);if (reference) {bool options_non_empty = options ?qdict_size (options) : false;
@@ -2976,10 +2978,10 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, bs->explicit_options =qdict_clone_shallow (options); -if (child_role) { +if (child_class) { bs->inherits_from = parent; - child_role->inherit_options (&flags, options, - parent->open_flags, parent->options); + child_class->inherit_options (&flags, options, + parent->open_flags, parent->options); } ret =bdrv_fill_options (&options, filename, &flags, &local_err);
@@ -3290,7 +3292,7 @@ static bool bdrv_recurse_has_child(BlockDriverState *bs,static BlockReopenQueue *bdrv_reopen_queue_child (BlockReopenQueue *bs_queue,BlockDriverState *bs,QDict *options, -const BdrvChildRole *role, +const BdrvChildClass *klass,QDict *parent_options,int parent_flags,bool keep_old_opts)
@@ -3346,7 +3348,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,/* Inherit from parent node */ if (parent_options) { flags =0 ; - role->inherit_options (&flags, options, parent_flags, parent_options); + klass->inherit_options (&flags, options, parent_flags, parent_options); }else { flags =bdrv_get_flags (bs); }
@@ -3437,7 +3439,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, }bdrv_reopen_queue_child (bs_queue, child->bs, new_child_options, - child->role, options, flags, child_keep_old); + child->klass, options, flags, child_keep_old); }return bs_queue;
@@ -3608,7 +3610,7 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, }else {uint64_t nperm, nshared; -bdrv_child_perm (parent->state.bs, bs, c, c->role, q, +bdrv_child_perm (parent->state.bs, bs, c, c->klass, q, parent->state.perm, parent->state.shared_perm, &nperm, &nshared);
@@ -4094,7 +4096,7 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to)GHashTable *found;bool ret; -if (c->role->stay_at_node) { +if (c->klass->stay_at_node) {return false; }
@@ -4564,9 +4566,9 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, }/* If so, update the backing file path in the image file */ -if (c->role->update_filename) { - ret = c->role->update_filename (c, base, backing_file_str, - &local_err); +if (c->klass->update_filename) { + ret = c->klass->update_filename (c, base, backing_file_str, + &local_err);if (ret <0 ) {bdrv_abort_perm_update (base);error_report_err (local_err);
@@ -5013,8 +5015,8 @@ const char *bdrv_get_parent_name(const BlockDriverState *bs)/* If multiple parents have a name, just pick the first one. */ QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c->role->get_name) { - name = c->role->get_name (c); +if (c->klass->get_name) { + name = c->klass->get_name (c);if (name && *name) {return name; }
@@ -5396,8 +5398,8 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, } QLIST_FOREACH(parent, &bs->parents, next_parent) { -if (parent->role->activate) { - parent->role->activate (parent, &local_err); +if (parent->klass->activate) { + parent->klass->activate (parent, &local_err);if (local_err) { bs->open_flags |=BDRV_O_INACTIVE ;error_propagate (errp, local_err);
@@ -5465,7 +5467,7 @@ static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active)BdrvChild *parent; QLIST_FOREACH(parent, &bs->parents, next_parent) { -if (parent->role->parent_is_bds) { +if (parent->klass->parent_is_bds) {BlockDriverState *parent_bs = parent->opaque;if (!only_active || !(parent_bs->open_flags &BDRV_O_INACTIVE )) {return true;
@@ -5504,8 +5506,8 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) } QLIST_FOREACH(parent, &bs->parents, next_parent) { -if (parent->role->inactivate) { - ret = parent->role->inactivate (parent); +if (parent->klass->inactivate) { + ret = parent->klass->inactivate (parent);if (ret <0 ) {return ret; }
@@ -5999,9 +6001,9 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs,if (g_slist_find (*ignore, child)) {continue ; } -assert (child->role->set_aio_ctx); +assert (child->klass->set_aio_ctx); *ignore =g_slist_prepend (*ignore, child); - child->role->set_aio_ctx (child, new_context, ignore); + child->klass->set_aio_ctx (child, new_context, ignore); }bdrv_detach_aio_context (bs);
@@ -6041,15 +6043,17 @@ static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, } *ignore =g_slist_prepend (*ignore, c); -/* A BdrvChildRole that doesn't handle AioContext changes cannot -* tolerate any AioContext changes */ -if (!c->role->can_set_aio_ctx) { +/* +* A BdrvChildClass that doesn't handle AioContext changes cannot +* tolerate any AioContext changes +*/ +if (!c->klass->can_set_aio_ctx) {char *user =bdrv_child_user_desc (c);error_setg (errp,"Changing iothreads is not supported by %s" , user);g_free (user);return false; } -if (!c->role->can_set_aio_ctx (c, ctx, ignore, errp)) { +if (!c->klass->can_set_aio_ctx (c, ctx, ignore, errp)) {assert (!errp || *errp);return false; }
@@ -6464,7 +6468,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->role == &child_backing && !backing_overridden) { +if (child->klass == &child_backing && !backing_overridden) {/* We can skip the backing BDS if it has not been overridden */ continue ; }
block/backup-top.c +4 -4
@@ -117,7 +117,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)
@@ -137,7 +137,7 @@ static void backup_top_child_perm(BlockDriverState *bs, BdrvChild *c,return ; } -if (role == &child_file) { +if (child_class == &child_file) {/* * Target child *
@@ -148,8 +148,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,
@@ -693,7 +693,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; } }
@@ -717,7 +717,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
@@ -236,7 +236,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));
@@ -3301,8 +3301,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
@@ -1496,7 +1496,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
@@ -1174,7 +1174,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
@@ -160,7 +160,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
@@ -3145,7 +3145,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, };
@@ -3219,14 +3219,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,
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 */
@@ -305,7 +305,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,
@@ -548,7 +548,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
@@ -549,14 +549,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);
@@ -658,7 +658,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;
@@ -731,14 +731,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;/**
@@ -765,7 +765,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.
@@ -1220,7 +1220,7 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr);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);
@@ -1248,7 +1248,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);
@@ -1258,7 +1258,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);
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.23.0
PATCH 2/31 block: Add BdrvChildRole
In reply to Max ReitzThis enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
include/block/block.h +38 -0
@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +typedef enum BdrvChildRole { +/* +* If present, bdrv_replace_node() will not change the node this +* BdrvChild points to. +*/ +BDRV_CHILD_STAY_AT_NODE = (1 <<0 ), + +/* Child stores data */ +BDRV_CHILD_DATA = (1 <<1 ), + +/* Child stores metadata */ +BDRV_CHILD_METADATA = (1 <<2 ), + +/* Filtered child */ +BDRV_CHILD_FILTERED = (1 <<3 ), + +/* Child to COW from (backing child) */ +BDRV_CHILD_COW = (1 <<4 ), + +/* Child is expected to be a protocol node */ +BDRV_CHILD_PROTOCOL = (1 <<5 ), + +/* Child is expected to be a format node */ +BDRV_CHILD_FORMAT = (1 <<6 ), + +/* +* The primary child. For most drivers, this is the child whose +* filename applies best to the parent node. +*/ +BDRV_CHILD_PRIMARY = (1 <<7 ), + +/* Useful combination of flags */ +BDRV_CHILD_IMAGE =BDRV_CHILD_DATA + |BDRV_CHILD_METADATA + |BDRV_CHILD_PROTOCOL + |BDRV_CHILD_PRIMARY , +}BdrvChildRole ; +char *bdrv_perm_names (uint64_t perm);uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm);
Signature · 1 line
2.23.0
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
Quoted 15 lines · Max Reitz
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +0
-0
include/block/block.h enum { · line 282
Quoted 4 lines
include/block/block.h +1
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +typedef enum BdrvChildRole {
Don't you want to call it just BdrvChildFlags ?
Benefits:
1. Do not intersect with old BdrvChildRole.
2. I think, BDRV_CHILD_STAY_AT_NODE is not a role, but just a property or flag..
Quoted 41 lines
include/block/block.h +37
-0+/* +* If present, bdrv_replace_node() will not change the node this +* BdrvChild points to. +*/ +BDRV_CHILD_STAY_AT_NODE = (1 <<0 ), + +/* Child stores data */ +BDRV_CHILD_DATA = (1 <<1 ), + +/* Child stores metadata */ +BDRV_CHILD_METADATA = (1 <<2 ), + +/* Filtered child */ +BDRV_CHILD_FILTERED = (1 <<3 ), + +/* Child to COW from (backing child) */ +BDRV_CHILD_COW = (1 <<4 ), + +/* Child is expected to be a protocol node */ +BDRV_CHILD_PROTOCOL = (1 <<5 ), + +/* Child is expected to be a format node */ +BDRV_CHILD_FORMAT = (1 <<6 ), + +/* +* The primary child. For most drivers, this is the child whose +* filename applies best to the parent node. +*/ +BDRV_CHILD_PRIMARY = (1 <<7 ), + +/* Useful combination of flags */ +BDRV_CHILD_IMAGE =BDRV_CHILD_DATA + |BDRV_CHILD_METADATA + |BDRV_CHILD_PROTOCOL + |BDRV_CHILD_PRIMARY , +} BdrvChildRole; +char *bdrv_perm_names (uint64_t perm);uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm);
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
Quoted 19 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Max Reitz
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +0
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, };
Quoted 6 lines
include/block/block.h enum { · line 282
Quoted 1 line
include/block/block.h +1
-0+typedef enum BdrvChildRole {Don't you want to call it just BdrvChildFlags ?
Benefits:1. Do not intersect with old BdrvChildRole.
Well, that doesn’t change the fact that the old BdrvChildRole just doesn’t describe a role.
Quoted 1 line
2. I think,
BDRV_CHILD_STAY_AT_NODEis not a role, but just a property or flag..
I can be convinced to let STAY_AT_NODE stay a property of BdrvChildClass. :-)
What I don’t like about “BdrvChildFlags” is that “flags” doesn’t express anything. The permissions are flags, too.
Max
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
Quoted 27 lines · Max Reitz
Quoted 19 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Max Reitz
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +0
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, };Quoted 6 lines
include/block/block.h enum { · line 282
Quoted 1 line
include/block/block.h +1
-0+typedef enum BdrvChildRole {Don't you want to call it just BdrvChildFlags ?
Benefits:1. Do not intersect with old BdrvChildRole.
Quoted 7 lines
Well, that doesn’t change the fact that the old BdrvChildRole just doesn’t describe a role.
Quoted 1 line
2. I think,
BDRV_CHILD_STAY_AT_NODEis not a role, but just a property or flag..I can be convinced to let
STAY_AT_NODEstay a property of BdrvChildClass. :-)
or BdrvChild if we want it to be property of object, not class.
Quoted 6 lines
What I don’t like about “BdrvChildFlags” is that “flags” doesn’t express anything. The permissions are flags, too.
Max
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
Quoted 31 lines · Vladimir Sementsov-Ogievskiy
Quoted 30 lines · Max Reitz
Quoted 19 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Max Reitz
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +0
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, };Quoted 6 lines
include/block/block.h enum { · line 282
Quoted 1 line
include/block/block.h +1
-0+typedef enum BdrvChildRole {Don't you want to call it just BdrvChildFlags ?
Benefits:1. Do not intersect with old BdrvChildRole.
Well, that doesn’t change the fact that the old BdrvChildRole just doesn’t describe a role.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
2. I think,
BDRV_CHILD_STAY_AT_NODEis not a role, but just a property or flag..I can be convinced to let
STAY_AT_NODEstay a property of BdrvChildClass. :-)or BdrvChild if we want it to be property of object, not class.
Sure, but that would then no longer concern this series, I think. (That is, either I make STAY_AT_NODE a BdrvChildRole in this series, or I just don’t.)
Max
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
In reply to Max ReitzAm 27.11.2019 um 14:15 hat Max Reitz geschrieben:
Quoted 32 lines
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +14
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +typedef enum BdrvChildRole { + /* + * If present, bdrv_replace_node() will not change the node this + * BdrvChild points to. + */ + BDRV_CHILD_STAY_AT_NODE = (1 << 0), + + /* Child stores data */ + BDRV_CHILD_DATA = (1 << 1), + + /* Child stores metadata */ + BDRV_CHILD_METADATA = (1 << 2), + + /* Filtered child */
include/block/block.h enum { · line 305
Quoted 10 lines
include/block/block.h +10
-0+BDRV_CHILD_FILTERED = (1 <<3 ), + +/* Child to COW from (backing child) */ +BDRV_CHILD_COW = (1 <<4 ), + +/* Child is expected to be a protocol node */ +BDRV_CHILD_PROTOCOL = (1 <<5 ), + +/* Child is expected to be a format node */ + BDRV_CHILD_FORMAT = (1 << 6),
In theory, a node shouldn't care what other nodes it has as its children. For a parent, protocols and formats look exactly the same.
Of course, we do have BDRV_O_PROTOCOL, but if I'm not mistaken this is basically only about probing or not probing an image format when a legacy filename is given rather than BlockdevOptions.
Therefore, unless you have a real reason for this to be here, I'd prefer if we could keep such legacy flags outside of the core infrastructure if at all possible.
include/block/block.h enum { · line 311
Quoted 5 lines
include/block/block.h +5
-0+/* +* The primary child. For most drivers, this is the child whose +* filename applies best to the parent node. +*/ + BDRV_CHILD_PRIMARY = (1 << 7),
If primary is a flag of each BdrvChild, then you could end up having multiple children that claim that they're the primary child. On the other hand, if we have a bs->primary_child instead to make sure that we only have one primary child, we'd have to keep this consistent when children change.
So maybe just document that this flag must be given to only one BdrvChild link for each parent.
include/block/block.h enum { · line 321
Quoted 9 lines
include/block/block.h +7
-0+/* Useful combination of flags */ +BDRV_CHILD_IMAGE =BDRV_CHILD_DATA + |BDRV_CHILD_METADATA + |BDRV_CHILD_PROTOCOL + |BDRV_CHILD_PRIMARY , +} BdrvChildRole; +char *bdrv_perm_names (uint64_t perm);uint64_t bdrv_qapi_perm_to_blk_perm (BlockPermission qapi_perm);
Kevin
Re: [PATCH for-5.0 02/31] block: Add BdrvChildRole
Quoted 47 lines · Kevin Wolf
Am 27.11.2019 um 14:15 hat Max Reitz geschrieben:
Quoted 32 lines
This enum will supplement BdrvChildClass when it comes to what role (or combination of roles) a child takes for its parent.
Because empty enums are not allowed, let us just start with it filled.
Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)include/block/block.h +14
-0@@ -279,6 +279,44 @@ enum { DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; +typedef enum BdrvChildRole { + /* + * If present, bdrv_replace_node() will not change the node this + * BdrvChild points to. + */ + BDRV_CHILD_STAY_AT_NODE = (1 << 0), + + /* Child stores data */ + BDRV_CHILD_DATA = (1 << 1), + + /* Child stores metadata */ + BDRV_CHILD_METADATA = (1 << 2), + + /* Filtered child */include/block/block.h enum { · line 305
Quoted 10 lines
include/block/block.h +10
-0+BDRV_CHILD_FILTERED = (1 <<3 ), + +/* Child to COW from (backing child) */ +BDRV_CHILD_COW = (1 <<4 ), + +/* Child is expected to be a protocol node */ +BDRV_CHILD_PROTOCOL = (1 <<5 ), + +/* Child is expected to be a format node */ + BDRV_CHILD_FORMAT = (1 << 6),In theory, a node shouldn't care what other nodes it has as its children. For a parent, protocols and formats look exactly the same.
Quoted 7 lines
Of course, we do have
BDRV_O_PROTOCOL, but if I'm not mistaken this is basically only about probing or not probing an image format when a legacy filename is given rather than BlockdevOptions.Therefore, unless you have a real reason for this to be here, I'd prefer if we could keep such legacy flags outside of the core infrastructure if at all possible.
Hm. The reason I have it here is because currently this is handled by BdrvChildClass.inherit_options. For filtered and backing children, that will leave PROTOCOL as it is; for the file child of format nodes it will set PROTOCOL; and for some children (blkverify and quorum) it will clear PROTOCOL.
So without these flags here, we can’t unify child_file, child_format, and child_backing in a single class, just because they bequeath the PROTOCOL flag differently. At least not directly.
(I’d like to note that this doesn’t make anything worse. Right now, drivers need to make a conscious choice on this flag, too, namely by choosing the right BdrvChildClass.)
Hmm. Can we do better? Instead of the driver hinting at what they expect from the child, can we somehow infer that automatically in block.c (i.e., in inherit_options without it being given PROTOCOL or FORMAT)? FILTERED || COW always means keeping it as-is. METADATA generally means setting PROTOCOL, I suppose.
The two problems that come to my mind are blkverify and quorum. blkverify is special: It must enforce format-probing on the test image, and it must disable format-probing on the verification (the raw) image.
Quorum wants format probing on everything, but all its children are simply DATA children. Other DATA children are e.g. external data files of qcow2, and we certainly want to force-disable format probing there.
I suppose for the quorum problem we could introduce a BlockDriver.is_format flag that would force O_PROTOCOL for all non-COW children, but we would unset O_PROTOCOL for DATA children of non-is_format drivers.
I suppose the same could work for blkverify’s test image. For its raw image, we’d probably just have to enforce the raw driver (or rely on the fact that blkverify is technically a protocol driver in a way (it implements .bdrv_file_open...), so it will always have O_PROTOCOL set on itself; thus, its filtered child (the raw child) will automatically have it, too, as long as we don’t touch it).
Do you have a better idea?
Quoted 6 lines
include/block/block.h enum { · line 311
Quoted 5 lines
include/block/block.h +5
-0+/* +* The primary child. For most drivers, this is the child whose +* filename applies best to the parent node. +*/ + BDRV_CHILD_PRIMARY = (1 << 7),
Quoted 8 lines
If primary is a flag of each BdrvChild, then you could end up having multiple children that claim that they're the primary child. On the other hand, if we have a
bs->primary_childinstead to make sure that we only have one primary child, we'd have to keep this consistent when children change.So maybe just document that this flag must be given to only one BdrvChild link for each parent.
Sure.
Max
PATCH 3/31 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.
--- 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/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 +++-- include/block/block.h | 2 ++ include/block/block_int.h | 2 ++ tests/test-bdrv-drain.c | 20 +++++++++++--------- tests/test-bdrv-graph-mod.c | 4 ++-- 30 files changed, 61 insertions(+), 48 deletions(-)
block.c +8 -3
@@ -2380,6 +2380,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)
@@ -2401,6 +2402,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,
@@ -2452,6 +2454,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;
@@ -2464,7 +2467,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 ;
@@ -2585,7 +2588,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). */
@@ -2776,6 +2779,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;
@@ -2786,7 +2790,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
@@ -199,7 +199,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, top->opaque = state =g_new0 (BDRVBackupTopState,1 );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
@@ -400,7 +400,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);
@@ -811,7 +811,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
@@ -200,7 +200,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/parallels.c +1 -1
@@ -728,7 +728,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
@@ -1536,7 +1536,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 ;
@@ -1546,7 +1546,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 ;
@@ -1805,7 +1805,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
@@ -997,7 +997,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,assert (ret <32 ); s->children[i].child =bdrv_open_child (NULL , options, indexstr, bs, - &child_format, false, + &child_format,0 , false, &local_err);if (local_err) { ret = -EINVAL ;
@@ -1074,7 +1074,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
@@ -431,7 +431,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
@@ -997,7 +997,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
@@ -3192,7 +3192,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); }
include/block/block.h +2 -0
@@ -344,6 +344,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,
@@ -587,6 +588,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
@@ -739,6 +739,7 @@ struct BdrvChild {BlockDriverState *bs;char *name;const BdrvChildClass *klass; +BdrvChildRole role;void *opaque;/**
@@ -1221,6 +1222,7 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr);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);
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.23.0
PATCH 4/31 block: Pass BdrvChildRole to bdrv_child_perm()
In reply to Max Reitz--- 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 + include/block/block_int.h | 5 ++++- tests/test-bdrv-drain.c | 5 +++-- tests/test-bdrv-graph-mod.c | 1 + 13 files changed, 36 insertions(+), 20 deletions(-)
block.c +12 -10
@@ -1764,12 +1764,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 */
@@ -1863,7 +1863,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,
@@ -1930,7 +1930,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);
@@ -2157,14 +2157,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)
@@ -2175,6 +2176,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)
@@ -2187,7 +2189,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 */
@@ -2463,7 +2465,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,
@@ -3501,7 +3503,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,
@@ -3615,7 +3617,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
@@ -118,6 +118,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)
@@ -148,7 +149,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
@@ -237,6 +237,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
@@ -1497,6 +1497,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
@@ -1175,6 +1175,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
@@ -161,6 +161,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
@@ -3220,6 +3220,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)
include/block/block_int.h +4 -1
@@ -549,7 +549,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
@@ -557,6 +557,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);
@@ -1251,6 +1252,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);
@@ -1261,6 +1263,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);
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.23.0
PATCH 5/31 block: Drop BdrvChildClass.stay_at_node
In reply to Max ReitzThis should better be in BdrvChildRole so that parents can decide when to and when not to keep the child node fixed.
--- block.c | 2 +- blockjob.c | 3 +-- include/block/block_int.h | 4 ---- 3 files changed, 2 insertions(+), 7 deletions(-)
block.c +1 -1
@@ -4103,7 +4103,7 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to)GHashTable *found;bool ret; -if (c->klass->stay_at_node) { +if (c->role &BDRV_CHILD_STAY_AT_NODE ) {return false; }
blockjob.c +1 -2
@@ -170,7 +170,6 @@ static const BdrvChildClass child_job = { .drained_end = child_job_drained_end, .can_set_aio_ctx = child_job_can_set_aio_ctx, .set_aio_ctx = child_job_set_aio_ctx, - .stay_at_node = true, };void block_job_remove_all_bdrv (BlockJob *job)
@@ -217,7 +216,7 @@ 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,0 , + c =bdrv_root_attach_child (bs, name, &child_job,BDRV_CHILD_STAY_AT_NODE , job->job.aio_context, perm, shared_perm, job, errp);if (job->job.aio_context !=qemu_get_aio_context ()) {
include/block/block_int.h +0 -4
@@ -660,10 +660,6 @@ typedef struct BdrvAioNotifier { } BdrvAioNotifier;struct BdrvChildClass { -/* If true, bdrv_replace_node() doesn't change the node this BdrvChild -* points to. */ -bool stay_at_node; -/* If true, the parent is a BlockDriverState and bdrv_next_all_states() * will return it. This information is used for drain_all, where every node * will be drained separately, so the drain only needs to be propagated to
Signature · 1 line
2.23.0
PATCH 6/31 block: Keep BDRV_O_NO_IO in *inherited_fmt_options
In reply to Max Reitzbdrv_inherited_fmt_options() is used only by (pseudo-)filter drivers, namely quorum and blkverify. Both should pass on BDRV_O_NO_IO to their children. There is no reason to clear it in bdrv_inherited_fmt_options().
--- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
@@ -1034,7 +1034,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, child_file.inherit_options (child_flags, child_options, parent_flags, parent_options); - *child_flags &= ~(BDRV_O_PROTOCOL |BDRV_O_NO_IO ); + *child_flags &= ~BDRV_O_PROTOCOL ; }const BdrvChildClass child_format = {
Signature · 1 line
2.23.0
PATCH 7/31 block: Pass BdrvChildRole to .inherit_options()
In reply to Max Reitz--- block.c | 40 +++++++++++++++++++++++---------------- block/block-backend.c | 3 ++- block/vvfat.c | 3 ++- include/block/block_int.h | 3 ++- 4 files changed, 30 insertions(+), 19 deletions(-)
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 */
@@ -979,7 +980,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;
@@ -1028,10 +1030,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 ;
@@ -1112,7 +1115,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;
@@ -2687,7 +2691,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: " );
@@ -2722,7 +2726,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;
@@ -2753,7 +2757,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; }
@@ -2787,7 +2791,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 ; }
@@ -2836,7 +2840,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 ; fail:
@@ -2935,6 +2939,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;
@@ -2987,7 +2992,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); }
@@ -3016,7 +3021,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;
@@ -3058,7 +3063,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; }
@@ -3203,7 +3208,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 */
@@ -3300,6 +3305,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)
@@ -3355,7 +3361,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); }
@@ -3446,7 +3453,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;
@@ -3456,7 +3464,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
@@ -3137,7 +3137,8 @@ static BlockDriver vvfat_write_target = { .bdrv_close = write_target_close, }; -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" );
include/block/block_int.h +2 -1
@@ -666,7 +666,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);
Signature · 1 line
2.23.0
PATCH 8/31 block: Unify bdrv_*inherited_options()
In reply to Max ReitzWe can keep the logic for child_file, child_format, and child_backing in a single function and differentiate based on the BdrvChildRole.
--- block.c | 96 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 36 deletions(-)
block.c +60 -36
@@ -977,8 +977,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 +* 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 bdrv_inherited_options(BdrvChildRole role, int *child_flags, QDict *child_options,
@@ -986,8 +986,16 @@ static void bdrv_inherited_options(BdrvChildRole role, {int flags = parent_flags; -/* Enable protocol handling, disable format probing for bs->file */ - flags |=BDRV_O_PROTOCOL ; +assert ((role & (BDRV_CHILD_PROTOCOL |BDRV_CHILD_FORMAT )) + != (BDRV_CHILD_PROTOCOL |BDRV_CHILD_FORMAT )); + +if (role &BDRV_CHILD_PROTOCOL ) { +/* Enable protocol handling, disable format probing */ + flags |=BDRV_O_PROTOCOL ; + }else if (role &BDRV_CHILD_FORMAT ) { +/* Enable format handling */ + flags &= ~BDRV_O_PROTOCOL ; + }/* If the cache mode isn't explicitly set, inherit direct and no-flush from * the parent. */
@@ -995,26 +1003,57 @@ static void bdrv_inherited_options(BdrvChildRole role,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 ); +if (role &BDRV_CHILD_COW ) { +/* 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" ); + }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 ); + } -/* 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" ); +if (role &BDRV_CHILD_PROTOCOL ) { +/* +* Our format drivers (which expect protocol children underneath, hence +* the condition) 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 ); + 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; } +/* +* 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_file_options (BdrvChildRole role, +int *child_flags,QDict *child_options, +int parent_flags,QDict *parent_options) +{ +bdrv_inherited_options (BDRV_CHILD_IMAGE , + 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_inherited_options, + .inherit_options = bdrv_inherited_file_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_poll = bdrv_child_cb_drained_poll, .drained_end = bdrv_child_cb_drained_end,
@@ -1034,10 +1073,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, child_flags, child_options, -parent_flags ,parent_options ); - - *child_flags &= ~BDRV_O_PROTOCOL ; + bdrv_inherited_options(BDRV_CHILD_DATA | BDRV_CHILD_FORMAT, +child_flags ,child_options , +parent_flags ,parent_options ); } const BdrvChildClass child_format = {
@@ -1119,23 +1157,9 @@ static void bdrv_backing_options(BdrvChildRole role, 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 , +child_flags ,child_options , +parent_flags ,parent_options ); } static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
@@ -3021,7 +3045,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_inherited_options (BDRV_CHILD_COW , &flags, options, flags, options); } bs->open_flags = flags;
Signature · 1 line
2.23.0
PATCH 9/31 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.
--- block.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
block.c +15 -1
@@ -920,9 +920,16 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,bdrv_drained_end_no_poll (bs, drained_end_counter); } +static void bdrv_backing_attach (BdrvChild *c); +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); }
@@ -1133,7 +1140,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); }
@@ -1192,7 +1206,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,
Signature · 1 line
2.23.0
PATCH 10/31 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.
--- block.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
block.c +14 -1
@@ -921,6 +921,7 @@ static void bdrv_child_cb_drained_end(BdrvChild *child, }static void bdrv_backing_attach (BdrvChild *c); +static void bdrv_backing_detach (BdrvChild *c);static void bdrv_child_cb_attach (BdrvChild *child) {
@@ -936,6 +937,11 @@ static void bdrv_child_cb_attach(BdrvChild *child)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); }
@@ -1159,7 +1165,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); }
@@ -1207,7 +1220,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,
Signature · 1 line
2.23.0
PATCH 11/31 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.)
--- block.c | 27 +++++++++++++++++++++++++++ include/block/block_int.h | 1 + 2 files changed, 28 insertions(+)
block.c +27 -0
@@ -1050,6 +1050,33 @@ static void bdrv_inherited_options(BdrvChildRole role, *child_flags = flags; } +static int bdrv_backing_update_filename (BdrvChild *c,BlockDriverState *base, +const char *filename,Error **errp); + +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, +}; +/* * 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
include/block/block_int.h +1 -0
@@ -729,6 +729,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;
Signature · 1 line
2.23.0
PATCH 12/31 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
@@ -2285,6 +2285,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. */
@@ -2301,14 +2308,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.23.0
PATCH 13/31 block: Pull out bdrv_default_perms_for_backing()
In reply to Max Reitz--- block.c | 62 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 22 deletions(-)
block.c +40 -22
@@ -2256,6 +2256,44 @@ void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, *nshared = (shared &DEFAULT_PERM_PASSTHROUGH ) |DEFAULT_PERM_UNCHANGED ; } +static void bdrv_default_perms_for_backing (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,
@@ -2293,28 +2331,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_backing (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } }
Signature · 1 line
2.23.0
PATCH 14/31 block: Pull out bdrv_default_perms_for_storage()
In reply to Max Reitz--- block.c | 71 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 25 deletions(-)
block.c +46 -25
@@ -2294,6 +2294,50 @@ static void bdrv_default_perms_for_backing(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,
@@ -2305,31 +2349,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_backing (bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared);
Signature · 1 line
2.23.0
PATCH 15/31 block: Split bdrv_default_perms_for_storage()
In reply to Max ReitzWe can be less restrictive about pure data children than those with metadata on them.
For bdrv_format_default_perms(), we keep the safe option of bdrv_default_perms_for_metadata() (until we drop bdrv_format_default_perms() altogether).
That means that bdrv_default_perms_for_data() is unused at this point. We will use it for all children that have the DATA role, but not the METADATA role. So far, no child has any role, so we do not use it, but that will change.
--- block.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-)
block.c +43 -10
@@ -2294,18 +2294,17 @@ static void bdrv_default_perms_for_backing(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) +static void bdrv_default_perms_for_metadata (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 )))); + (child_class == &child_of_bds && (role &BDRV_CHILD_METADATA ))); flags =bdrv_reopen_get_flags (reopen_queue, bs);
@@ -2338,6 +2337,40 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } +/* TODO: Use */ +static void __attribute__((unused)) +bdrv_default_perms_for_data (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_DATA )); + +/* +* 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); + +/* +* 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 ; + +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,
@@ -2349,8 +2382,8 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,assert (child_class == &child_backing || child_class == &child_file);if (!backing) { -bdrv_default_perms_for_storage (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); +bdrv_default_perms_for_metadata (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); }else {bdrv_default_perms_for_backing (bs, c, child_class, role, reopen_queue, perm, shared, nperm, nshared);
Signature · 1 line
2.23.0
PATCH 16/31 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).
--- block.c | 46 ++++++++++++++++++++++++++++++++------- include/block/block_int.h | 11 ++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-)
block.c +38 -8
@@ -2337,14 +2337,12 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, *nshared = shared; } -/* TODO: Use */ -static void __attribute__((unused)) -bdrv_default_perms_for_data (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) +static void bdrv_default_perms_for_data (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_DATA ));
@@ -2379,6 +2377,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) {
@@ -2390,6 +2395,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 ) { +bdrv_filter_default_perms (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else if (role &BDRV_CHILD_COW ) { +bdrv_default_perms_for_backing (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else if (role &BDRV_CHILD_METADATA ) { +bdrv_default_perms_for_metadata (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); + }else if (role &BDRV_CHILD_DATA ) { +bdrv_default_perms_for_data (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[] = {
include/block/block_int.h +11 -0
@@ -1272,6 +1272,17 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs,bool bdrv_is_child_of (BlockDriverState *child,BlockDriverState *parent,int min_level); +/* +* 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.
Signature · 1 line
2.23.0
PATCH 17/31 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)
@@ -429,8 +442,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) {
@@ -456,7 +476,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.23.0
PATCH 18/31 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 | FORMAT.
--- block/blkverify.c | 5 +++-- block/quorum.c | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-)
block/blkverify.c +3 -2
@@ -134,8 +134,9 @@ 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 |BDRV_CHILD_FORMAT , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/quorum.c +6 -3
@@ -997,8 +997,10 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,assert (ret <32 ); s->children[i].child =bdrv_open_child (NULL , options, indexstr, bs, - &child_format,0 , false, - &local_err); + &child_of_bds, +BDRV_CHILD_DATA | +BDRV_CHILD_FORMAT , + false, &local_err);if (local_err) { ret = -EINVAL ; goto close_exit;
@@ -1074,7 +1076,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 |BDRV_CHILD_FORMAT , errp);if (child ==NULL ) { s->next_child_index--; goto out;
Signature · 1 line
2.23.0
PATCH 19/31 block: Drop child_format
In reply to Max Reitz--- block.c | 28 ---------------------------- include/block/block_int.h | 1 - 2 files changed, 29 deletions(-)
block.c +0 -28
@@ -1104,34 +1104,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, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) -{ -bdrv_inherited_options (BDRV_CHILD_DATA |BDRV_CHILD_FORMAT , - 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;
include/block/block_int.h +0 -1
@@ -731,7 +731,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 {
Signature · 1 line
2.23.0
PATCH 20/31 block: Make backing files child_of_bds children
In reply to Max Reitz--- 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
@@ -2725,6 +2725,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().
@@ -2752,8 +2766,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). */
@@ -2850,7 +2864,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_CHILD_COW , errp);if (!backing_hd) { bs->open_flags |=BDRV_O_NO_BACKING ;error_prepend (errp,"Could not open backing file: " );
@@ -3670,8 +3684,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);
@@ -6642,7 +6656,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
@@ -138,7 +138,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
@@ -3228,7 +3228,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.23.0
PATCH 21/31 block: Drop child_backing
In reply to Max Reitz--- block.c | 62 +++------------------------------------ include/block/block_int.h | 1 - 2 files changed, 4 insertions(+), 59 deletions(-)
block.c +4 -58
@@ -1147,15 +1147,6 @@ static void bdrv_backing_attach(BdrvChild *c) 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); -} -static void bdrv_backing_detach (BdrvChild *c) {BlockDriverState *parent = c->opaque;
@@ -1166,28 +1157,6 @@ static void bdrv_backing_detach(BdrvChild *c) 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); -} - -/* -* 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, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) -{ -bdrv_inherited_options (BDRV_CHILD_COW , - child_flags, child_options, - parent_flags, parent_options); -} -static int bdrv_backing_update_filename (BdrvChild *c,BlockDriverState *base,const char *filename,Error **errp) {
@@ -1215,21 +1184,6 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,return ret; } -const BdrvChildClass child_backing = { - .parent_is_bds = true, - .get_parent_desc = bdrv_child_get_parent_desc, - .attach = bdrv_child_cb_attach_backing, - .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, - .drained_end = bdrv_child_cb_drained_end, - .inactivate = bdrv_child_cb_inactivate, - .update_filename = bdrv_backing_update_filename, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, -}; -static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags;
@@ -2235,8 +2189,7 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, 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))); + assert(child_class == &child_of_bds && (role & BDRV_CHILD_COW));/* * We want consistent read from backing files if the parent needs it.
@@ -2348,23 +2301,16 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, 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); +assert (child_class == &child_file); -if (!backing) { -bdrv_default_perms_for_metadata (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); - }else { -bdrv_default_perms_for_backing (bs, c, child_class, role, reopen_queue, - perm, shared, nperm, nshared); - } +bdrv_default_perms_for_metadata (bs, c, child_class, role, reopen_queue, + perm, shared, nperm, nshared); } void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c,
include/block/block_int.h +0 -1
@@ -731,7 +731,6 @@ struct BdrvChildClass {extern const BdrvChildClass child_of_bds;extern const BdrvChildClass child_file; -extern const BdrvChildClass child_backing;struct BdrvChild {BlockDriverState *bs;
Signature · 1 line
2.23.0
PATCH 22/31 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 | 20 +++++++++++++++----- block/qed.c | 4 ++-- block/vdi.c | 4 ++-- block/vhdx.c | 4 ++-- block/vmdk.c | 20 +++++++++++++++++--- block/vpc.c | 4 ++-- 12 files changed, 52 insertions(+), 28 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
@@ -200,8 +200,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
@@ -728,8 +728,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 +15 -5
@@ -1535,8 +1535,10 @@ 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 |BDRV_CHILD_PROTOCOL , + true, &local_err);if (local_err) {error_propagate (errp, local_err); ret = -EINVAL ;
@@ -1546,7 +1548,9 @@ 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 , +"data-file" , bs, &child_of_bds, +BDRV_CHILD_DATA | +BDRV_CHILD_PROTOCOL , false, errp);if (!s->data_file) { ret = -EINVAL ;
@@ -1558,6 +1562,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 "
@@ -1805,8 +1815,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
@@ -997,8 +997,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 |BDRV_CHILD_PROTOCOL ; +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.23.0
PATCH 23/31 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.
--- block/blkdebug.c | 4 +++- block/blklogwrites.c | 3 ++- block/blkverify.c | 5 ++++- block/copy-on-read.c | 5 +++-- block/replication.c | 3 ++- block/throttle.c | 5 +++-- 6 files changed, 17 insertions(+), 8 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/blkverify.c +4 -1
@@ -125,7 +125,10 @@ 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_PROTOCOL | +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/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.23.0
PATCH 24/31 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 | 3 ++- block/blkreplay.c | 5 +++-- block/raw-format.c | 16 ++++++++++++++-- 5 files changed, 23 insertions(+), 8 deletions(-)
block.c +2 -1
@@ -3182,7 +3182,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
@@ -200,8 +200,8 @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source, top->opaque = state =g_new0 (BDRVBackupTopState,1 );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 -1
@@ -167,7 +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 , + s->log_file =bdrv_open_child (NULL , options,"log" , bs, &child_of_bds, +BDRV_CHILD_METADATA |BDRV_CHILD_PROTOCOL , 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_DATA |BDRV_CHILD_PRIMARY , + false, &local_err);if (local_err) { ret = -EINVAL ;error_propagate (errp, local_err);
block/raw-format.c +14 -2
@@ -444,6 +444,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);
@@ -451,8 +452,19 @@ 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_PROTOCOL |BDRV_CHILD_PRIMARY ; + }else { + file_role =BDRV_CHILD_FILTERED |BDRV_CHILD_PROTOCOL | +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.23.0
PATCH 25/31 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.23.0
PATCH 26/31 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/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 ++++++++++++++--- 22 files changed, 42 insertions(+), 36 deletions(-)
block/backup-top.c +2 -2
@@ -149,8 +149,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
@@ -296,13 +296,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
@@ -138,7 +138,7 @@ static BlockDriver bdrv_blkreplay = { .instance_size = 0, .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
@@ -321,7 +321,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
@@ -659,7 +659,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, };
block/parallels.c +1 -1
@@ -904,7 +904,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
@@ -1179,7 +1179,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
@@ -5504,7 +5504,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_reopen_commit = qcow2_reopen_commit, .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
@@ -1669,7 +1669,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
@@ -588,7 +588,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
@@ -1037,7 +1037,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
@@ -2232,7 +2232,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
@@ -3055,7 +3055,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
@@ -1238,7 +1238,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
@@ -481,8 +481,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);
@@ -565,7 +570,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.23.0
PATCH 27/31 block: Make bdrv_filter_default_perms() static
In reply to Max Reitz--- block.c | 12 ++++++------ include/block/block_int.h | 10 ---------- 2 files changed, 6 insertions(+), 16 deletions(-)
block.c +6 -6
@@ -2171,12 +2171,12 @@ 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) +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 ;
include/block/block_int.h +0 -10
@@ -1243,16 +1243,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
Signature · 1 line
2.23.0
PATCH 28/31 block: Drop bdrv_format_default_perms()
In reply to Max Reitz--- block.c | 19 ------------------- include/block/block_int.h | 11 ----------- 2 files changed, 30 deletions(-)
block.c +0 -19
@@ -2294,25 +2294,6 @@ static void bdrv_default_perms_for_data(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_metadata (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,
include/block/block_int.h +0 -11
@@ -1243,17 +1243,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);
Signature · 1 line
2.23.0
PATCH 29/31 block: Drop child_file
In reply to Max Reitz--- block.c | 30 +----------------------------- include/block/block_int.h | 1 - tests/test-bdrv-drain.c | 8 +++----- 3 files changed, 4 insertions(+), 35 deletions(-)
block.c +1 -29
@@ -1077,33 +1077,6 @@ const BdrvChildClass child_of_bds = { .update_filename = bdrv_child_cb_update_filename, }; -/* -* 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_file_options (BdrvChildRole role, -int *child_flags,QDict *child_options, -int parent_flags,QDict *parent_options) -{ -bdrv_inherited_options (BDRV_CHILD_IMAGE , - 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_inherited_file_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;
@@ -2228,8 +2201,7 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, {int flags; -assert (child_class == &child_file || - (child_class == &child_of_bds && (role &BDRV_CHILD_METADATA ))); +assert (child_class == &child_of_bds && (role &BDRV_CHILD_METADATA )); flags =bdrv_reopen_get_flags (reopen_queue, bs);
include/block/block_int.h +0 -1
@@ -730,7 +730,6 @@ struct BdrvChildClass { };extern const BdrvChildClass child_of_bds; -extern const BdrvChildClass child_file;struct BdrvChild {BlockDriverState *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.23.0
PATCH 30/31 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 | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-)
block/block-backend.c +7 -4
@@ -401,8 +401,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 ;
@@ -812,8 +813,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 +1 -1
@@ -3193,7 +3193,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,0 , false, errp); + &child_vvfat_qcow,BDRV_CHILD_DATA , false, errp);qobject_unref (options);if (!s->qcow) { ret = -EINVAL ;
Signature · 1 line
2.23.0
PATCH 31/31 block: Drop @child_class from bdrv_child_perm()
In reply to Max ReitzImplementations should decide the necessary permissions based on @role.
--- block.c | 45 ++++++++++++++++--------------------- 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 +--- include/block/block_int.h | 4 +--- tests/test-bdrv-drain.c | 19 +--------------- tests/test-bdrv-graph-mod.c | 1 - 13 files changed, 25 insertions(+), 62 deletions(-)
block.c +19 -26
@@ -1744,13 +1744,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 */
@@ -1844,7 +1844,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,
@@ -1911,7 +1911,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);
@@ -2138,14 +2138,13 @@ 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); } 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,
@@ -2156,13 +2155,12 @@ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, }static void bdrv_default_perms_for_backing (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.
@@ -2193,7 +2191,6 @@ static void bdrv_default_perms_for_backing(BlockDriverState *bs, BdrvChild *c, } static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, - const BdrvChildClass *child_class, BdrvChildRole role, BlockReopenQueue *reopen_queue, uint64_t perm, uint64_t shared,
@@ -2201,7 +2198,7 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, {int flags; -assert (child_class == &child_of_bds && (role &BDRV_CHILD_METADATA )); +assert (role &BDRV_CHILD_METADATA ); flags =bdrv_reopen_get_flags (reopen_queue, bs);
@@ -2209,7 +2206,7 @@ static void bdrv_default_perms_for_metadata(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);/* Format drivers may touch metadata even if the guest doesn't write */
@@ -2235,19 +2232,18 @@ static void bdrv_default_perms_for_metadata(BlockDriverState *bs, BdrvChild *c, }static void bdrv_default_perms_for_data (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_DATA )); +assert (role &BDRV_CHILD_DATA );/* * 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);/*
@@ -2267,24 +2263,21 @@ static void bdrv_default_perms_for_data(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 ) { -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 ) { -bdrv_default_perms_for_backing (bs, c, child_class, role, reopen_queue, +bdrv_default_perms_for_backing (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else if (role &BDRV_CHILD_METADATA ) { -bdrv_default_perms_for_metadata (bs, c, child_class, role, reopen_queue, +bdrv_default_perms_for_metadata (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else if (role &BDRV_CHILD_DATA ) { -bdrv_default_perms_for_data (bs, c, child_class, role, reopen_queue, +bdrv_default_perms_for_data (bs, c, role, reopen_queue, perm, shared, nperm, nshared); }else {g_assert_not_reached ();
@@ -2527,7 +2520,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,
@@ -3584,7 +3577,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,
@@ -3698,7 +3691,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
@@ -117,7 +117,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,
@@ -149,7 +148,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
@@ -284,7 +284,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,
@@ -296,7 +295,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
@@ -236,7 +236,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
@@ -1496,7 +1496,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
@@ -1177,7 +1177,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
@@ -161,7 +161,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
@@ -3220,7 +3220,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,
@@ -3228,8 +3227,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 */
include/block/block_int.h +1 -3
@@ -556,7 +556,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,
@@ -1254,8 +1253,7 @@ bool bdrv_is_child_of(BlockDriverState *child, BlockDriverState *parent,* 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);
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.23.0