Revert "fio: Simplify forking of processes"
authorJens Axboe <axboe@fb.com>
Sun, 12 Jun 2016 03:27:29 +0000 (21:27 -0600)
committerJens Axboe <axboe@fb.com>
Sun, 12 Jun 2016 03:27:29 +0000 (21:27 -0600)
This reverts commit d7982dd0ab2a1a315b5f9859c67a02414ce6274f.

Causes a regression in the logging, looks like a problem with
shared memory. Will need to investigate further, but it's
reproducibly broken.

backend.c

index d8f4f4cfb28e807ba98e2dc8735cc0609acd980e..bb0200bb2b0fdb29c80aacdc03ca1b026385191e 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1799,6 +1799,39 @@ err:
        return (void *) (uintptr_t) td->error;
 }
 
+
+/*
+ * We cannot pass the td data into a forked process, so attach the td and
+ * pass it to the thread worker.
+ */
+static int fork_main(struct sk_out *sk_out, int shmid, int offset)
+{
+       struct fork_data *fd;
+       void *data, *ret;
+
+#if !defined(__hpux) && !defined(CONFIG_NO_SHM)
+       data = shmat(shmid, NULL, 0);
+       if (data == (void *) -1) {
+               int __err = errno;
+
+               perror("shmat");
+               return __err;
+       }
+#else
+       /*
+        * HP-UX inherits shm mappings?
+        */
+       data = threads;
+#endif
+
+       fd = calloc(1, sizeof(*fd));
+       fd->td = data + offset * sizeof(struct thread_data);
+       fd->sk_out = sk_out;
+       ret = thread_main(fd);
+       shmdt(data);
+       return (int) (uintptr_t) ret;
+}
+
 static void dump_td_info(struct thread_data *td)
 {
        log_err("fio: job '%s' (state=%d) hasn't exited in %lu seconds, it "
@@ -2136,7 +2169,6 @@ reap:
                struct thread_data *map[REAL_MAX_JOBS];
                struct timeval this_start;
                int this_jobs = 0, left;
-               struct fork_data *fd;
 
                /*
                 * create threads (TD_NOT_CREATED -> TD_CREATED)
@@ -2186,13 +2218,14 @@ reap:
                        map[this_jobs++] = td;
                        nr_started++;
 
-                       fd = calloc(1, sizeof(*fd));
-                       fd->td = td;
-                       fd->sk_out = sk_out;
-
                        if (td->o.use_thread) {
+                               struct fork_data *fd;
                                int ret;
 
+                               fd = calloc(1, sizeof(*fd));
+                               fd->td = td;
+                               fd->sk_out = sk_out;
+
                                dprint(FD_PROCESS, "will pthread_create\n");
                                ret = pthread_create(&td->thread, NULL,
                                                        thread_main, fd);
@@ -2212,9 +2245,8 @@ reap:
                                dprint(FD_PROCESS, "will fork\n");
                                pid = fork();
                                if (!pid) {
-                                       int ret;
+                                       int ret = fork_main(sk_out, shm_id, i);
 
-                                       ret = (int)(uintptr_t)thread_main(fd);
                                        _exit(ret);
                                } else if (i == fio_debug_jobno)
                                        *fio_debug_jobp = pid;