aboutsummaryrefslogtreecommitdiff
path: root/block/replication.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/replication.c')
-rw-r--r--block/replication.c67
1 files changed, 20 insertions, 47 deletions
diff --git a/block/replication.c b/block/replication.c
index 6349d6958e..e70dd95001 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -20,6 +20,7 @@
#include "block/block_backup.h"
#include "sysemu/block-backend.h"
#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
#include "replication.h"
typedef enum {
@@ -39,8 +40,8 @@ typedef struct BDRVReplicationState {
char *top_id;
ReplicationState *rs;
Error *blocker;
- int orig_hidden_flags;
- int orig_secondary_flags;
+ bool orig_hidden_read_only;
+ bool orig_secondary_read_only;
int error;
} BDRVReplicationState;
@@ -218,9 +219,6 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs,
QEMUIOVector *qiov)
{
BDRVReplicationState *s = bs->opaque;
- BdrvChild *child = s->secondary_disk;
- BlockJob *job = NULL;
- CowRequest req;
int ret;
if (s->mode == REPLICATION_MODE_PRIMARY) {
@@ -233,28 +231,9 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs,
return ret;
}
- if (child && child->bs) {
- job = child->bs->job;
- }
-
- if (job) {
- uint64_t remaining_bytes = remaining_sectors * BDRV_SECTOR_SIZE;
-
- backup_wait_for_overlapping_requests(child->bs->job,
- sector_num * BDRV_SECTOR_SIZE,
- remaining_bytes);
- backup_cow_request_begin(&req, child->bs->job,
- sector_num * BDRV_SECTOR_SIZE,
- remaining_bytes);
- ret = bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE,
- remaining_bytes, qiov, 0);
- backup_cow_request_end(&req);
- goto out;
- }
-
ret = bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE,
remaining_sectors * BDRV_SECTOR_SIZE, qiov, 0);
-out:
+
return replication_return_value(s, ret);
}
@@ -371,44 +350,38 @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp)
}
}
+/* This function is supposed to be called twice:
+ * first with writable = true, then with writable = false.
+ * The first call puts s->hidden_disk and s->secondary_disk in
+ * r/w mode, and the second puts them back in their original state.
+ */
static void reopen_backing_file(BlockDriverState *bs, bool writable,
Error **errp)
{
BDRVReplicationState *s = bs->opaque;
BlockReopenQueue *reopen_queue = NULL;
- int orig_hidden_flags, orig_secondary_flags;
- int new_hidden_flags, new_secondary_flags;
Error *local_err = NULL;
if (writable) {
- orig_hidden_flags = s->orig_hidden_flags =
- bdrv_get_flags(s->hidden_disk->bs);
- new_hidden_flags = (orig_hidden_flags | BDRV_O_RDWR) &
- ~BDRV_O_INACTIVE;
- orig_secondary_flags = s->orig_secondary_flags =
- bdrv_get_flags(s->secondary_disk->bs);
- new_secondary_flags = (orig_secondary_flags | BDRV_O_RDWR) &
- ~BDRV_O_INACTIVE;
- } else {
- orig_hidden_flags = (s->orig_hidden_flags | BDRV_O_RDWR) &
- ~BDRV_O_INACTIVE;
- new_hidden_flags = s->orig_hidden_flags;
- orig_secondary_flags = (s->orig_secondary_flags | BDRV_O_RDWR) &
- ~BDRV_O_INACTIVE;
- new_secondary_flags = s->orig_secondary_flags;
+ s->orig_hidden_read_only = bdrv_is_read_only(s->hidden_disk->bs);
+ s->orig_secondary_read_only = bdrv_is_read_only(s->secondary_disk->bs);
}
bdrv_subtree_drained_begin(s->hidden_disk->bs);
bdrv_subtree_drained_begin(s->secondary_disk->bs);
- if (orig_hidden_flags != new_hidden_flags) {
- reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL,
- new_hidden_flags);
+ if (s->orig_hidden_read_only) {
+ QDict *opts = qdict_new();
+ qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable);
+ reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs,
+ opts);
}
- if (!(orig_secondary_flags & BDRV_O_RDWR)) {
+ if (s->orig_secondary_read_only) {
+ QDict *opts = qdict_new();
+ qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable);
reopen_queue = bdrv_reopen_queue(reopen_queue, s->secondary_disk->bs,
- NULL, new_secondary_flags);
+ opts);
}
if (reopen_queue) {