From dc37504ae94313bf395ab6b9efa8dde4d150d627 Mon Sep 17 00:00:00 2001 From: torben Date: Fri, 15 Jan 2016 17:46:14 +0100 Subject: Fix. --- dev-tools/qemuDebuggingPatch/qemu-nbd.c | 116 ++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 50 deletions(-) (limited to 'dev-tools/qemuDebuggingPatch') diff --git a/dev-tools/qemuDebuggingPatch/qemu-nbd.c b/dev-tools/qemuDebuggingPatch/qemu-nbd.c index 3af28a07..ce0043d4 100644 --- a/dev-tools/qemuDebuggingPatch/qemu-nbd.c +++ b/dev-tools/qemuDebuggingPatch/qemu-nbd.c @@ -244,64 +244,80 @@ static void *nbd_client_thread(void *arg) pthread_t show_parts_thread; Error *local_error = NULL; + // changed + while(1) { + // -- + sock = socket_connect(saddr, &local_error, NULL, NULL); + if (sock < 0) { + error_report_err(local_error); + goto out; + } - sock = socket_connect(saddr, &local_error, NULL, NULL); - if (sock < 0) { - error_report_err(local_error); - goto out; - } - - ret = nbd_receive_negotiate(sock, NULL, &nbdflags, - &size, &local_error); - if (ret < 0) { - if (local_error) { - fprintf(stderr, "%s\n", error_get_pretty(local_error)); - error_free(local_error); + ret = nbd_receive_negotiate(sock, NULL, &nbdflags, + &size, &local_error); + if (ret < 0) { + if (local_error) { + fprintf(stderr, "%s\n", error_get_pretty(local_error)); + error_free(local_error); + } + goto out_socket; } - goto out_socket; - } - fd = open(device, O_RDWR); - if (fd < 0) { - /* Linux-only, we can use %m in printf. */ - fprintf(stderr, "Failed to open %s: %m\n", device); - goto out_socket; - } + fd = open(device, O_RDWR); + if (fd < 0) { + /* Linux-only, we can use %m in printf. */ + fprintf(stderr, "Failed to open %s: %m\n", device); + goto out_socket; + } - ret = nbd_init(fd, sock, nbdflags, size); - if (ret < 0) { - fprintf(stderr, "------------------------\nJAU: nbd_client_thread -> trigger out_fd caused by nbd_init PID: %d\n-------------------\n", getpid()); - goto out_fd; - } + ret = nbd_init(fd, sock, nbdflags, size); + if (ret < 0) { + fprintf(stderr, "------------------------\nJAU: nbd_client_thread -> trigger out_fd caused by nbd_init PID: %d\n-------------------\n", getpid()); + goto out_fd; + } - /* update partition table */ - pthread_create(&show_parts_thread, NULL, show_parts, device); + /* 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); - } + 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); + } - // Changed - pid_t pid; - pid = fork(); - if (pid == 0) { - fprintf(stderr, "------------------------\nJAU: nbd_client -> custom fork sleep started PID: %d\n-------------------\n", getpid()); - sleep(10); - int a = chdir("/sysroot/"); - fprintf(stderr, "------------------------\nJAU: nbd_client -> custom fork sleep finished chdir returned %d PID: %d\n-------------------\n", a, getpid()); - exit(0); - } - // -- - ret = nbd_client(fd); - if (ret) { - fprintf(stderr, "------------------------\nJAU: nbd_client_thread -> trigger out_fd caused by nbd_client PID: %d\n-------------------\n", getpid()); - goto out_fd; + /* Changed + pid_t pid; + pid = fork(); + if (pid == 0) { + fprintf(stderr, "------------------------\nJAU: nbd_client -> custom fork sleep started PID: %d\n-------------------\n", getpid()); + sleep(10); + int a = chdir("/sysroot/"); + fprintf(stderr, "------------------------\nJAU: nbd_client -> custom fork sleep finished chdir returned %d PID: %d\n-------------------\n", a, getpid()); + exit(0); + } + */ + ret = nbd_client(fd); + // changed + if (errno == ETIMEDOUT) { + fprintf(stderr, "------------------------\nJAU: nbd_client_thread -> trigger out_fd caused by nbd_client -> BUT Ignored and starting reconnect! PID: %d\n-------------------\n", getpid()); + close(fd); + continue; + } + // + if (ret) { + goto out_fd; + // changed + } else { + close(fd); + break; + } + // + close(fd); + // changed } - close(fd); + //-- kill(getpid(), SIGTERM); fprintf(stderr, "------------------------\nJAU: nbd_client_thread -> STOP PID: %d\n-------------------\n", getpid()); return (void *) EXIT_SUCCESS; -- cgit v1.2.3-55-g7522