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().
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). */
}
backing_hd = bdrv_open_inherit(backing_filename, reference, options, 0, bs,
- &child_backing, 0, errp);
+ &child_of_bds, bdrv_backing_role(bs), errp);
if (!backing_hd) {
bs->open_flags |= BDRV_O_NO_BACKING;
error_prepend(errp, "Could not open backing file: ");
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);
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;
}
* 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;
}
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",
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++) {
/* 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);
}
}
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);