static void *nbd_client_thread(void *arg)

{

    char *device = arg;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int fd, sock;

    int ret;

    pthread_t show_parts_thread;



    sock = unix_socket_outgoing(sockpath);

    if (sock < 0) {

        goto out;

    }



    ret = nbd_receive_negotiate(sock, NULL, &nbdflags,

                                &size, &blocksize);

    if (ret < 0) {

        goto out;

    }



    fd = open(device, O_RDWR);

    if (fd < 0) {

        /* Linux-only, we can use %m in printf.  */

        fprintf(stderr, "Failed to open %s: %m", device);

        goto out;

    }



    ret = nbd_init(fd, sock, nbdflags, size, blocksize);

    if (ret < 0) {

        goto out;

    }



    /* update partition table */

    pthread_create(&show_parts_thread, NULL, show_parts, device);



    if (verbose) {

        fprintf(stderr, "NBD device %s is now connected to %s\n",

                device, srcpath);

    } else {

        /* Close stderr so that the qemu-nbd process exits.  */

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    ret = nbd_client(fd);

    if (ret) {

        goto out;

    }

    close(fd);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

static void *nbd_client_thread(void *arg)

{

    char *device = arg;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int fd, sock;

    int ret;

    pthread_t show_parts_thread;



    sock = unix_socket_outgoing(sockpath);

    if (sock < 0) {

        goto out;

    }



    ret = nbd_receive_negotiate(sock, NULL, &nbdflags,

                                &size, &blocksize);

    if (ret < 0) {

        goto out;

    }



    fd = open(device, O_RDWR);

    if (fd < 0) {

        

        fprintf(stderr, "Failed to open %s: %m", device);

        goto out;

    }



    ret = nbd_init(fd, sock, nbdflags, size, blocksize);

    if (ret < 0) {

        goto out;

    }



    

    pthread_create(&show_parts_thread, NULL, show_parts, device);



    if (verbose) {

        fprintf(stderr, "NBD device %s is now connected to %s\n",

                device, srcpath);

    } else {

        

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    ret = nbd_client(fd);

    if (ret) {

        goto out;

    }

    close(fd);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

        goto out;         goto out;         goto out;         goto out;
static void *FUNC_0(void *VAR_0)

{

    char *VAR_1 = VAR_0;

    off_t size;

    size_t blocksize;

    uint32_t nbdflags;

    int VAR_2, VAR_3;

    int VAR_4;

    pthread_t show_parts_thread;



    VAR_3 = unix_socket_outgoing(sockpath);

    if (VAR_3 < 0) {

        goto out;

    }



    VAR_4 = nbd_receive_negotiate(VAR_3, NULL, &nbdflags,

                                &size, &blocksize);

    if (VAR_4 < 0) {

        goto out;

    }



    VAR_2 = open(VAR_1, O_RDWR);

    if (VAR_2 < 0) {

        

        fprintf(stderr, "Failed to open %s: %m", VAR_1);

        goto out;

    }



    VAR_4 = nbd_init(VAR_2, VAR_3, nbdflags, size, blocksize);

    if (VAR_4 < 0) {

        goto out;

    }



    

    pthread_create(&show_parts_thread, NULL, show_parts, VAR_1);



    if (verbose) {

        fprintf(stderr, "NBD VAR_1 %s is now connected to %s\n",

                VAR_1, srcpath);

    } else {

        

        dup2(STDOUT_FILENO, STDERR_FILENO);

    }



    VAR_4 = nbd_client(VAR_2);

    if (VAR_4) {

        goto out;

    }

    close(VAR_2);

    kill(getpid(), SIGTERM);

    return (void *) EXIT_SUCCESS;



out:

    kill(getpid(), SIGTERM);

    return (void *) EXIT_FAILURE;

}

static void *FUNC_0(void *VAR_0)
{ char *VAR_1 = VAR_0; off_t size; size_t blocksize; uint32_t nbdflags; int VAR_2, VAR_3; int VAR_4; pthread_t show_parts_thread; VAR_3 = unix_socket_outgoing(sockpath); if (VAR_3 < 0) { goto out; } VAR_4 = nbd_receive_negotiate(VAR_3, NULL, &nbdflags,
&size, &blocksize); if (VAR_4 < 0) { goto out; } VAR_2 = open(VAR_1, O_RDWR); if (VAR_2 < 0) { fprintf(stderr, "Failed to open %s: %m", VAR_1); goto out; } VAR_4 = nbd_init(VAR_2, VAR_3, nbdflags, size, blocksize); if (VAR_4 < 0) { goto out; } pthread_create(&show_parts_thread, NULL, show_parts, VAR_1); if (verbose) { fprintf(stderr, "NBD VAR_1 %s is now connected to %s\n",
VAR_1, srcpath); } else { dup2(STDOUT_FILENO, STDERR_FILENO); } VAR_4 = nbd_client(VAR_2); if (VAR_4) { goto out; } close(VAR_2); kill(getpid(), SIGTERM); return (void *) EXIT_SUCCESS; out:
kill(getpid(), SIGTERM); return (void *) EXIT_FAILURE; }