@@ -454,6 +454,17 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,
aio_context_acquire(aio_context);
s = bs->opaque;
+ if (s->stage == BLOCK_REPLICATION_DONE ||
+ s->stage == BLOCK_REPLICATION_FAILOVER) {
+ /*
+ * This case happens when a secondary is promoted to primary.
+ * Ignore the request because the secondary side of replication
+ * doesn't have to do anything anymore.
+ */
+ aio_context_release(aio_context);
+ return;
+ }
+
if (s->stage != BLOCK_REPLICATION_NONE) {
error_setg(errp, "Block replication is running or done");
aio_context_release(aio_context);
@@ -577,6 +588,17 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)
aio_context_acquire(aio_context);
s = bs->opaque;
+ if (s->stage == BLOCK_REPLICATION_DONE ||
+ s->stage == BLOCK_REPLICATION_FAILOVER) {
+ /*
+ * This case happens when a secondary was promoted to primary.
+ * Ignore the request because the secondary side of replication
+ * doesn't have to do anything anymore.
+ */
+ aio_context_release(aio_context);
+ return;
+ }
+
if (s->mode == REPLICATION_MODE_SECONDARY) {
secondary_do_checkpoint(s, errp);
}
@@ -593,7 +615,7 @@ static void replication_get_error(ReplicationState *rs, Error **errp)
aio_context_acquire(aio_context);
s = bs->opaque;
- if (s->stage != BLOCK_REPLICATION_RUNNING) {
+ if (s->stage == BLOCK_REPLICATION_NONE) {
error_setg(errp, "Block replication is not running");
aio_context_release(aio_context);
return;
@@ -635,6 +657,17 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
aio_context_acquire(aio_context);
s = bs->opaque;
+ if (s->stage == BLOCK_REPLICATION_DONE ||
+ s->stage == BLOCK_REPLICATION_FAILOVER) {
+ /*
+ * This case happens when a secondary was promoted to primary.
+ * Ignore the request because the secondary side of replication
+ * doesn't have to do anything anymore.
+ */
+ aio_context_release(aio_context);
+ return;
+ }
+
if (s->stage != BLOCK_REPLICATION_RUNNING) {
error_setg(errp, "Block replication is not running");
aio_context_release(aio_context);