int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs,

                            int sock, const char *export, Error **errp)

{

    int ret;



    /* NBD handshake */

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

    qemu_set_block(sock);

    ret = nbd_receive_negotiate(sock, export,

                                &client->nbdflags, &client->size,

                                &client->blocksize, errp);

    if (ret < 0) {

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

        closesocket(sock);

        return ret;

    }



    qemu_co_mutex_init(&client->send_mutex);

    qemu_co_mutex_init(&client->free_sema);

    client->bs = bs;

    client->sock = sock;



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

     * kick the reply mechanism.  */

    qemu_set_nonblock(sock);

    nbd_client_session_attach_aio_context(client, bdrv_get_aio_context(bs));



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

    return 0;

}

int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs,

                            int sock, const char *export, Error **errp)

{

    int ret;



    

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

    qemu_set_block(sock);

    ret = nbd_receive_negotiate(sock, export,

                                &client->nbdflags, &client->size,

                                &client->blocksize, errp);

    if (ret < 0) {

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

        closesocket(sock);

        return ret;

    }



    qemu_co_mutex_init(&client->send_mutex);

    qemu_co_mutex_init(&client->free_sema);

    client->bs = bs;

    client->sock = sock;



    



    qemu_set_nonblock(sock);

    nbd_client_session_attach_aio_context(client, bdrv_get_aio_context(bs));



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

    return 0;

}

int FUNC_0(NbdClientSession *VAR_0, BlockDriverState *VAR_1,

                            int VAR_2, const char *VAR_3, Error **VAR_4)

{

    int VAR_5;



    

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

    qemu_set_block(VAR_2);

    VAR_5 = nbd_receive_negotiate(VAR_2, VAR_3,

                                &VAR_0->nbdflags, &VAR_0->size,

                                &VAR_0->blocksize, VAR_4);

    if (VAR_5 < 0) {

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

        closesocket(VAR_2);

        return VAR_5;

    }



    qemu_co_mutex_init(&VAR_0->send_mutex);

    qemu_co_mutex_init(&VAR_0->free_sema);

    VAR_0->VAR_1 = VAR_1;

    VAR_0->VAR_2 = VAR_2;



    



    qemu_set_nonblock(VAR_2);

    nbd_client_session_attach_aio_context(VAR_0, bdrv_get_aio_context(VAR_1));



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

    return 0;

}

int FUNC_0(NbdClientSession *VAR_0, BlockDriverState *VAR_1,
int VAR_2, const char *VAR_3, Error **VAR_4)
{ int VAR_5; logout("session init %s\n", VAR_3); qemu_set_block(VAR_2); VAR_5 = nbd_receive_negotiate(VAR_2, VAR_3,
&VAR_0->nbdflags, &VAR_0->size,
&VAR_0->blocksize, VAR_4); if (VAR_5 < 0) { logout("Failed to negotiate with the NBD server\n"); closesocket(VAR_2); return VAR_5; } qemu_co_mutex_init(&VAR_0->send_mutex); qemu_co_mutex_init(&VAR_0->free_sema); VAR_0->VAR_1 = VAR_1; VAR_0->VAR_2 = VAR_2; qemu_set_nonblock(VAR_2); nbd_client_session_attach_aio_context(VAR_0, bdrv_get_aio_context(VAR_1)); logout("Established connection with NBD server\n"); return 0; }