static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t length,

                                            uint16_t myflags, bool no_zeroes,

                                            Error **errp)

{

    char name[NBD_MAX_NAME_SIZE + 1];

    char buf[8 + 4 + 124] = "";

    size_t len;

    int ret;



    /* Client sends:

        [20 ..  xx]   export name (length bytes)

     */

    trace_nbd_negotiate_handle_export_name();

    if (length >= sizeof(name)) {

        error_setg(errp, "Bad length received");

        return -EINVAL;

    }

    if (nbd_read(client->ioc, name, length, errp) < 0) {

        error_prepend(errp, "read failed: ");

        return -EINVAL;

    }

    name[length] = '\0';



    trace_nbd_negotiate_handle_export_name_request(name);



    client->exp = nbd_export_find(name);

    if (!client->exp) {

        error_setg(errp, "export not found");

        return -EINVAL;

    }



    trace_nbd_negotiate_new_style_size_flags(client->exp->size,

                                             client->exp->nbdflags | myflags);

    stq_be_p(buf, client->exp->size);

    stw_be_p(buf + 8, client->exp->nbdflags | myflags);

    len = no_zeroes ? 10 : sizeof(buf);

    ret = nbd_write(client->ioc, buf, len, errp);

    if (ret < 0) {

        error_prepend(errp, "write failed: ");

        return ret;

    }



    QTAILQ_INSERT_TAIL(&client->exp->clients, client, next);

    nbd_export_get(client->exp);



    return 0;

}

static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t length,

                                            uint16_t myflags, bool no_zeroes,

                                            Error **errp)

{

    char name[NBD_MAX_NAME_SIZE + 1];

    char buf[8 + 4 + 124] = "";

    size_t len;

    int ret;



    





    trace_nbd_negotiate_handle_export_name();

    if (length >= sizeof(name)) {

        error_setg(errp, "Bad length received");

        return -EINVAL;

    }

    if (nbd_read(client->ioc, name, length, errp) < 0) {

        error_prepend(errp, "read failed: ");

        return -EINVAL;

    }

    name[length] = '\0';



    trace_nbd_negotiate_handle_export_name_request(name);



    client->exp = nbd_export_find(name);

    if (!client->exp) {

        error_setg(errp, "export not found");

        return -EINVAL;

    }



    trace_nbd_negotiate_new_style_size_flags(client->exp->size,

                                             client->exp->nbdflags | myflags);

    stq_be_p(buf, client->exp->size);

    stw_be_p(buf + 8, client->exp->nbdflags | myflags);

    len = no_zeroes ? 10 : sizeof(buf);

    ret = nbd_write(client->ioc, buf, len, errp);

    if (ret < 0) {

        error_prepend(errp, "write failed: ");

        return ret;

    }



    QTAILQ_INSERT_TAIL(&client->exp->clients, client, next);

    nbd_export_get(client->exp);



    return 0;

}

static int FUNC_0(NBDClient *VAR_0, uint32_t VAR_1,

                                            uint16_t VAR_2, bool VAR_3,

                                            Error **VAR_4)

{

    char VAR_5[NBD_MAX_NAME_SIZE + 1];

    char VAR_6[8 + 4 + 124] = "";

    size_t len;

    int VAR_7;



    





    trace_nbd_negotiate_handle_export_name();

    if (VAR_1 >= sizeof(VAR_5)) {

        error_setg(VAR_4, "Bad VAR_1 received");

        return -EINVAL;

    }

    if (nbd_read(VAR_0->ioc, VAR_5, VAR_1, VAR_4) < 0) {

        error_prepend(VAR_4, "read failed: ");

        return -EINVAL;

    }

    VAR_5[VAR_1] = '\0';



    trace_nbd_negotiate_handle_export_name_request(VAR_5);



    VAR_0->exp = nbd_export_find(VAR_5);

    if (!VAR_0->exp) {

        error_setg(VAR_4, "export not found");

        return -EINVAL;

    }



    trace_nbd_negotiate_new_style_size_flags(VAR_0->exp->size,

                                             VAR_0->exp->nbdflags | VAR_2);

    stq_be_p(VAR_6, VAR_0->exp->size);

    stw_be_p(VAR_6 + 8, VAR_0->exp->nbdflags | VAR_2);

    len = VAR_3 ? 10 : sizeof(VAR_6);

    VAR_7 = nbd_write(VAR_0->ioc, VAR_6, len, VAR_4);

    if (VAR_7 < 0) {

        error_prepend(VAR_4, "write failed: ");

        return VAR_7;

    }



    QTAILQ_INSERT_TAIL(&VAR_0->exp->clients, VAR_0, next);

    nbd_export_get(VAR_0->exp);



    return 0;

}

static int FUNC_0(NBDClient *VAR_0, uint32_t VAR_1,
uint16_t VAR_2, bool VAR_3,
Error **VAR_4)
{ char VAR_5[NBD_MAX_NAME_SIZE + 1]; char VAR_6[8 + 4 + 124] = ""; size_t len; int VAR_7; trace_nbd_negotiate_handle_export_name(); if (VAR_1 >= sizeof(VAR_5)) { error_setg(VAR_4, "Bad VAR_1 received"); return -EINVAL; } if (nbd_read(VAR_0->ioc, VAR_5, VAR_1, VAR_4) < 0) { error_prepend(VAR_4, "read failed: "); return -EINVAL; } VAR_5[VAR_1] = '\0'; trace_nbd_negotiate_handle_export_name_request(VAR_5); VAR_0->exp = nbd_export_find(VAR_5); if (!VAR_0->exp) { error_setg(VAR_4, "export not found"); return -EINVAL; } trace_nbd_negotiate_new_style_size_flags(VAR_0->exp->size,
VAR_0->exp->nbdflags | VAR_2); stq_be_p(VAR_6, VAR_0->exp->size); stw_be_p(VAR_6 + 8, VAR_0->exp->nbdflags | VAR_2); len = VAR_3 ? 10 : sizeof(VAR_6); VAR_7 = nbd_write(VAR_0->ioc, VAR_6, len, VAR_4); if (VAR_7 < 0) { error_prepend(VAR_4, "write failed: "); return VAR_7; } QTAILQ_INSERT_TAIL(&VAR_0->exp->clients, VAR_0, next); nbd_export_get(VAR_0->exp); return 0; }