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

                  BlockDriverState *base, const char *backing_file_str,

                  int64_t speed, BlockdevOnError on_error, Error **errp)

{

    StreamBlockJob *s;

    BlockDriverState *iter;

    int orig_bs_flags;



    /* Make sure that the image is opened in read-write mode */

    orig_bs_flags = bdrv_get_flags(bs);

    if (!(orig_bs_flags & BDRV_O_RDWR)) {

        if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) {

            return;

        }

    }



    /* Prevent concurrent jobs trying to modify the graph structure here, we

     * already have our own plans. Also don't allow resize as the image size is

     * queried only at the job start and then cached. */

    s = block_job_create(job_id, &stream_job_driver, bs,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_GRAPH_MOD,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_WRITE,

                         speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);

    if (!s) {

        goto fail;

    }



    /* Block all intermediate nodes between bs and base, because they will

     * disappear from the chain after this operation. The streaming job reads

     * every block only once, assuming that it doesn't change, so block writes

     * and resizes. */

    for (iter = backing_bs(bs); iter && iter != base; iter = backing_bs(iter)) {

        block_job_add_bdrv(&s->common, "intermediate node", iter, 0,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,

                           &error_abort);

    }



    s->base = base;

    s->backing_file_str = g_strdup(backing_file_str);

    s->bs_flags = orig_bs_flags;



    s->on_error = on_error;

    trace_stream_start(bs, base, s);

    block_job_start(&s->common);

    return;



fail:

    if (orig_bs_flags != bdrv_get_flags(bs)) {

        bdrv_reopen(bs, s->bs_flags, NULL);

    }

}

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

                  BlockDriverState *base, const char *backing_file_str,

                  int64_t speed, BlockdevOnError on_error, Error **errp)

{

    StreamBlockJob *s;

    BlockDriverState *iter;

    int orig_bs_flags;



    

    orig_bs_flags = bdrv_get_flags(bs);

    if (!(orig_bs_flags & BDRV_O_RDWR)) {

        if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) {

            return;

        }

    }



    





    s = block_job_create(job_id, &stream_job_driver, bs,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_GRAPH_MOD,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_WRITE,

                         speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);

    if (!s) {

        goto fail;

    }



    







    for (iter = backing_bs(bs); iter && iter != base; iter = backing_bs(iter)) {

        block_job_add_bdrv(&s->common, "intermediate node", iter, 0,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,

                           &error_abort);

    }



    s->base = base;

    s->backing_file_str = g_strdup(backing_file_str);

    s->bs_flags = orig_bs_flags;



    s->on_error = on_error;

    trace_stream_start(bs, base, s);

    block_job_start(&s->common);

    return;



fail:

    if (orig_bs_flags != bdrv_get_flags(bs)) {

        bdrv_reopen(bs, s->bs_flags, NULL);

    }

}

        bdrv_reopen(bs, s->bs_flags, NULL);
void FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,

                  BlockDriverState *VAR_2, const char *VAR_3,

                  int64_t VAR_4, BlockdevOnError VAR_5, Error **VAR_6)

{

    StreamBlockJob *s;

    BlockDriverState *iter;

    int VAR_7;



    

    VAR_7 = bdrv_get_flags(VAR_1);

    if (!(VAR_7 & BDRV_O_RDWR)) {

        if (bdrv_reopen(VAR_1, VAR_7 | BDRV_O_RDWR, VAR_6) != 0) {

            return;

        }

    }



    





    s = block_job_create(VAR_0, &stream_job_driver, VAR_1,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_GRAPH_MOD,

                         BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |

                         BLK_PERM_WRITE,

                         VAR_4, BLOCK_JOB_DEFAULT, NULL, NULL, VAR_6);

    if (!s) {

        goto fail;

    }



    







    for (iter = backing_bs(VAR_1); iter && iter != VAR_2; iter = backing_bs(iter)) {

        block_job_add_bdrv(&s->common, "intermediate node", iter, 0,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,

                           &error_abort);

    }



    s->VAR_2 = VAR_2;

    s->VAR_3 = g_strdup(VAR_3);

    s->bs_flags = VAR_7;



    s->VAR_5 = VAR_5;

    trace_stream_start(VAR_1, VAR_2, s);

    block_job_start(&s->common);

    return;



fail:

    if (VAR_7 != bdrv_get_flags(VAR_1)) {

        bdrv_reopen(VAR_1, s->bs_flags, NULL);

    }

}

void FUNC_0(const char *VAR_0, BlockDriverState *VAR_1,
BlockDriverState *VAR_2, const char *VAR_3,
int64_t VAR_4, BlockdevOnError VAR_5, Error **VAR_6)
{ StreamBlockJob *s; BlockDriverState *iter; int VAR_7; VAR_7 = bdrv_get_flags(VAR_1); if (!(VAR_7 & BDRV_O_RDWR)) { if (bdrv_reopen(VAR_1, VAR_7 | BDRV_O_RDWR, VAR_6) != 0) { return; } } s = block_job_create(VAR_0, &stream_job_driver, VAR_1,
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
BLK_PERM_GRAPH_MOD,
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
BLK_PERM_WRITE,
VAR_4, BLOCK_JOB_DEFAULT, NULL, NULL, VAR_6); if (!s) { goto fail; } for (iter = backing_bs(VAR_1); iter && iter != VAR_2; iter = backing_bs(iter)) { block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,
&error_abort); } s->VAR_2 = VAR_2; s->VAR_3 = g_strdup(VAR_3); s->bs_flags = VAR_7; s->VAR_5 = VAR_5; trace_stream_start(VAR_1, VAR_2, s); block_job_start(&s->common); return; fail:
if (VAR_7 != bdrv_get_flags(VAR_1)) { bdrv_reopen(VAR_1, s->bs_flags, NULL); } }