int nbd_client_init(BlockDriverState *bs, QIOChannelSocket *sioc,

                    const char *export, 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,

                                NULL, NULL,

                                &client->ioc,

                                &client->size, errp);

    if (ret < 0) {

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

        return ret;

    }



    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, 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,

                                NULL, NULL,

                                &client->ioc,

                                &client->size, errp);

    if (ret < 0) {

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

        return ret;

    }



    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;

}

int FUNC_0(BlockDriverState *VAR_0, QIOChannelSocket *VAR_1,

                    const char *VAR_2, Error **VAR_3)

{

    NbdClientSession *client = nbd_get_client_session(VAR_0);

    int VAR_4;



    

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

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



    VAR_4 = nbd_receive_negotiate(QIO_CHANNEL(VAR_1), VAR_2,

                                &client->nbdflags,

                                NULL, NULL,

                                &client->ioc,

                                &client->size, VAR_3);

    if (VAR_4 < 0) {

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

        return VAR_4;

    }



    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, Error **VAR_3)
{ NbdClientSession *client = nbd_get_client_session(VAR_0); int VAR_4; logout("session init %s\n", VAR_2); qio_channel_set_blocking(QIO_CHANNEL(VAR_1), true, NULL); VAR_4 = nbd_receive_negotiate(QIO_CHANNEL(VAR_1), VAR_2,
&client->nbdflags,
NULL, NULL,
&client->ioc,
&client->size, VAR_3); if (VAR_4 < 0) { logout("Failed to negotiate with the NBD server\n"); return VAR_4; } 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; }