aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2017-05-10 12:31:13 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2017-05-10 12:31:19 -0400
commitf465706e590a6543542246a9f1b591e5be39c568 (patch)
tree611797f83d6c53bfe8cb5371ba4fd53c4d122541 /block
parent1effe6ad5eac1b2e50a077695ac801d172891d6a (diff)
parente1ae9fb6c2a35015ed4881def4a4a7b6be2d15f0 (diff)
Merge remote-tracking branch 'mjt/tags/trivial-patches-fetch' into staging
trivial patches for 2017-05-10 # gpg: Signature made Wed 10 May 2017 03:19:30 AM EDT # gpg: using RSA key 0x701B4F6B1A693E59 # gpg: Good signature from "Michael Tokarev <mjt@tls.msk.ru>" # gpg: aka "Michael Tokarev <mjt@corpit.ru>" # gpg: aka "Michael Tokarev <mjt@debian.org>" # Primary key fingerprint: 6EE1 95D1 886E 8FFB 810D 4324 457C E0A0 8044 65C5 # Subkey fingerprint: 7B73 BAD6 8BE7 A2C2 8931 4B22 701B 4F6B 1A69 3E59 * mjt/tags/trivial-patches-fetch: (23 commits) tests: Remove redundant assignment MAINTAINERS: Update paths for AioContext implementation MAINTAINERS: Update paths for main loop jazz_led: fix bad snprintf tests: Ignore another built executable (test-hmp) scripts: Switch to more portable Perl shebang scripts/qemu-binfmt-conf.sh: Fix shell portability issue virtfs: allow a device id to be specified in the -virtfs option hw/core/generic-loader: Fix crash when running without CPU virtio-blk: Remove useless condition around g_free() qemu-doc: Fix broken URLs of amnhltm.zip and dosidle210.zip use _Static_assert in QEMU_BUILD_BUG_ON channel-file: fix wrong parameter comments block: Make 'replication_state' an enum util: Use g_malloc/g_free in envlist.c qga: fix compiler warnings (clang 5) device_tree: fix compiler warnings (clang 5) usb-ccid: make ccid_write_data_block() cope with null buffers tests: Ignore more test executables Add 'none' as type for drive's if option ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/replication.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/block/replication.c b/block/replication.c
index d300c15475..3885f04c31 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -22,9 +22,17 @@
#include "qapi/error.h"
#include "replication.h"
+typedef enum {
+ BLOCK_REPLICATION_NONE, /* block replication is not started */
+ BLOCK_REPLICATION_RUNNING, /* block replication is running */
+ BLOCK_REPLICATION_FAILOVER, /* failover is running in background */
+ BLOCK_REPLICATION_FAILOVER_FAILED, /* failover failed */
+ BLOCK_REPLICATION_DONE, /* block replication is done */
+} ReplicationStage;
+
typedef struct BDRVReplicationState {
ReplicationMode mode;
- int replication_state;
+ ReplicationStage stage;
BdrvChild *active_disk;
BdrvChild *hidden_disk;
BdrvChild *secondary_disk;
@@ -36,14 +44,6 @@ typedef struct BDRVReplicationState {
int error;
} BDRVReplicationState;
-enum {
- BLOCK_REPLICATION_NONE, /* block replication is not started */
- BLOCK_REPLICATION_RUNNING, /* block replication is running */
- BLOCK_REPLICATION_FAILOVER, /* failover is running in background */
- BLOCK_REPLICATION_FAILOVER_FAILED, /* failover failed */
- BLOCK_REPLICATION_DONE, /* block replication is done */
-};
-
static void replication_start(ReplicationState *rs, ReplicationMode mode,
Error **errp);
static void replication_do_checkpoint(ReplicationState *rs, Error **errp);
@@ -141,10 +141,10 @@ static void replication_close(BlockDriverState *bs)
{
BDRVReplicationState *s = bs->opaque;
- if (s->replication_state == BLOCK_REPLICATION_RUNNING) {
+ if (s->stage == BLOCK_REPLICATION_RUNNING) {
replication_stop(s->rs, false, NULL);
}
- if (s->replication_state == BLOCK_REPLICATION_FAILOVER) {
+ if (s->stage == BLOCK_REPLICATION_FAILOVER) {
block_job_cancel_sync(s->active_disk->bs->job);
}
@@ -174,7 +174,7 @@ static int64_t replication_getlength(BlockDriverState *bs)
static int replication_get_io_status(BDRVReplicationState *s)
{
- switch (s->replication_state) {
+ switch (s->stage) {
case BLOCK_REPLICATION_NONE:
return -EIO;
case BLOCK_REPLICATION_RUNNING:
@@ -403,7 +403,7 @@ static void backup_job_completed(void *opaque, int ret)
BlockDriverState *bs = opaque;
BDRVReplicationState *s = bs->opaque;
- if (s->replication_state != BLOCK_REPLICATION_FAILOVER) {
+ if (s->stage != BLOCK_REPLICATION_FAILOVER) {
/* The backup job is cancelled unexpectedly */
s->error = -EIO;
}
@@ -445,7 +445,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,
aio_context_acquire(aio_context);
s = bs->opaque;
- if (s->replication_state != BLOCK_REPLICATION_NONE) {
+ if (s->stage != BLOCK_REPLICATION_NONE) {
error_setg(errp, "Block replication is running or done");
aio_context_release(aio_context);
return;
@@ -545,7 +545,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,
abort();
}
- s->replication_state = BLOCK_REPLICATION_RUNNING;
+ s->stage = BLOCK_REPLICATION_RUNNING;
if (s->mode == REPLICATION_MODE_SECONDARY) {
secondary_do_checkpoint(s, errp);
@@ -581,7 +581,7 @@ static void replication_get_error(ReplicationState *rs, Error **errp)
aio_context_acquire(aio_context);
s = bs->opaque;
- if (s->replication_state != BLOCK_REPLICATION_RUNNING) {
+ if (s->stage != BLOCK_REPLICATION_RUNNING) {
error_setg(errp, "Block replication is not running");
aio_context_release(aio_context);
return;
@@ -601,7 +601,7 @@ static void replication_done(void *opaque, int ret)
BDRVReplicationState *s = bs->opaque;
if (ret == 0) {
- s->replication_state = BLOCK_REPLICATION_DONE;
+ s->stage = BLOCK_REPLICATION_DONE;
/* refresh top bs's filename */
bdrv_refresh_filename(bs);
@@ -610,7 +610,7 @@ static void replication_done(void *opaque, int ret)
s->hidden_disk = NULL;
s->error = 0;
} else {
- s->replication_state = BLOCK_REPLICATION_FAILOVER_FAILED;
+ s->stage = BLOCK_REPLICATION_FAILOVER_FAILED;
s->error = -EIO;
}
}
@@ -625,7 +625,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
aio_context_acquire(aio_context);
s = bs->opaque;
- if (s->replication_state != BLOCK_REPLICATION_RUNNING) {
+ if (s->stage != BLOCK_REPLICATION_RUNNING) {
error_setg(errp, "Block replication is not running");
aio_context_release(aio_context);
return;
@@ -633,7 +633,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
switch (s->mode) {
case REPLICATION_MODE_PRIMARY:
- s->replication_state = BLOCK_REPLICATION_DONE;
+ s->stage = BLOCK_REPLICATION_DONE;
s->error = 0;
break;
case REPLICATION_MODE_SECONDARY:
@@ -648,12 +648,12 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
if (!failover) {
secondary_do_checkpoint(s, errp);
- s->replication_state = BLOCK_REPLICATION_DONE;
+ s->stage = BLOCK_REPLICATION_DONE;
aio_context_release(aio_context);
return;
}
- s->replication_state = BLOCK_REPLICATION_FAILOVER;
+ s->stage = BLOCK_REPLICATION_FAILOVER;
commit_active_start(NULL, s->active_disk->bs, s->secondary_disk->bs,
BLOCK_JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPORT,
NULL, replication_done, bs, true, errp);