static void do_drive_backup(const char *job_id, const char *device,

                            const char *target, bool has_format,

                            const char *format, enum MirrorSyncMode sync,

                            bool has_mode, enum NewImageMode mode,

                            bool has_speed, int64_t speed,

                            bool has_bitmap, const char *bitmap,

                            bool has_on_source_error,

                            BlockdevOnError on_source_error,

                            bool has_on_target_error,

                            BlockdevOnError on_target_error,

                            BlockJobTxn *txn, Error **errp)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriverState *target_bs;

    BlockDriverState *source = NULL;

    BdrvDirtyBitmap *bmap = NULL;

    AioContext *aio_context;

    QDict *options = NULL;

    Error *local_err = NULL;

    int flags;

    int64_t size;



    if (!has_speed) {

        speed = 0;

    }

    if (!has_on_source_error) {

        on_source_error = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!has_on_target_error) {

        on_target_error = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!has_mode) {

        mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;

    }



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", device);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    /* Although backup_run has this check too, we need to use bs->drv below, so

     * do an early check redundantly. */

    if (!blk_is_available(blk)) {

        error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);

        goto out;

    }

    bs = blk_bs(blk);



    if (!has_format) {

        format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;

    }



    /* Early check to avoid creating target */

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

        goto out;

    }



    flags = bs->open_flags | BDRV_O_RDWR;



    /* See if we have a backing HD we can use to create our new image

     * on top of. */

    if (sync == MIRROR_SYNC_MODE_TOP) {

        source = backing_bs(bs);

        if (!source) {

            sync = MIRROR_SYNC_MODE_FULL;

        }

    }

    if (sync == MIRROR_SYNC_MODE_NONE) {

        source = bs;

    }



    size = bdrv_getlength(bs);

    if (size < 0) {

        error_setg_errno(errp, -size, "bdrv_getlength failed");

        goto out;

    }



    if (mode != NEW_IMAGE_MODE_EXISTING) {

        assert(format);

        if (source) {

            bdrv_img_create(target, format, source->filename,

                            source->drv->format_name, NULL,

                            size, flags, &local_err, false);

        } else {

            bdrv_img_create(target, format, NULL, NULL, NULL,

                            size, flags, &local_err, false);

        }

    }



    if (local_err) {

        error_propagate(errp, local_err);

        goto out;

    }



    if (format) {

        options = qdict_new();

        qdict_put(options, "driver", qstring_from_str(format));

    }



    target_bs = bdrv_open(target, NULL, options, flags, errp);

    if (!target_bs) {

        goto out;

    }



    bdrv_set_aio_context(target_bs, aio_context);



    if (has_bitmap) {

        bmap = bdrv_find_dirty_bitmap(bs, bitmap);

        if (!bmap) {

            error_setg(errp, "Bitmap '%s' could not be found", bitmap);

            bdrv_unref(target_bs);

            goto out;

        }

    }



    backup_start(job_id, bs, target_bs, speed, sync, bmap,

                 on_source_error, on_target_error,

                 block_job_cb, bs, txn, &local_err);

    bdrv_unref(target_bs);

    if (local_err != NULL) {

        error_propagate(errp, local_err);

        goto out;

    }



out:

    aio_context_release(aio_context);

}

