@@ -1755,31 +1755,13 @@ static BlockJob *mirror_start_job(
GLOBAL_STATE_CODE();
- if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
- error_setg(errp, "Sync mode '%s' not supported",
- MirrorSyncMode_str(sync_mode));
- return NULL;
- } else if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
- if (!bitmap) {
- error_setg(errp, "Must provide a valid bitmap name for '%s'"
- " sync mode",
- MirrorSyncMode_str(sync_mode));
- return NULL;
- }
- } else if (bitmap) {
- error_setg(errp,
- "sync mode '%s' is not compatible with bitmaps",
- MirrorSyncMode_str(sync_mode));
- return NULL;
- }
+ /* QMP interface protects us from these cases */
+ assert(sync_mode != MIRROR_SYNC_MODE_INCREMENTAL);
+ assert((bitmap && sync_mode == MIRROR_SYNC_MODE_BITMAP) ||
+ (!bitmap && sync_mode != MIRROR_SYNC_MODE_BITMAP));
+ assert(!(bitmap && granularity));
if (bitmap) {
- if (granularity) {
- error_setg(errp, "granularity (%d)"
- "cannot be specified when a bitmap is provided",
- granularity);
- return NULL;
- }
granularity = bdrv_dirty_bitmap_granularity(bitmap);
if (bitmap_mode != BITMAP_SYNC_MODE_NEVER) {
@@ -2852,7 +2852,36 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
sync = MIRROR_SYNC_MODE_FULL;
}
+ if ((sync == MIRROR_SYNC_MODE_BITMAP) ||
+ (sync == MIRROR_SYNC_MODE_INCREMENTAL)) {
+ /* done before desugaring 'incremental' to print the right message */
+ if (!bitmap_name) {
+ error_setg(errp, "Must provide a valid bitmap name for "
+ "'%s' sync mode", MirrorSyncMode_str(sync));
+ return;
+ }
+ }
+
+ if (sync == MIRROR_SYNC_MODE_INCREMENTAL) {
+ if (has_bitmap_mode &&
+ bitmap_mode != BITMAP_SYNC_MODE_ON_SUCCESS) {
+ error_setg(errp, "Bitmap sync mode must be '%s' "
+ "when using sync mode '%s'",
+ BitmapSyncMode_str(BITMAP_SYNC_MODE_ON_SUCCESS),
+ MirrorSyncMode_str(sync));
+ return;
+ }
+ has_bitmap_mode = true;
+ sync = MIRROR_SYNC_MODE_BITMAP;
+ bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
+ }
+
if (bitmap_name) {
+ if (sync != MIRROR_SYNC_MODE_BITMAP) {
+ error_setg(errp, "Sync mode '%s' not supported with bitmap.",
+ MirrorSyncMode_str(sync));
+ return;
+ }
if (granularity) {
error_setg(errp, "Granularity and bitmap cannot both be set");
return;