Hi Wen!

I'm trying to understand block/replication code and have a question.

Why should we block the region from intersecting cow requests when read? If I understand correctly

regardless of writes to the secondary-disk we have consistent view of it through hidden-disk:

Even if we are intersecting with some writes to secondary-disk (and corresponding cow-requests), the

data in secondary disk will not be updated until backed up to hidden-disk, therefore, for read we have two


1. read old data from secondary-disk (unallocated region in hidden-disk means data in secondary-disk is not updated yet)

2. read backed-up data from hidden-disk (data in secondary-disk may be already updated but we don't care)

(the whole region to read may consists of parts, corresponding to 1 or 2, but this should be ok too)

Where am I wrong?


static coroutine_fn int replication_co_readv(BlockDriverState *bs,
                                             int64_t sector_num,
                                             int remaining_sectors,
                                             QEMUIOVector *qiov)
    BDRVReplicationState *s = bs->opaque;
    BdrvChild *child = s->secondary_disk;
    BlockJob *job = NULL;
    CowRequest req;
    int ret;

    if (s->mode == REPLICATION_MODE_PRIMARY) {
        /* We only use it to forward primary write requests */
        return -EIO;

    ret = replication_get_io_status(s);
    if (ret < 0) {
        return ret;

    if (child && child->bs) {
        job = child->bs->job;

    if (job) {
        uint64_t remaining_bytes = remaining_sectors * BDRV_SECTOR_SIZE;

sector_num * BDRV_SECTOR_SIZE,
        backup_cow_request_begin(&req, child->bs->job,
                                 sector_num * BDRV_SECTOR_SIZE,
        ret = bdrv_co_readv(bs->file, sector_num, remaining_sectors,
        goto out;

    ret = bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov);
    return replication_return_value(s, ret);

Best regards,

Reply via email to