int nbd_client_init(BlockDriverState *bs,

                    QIOChannelSocket *sioc,

                    const char *export,

                    QCryptoTLSCreds *tlscreds,

                    const char *hostname,

                    Error **errp)

{

    NbdClientSession *client = nbd_get_client_session(bs);

    int ret;



    /* NBD handshake */

    logout("session init %s\n", export);

    qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL);



    ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), export,

                                &client->nbdflags,

                                tlscreds, hostname,

                                &client->ioc,

                                &client->size, errp);

    if (ret < 0) {

        logout("Failed to negotiate with the NBD server\n");

        return ret;

    }

    if (client->nbdflags & NBD_FLAG_SEND_FUA) {

        bs->supported_write_flags = BDRV_REQ_FUA;

    }



    qemu_co_mutex_init(&client->send_mutex);

    qemu_co_mutex_init(&client->free_sema);

    client->sioc = sioc;

    object_ref(OBJECT(client->sioc));



    if (!client->ioc) {

        client->ioc = QIO_CHANNEL(sioc);

        object_ref(OBJECT(client->ioc));

    }



    /* Now that we're connected, set the socket to be non-blocking and

     * kick the reply mechanism.  */

    qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);



    nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs));



    logout("Established connection with NBD server\n");

    return 0;

}

int nbd_client_init(BlockDriverState *bs,

                    QIOChannelSocket *sioc,

                    const char *export,

                    QCryptoTLSCreds *tlscreds,

                    const char *hostname,

                    Error **errp)

{

    NbdClientSession *client = nbd_get_client_session(bs);

    int ret;



    

    logout("session init %s\n", export);

    qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL);



    ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), export,

                                &client->nbdflags,

                                tlscreds, hostname,

                                &client->ioc,

                                &client->size, errp);

    if (ret < 0) {

        logout("Failed to negotiate with the NBD server\n");

        return ret;

    }

    if (client->nbdflags & NBD_FLAG_SEND_FUA) {

        bs->supported_write_flags = BDRV_REQ_FUA;

    }



    qemu_co_mutex_init(&client->send_mutex);

    qemu_co_mutex_init(&client->free_sema);

    client->sioc = sioc;

    object_ref(OBJECT(client->sioc));



    if (!client->ioc) {

        client->ioc = QIO_CHANNEL(sioc);

        object_ref(OBJECT(client->ioc));

    }



    



    qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);



    nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs));



    logout("Established connection with NBD server\n");

    return 0;

}

    qemu_co_mutex_init(&client->free_sema);
int FUNC_0(BlockDriverState *VAR_0,

                    QIOChannelSocket *VAR_1,

                    const char *VAR_2,

                    QCryptoTLSCreds *VAR_3,

                    const char *VAR_4,

                    Error **VAR_5)

{

    NbdClientSession *client = nbd_get_client_session(VAR_0);

    int VAR_6;



    

    logout("session init %s\n", VAR_2);

    qio_channel_set_blocking(QIO_CHANNEL(VAR_1), true, NULL);



    VAR_6 = nbd_receive_negotiate(QIO_CHANNEL(VAR_1), VAR_2,

                                &client->nbdflags,

                                VAR_3, VAR_4,

                                &client->ioc,

                                &client->size, VAR_5);

    if (VAR_6 < 0) {

        logout("Failed to negotiate with the NBD server\n");

        return VAR_6;

    }

    if (client->nbdflags & NBD_FLAG_SEND_FUA) {

        VAR_0->supported_write_flags = BDRV_REQ_FUA;

    }



    qemu_co_mutex_init(&client->send_mutex);

    qemu_co_mutex_init(&client->free_sema);

    client->VAR_1 = VAR_1;

    object_ref(OBJECT(client->VAR_1));



    if (!client->ioc) {

        client->ioc = QIO_CHANNEL(VAR_1);

        object_ref(OBJECT(client->ioc));

    }



    



    qio_channel_set_blocking(QIO_CHANNEL(VAR_1), false, NULL);



    nbd_client_attach_aio_context(VAR_0, bdrv_get_aio_context(VAR_0));



    logout("Established connection with NBD server\n");

    return 0;

}

int FUNC_0(BlockDriverState *VAR_0,
QIOChannelSocket *VAR_1,
const char *VAR_2,
QCryptoTLSCreds *VAR_3,
const char *VAR_4,
Error **VAR_5)
{ NbdClientSession *client = nbd_get_client_session(VAR_0); int VAR_6; logout("session init %s\n", VAR_2); qio_channel_set_blocking(QIO_CHANNEL(VAR_1), true, NULL); VAR_6 = nbd_receive_negotiate(QIO_CHANNEL(VAR_1), VAR_2,
&client->nbdflags,
VAR_3, VAR_4,
&client->ioc,
&client->size, VAR_5); if (VAR_6 < 0) { logout("Failed to negotiate with the NBD server\n"); return VAR_6; } if (client->nbdflags & NBD_FLAG_SEND_FUA) { VAR_0->supported_write_flags = BDRV_REQ_FUA; } qemu_co_mutex_init(&client->send_mutex); qemu_co_mutex_init(&client->free_sema); client->VAR_1 = VAR_1; object_ref(OBJECT(client->VAR_1)); if (!client->ioc) { client->ioc = QIO_CHANNEL(VAR_1); object_ref(OBJECT(client->ioc)); } qio_channel_set_blocking(QIO_CHANNEL(VAR_1), false, NULL); nbd_client_attach_aio_context(VAR_0, bdrv_get_aio_context(VAR_0)); logout("Established connection with NBD server\n"); return 0; }