static void do_drive_backup(const char *job_id, const char *device,

                            const char *target, bool has_format,

                            const char *format, enum MirrorSyncMode sync,

                            bool has_mode, enum NewImageMode mode,

                            bool has_speed, int64_t speed,

                            bool has_bitmap, const char *bitmap,

                            bool has_on_source_error,

                            BlockdevOnError on_source_error,

                            bool has_on_target_error,

                            BlockdevOnError on_target_error,

                            BlockJobTxn *txn, Error **errp)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriverState *target_bs;

    BlockDriverState *source = NULL;

    BdrvDirtyBitmap *bmap = NULL;

    AioContext *aio_context;

    QDict *options = NULL;

    Error *local_err = NULL;

    int flags;

    int64_t size;



    if (!has_speed) {

        speed = 0;

    }

    if (!has_on_source_error) {

        on_source_error = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!has_on_target_error) {

        on_target_error = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!has_mode) {

        mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;

    }



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", device);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    



    if (!blk_is_available(blk)) {

        error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);

        goto out;

    }

    bs = blk_bs(blk);



    if (!has_format) {

        format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;

    }



    

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

        goto out;

    }



    flags = bs->open_flags | BDRV_O_RDWR;



    



    if (sync == MIRROR_SYNC_MODE_TOP) {

        source = backing_bs(bs);

        if (!source) {

            sync = MIRROR_SYNC_MODE_FULL;

        }

    }

    if (sync == MIRROR_SYNC_MODE_NONE) {

        source = bs;

    }



    size = bdrv_getlength(bs);

    if (size < 0) {

        error_setg_errno(errp, -size, "bdrv_getlength failed");

        goto out;

    }



    if (mode != NEW_IMAGE_MODE_EXISTING) {

        assert(format);

        if (source) {

            bdrv_img_create(target, format, source->filename,

                            source->drv->format_name, NULL,

                            size, flags, &local_err, false);

        } else {

            bdrv_img_create(target, format, NULL, NULL, NULL,

                            size, flags, &local_err, false);

        }

    }



    if (local_err) {

        error_propagate(errp, local_err);

        goto out;

    }



    if (format) {

        options = qdict_new();

        qdict_put(options, "driver", qstring_from_str(format));

    }



    target_bs = bdrv_open(target, NULL, options, flags, errp);

    if (!target_bs) {

        goto out;

    }



    bdrv_set_aio_context(target_bs, aio_context);



    if (has_bitmap) {

        bmap = bdrv_find_dirty_bitmap(bs, bitmap);

        if (!bmap) {

            error_setg(errp, "Bitmap '%s' could not be found", bitmap);

            bdrv_unref(target_bs);

            goto out;

        }

    }



    backup_start(job_id, bs, target_bs, speed, sync, bmap,

                 on_source_error, on_target_error,

                 block_job_cb, bs, txn, &local_err);

    bdrv_unref(target_bs);

    if (local_err != NULL) {

        error_propagate(errp, local_err);

        goto out;

    }



out:

    aio_context_release(aio_context);

}

static void FUNC_0(const char *VAR_0, const char *VAR_1,

                            const char *VAR_2, bool VAR_3,

                            const char *VAR_4, enum MirrorSyncMode VAR_5,

                            bool VAR_6, enum NewImageMode VAR_7,

                            bool VAR_8, int64_t VAR_9,

                            bool VAR_10, const char *VAR_11,

                            bool VAR_12,

                            BlockdevOnError VAR_13,

                            bool VAR_14,

                            BlockdevOnError VAR_15,

                            BlockJobTxn *VAR_16, Error **VAR_17)

