[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PULL for-3.0 1/1] trace/simple: fix hang in child afte
From: |
Daniel P . Berrangé |
Subject: |
Re: [Qemu-devel] [PULL for-3.0 1/1] trace/simple: fix hang in child after fork(2) |
Date: |
Tue, 24 Jul 2018 15:35:51 +0100 |
User-agent: |
Mutt/1.10.0 (2018-05-17) |
On Tue, Jul 24, 2018 at 03:25:04PM +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.
I'm not convinced this is safe, as it looks like it has a window in
which both the parent and child processes will be doing write-out to
the same file.
In particular in the main QEMU system emulators it means that any
time we fork() in QEMU, eg for spawning commands with migration
exec: URI, or TAP devuce ifup scripts, etc, we'll be starting a
write-out thread in the child.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|