void backup_start(const char *job_id, BlockDriverState *bs,

                  BlockDriverState *target, int64_t speed,

                  MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap,

                  bool compress,

                  BlockdevOnError on_source_error,

                  BlockdevOnError on_target_error,

                  int creation_flags,

                  BlockCompletionFunc *cb, void *opaque,

                  BlockJobTxn *txn, Error **errp)

{

    int64_t len;

    BlockDriverInfo bdi;

    BackupBlockJob *job = NULL;

    int ret;



    assert(bs);

    assert(target);



    if (bs == target) {

        error_setg(errp, "Source and target cannot be the same");

        return;

    }



    if (!bdrv_is_inserted(bs)) {

        error_setg(errp, "Device is not inserted: %s",

                   bdrv_get_device_name(bs));

        return;

    }



    if (!bdrv_is_inserted(target)) {

        error_setg(errp, "Device is not inserted: %s",

                   bdrv_get_device_name(target));

        return;

    }



    if (compress && target->drv->bdrv_co_pwritev_compressed == NULL) {

        error_setg(errp, "Compression is not supported for this drive %s",

                   bdrv_get_device_name(target));

        return;

    }



    if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {

        return;

    }



    if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) {

        return;

    }



    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {

        if (!sync_bitmap) {

            error_setg(errp, "must provide a valid bitmap name for "

                             "\"incremental\" sync mode");

            return;

        }



        /* Create a new bitmap, and freeze/disable this one. */

        if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) {

            return;

        }

    } else if (sync_bitmap) {

        error_setg(errp,

                   "a sync_bitmap was provided to backup_run, "

                   "but received an incompatible sync_mode (%s)",

                   MirrorSyncMode_lookup[sync_mode]);

        return;

    }



    len = bdrv_getlength(bs);

    if (len < 0) {

        error_setg_errno(errp, -len, "unable to get length for '%s'",

                         bdrv_get_device_name(bs));

        goto error;

    }



    job = block_job_create(job_id, &backup_job_driver, bs, speed,

                           creation_flags, cb, opaque, errp);

    if (!job) {

        goto error;

    }



    job->target = blk_new();

    blk_insert_bs(job->target, target);



    job->on_source_error = on_source_error;

    job->on_target_error = on_target_error;

    job->sync_mode = sync_mode;

    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?

                       sync_bitmap : NULL;

    job->compress = compress;



    /* If there is no backing file on the target, we cannot rely on COW if our

     * backup cluster size is smaller than the target cluster size. Even for

     * targets with a backing file, try to avoid COW if possible. */

    ret = bdrv_get_info(target, &bdi);

    if (ret < 0 && !target->backing) {

        error_setg_errno(errp, -ret,

            "Couldn't determine the cluster size of the target image, "

            "which has no backing file");

        error_append_hint(errp,

            "Aborting, since this may create an unusable destination image\n");

        goto error;

    } else if (ret < 0 && target->backing) {

        /* Not fatal; just trudge on ahead. */

        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;

    } else {

        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);

    }



    block_job_add_bdrv(&job->common, target);

    job->common.len = len;

    job->common.co = qemu_coroutine_create(backup_run, job);

    block_job_txn_add_job(txn, &job->common);

    qemu_coroutine_enter(job->common.co);

    return;



 error:

    if (sync_bitmap) {

        bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);

    }

    if (job) {

        blk_unref(job->target);

        block_job_unref(&job->common);

    }

}

void backup_start(const char *job_id, BlockDriverState *bs,

                  BlockDriverState *target, int64_t speed,

                  MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap,

                  bool compress,

                  BlockdevOnError on_source_error,

                  BlockdevOnError on_target_error,

                  int creation_flags,

                  BlockCompletionFunc *cb, void *opaque,

                  BlockJobTxn *txn, Error **errp)

