aboutsummaryrefslogtreecommitdiff
path: root/block/mirror.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/mirror.c')
-rw-r--r--block/mirror.c70
1 files changed, 45 insertions, 25 deletions
diff --git a/block/mirror.c b/block/mirror.c
index f8bdb5b21b..d17be4cdbc 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -85,6 +85,7 @@ typedef struct MirrorBlockJob {
typedef struct MirrorBDSOpaque {
MirrorBlockJob *job;
+ bool stop;
} MirrorBDSOpaque;
struct MirrorOp {
@@ -656,8 +657,9 @@ static int mirror_exit_common(Job *job)
/* We don't access the source any more. Dropping any WRITE/RESIZE is
* required before it could become a backing file of target_bs. */
- bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
- &error_abort);
+ bs_opaque->stop = true;
+ bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
+ &error_abort);
if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
BlockDriverState *backing = s->is_none_mode ? src : s->base;
if (backing_bs(target_bs) != backing) {
@@ -704,13 +706,12 @@ static int mirror_exit_common(Job *job)
g_free(s->replaces);
bdrv_unref(target_bs);
- /* Remove the mirror filter driver from the graph. Before this, get rid of
+ /*
+ * Remove the mirror filter driver from the graph. Before this, get rid of
* the blockers on the intermediate nodes so that the resulting state is
- * valid. Also give up permissions on mirror_top_bs->backing, which might
- * block the removal. */
+ * valid.
+ */
block_job_remove_all_bdrv(bjob);
- bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
- &error_abort);
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
/* We just changed the BDS the job BB refers to (with either or both of the
@@ -1459,6 +1460,18 @@ static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
{
+ MirrorBDSOpaque *s = bs->opaque;
+
+ if (s->stop) {
+ /*
+ * If the job is to be stopped, we do not need to forward
+ * anything to the real image.
+ */
+ *nperm = 0;
+ *nshared = BLK_PERM_ALL;
+ return;
+ }
+
/* Must be able to forward guest writes to the real image */
*nperm = 0;
if (perm & BLK_PERM_WRITE) {
@@ -1482,7 +1495,8 @@ static BlockDriver bdrv_mirror_top = {
.bdrv_child_perm = bdrv_mirror_top_child_perm,
};
-static void mirror_start_job(const char *job_id, BlockDriverState *bs,
+static BlockJob *mirror_start_job(
+ const char *job_id, BlockDriverState *bs,
int creation_flags, BlockDriverState *target,
const char *replaces, int64_t speed,
uint32_t granularity, int64_t buf_size,
@@ -1514,7 +1528,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
if (buf_size < 0) {
error_setg(errp, "Invalid parameter 'buf-size'");
- return;
+ return NULL;
}
if (buf_size == 0) {
@@ -1523,7 +1537,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
if (bs == target) {
error_setg(errp, "Can't mirror node into itself");
- return;
+ return NULL;
}
/* In the case of active commit, add dummy driver to provide consistent
@@ -1532,7 +1546,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
mirror_top_bs = bdrv_new_open_driver(&bdrv_mirror_top, filter_node_name,
BDRV_O_RDWR, errp);
if (mirror_top_bs == NULL) {
- return;
+ return NULL;
}
if (!filter_node_name) {
mirror_top_bs->implicit = true;
@@ -1554,7 +1568,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
if (local_err) {
bdrv_unref(mirror_top_bs);
error_propagate(errp, local_err);
- return;
+ return NULL;
}
/* Make sure that the source is not resized while the job is running */
@@ -1662,7 +1676,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
trace_mirror_start(bs, s, opaque);
job_start(&s->common.job);
- return;
+
+ return &s->common;
fail:
if (s) {
@@ -1679,11 +1694,14 @@ fail:
job_early_fail(&s->common.job);
}
- bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
- &error_abort);
+ bs_opaque->stop = true;
+ bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
+ &error_abort);
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
bdrv_unref(mirror_top_bs);
+
+ return NULL;
}
void mirror_start(const char *job_id, BlockDriverState *bs,
@@ -1712,25 +1730,27 @@ void mirror_start(const char *job_id, BlockDriverState *bs,
filter_node_name, true, copy_mode, errp);
}
-void commit_active_start(const char *job_id, BlockDriverState *bs,
- BlockDriverState *base, int creation_flags,
- int64_t speed, BlockdevOnError on_error,
- const char *filter_node_name,
- BlockCompletionFunc *cb, void *opaque,
- bool auto_complete, Error **errp)
+BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
+ BlockDriverState *base, int creation_flags,
+ int64_t speed, BlockdevOnError on_error,
+ const char *filter_node_name,
+ BlockCompletionFunc *cb, void *opaque,
+ bool auto_complete, Error **errp)
{
bool base_read_only;
Error *local_err = NULL;
+ BlockJob *ret;
base_read_only = bdrv_is_read_only(base);
if (base_read_only) {
if (bdrv_reopen_set_read_only(base, false, errp) < 0) {
- return;
+ return NULL;
}
}
- mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0,
+ ret = mirror_start_job(
+ job_id, bs, creation_flags, base, NULL, speed, 0, 0,
MIRROR_LEAVE_BACKING_CHAIN,
on_error, on_error, true, cb, opaque,
&commit_active_job_driver, false, base, auto_complete,
@@ -1741,7 +1761,7 @@ void commit_active_start(const char *job_id, BlockDriverState *bs,
goto error_restore_flags;
}
- return;
+ return ret;
error_restore_flags:
/* ignore error and errp for bdrv_reopen, because we want to propagate
@@ -1749,5 +1769,5 @@ error_restore_flags:
if (base_read_only) {
bdrv_reopen_set_read_only(base, true, NULL);
}
- return;
+ return NULL;
}