static int nbd_handle_reply_err(QIOChannel *ioc, nbd_opt_reply *reply,

                                Error **errp)

{

    char *msg = NULL;

    int result = -1;



    if (!(reply->type & (1 << 31))) {

        return 1;

    }



    if (reply->length) {

        if (reply->length > NBD_MAX_BUFFER_SIZE) {

            error_setg(errp, "server's error message is too long");

            goto cleanup;

        }

        msg = g_malloc(reply->length + 1);

        if (read_sync(ioc, msg, reply->length, errp) < 0) {

            error_prepend(errp, "failed to read option error message");

            goto cleanup;

        }

        msg[reply->length] = '\0';

    }



    switch (reply->type) {

    case NBD_REP_ERR_UNSUP:

        TRACE("server doesn't understand request %" PRIx32

              ", attempting fallback", reply->option);

        result = 0;

        goto cleanup;



    case NBD_REP_ERR_POLICY:

        error_setg(errp, "Denied by server for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_INVALID:

        error_setg(errp, "Invalid data length for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_PLATFORM:

        error_setg(errp, "Server lacks support for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_TLS_REQD:

        error_setg(errp, "TLS negotiation required before option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_SHUTDOWN:

        error_setg(errp, "Server shutting down before option %" PRIx32,

                   reply->option);

        break;



    default:

        error_setg(errp, "Unknown error code when asking for option %" PRIx32,

                   reply->option);

        break;

    }



    if (msg) {

        error_append_hint(errp, "%s\n", msg);

    }



 cleanup:

    g_free(msg);

    if (result < 0) {

        nbd_send_opt_abort(ioc);

    }

    return result;

}

static int nbd_handle_reply_err(QIOChannel *ioc, nbd_opt_reply *reply,

                                Error **errp)

{

    char *msg = NULL;

    int result = -1;



    if (!(reply->type & (1 << 31))) {

        return 1;

    }



    if (reply->length) {

        if (reply->length > NBD_MAX_BUFFER_SIZE) {

            error_setg(errp, "server's error message is too long");

            goto cleanup;

        }

        msg = g_malloc(reply->length + 1);

        if (read_sync(ioc, msg, reply->length, errp) < 0) {

            error_prepend(errp, "failed to read option error message");

            goto cleanup;

        }

        msg[reply->length] = '\0';

    }



    switch (reply->type) {

    case NBD_REP_ERR_UNSUP:

        TRACE("server doesn't understand request %" PRIx32

              ", attempting fallback", reply->option);

        result = 0;

        goto cleanup;



    case NBD_REP_ERR_POLICY:

        error_setg(errp, "Denied by server for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_INVALID:

        error_setg(errp, "Invalid data length for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_PLATFORM:

        error_setg(errp, "Server lacks support for option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_TLS_REQD:

        error_setg(errp, "TLS negotiation required before option %" PRIx32,

                   reply->option);

        break;



    case NBD_REP_ERR_SHUTDOWN:

        error_setg(errp, "Server shutting down before option %" PRIx32,

                   reply->option);

        break;



    default:

        error_setg(errp, "Unknown error code when asking for option %" PRIx32,

                   reply->option);

        break;

    }



    if (msg) {

        error_append_hint(errp, "%s\n", msg);

    }



 cleanup:

    g_free(msg);

    if (result < 0) {

        nbd_send_opt_abort(ioc);

    }

    return result;

}

static int FUNC_0(QIOChannel *VAR_0, nbd_opt_reply *VAR_1,

                                Error **VAR_2)

{

    char *VAR_3 = NULL;

    int VAR_4 = -1;



    if (!(VAR_1->type & (1 << 31))) {

        return 1;

    }



    if (VAR_1->length) {

        if (VAR_1->length > NBD_MAX_BUFFER_SIZE) {

            error_setg(VAR_2, "server's error message is too long");

            goto cleanup;

        }

        VAR_3 = g_malloc(VAR_1->length + 1);

        if (read_sync(VAR_0, VAR_3, VAR_1->length, VAR_2) < 0) {

            error_prepend(VAR_2, "failed to read option error message");

            goto cleanup;

        }

        VAR_3[VAR_1->length] = '\0';

    }



    switch (VAR_1->type) {

    case NBD_REP_ERR_UNSUP:

        TRACE("server doesn't understand request %" PRIx32

              ", attempting fallback", VAR_1->option);

        VAR_4 = 0;

        goto cleanup;



    case NBD_REP_ERR_POLICY:

        error_setg(VAR_2, "Denied by server for option %" PRIx32,

                   VAR_1->option);

        break;



    case NBD_REP_ERR_INVALID:

        error_setg(VAR_2, "Invalid data length for option %" PRIx32,

                   VAR_1->option);

        break;



    case NBD_REP_ERR_PLATFORM:

        error_setg(VAR_2, "Server lacks support for option %" PRIx32,

                   VAR_1->option);

        break;



    case NBD_REP_ERR_TLS_REQD:

        error_setg(VAR_2, "TLS negotiation required before option %" PRIx32,

                   VAR_1->option);

        break;



    case NBD_REP_ERR_SHUTDOWN:

        error_setg(VAR_2, "Server shutting down before option %" PRIx32,

                   VAR_1->option);

        break;



    default:

        error_setg(VAR_2, "Unknown error code when asking for option %" PRIx32,

                   VAR_1->option);

        break;

    }



    if (VAR_3) {

        error_append_hint(VAR_2, "%s\n", VAR_3);

    }



 cleanup:

    g_free(VAR_3);

    if (VAR_4 < 0) {

        nbd_send_opt_abort(VAR_0);

    }

    return VAR_4;

}

static int FUNC_0(QIOChannel *VAR_0, nbd_opt_reply *VAR_1,
Error **VAR_2)
{ char *VAR_3 = NULL; int VAR_4 = -1; if (!(VAR_1->type & (1 << 31))) { return 1; } if (VAR_1->length) { if (VAR_1->length > NBD_MAX_BUFFER_SIZE) { error_setg(VAR_2, "server's error message is too long"); goto cleanup; } VAR_3 = g_malloc(VAR_1->length + 1); if (read_sync(VAR_0, VAR_3, VAR_1->length, VAR_2) < 0) { error_prepend(VAR_2, "failed to read option error message"); goto cleanup; } VAR_3[VAR_1->length] = '\0'; } switch (VAR_1->type) { case NBD_REP_ERR_UNSUP:
TRACE("server doesn't understand request %" PRIx32
", attempting fallback", VAR_1->option); VAR_4 = 0; goto cleanup; case NBD_REP_ERR_POLICY:
error_setg(VAR_2, "Denied by server for option %" PRIx32,
VAR_1->option); break; case NBD_REP_ERR_INVALID:
error_setg(VAR_2, "Invalid data length for option %" PRIx32,
VAR_1->option); break; case NBD_REP_ERR_PLATFORM:
error_setg(VAR_2, "Server lacks support for option %" PRIx32,
VAR_1->option); break; case NBD_REP_ERR_TLS_REQD:
error_setg(VAR_2, "TLS negotiation required before option %" PRIx32,
VAR_1->option); break; case NBD_REP_ERR_SHUTDOWN:
error_setg(VAR_2, "Server shutting down before option %" PRIx32,
VAR_1->option); break; default:
error_setg(VAR_2, "Unknown error code when asking for option %" PRIx32,
VAR_1->option); break; } if (VAR_3) { error_append_hint(VAR_2, "%s\n", VAR_3); } cleanup:
g_free(VAR_3); if (VAR_4 < 0) { nbd_send_opt_abort(VAR_0); } return VAR_4; }