int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)

{

    int ret;

    const char *type;



    ret = nbd_read_eof(ioc, &reply->magic, sizeof(reply->magic), errp);

    if (ret <= 0) {

        return ret;

    }



    be32_to_cpus(&reply->magic);



    switch (reply->magic) {

    case NBD_SIMPLE_REPLY_MAGIC:

        ret = nbd_receive_simple_reply(ioc, &reply->simple, errp);

        if (ret < 0) {

            break;

        }



        trace_nbd_receive_simple_reply(reply->simple.error,

                                       nbd_err_lookup(reply->simple.error),

                                       reply->handle);

        if (reply->simple.error == NBD_ESHUTDOWN) {

            /* This works even on mingw which lacks a native ESHUTDOWN */

            error_setg(errp, "server shutting down");

            return -EINVAL;

        }

        break;

    case NBD_STRUCTURED_REPLY_MAGIC:

        ret = nbd_receive_structured_reply_chunk(ioc, &reply->structured, errp);

        if (ret < 0) {

            break;

        }

        type = nbd_reply_type_lookup(reply->structured.type);

        trace_nbd_receive_structured_reply_chunk(reply->structured.flags,

                                                 reply->structured.type, type,

                                                 reply->structured.handle,

                                                 reply->structured.length);

        break;

    default:

        error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", reply->magic);

        return -EINVAL;

    }

    if (ret < 0) {

        return ret;

    }



    return 1;

}

int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)

{

    int ret;

    const char *type;



    ret = nbd_read_eof(ioc, &reply->magic, sizeof(reply->magic), errp);

    if (ret <= 0) {

        return ret;

    }



    be32_to_cpus(&reply->magic);



    switch (reply->magic) {

    case NBD_SIMPLE_REPLY_MAGIC:

        ret = nbd_receive_simple_reply(ioc, &reply->simple, errp);

        if (ret < 0) {

            break;

        }



        trace_nbd_receive_simple_reply(reply->simple.error,

                                       nbd_err_lookup(reply->simple.error),

                                       reply->handle);

        if (reply->simple.error == NBD_ESHUTDOWN) {

            

            error_setg(errp, "server shutting down");

            return -EINVAL;

        }

        break;

    case NBD_STRUCTURED_REPLY_MAGIC:

        ret = nbd_receive_structured_reply_chunk(ioc, &reply->structured, errp);

        if (ret < 0) {

            break;

        }

        type = nbd_reply_type_lookup(reply->structured.type);

        trace_nbd_receive_structured_reply_chunk(reply->structured.flags,

                                                 reply->structured.type, type,

                                                 reply->structured.handle,

                                                 reply->structured.length);

        break;

    default:

        error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", reply->magic);

        return -EINVAL;

    }

    if (ret < 0) {

        return ret;

    }



    return 1;

}

        if (reply->simple.error == NBD_ESHUTDOWN) {             error_setg(errp, "server shutting down");             return -EINVAL;
int FUNC_0(QIOChannel *VAR_0, NBDReply *VAR_1, Error **VAR_2)

{

    int VAR_3;

    const char *VAR_4;



    VAR_3 = nbd_read_eof(VAR_0, &VAR_1->magic, sizeof(VAR_1->magic), VAR_2);

    if (VAR_3 <= 0) {

        return VAR_3;

    }



    be32_to_cpus(&VAR_1->magic);



    switch (VAR_1->magic) {

    case NBD_SIMPLE_REPLY_MAGIC:

        VAR_3 = nbd_receive_simple_reply(VAR_0, &VAR_1->simple, VAR_2);

        if (VAR_3 < 0) {

            break;

        }



        trace_nbd_receive_simple_reply(VAR_1->simple.error,

                                       nbd_err_lookup(VAR_1->simple.error),

                                       VAR_1->handle);

        if (VAR_1->simple.error == NBD_ESHUTDOWN) {

            

            error_setg(VAR_2, "server shutting down");

            return -EINVAL;

        }

        break;

    case NBD_STRUCTURED_REPLY_MAGIC:

        VAR_3 = nbd_receive_structured_reply_chunk(VAR_0, &VAR_1->structured, VAR_2);

        if (VAR_3 < 0) {

            break;

        }

        VAR_4 = nbd_reply_type_lookup(VAR_1->structured.VAR_4);

        trace_nbd_receive_structured_reply_chunk(VAR_1->structured.flags,

                                                 VAR_1->structured.VAR_4, VAR_4,

                                                 VAR_1->structured.handle,

                                                 VAR_1->structured.length);

        break;

    default:

        error_setg(VAR_2, "invalid magic (got 0x%" PRIx32 ")", VAR_1->magic);

        return -EINVAL;

    }

    if (VAR_3 < 0) {

        return VAR_3;

    }



    return 1;

}

int FUNC_0(QIOChannel *VAR_0, NBDReply *VAR_1, Error **VAR_2)
{ int VAR_3; const char *VAR_4; VAR_3 = nbd_read_eof(VAR_0, &VAR_1->magic, sizeof(VAR_1->magic), VAR_2); if (VAR_3 <= 0) { return VAR_3; } be32_to_cpus(&VAR_1->magic); switch (VAR_1->magic) { case NBD_SIMPLE_REPLY_MAGIC:
VAR_3 = nbd_receive_simple_reply(VAR_0, &VAR_1->simple, VAR_2); if (VAR_3 < 0) { break; } trace_nbd_receive_simple_reply(VAR_1->simple.error,
nbd_err_lookup(VAR_1->simple.error),
VAR_1->handle); if (VAR_1->simple.error == NBD_ESHUTDOWN) { error_setg(VAR_2, "server shutting down"); return -EINVAL; } break; case NBD_STRUCTURED_REPLY_MAGIC:
VAR_3 = nbd_receive_structured_reply_chunk(VAR_0, &VAR_1->structured, VAR_2); if (VAR_3 < 0) { break; } VAR_4 = nbd_reply_type_lookup(VAR_1->structured.VAR_4); trace_nbd_receive_structured_reply_chunk(VAR_1->structured.flags,
VAR_1->structured.VAR_4, VAR_4,
VAR_1->structured.handle,
VAR_1->structured.length); break; default:
error_setg(VAR_2, "invalid magic (got 0x%" PRIx32 ")", VAR_1->magic); return -EINVAL; } if (VAR_3 < 0) { return VAR_3; } return 1; }