BlockDriverState *old_bs = child->bs;
if (old_bs) {
+ if (old_bs->quiesce_counter && child->role->drained_end) {
+ child->role->drained_end(child);
+ }
QLIST_REMOVE(child, next_parent);
}
+
+ child->bs = new_bs;
+
if (new_bs) {
QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
+ if (new_bs->quiesce_counter && child->role->drained_begin) {
+ child->role->drained_begin(child);
+ }
}
-
- child->bs = new_bs;
}
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
- const BdrvChildRole *child_role)
+ const BdrvChildRole *child_role,
+ void *opaque)
{
BdrvChild *child = g_new(BdrvChild, 1);
*child = (BdrvChild) {
.bs = NULL,
.name = g_strdup(child_name),
.role = child_role,
+ .opaque = opaque,
};
bdrv_replace_child(child, child_bs);
const char *child_name,
const BdrvChildRole *child_role)
{
- BdrvChild *child = bdrv_root_attach_child(child_bs, child_name, child_role);
+ BdrvChild *child = bdrv_root_attach_child(child_bs, child_name, child_role,
+ NULL);
QLIST_INSERT_HEAD(&parent_bs->children, child, next);
return child;
}
}
blk_set_enable_write_cache(blk, true);
- blk->root = bdrv_root_attach_child(bs, "root", &child_root);
- blk->root->opaque = blk;
+ blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk);
return blk;
}
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
{
bdrv_ref(bs);
- blk->root = bdrv_root_attach_child(bs, "root", &child_root);
- blk->root->opaque = blk;
+ blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk);
notifier_list_notify(&blk->insert_bs_notifiers, blk);
if (blk->public.throttle_state) {
{
BlockBackend *blk = child->opaque;
+ /* Note that blk->root may not be accessible here yet if we are just
+ * attaching to a BlockDriverState that is drained. Use child instead. */
+
if (blk->public.io_limits_disabled++ == 0) {
throttle_group_restart_blk(blk);
}
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
const char *child_name,
- const BdrvChildRole *child_role);
+ const BdrvChildRole *child_role,
+ void *opaque);
void bdrv_root_unref_child(BdrvChild *child);
const char *bdrv_get_parent_name(const BlockDriverState *bs);