void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)

{

    BlockDriverState tmp;



    /* The code needs to swap the node_name but simply swapping node_list won't

     * work so first remove the nodes from the graph list, do the swap then

     * insert them back if needed.

     */

    if (bs_new->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, bs_new, node_list);

    }

    if (bs_old->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);

    }



    /* bs_new must be anonymous and shouldn't have anything fancy enabled */

    assert(bs_new->device_name[0] == '\0');

    assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));

    assert(bs_new->job == NULL);

    assert(bs_new->dev == NULL);

    assert(bdrv_op_blocker_is_empty(bs_new));

    assert(bs_new->io_limits_enabled == false);

    assert(!throttle_have_timer(&bs_new->throttle_state));



    tmp = *bs_new;

    *bs_new = *bs_old;

    *bs_old = tmp;



    /* there are some fields that should not be swapped, move them back */

    bdrv_move_feature_fields(&tmp, bs_old);

    bdrv_move_feature_fields(bs_old, bs_new);

    bdrv_move_feature_fields(bs_new, &tmp);



    /* bs_new shouldn't be in bdrv_states even after the swap!  */

    assert(bs_new->device_name[0] == '\0');



    /* Check a few fields that should remain attached to the device */

    assert(bs_new->dev == NULL);

    assert(bs_new->job == NULL);

    assert(bdrv_op_blocker_is_empty(bs_new));

    assert(bs_new->io_limits_enabled == false);

    assert(!throttle_have_timer(&bs_new->throttle_state));



    /* insert the nodes back into the graph node list if needed */

    if (bs_new->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_new, node_list);

    }

    if (bs_old->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list);

    }



    bdrv_rebind(bs_new);

    bdrv_rebind(bs_old);

}

void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)

{

    BlockDriverState tmp;



    







    if (bs_new->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, bs_new, node_list);

    }

    if (bs_old->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);

    }



    

    assert(bs_new->device_name[0] == '\0');

    assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));

    assert(bs_new->job == NULL);

    assert(bs_new->dev == NULL);

    assert(bdrv_op_blocker_is_empty(bs_new));

    assert(bs_new->io_limits_enabled == false);

    assert(!throttle_have_timer(&bs_new->throttle_state));



    tmp = *bs_new;

    *bs_new = *bs_old;

    *bs_old = tmp;



    

    bdrv_move_feature_fields(&tmp, bs_old);

    bdrv_move_feature_fields(bs_old, bs_new);

    bdrv_move_feature_fields(bs_new, &tmp);



    

    assert(bs_new->device_name[0] == '\0');



    

    assert(bs_new->dev == NULL);

    assert(bs_new->job == NULL);

    assert(bdrv_op_blocker_is_empty(bs_new));

    assert(bs_new->io_limits_enabled == false);

    assert(!throttle_have_timer(&bs_new->throttle_state));



    

    if (bs_new->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_new, node_list);

    }

    if (bs_old->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list);

    }



    bdrv_rebind(bs_new);

    bdrv_rebind(bs_old);

}

void FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1)

{

    BlockDriverState tmp;



    







    if (VAR_0->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, VAR_0, node_list);

    }

    if (VAR_1->node_name[0] != '\0') {

        QTAILQ_REMOVE(&graph_bdrv_states, VAR_1, node_list);

    }



    

    assert(VAR_0->device_name[0] == '\0');

    assert(QLIST_EMPTY(&VAR_0->dirty_bitmaps));

    assert(VAR_0->job == NULL);

    assert(VAR_0->dev == NULL);

    assert(bdrv_op_blocker_is_empty(VAR_0));

    assert(VAR_0->io_limits_enabled == false);

    assert(!throttle_have_timer(&VAR_0->throttle_state));



    tmp = *VAR_0;

    *VAR_0 = *VAR_1;

    *VAR_1 = tmp;



    

    bdrv_move_feature_fields(&tmp, VAR_1);

    bdrv_move_feature_fields(VAR_1, VAR_0);

    bdrv_move_feature_fields(VAR_0, &tmp);



    

    assert(VAR_0->device_name[0] == '\0');



    

    assert(VAR_0->dev == NULL);

    assert(VAR_0->job == NULL);

    assert(bdrv_op_blocker_is_empty(VAR_0));

    assert(VAR_0->io_limits_enabled == false);

    assert(!throttle_have_timer(&VAR_0->throttle_state));



    

    if (VAR_0->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, VAR_0, node_list);

    }

    if (VAR_1->node_name[0] != '\0') {

        QTAILQ_INSERT_TAIL(&graph_bdrv_states, VAR_1, node_list);

    }



    bdrv_rebind(VAR_0);

    bdrv_rebind(VAR_1);

}

void FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1)
{ BlockDriverState tmp; if (VAR_0->node_name[0] != '\0') { QTAILQ_REMOVE(&graph_bdrv_states, VAR_0, node_list); } if (VAR_1->node_name[0] != '\0') { QTAILQ_REMOVE(&graph_bdrv_states, VAR_1, node_list); } assert(VAR_0->device_name[0] == '\0'); assert(QLIST_EMPTY(&VAR_0->dirty_bitmaps)); assert(VAR_0->job == NULL); assert(VAR_0->dev == NULL); assert(bdrv_op_blocker_is_empty(VAR_0)); assert(VAR_0->io_limits_enabled == false); assert(!throttle_have_timer(&VAR_0->throttle_state)); tmp = *VAR_0; *VAR_0 = *VAR_1; *VAR_1 = tmp; bdrv_move_feature_fields(&tmp, VAR_1); bdrv_move_feature_fields(VAR_1, VAR_0); bdrv_move_feature_fields(VAR_0, &tmp); assert(VAR_0->device_name[0] == '\0'); assert(VAR_0->dev == NULL); assert(VAR_0->job == NULL); assert(bdrv_op_blocker_is_empty(VAR_0)); assert(VAR_0->io_limits_enabled == false); assert(!throttle_have_timer(&VAR_0->throttle_state)); if (VAR_0->node_name[0] != '\0') { QTAILQ_INSERT_TAIL(&graph_bdrv_states, VAR_0, node_list); } if (VAR_1->node_name[0] != '\0') { QTAILQ_INSERT_TAIL(&graph_bdrv_states, VAR_1, node_list); } bdrv_rebind(VAR_0); bdrv_rebind(VAR_1); }