[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: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v3] trace/simple: fix hang in child after fork(2) |
Date: |
Mon, 23 Jul 2018 14:14:18 +0100 |
User-agent: |
Mutt/1.10.0 (2018-05-17) |
On Tue, Jul 17, 2018 at 11:19:44AM +0100, Stefan Hajnoczi 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(-)
Thanks, applied to my tracing tree for 3.0:
https://github.com/stefanha/qemu/commits/tracing
Stefan
signature.asc
Description: PGP signature