[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3] trace/simple: fix hang in child after fork(2
From: |
Cornelia Huck |
Subject: |
Re: [Qemu-devel] [PATCH v3] trace/simple: fix hang in child after fork(2) |
Date: |
Tue, 17 Jul 2018 15:11:57 +0200 |
On Tue, 17 Jul 2018 11:19:44 +0100
Stefan Hajnoczi <address@hidden> 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 <address@hidden>
> Suggested-by: Paolo Bonzini <address@hidden>
> Signed-off-by: Stefan Hajnoczi <address@hidden>
> ---
> 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 <address@hidden>