[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 06/48] mirror: Error out when a BDS would get two BBs
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 06/48] mirror: Error out when a BDS would get two BBs |
Date: |
Fri, 18 Dec 2015 16:07:12 +0100 |
bdrv_replace_in_backing_chain() asserts that not both old and new
BlockDdriverState have a BlockBackend attached to them because both
would have to end up pointing to the new BDS and we don't support more
than one BB per BDS yet.
Before we can safely allow references to existing nodes as backing
files, we need to make sure that even if a backing file has a BB on it,
this doesn't crash qemu.
There are probably also some cases with the 'replaces' option set where
drive-mirror could fail this assertion today. They are fixed with this
error check as well.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/mirror.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/block/mirror.c b/block/mirror.c
index 0e8f556..8e3f524 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -18,6 +18,7 @@
#include "qapi/qmp/qerror.h"
#include "qemu/ratelimit.h"
#include "qemu/bitmap.h"
+#include "qemu/error-report.h"
#define SLICE_TIME 100000000ULL /* ns */
#define MAX_IN_FLIGHT 16
@@ -370,11 +371,22 @@ static void mirror_exit(BlockJob *job, void *opaque)
if (s->to_replace) {
to_replace = s->to_replace;
}
+
+ /* This was checked in mirror_start_job(), but meanwhile one of the
+ * nodes could have been newly attached to a BlockBackend. */
+ if (to_replace->blk && s->target->blk) {
+ error_report("block job: Can't create node with two
BlockBackends");
+ data->ret = -EINVAL;
+ goto out;
+ }
+
if (bdrv_get_flags(s->target) != bdrv_get_flags(to_replace)) {
bdrv_reopen(s->target, bdrv_get_flags(to_replace), NULL);
}
bdrv_replace_in_backing_chain(to_replace, s->target);
}
+
+out:
if (s->to_replace) {
bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
error_free(s->replace_blocker);
@@ -705,6 +717,7 @@ static void mirror_start_job(BlockDriverState *bs,
BlockDriverState *target,
bool is_none_mode, BlockDriverState *base)
{
MirrorBlockJob *s;
+ BlockDriverState *replaced_bs;
if (granularity == 0) {
granularity = bdrv_get_default_bitmap_granularity(target);
@@ -728,6 +741,21 @@ static void mirror_start_job(BlockDriverState *bs,
BlockDriverState *target,
buf_size = DEFAULT_MIRROR_BUF_SIZE;
}
+ /* We can't support this case as long as the block layer can't handle
+ * multiple BlockBackends per BlockDriverState. */
+ if (replaces) {
+ replaced_bs = bdrv_lookup_bs(replaces, replaces, errp);
+ if (replaced_bs == NULL) {
+ return;
+ }
+ } else {
+ replaced_bs = bs;
+ }
+ if (replaced_bs->blk && target->blk) {
+ error_setg(errp, "Can't create node with two BlockBackends");
+ return;
+ }
+
s = block_job_create(driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
--
1.8.3.1
- [Qemu-block] [PULL 41/48] qemu-iotests: refine common.config, (continued)
- [Qemu-block] [PULL 41/48] qemu-iotests: refine common.config, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 34/48] iotests: Extend test 112 for qemu-img amend, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 24/48] qemu-iotests: Test reopen with node-name/driver options, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 03/48] iotests: 124: don't reopen qcow2, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 33/48] qcow2: Point to amend function in check, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 40/48] block: fix bdrv_ioctl called from coroutine, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 39/48] block: use drained section around bdrv_snapshot_delete, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 35/48] qcow2: insert assert into qcow2_get_specific_info(), Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 31/48] qcow2: Add function for refcount order amendment, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 04/48] qcow2: Add .bdrv_join_options callback, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 06/48] mirror: Error out when a BDS would get two BBs,
Kevin Wolf <=
- [Qemu-block] [PULL 22/48] qemu-iotests: Try setting cache mode for children, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 38/48] iotests: Update comments for bdrv_swap() in 094, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 28/48] qcow2: Use abort() instead of assert(false), Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 25/48] progress: Allow regressing progress, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 08/48] block: Consider all block layer options in append_open_options, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 48/48] block/qapi: allow best-effort query, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 27/48] qcow2: Use error_report() in qcow2_amend_options(), Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 29/48] qcow2: Split upgrade/downgrade paths for amend, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 46/48] block/qapi: explicitly warn if !has_full_backing_filename, Kevin Wolf, 2015/12/18
- [Qemu-block] [PULL 13/48] block: reopen: Document option precedence and refactor accordingly, Kevin Wolf, 2015/12/18