On Tue, 17 Jul 2018 11:19:44 +0100 Stefan Hajnoczi <stefa...@redhat.com> wrote:
> The simple trace backend spawns a write-out thread which is used to > asynchronously flush the in-memory ring buffer to disk. > > fork(2) does not clone all threads, only the thread that invoked > fork(2). As a result there is no write-out thread in the child process! > > This causes a hang during shutdown when atexit(3) handler installed by > the simple trace backend waits for the non-existent write-out thread. > > This patch uses pthread_atfork(3) to terminate the write-out thread > before fork and restart it in both the parent and child after fork. > This solves a hang in qemu-iotests 147 due to qemu-nbd --fork usage. > > Reported-by: Cornelia Huck <coh...@redhat.com> > Suggested-by: Paolo Bonzini <pbonz...@redhat.com> > Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com> > --- > v3: > * Hold trace_lock across fork() to prevent possibility of another > thread holding it and disappearing [Paolo] > > trace/simple.c | 80 ++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 71 insertions(+), 9 deletions(-) Tested-by: Cornelia Huck <coh...@redhat.com>