{

    BlockBackend *blk;

    BlockDriverState *bs;

    BlockDriverState *target_bs;

    BlockDriverState *source = NULL;

    BdrvDirtyBitmap *bmap = NULL;

    AioContext *aio_context;

    QDict *options = NULL;

    Error *local_err = NULL;

    int VAR_18;

    int64_t size;



    if (!VAR_8) {

        VAR_9 = 0;

    }

    if (!VAR_12) {

        VAR_13 = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!VAR_14) {

        VAR_15 = BLOCKDEV_ON_ERROR_REPORT;

    }

    if (!VAR_6) {

        VAR_7 = NEW_IMAGE_MODE_ABSOLUTE_PATHS;

    }



    blk = blk_by_name(VAR_1);

    if (!blk) {

        error_set(VAR_17, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", VAR_1);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    



    if (!blk_is_available(blk)) {

        error_setg(VAR_17, QERR_DEVICE_HAS_NO_MEDIUM, VAR_1);

        goto out;

    }

    bs = blk_bs(blk);



    if (!VAR_3) {

        VAR_4 = VAR_7 == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;

    }



    

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

        goto out;

    }



    VAR_18 = bs->open_flags | BDRV_O_RDWR;



    



    if (VAR_5 == MIRROR_SYNC_MODE_TOP) {

        source = backing_bs(bs);

        if (!source) {

            VAR_5 = MIRROR_SYNC_MODE_FULL;

        }

    }

    if (VAR_5 == MIRROR_SYNC_MODE_NONE) {

        source = bs;

    }



    size = bdrv_getlength(bs);

    if (size < 0) {

        error_setg_errno(VAR_17, -size, "bdrv_getlength failed");

        goto out;

    }



    if (VAR_7 != NEW_IMAGE_MODE_EXISTING) {

        assert(VAR_4);

        if (source) {

            bdrv_img_create(VAR_2, VAR_4, source->filename,

                            source->drv->format_name, NULL,

                            size, VAR_18, &local_err, false);

        } else {

            bdrv_img_create(VAR_2, VAR_4, NULL, NULL, NULL,

                            size, VAR_18, &local_err, false);

        }

    }



    if (local_err) {

        error_propagate(VAR_17, local_err);

        goto out;

    }



    if (VAR_4) {

        options = qdict_new();

        qdict_put(options, "driver", qstring_from_str(VAR_4));

    }



    target_bs = bdrv_open(VAR_2, NULL, options, VAR_18, VAR_17);

    if (!target_bs) {

        goto out;

    }



    bdrv_set_aio_context(target_bs, aio_context);



    if (VAR_10) {

        bmap = bdrv_find_dirty_bitmap(bs, VAR_11);

        if (!bmap) {

            error_setg(VAR_17, "Bitmap '%s' could not be found", VAR_11);

            bdrv_unref(target_bs);

            goto out;

        }

    }



    backup_start(VAR_0, bs, target_bs, VAR_9, VAR_5, bmap,

                 VAR_13, VAR_15,

                 block_job_cb, bs, VAR_16, &local_err);

    bdrv_unref(target_bs);

    if (local_err != NULL) {

        error_propagate(VAR_17, local_err);

        goto out;

    }



out:

    aio_context_release(aio_context);

}

static void FUNC_0(const char *VAR_0, const char *VAR_1,
const char *VAR_2, bool VAR_3,
const char *VAR_4, enum MirrorSyncMode VAR_5,
bool VAR_6, enum NewImageMode VAR_7,
bool VAR_8, int64_t VAR_9,
bool VAR_10, const char *VAR_11,
bool VAR_12,
BlockdevOnError VAR_13,
bool VAR_14,
BlockdevOnError VAR_15,
BlockJobTxn *VAR_16, Error **VAR_17)
{ BlockBackend *blk; BlockDriverState *bs; BlockDriverState *target_bs; BlockDriverState *source = NULL; BdrvDirtyBitmap *bmap = NULL; AioContext *aio_context; QDict *options = NULL; Error *local_err = NULL; int VAR_18; int64_t size; if (!VAR_8) { VAR_9 = 0; } if (!VAR_12) { VAR_13 = BLOCKDEV_ON_ERROR_REPORT; } if (!VAR_14) { VAR_15 = BLOCKDEV_ON_ERROR_REPORT; } if (!VAR_6) { VAR_7 = NEW_IMAGE_MODE_ABSOLUTE_PATHS; } blk = blk_by_name(VAR_1); if (!blk) { error_set(VAR_17, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", VAR_1); return; } aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); if (!blk_is_available(blk)) { error_setg(VAR_17, QERR_DEVICE_HAS_NO_MEDIUM, VAR_1); goto out; } bs = blk_bs(blk); if (!VAR_3) { VAR_4 = VAR_7 == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, VAR_17)) { goto out; } VAR_18 = bs->open_flags | BDRV_O_RDWR; if (VAR_5 == MIRROR_SYNC_MODE_TOP) { source = backing_bs(bs); if (!source) { VAR_5 = MIRROR_SYNC_MODE_FULL; } } if (VAR_5 == MIRROR_SYNC_MODE_NONE) { source = bs; } size = bdrv_getlength(bs); if (size < 0) { error_setg_errno(VAR_17, -size, "bdrv_getlength failed"); goto out; } if (VAR_7 != NEW_IMAGE_MODE_EXISTING) { assert(VAR_4); if (source) { bdrv_img_create(VAR_2, VAR_4, source->filename,
source->drv->format_name, NULL,
size, VAR_18, &local_err, false); } else { bdrv_img_create(VAR_2, VAR_4, NULL, NULL, NULL,
size, VAR_18, &local_err, false); } } if (local_err) { error_propagate(VAR_17, local_err); goto out; } if (VAR_4) { options = qdict_new(); qdict_put(options, "driver", qstring_from_str(VAR_4)); } target_bs = bdrv_open(VAR_2, NULL, options, VAR_18, VAR_17); if (!target_bs) { goto out; } bdrv_set_aio_context(target_bs, aio_context); if (VAR_10) { bmap = bdrv_find_dirty_bitmap(bs, VAR_11); if (!bmap) { error_setg(VAR_17, "Bitmap '%s' could not be found", VAR_11); bdrv_unref(target_bs); goto out; } } backup_start(VAR_0, bs, target_bs, VAR_9, VAR_5, bmap,
VAR_13, VAR_15,
block_job_cb, bs, VAR_16, &local_err); bdrv_unref(target_bs); if (local_err != NULL) { error_propagate(VAR_17, local_err); goto out; } out:
aio_context_release(aio_context); }