static void buffered_flush(QEMUFileBuffered *s)

{

    size_t offset = 0;

    int error;



    error = qemu_file_get_error(s->file);

    if (error != 0) {

        DPRINTF("flush when error, bailing: %s\n", strerror(-error));

        return;

    }



    DPRINTF("flushing %zu byte(s) of data\n", s->buffer_size);



    while (s->bytes_xfer < s->xfer_limit && offset < s->buffer_size) {

        ssize_t ret;



        ret = migrate_fd_put_buffer(s->migration_state, s->buffer + offset,

                                    s->buffer_size - offset);

        if (ret == -EAGAIN) {

            DPRINTF("backend not ready, freezing\n");

            s->freeze_output = 1;

            break;

        }



        if (ret <= 0) {

            DPRINTF("error flushing data, %zd\n", ret);

            qemu_file_set_error(s->file, ret);

            break;

        } else {

            DPRINTF("flushed %zd byte(s)\n", ret);

            offset += ret;

            s->bytes_xfer += ret;

        }

    }



    DPRINTF("flushed %zu of %zu byte(s)\n", offset, s->buffer_size);

    memmove(s->buffer, s->buffer + offset, s->buffer_size - offset);

    s->buffer_size -= offset;

}

static void buffered_flush(QEMUFileBuffered *s)

{

    size_t offset = 0;

    int error;



    error = qemu_file_get_error(s->file);

    if (error != 0) {

        DPRINTF("flush when error, bailing: %s\n", strerror(-error));

        return;

    }



    DPRINTF("flushing %zu byte(s) of data\n", s->buffer_size);



    while (s->bytes_xfer < s->xfer_limit && offset < s->buffer_size) {

        ssize_t ret;



        ret = migrate_fd_put_buffer(s->migration_state, s->buffer + offset,

                                    s->buffer_size - offset);

        if (ret == -EAGAIN) {

            DPRINTF("backend not ready, freezing\n");

            s->freeze_output = 1;

            break;

        }



        if (ret <= 0) {

            DPRINTF("error flushing data, %zd\n", ret);

            qemu_file_set_error(s->file, ret);

            break;

        } else {

            DPRINTF("flushed %zd byte(s)\n", ret);

            offset += ret;

            s->bytes_xfer += ret;

        }

    }



    DPRINTF("flushed %zu of %zu byte(s)\n", offset, s->buffer_size);

    memmove(s->buffer, s->buffer + offset, s->buffer_size - offset);

    s->buffer_size -= offset;

}

static void FUNC_0(QEMUFileBuffered *VAR_0)

{

    size_t offset = 0;

    int VAR_1;



    VAR_1 = qemu_file_get_error(VAR_0->file);

    if (VAR_1 != 0) {

        DPRINTF("flush when VAR_1, bailing: %VAR_0\n", strerror(-VAR_1));

        return;

    }



    DPRINTF("flushing %zu byte(VAR_0) of data\n", VAR_0->buffer_size);



    while (VAR_0->bytes_xfer < VAR_0->xfer_limit && offset < VAR_0->buffer_size) {

        ssize_t ret;



        ret = migrate_fd_put_buffer(VAR_0->migration_state, VAR_0->buffer + offset,

                                    VAR_0->buffer_size - offset);

        if (ret == -EAGAIN) {

            DPRINTF("backend not ready, freezing\n");

            VAR_0->freeze_output = 1;

            break;

        }



        if (ret <= 0) {

            DPRINTF("VAR_1 flushing data, %zd\n", ret);

            qemu_file_set_error(VAR_0->file, ret);

            break;

        } else {

            DPRINTF("flushed %zd byte(VAR_0)\n", ret);

            offset += ret;

            VAR_0->bytes_xfer += ret;

        }

    }



    DPRINTF("flushed %zu of %zu byte(VAR_0)\n", offset, VAR_0->buffer_size);

    memmove(VAR_0->buffer, VAR_0->buffer + offset, VAR_0->buffer_size - offset);

    VAR_0->buffer_size -= offset;

}

static void FUNC_0(QEMUFileBuffered *VAR_0)
{ size_t offset = 0; int VAR_1; VAR_1 = qemu_file_get_error(VAR_0->file); if (VAR_1 != 0) { DPRINTF("flush when VAR_1, bailing: %VAR_0\n", strerror(-VAR_1)); return; } DPRINTF("flushing %zu byte(VAR_0) of data\n", VAR_0->buffer_size); while (VAR_0->bytes_xfer < VAR_0->xfer_limit && offset < VAR_0->buffer_size) { ssize_t ret; ret = migrate_fd_put_buffer(VAR_0->migration_state, VAR_0->buffer + offset,
VAR_0->buffer_size - offset); if (ret == -EAGAIN) { DPRINTF("backend not ready, freezing\n"); VAR_0->freeze_output = 1; break; } if (ret <= 0) { DPRINTF("VAR_1 flushing data, %zd\n", ret); qemu_file_set_error(VAR_0->file, ret); break; } else { DPRINTF("flushed %zd byte(VAR_0)\n", ret); offset += ret; VAR_0->bytes_xfer += ret; } } DPRINTF("flushed %zu of %zu byte(VAR_0)\n", offset, VAR_0->buffer_size); memmove(VAR_0->buffer, VAR_0->buffer + offset, VAR_0->buffer_size - offset); VAR_0->buffer_size -= offset; }