{

    int64_t len;

    BlockDriverInfo bdi;

    BackupBlockJob *job = NULL;

    int ret;



    assert(bs);

    assert(target);



    if (bs == target) {

        error_setg(errp, "Source and target cannot be the same");

        return;

    }



    if (!bdrv_is_inserted(bs)) {

        error_setg(errp, "Device is not inserted: %s",

                   bdrv_get_device_name(bs));

        return;

    }



    if (!bdrv_is_inserted(target)) {

        error_setg(errp, "Device is not inserted: %s",

                   bdrv_get_device_name(target));

        return;

    }



    if (compress && target->drv->bdrv_co_pwritev_compressed == NULL) {

        error_setg(errp, "Compression is not supported for this drive %s",

                   bdrv_get_device_name(target));

        return;

    }



    if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {

        return;

    }



    if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) {

        return;

    }



    if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {

        if (!sync_bitmap) {

            error_setg(errp, "must provide a valid bitmap name for "

                             "\"incremental\" sync mode");

            return;

        }



        

        if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) {

            return;

        }

    } else if (sync_bitmap) {

        error_setg(errp,

                   "a sync_bitmap was provided to backup_run, "

                   "but received an incompatible sync_mode (%s)",

                   MirrorSyncMode_lookup[sync_mode]);

        return;

    }



    len = bdrv_getlength(bs);

    if (len < 0) {

        error_setg_errno(errp, -len, "unable to get length for '%s'",

                         bdrv_get_device_name(bs));

        goto error;

    }



    job = block_job_create(job_id, &backup_job_driver, bs, speed,

                           creation_flags, cb, opaque, errp);

    if (!job) {

        goto error;

    }



    job->target = blk_new();

    blk_insert_bs(job->target, target);



    job->on_source_error = on_source_error;

    job->on_target_error = on_target_error;

    job->sync_mode = sync_mode;

    job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ?

                       sync_bitmap : NULL;

    job->compress = compress;



    





    ret = bdrv_get_info(target, &bdi);

    if (ret < 0 && !target->backing) {

        error_setg_errno(errp, -ret,

            "Couldn't determine the cluster size of the target image, "

            "which has no backing file");

        error_append_hint(errp,

            "Aborting, since this may create an unusable destination image\n");

        goto error;

    } else if (ret < 0 && target->backing) {

        

        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;

    } else {

        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);

    }



    block_job_add_bdrv(&job->common, target);

    job->common.len = len;

    job->common.co = qemu_coroutine_create(backup_run, job);

    block_job_txn_add_job(txn, &job->common);

    qemu_coroutine_enter(job->common.co);

    return;



 error:

    if (sync_bitmap) {

        bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);

    }

    if (job) {

        blk_unref(job->target);

        block_job_unref(&job->common);

    }

}

        blk_unref(job->target);
void FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,

                  BlockDriverState *VAR_2, int64_t VAR_3,

                  MirrorSyncMode VAR_4, BdrvDirtyBitmap *VAR_5,

                  bool VAR_6,

                  BlockdevOnError VAR_7,

                  BlockdevOnError VAR_8,

                  int VAR_9,

                  BlockCompletionFunc *VAR_10, void *VAR_11,

                  BlockJobTxn *VAR_12, Error **VAR_13)

{

    int64_t len;

    BlockDriverInfo bdi;

    BackupBlockJob *job = NULL;

    int VAR_14;



    assert(VAR_1);

    assert(VAR_2);



    if (VAR_1 == VAR_2) {

        error_setg(VAR_13, "Source and VAR_2 cannot be the same");

        return;

    }



    if (!bdrv_is_inserted(VAR_1)) {

        error_setg(VAR_13, "Device is not inserted: %s",

                   bdrv_get_device_name(VAR_1));

        return;

    }



    if (!bdrv_is_inserted(VAR_2)) {

        error_setg(VAR_13, "Device is not inserted: %s",

                   bdrv_get_device_name(VAR_2));

        return;

    }



    if (VAR_6 && VAR_2->drv->bdrv_co_pwritev_compressed == NULL) {

        error_setg(VAR_13, "Compression is not supported for this drive %s",

                   bdrv_get_device_name(VAR_2));

        return;

    }



    if (bdrv_op_is_blocked(VAR_1, BLOCK_OP_TYPE_BACKUP_SOURCE, VAR_13)) {

        return;

    }



    if (bdrv_op_is_blocked(VAR_2, BLOCK_OP_TYPE_BACKUP_TARGET, VAR_13)) {

        return;

    }



    if (VAR_4 == MIRROR_SYNC_MODE_INCREMENTAL) {

        if (!VAR_5) {

            error_setg(VAR_13, "must provide a valid bitmap name for "

                             "\"incremental\" sync mode");

            return;

        }



        

        if (bdrv_dirty_bitmap_create_successor(VAR_1, VAR_5, VAR_13) < 0) {

            return;

        }

    } else if (VAR_5) {

        error_setg(VAR_13,

                   "a VAR_5 was provided to backup_run, "

                   "but received an incompatible VAR_4 (%s)",

                   MirrorSyncMode_lookup[VAR_4]);

        return;

    }



    len = bdrv_getlength(VAR_1);

    if (len < 0) {

        error_setg_errno(VAR_13, -len, "unable to get length for '%s'",

                         bdrv_get_device_name(VAR_1));

        goto error;

    }



    job = block_job_create(VAR_0, &backup_job_driver, VAR_1, VAR_3,

                           VAR_9, VAR_10, VAR_11, VAR_13);

    if (!job) {

        goto error;

    }



    job->VAR_2 = blk_new();

    blk_insert_bs(job->VAR_2, VAR_2);



    job->VAR_7 = VAR_7;

    job->VAR_8 = VAR_8;

    job->VAR_4 = VAR_4;

    job->VAR_5 = VAR_4 == MIRROR_SYNC_MODE_INCREMENTAL ?

                       VAR_5 : NULL;

    job->VAR_6 = VAR_6;



    





    VAR_14 = bdrv_get_info(VAR_2, &bdi);

    if (VAR_14 < 0 && !VAR_2->backing) {

        error_setg_errno(VAR_13, -VAR_14,

            "Couldn't determine the cluster size of the VAR_2 image, "

            "which has no backing file");

        error_append_hint(VAR_13,

            "Aborting, since this may create an unusable destination image\n");

        goto error;

    } else if (VAR_14 < 0 && VAR_2->backing) {

        

        job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;

    } else {

        job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);

    }



    block_job_add_bdrv(&job->common, VAR_2);

    job->common.len = len;

    job->common.co = qemu_coroutine_create(backup_run, job);

    block_job_txn_add_job(VAR_12, &job->common);

    qemu_coroutine_enter(job->common.co);

    return;



 error:

    if (VAR_5) {

        bdrv_reclaim_dirty_bitmap(VAR_1, VAR_5, NULL);

    }

    if (job) {

        blk_unref(job->VAR_2);

        block_job_unref(&job->common);

    }

}

void FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,
BlockDriverState *VAR_2, int64_t VAR_3,
MirrorSyncMode VAR_4, BdrvDirtyBitmap *VAR_5,
bool VAR_6,
BlockdevOnError VAR_7,
BlockdevOnError VAR_8,
int VAR_9,
BlockCompletionFunc *VAR_10, void *VAR_11,
BlockJobTxn *VAR_12, Error **VAR_13)
{ int64_t len; BlockDriverInfo bdi; BackupBlockJob *job = NULL; int VAR_14; assert(VAR_1); assert(VAR_2); if (VAR_1 == VAR_2) { error_setg(VAR_13, "Source and VAR_2 cannot be the same"); return; } if (!bdrv_is_inserted(VAR_1)) { error_setg(VAR_13, "Device is not inserted: %s",
bdrv_get_device_name(VAR_1)); return; } if (!bdrv_is_inserted(VAR_2)) { error_setg(VAR_13, "Device is not inserted: %s",
bdrv_get_device_name(VAR_2)); return; } if (VAR_6 && VAR_2->drv->bdrv_co_pwritev_compressed == NULL) { error_setg(VAR_13, "Compression is not supported for this drive %s",
bdrv_get_device_name(VAR_2)); return; } if (bdrv_op_is_blocked(VAR_1, BLOCK_OP_TYPE_BACKUP_SOURCE, VAR_13)) { return; } if (bdrv_op_is_blocked(VAR_2, BLOCK_OP_TYPE_BACKUP_TARGET, VAR_13)) { return; } if (VAR_4 == MIRROR_SYNC_MODE_INCREMENTAL) { if (!VAR_5) { error_setg(VAR_13, "must provide a valid bitmap name for "
"\"incremental\" sync mode"); return; } if (bdrv_dirty_bitmap_create_successor(VAR_1, VAR_5, VAR_13) < 0) { return; } } else if (VAR_5) { error_setg(VAR_13,
"a VAR_5 was provided to backup_run, "
"but received an incompatible VAR_4 (%s)",
MirrorSyncMode_lookup[VAR_4]); return; } len = bdrv_getlength(VAR_1); if (len < 0) { error_setg_errno(VAR_13, -len, "unable to get length for '%s'",
bdrv_get_device_name(VAR_1)); goto error; } job = block_job_create(VAR_0, &backup_job_driver, VAR_1, VAR_3,
VAR_9, VAR_10, VAR_11, VAR_13); if (!job) { goto error; } job->VAR_2 = blk_new(); blk_insert_bs(job->VAR_2, VAR_2); job->VAR_7 = VAR_7; job->VAR_8 = VAR_8; job->VAR_4 = VAR_4; job->VAR_5 = VAR_4 == MIRROR_SYNC_MODE_INCREMENTAL ?
VAR_5 : NULL; job->VAR_6 = VAR_6; VAR_14 = bdrv_get_info(VAR_2, &bdi); if (VAR_14 < 0 && !VAR_2->backing) { error_setg_errno(VAR_13, -VAR_14,
"Couldn't determine the cluster size of the VAR_2 image, "
"which has no backing file"); error_append_hint(VAR_13,
"Aborting, since this may create an unusable destination image\n"); goto error; } else if (VAR_14 < 0 && VAR_2->backing) { job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT; } else { job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size); } block_job_add_bdrv(&job->common, VAR_2); job->common.len = len; job->common.co = qemu_coroutine_create(backup_run, job); block_job_txn_add_job(VAR_12, &job->common); qemu_coroutine_enter(job->common.co); return; error:
if (VAR_5) { bdrv_reclaim_dirty_bitmap(VAR_1, VAR_5, NULL); } if (job) { blk_unref(job->VAR_2); block_job_unref(&job->common); } }