static int raw_reopen_prepare(BDRVReopenState *state,

                              BlockReopenQueue *queue, Error **errp)

{

    BDRVRawState *s;

    BDRVRawReopenState *raw_s;

    int ret = 0;

    Error *local_err = NULL;



    assert(state != NULL);

    assert(state->bs != NULL);



    s = state->bs->opaque;



    state->opaque = g_malloc0(sizeof(BDRVRawReopenState));

    raw_s = state->opaque;



#ifdef CONFIG_LINUX_AIO

    raw_s->use_aio = s->use_aio;



    /* we can use s->aio_ctx instead of a copy, because the use_aio flag is

     * valid in the 'false' condition even if aio_ctx is set, and raw_set_aio()

     * won't override aio_ctx if aio_ctx is non-NULL */

    if (raw_set_aio(&s->aio_ctx, &raw_s->use_aio, state->flags)) {

        error_setg(errp, "Could not set AIO state");

        return -1;

    }

#endif



    if (s->type == FTYPE_FD || s->type == FTYPE_CD) {

        raw_s->open_flags |= O_NONBLOCK;

    }



    raw_parse_flags(state->flags, &raw_s->open_flags);



    raw_s->fd = -1;



    int fcntl_flags = O_APPEND | O_NONBLOCK;

#ifdef O_NOATIME

    fcntl_flags |= O_NOATIME;

#endif



#ifdef O_ASYNC

    /* Not all operating systems have O_ASYNC, and those that don't

     * will not let us track the state into raw_s->open_flags (typically

     * you achieve the same effect with an ioctl, for example I_SETSIG

     * on Solaris). But we do not use O_ASYNC, so that's fine.

     */

    assert((s->open_flags & O_ASYNC) == 0);

#endif



    if ((raw_s->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {

        /* dup the original fd */

        /* TODO: use qemu fcntl wrapper */

#ifdef F_DUPFD_CLOEXEC

        raw_s->fd = fcntl(s->fd, F_DUPFD_CLOEXEC, 0);

#else

        raw_s->fd = dup(s->fd);

        if (raw_s->fd != -1) {

            qemu_set_cloexec(raw_s->fd);

        }

#endif

        if (raw_s->fd >= 0) {

            ret = fcntl_setfl(raw_s->fd, raw_s->open_flags);

            if (ret) {

                qemu_close(raw_s->fd);

                raw_s->fd = -1;

            }

        }

    }



    /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */

    if (raw_s->fd == -1) {

        assert(!(raw_s->open_flags & O_CREAT));

        raw_s->fd = qemu_open(state->bs->filename, raw_s->open_flags);

        if (raw_s->fd == -1) {

            error_setg_errno(errp, errno, "Could not reopen file");

            ret = -1;

        }

    }



    /* Fail already reopen_prepare() if we can't get a working O_DIRECT

     * alignment with the new fd. */

    if (raw_s->fd != -1) {

        raw_probe_alignment(state->bs, raw_s->fd, &local_err);

        if (local_err) {

            qemu_close(raw_s->fd);

            raw_s->fd = -1;

            error_propagate(errp, local_err);

            ret = -EINVAL;

        }

    }



    return ret;

}

static int raw_reopen_prepare(BDRVReopenState *state,

                              BlockReopenQueue *queue, Error **errp)

{

    BDRVRawState *s;

    BDRVRawReopenState *raw_s;

    int ret = 0;

    Error *local_err = NULL;



    assert(state != NULL);

    assert(state->bs != NULL);



    s = state->bs->opaque;



    state->opaque = g_malloc0(sizeof(BDRVRawReopenState));

    raw_s = state->opaque;



#ifdef CONFIG_LINUX_AIO

    raw_s->use_aio = s->use_aio;



    





    if (raw_set_aio(&s->aio_ctx, &raw_s->use_aio, state->flags)) {

        error_setg(errp, "Could not set AIO state");

        return -1;

    }

#endif



    if (s->type == FTYPE_FD || s->type == FTYPE_CD) {

        raw_s->open_flags |= O_NONBLOCK;

    }



    raw_parse_flags(state->flags, &raw_s->open_flags);



    raw_s->fd = -1;



    int fcntl_flags = O_APPEND | O_NONBLOCK;

#ifdef O_NOATIME

    fcntl_flags |= O_NOATIME;

#endif



#ifdef O_ASYNC

    









    assert((s->open_flags & O_ASYNC) == 0);

#endif



    if ((raw_s->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {

        

        

#ifdef F_DUPFD_CLOEXEC

        raw_s->fd = fcntl(s->fd, F_DUPFD_CLOEXEC, 0);

#else

        raw_s->fd = dup(s->fd);

        if (raw_s->fd != -1) {

            qemu_set_cloexec(raw_s->fd);

        }

#endif

        if (raw_s->fd >= 0) {

            ret = fcntl_setfl(raw_s->fd, raw_s->open_flags);

            if (ret) {

                qemu_close(raw_s->fd);

                raw_s->fd = -1;

            }

        }

    }



    

    if (raw_s->fd == -1) {

        assert(!(raw_s->open_flags & O_CREAT));

        raw_s->fd = qemu_open(state->bs->filename, raw_s->open_flags);

        if (raw_s->fd == -1) {

            error_setg_errno(errp, errno, "Could not reopen file");

            ret = -1;

        }

    }



    



    if (raw_s->fd != -1) {

        raw_probe_alignment(state->bs, raw_s->fd, &local_err);

        if (local_err) {

            qemu_close(raw_s->fd);

            raw_s->fd = -1;

            error_propagate(errp, local_err);

            ret = -EINVAL;

        }

    }



    return ret;

}

    state->opaque = g_malloc0(sizeof(BDRVRawReopenState));
static int FUNC_0(BDRVReopenState *VAR_0,

                              BlockReopenQueue *VAR_1, Error **VAR_2)

{

    BDRVRawState *s;

    BDRVRawReopenState *raw_s;

    int VAR_3 = 0;

    Error *local_err = NULL;



    assert(VAR_0 != NULL);

    assert(VAR_0->bs != NULL);



    s = VAR_0->bs->opaque;



    VAR_0->opaque = g_malloc0(sizeof(BDRVRawReopenState));

    raw_s = VAR_0->opaque;



#ifdef CONFIG_LINUX_AIO

    raw_s->use_aio = s->use_aio;



    





    if (raw_set_aio(&s->aio_ctx, &raw_s->use_aio, VAR_0->flags)) {

        error_setg(VAR_2, "Could not set AIO VAR_0");

        return -1;

    }

#endif



    if (s->type == FTYPE_FD || s->type == FTYPE_CD) {

        raw_s->open_flags |= O_NONBLOCK;

    }



    raw_parse_flags(VAR_0->flags, &raw_s->open_flags);



    raw_s->fd = -1;



    int VAR_4 = O_APPEND | O_NONBLOCK;

#ifdef O_NOATIME

    VAR_4 |= O_NOATIME;

#endif



#ifdef O_ASYNC

    









    assert((s->open_flags & O_ASYNC) == 0);

#endif



    if ((raw_s->open_flags & ~VAR_4) == (s->open_flags & ~VAR_4)) {

        

        

#ifdef F_DUPFD_CLOEXEC

        raw_s->fd = fcntl(s->fd, F_DUPFD_CLOEXEC, 0);

#else

        raw_s->fd = dup(s->fd);

        if (raw_s->fd != -1) {

            qemu_set_cloexec(raw_s->fd);

        }

#endif

        if (raw_s->fd >= 0) {

            VAR_3 = fcntl_setfl(raw_s->fd, raw_s->open_flags);

            if (VAR_3) {

                qemu_close(raw_s->fd);

                raw_s->fd = -1;

            }

        }

    }



    

    if (raw_s->fd == -1) {

        assert(!(raw_s->open_flags & O_CREAT));

        raw_s->fd = qemu_open(VAR_0->bs->filename, raw_s->open_flags);

        if (raw_s->fd == -1) {

            error_setg_errno(VAR_2, errno, "Could not reopen file");

            VAR_3 = -1;

        }

    }



    



    if (raw_s->fd != -1) {

        raw_probe_alignment(VAR_0->bs, raw_s->fd, &local_err);

        if (local_err) {

            qemu_close(raw_s->fd);

            raw_s->fd = -1;

            error_propagate(VAR_2, local_err);

            VAR_3 = -EINVAL;

        }

    }



    return VAR_3;

}

static int FUNC_0(BDRVReopenState *VAR_0,
BlockReopenQueue *VAR_1, Error **VAR_2)
{ BDRVRawState *s; BDRVRawReopenState *raw_s; int VAR_3 = 0; Error *local_err = NULL; assert(VAR_0 != NULL); assert(VAR_0->bs != NULL); s = VAR_0->bs->opaque; VAR_0->opaque = g_malloc0(sizeof(BDRVRawReopenState)); raw_s = VAR_0->opaque; #ifdef CONFIG_LINUX_AIO
raw_s->use_aio = s->use_aio; if (raw_set_aio(&s->aio_ctx, &raw_s->use_aio, VAR_0->flags)) { error_setg(VAR_2, "Could not set AIO VAR_0"); return -1; } #endif
if (s->type == FTYPE_FD || s->type == FTYPE_CD) { raw_s->open_flags |= O_NONBLOCK; } raw_parse_flags(VAR_0->flags, &raw_s->open_flags); raw_s->fd = -1; int VAR_4 = O_APPEND | O_NONBLOCK; #ifdef O_NOATIME
VAR_4 |= O_NOATIME; #endif
#ifdef O_ASYNC
assert((s->open_flags & O_ASYNC) == 0); #endif
if ((raw_s->open_flags & ~VAR_4) == (s->open_flags & ~VAR_4)) { #ifdef F_DUPFD_CLOEXEC
raw_s->fd = fcntl(s->fd, F_DUPFD_CLOEXEC, 0); #else
raw_s->fd = dup(s->fd); if (raw_s->fd != -1) { qemu_set_cloexec(raw_s->fd); } #endif
if (raw_s->fd >= 0) { VAR_3 = fcntl_setfl(raw_s->fd, raw_s->open_flags); if (VAR_3) { qemu_close(raw_s->fd); raw_s->fd = -1; } } } if (raw_s->fd == -1) { assert(!(raw_s->open_flags & O_CREAT)); raw_s->fd = qemu_open(VAR_0->bs->filename, raw_s->open_flags); if (raw_s->fd == -1) { error_setg_errno(VAR_2, errno, "Could not reopen file"); VAR_3 = -1; } } if (raw_s->fd != -1) { raw_probe_alignment(VAR_0->bs, raw_s->fd, &local_err); if (local_err) { qemu_close(raw_s->fd); raw_s->fd = -1; error_propagate(VAR_2, local_err); VAR_3 = -EINVAL; } } return VAR_3; }