On 2018-09-01 00:28, John Snow wrote: > In cases where we abort the block/mirror job, there's no point in > installing the new backing chain before we finish aborting. > > Move this to the "success" portion of mirror_exit. > > Signed-off-by: John Snow > --- > block/mirror.c | 27 ++++++++++++++------------- > 1 file changed, 14 insertions(+), 13 deletions(-) > > diff --git a/block/mirror.c b/block/mirror.c > index cba555b4ef..c164fee883 100644 > --- a/block/mirror.c > +++ b/block/mirror.c > @@ -642,16 +642,6 @@ static void mirror_exit(Job *job) > * 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); > - if (s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) { > - BlockDriverState *backing = s->is_none_mode ? src : s->base; > - if (backing_bs(target_bs) != backing) { > - bdrv_set_backing_hd(target_bs, backing, &local_err); > - if (local_err) { > - error_report_err(local_err); > - ret = -EPERM; > - } > - } > - } > > if (s->to_replace) { > replace_aio_context = bdrv_get_aio_context(s->to_replace); > @@ -659,9 +649,18 @@ static void mirror_exit(Job *job) > } > > if (s->should_complete && ret == 0) { > - BlockDriverState *to_replace = src; > - if (s->to_replace) { > - to_replace = s->to_replace; > + BlockDriverState *to_replace = s->to_replace ? s->to_replace : src; > + > + if (s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) { > + BlockDriverState *backing = s->is_none_mode ? src : s->base; > + if (backing_bs(target_bs) != backing) { > + bdrv_set_backing_hd(target_bs, backing, &local_err); > + if (local_err) { > + error_report_err(local_err); > + ret = -EPERM; > + goto clean; > + } > + } > } > > if (bdrv_get_flags(target_bs) != bdrv_get_flags(to_replace)) { Testing shows that on post-READY cancel, s->should_complete is 0 (which makes sense, because all the rest in this path is about replacing to_replace by target_bs, which we don't want to do on cancel), so this would not be executed. However, I think we do want to give the target the correct backing chain when the job is canceled this way (as I suppose there are ways to keep the target around even with drive-mirror). So we should attach the backing chain whenever ret == 0, not just when s->should_complete is true. Max > @@ -678,6 +677,8 @@ static void mirror_exit(Job *job) > ret = -EPERM; > } > } > + > + clean: > if (s->to_replace) { > bdrv_op_unblock_all(s->to_replace, s->replace_blocker); > error_free(s->replace_blocker); >