static int nbd_open(BlockDriverState *bs, QDict *options, int flags,

                    Error **errp)

{

    BDRVNBDState *s = bs->opaque;

    char *export = NULL;

    int result, sock;



    /* Pop the config into our state object. Exit if invalid. */

    result = nbd_config(s, options, &export);

    if (result != 0) {

        return result;

    }



    /* establish TCP connection, return error if it fails

     * TODO: Configurable retry-until-timeout behaviour.

     */

    sock = nbd_establish_connection(bs);

    if (sock < 0) {

        return sock;

    }



    /* NBD handshake */

    result = nbd_client_session_init(&s->client, bs, sock, export);

    g_free(export);

    return result;

}

static int nbd_open(BlockDriverState *bs, QDict *options, int flags,

                    Error **errp)

{

    BDRVNBDState *s = bs->opaque;

    char *export = NULL;

    int result, sock;



    

    result = nbd_config(s, options, &export);

    if (result != 0) {

        return result;

    }



    





    sock = nbd_establish_connection(bs);

    if (sock < 0) {

        return sock;

    }



    

    result = nbd_client_session_init(&s->client, bs, sock, export);

    g_free(export);

    return result;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,

                    Error **VAR_3)

{

    BDRVNBDState *s = VAR_0->opaque;

    char *VAR_4 = NULL;

    int VAR_5, VAR_6;



    

    VAR_5 = nbd_config(s, VAR_1, &VAR_4);

    if (VAR_5 != 0) {

        return VAR_5;

    }



    





    VAR_6 = nbd_establish_connection(VAR_0);

    if (VAR_6 < 0) {

        return VAR_6;

    }



    

    VAR_5 = nbd_client_session_init(&s->client, VAR_0, VAR_6, VAR_4);

    g_free(VAR_4);

    return VAR_5;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,
Error **VAR_3)
{ BDRVNBDState *s = VAR_0->opaque; char *VAR_4 = NULL; int VAR_5, VAR_6; VAR_5 = nbd_config(s, VAR_1, &VAR_4); if (VAR_5 != 0) { return VAR_5; } VAR_6 = nbd_establish_connection(VAR_0); if (VAR_6 < 0) { return VAR_6; } VAR_5 = nbd_client_session_init(&s->client, VAR_0, VAR_6, VAR_4); g_free(VAR_4); return VAR_5; }