]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
log: use non-blocking atomic writes to stderr fifos
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 25 Oct 2022 15:42:10 +0000 (11:42 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 5 Apr 2023 15:32:20 +0000 (11:32 -0400)
commitcfb6f4632140d96c87dc0a501bb8a9ae5dc7ac93
treeee67b3d76f54355701bb246ad2805a9a7d0d1e7a
parent678703828a3239d9357110d56258e205e5b3aa39
log: use non-blocking atomic writes to stderr fifos

Buggy container runtimes are known to do partial reads on container's
stderr and emit torn logs [1]. This is due to write(2) allowing partial
data transfer. One way to avoid this when stderr is a FIFO (which is the
case for container runtimes) is to change the file flags to set
O_NONBLOCK which alters the behavior of write(2) when the write size is
less than PIPE_BUF. This makes a write guaranteed to be atomic.

The small complexity added is to poll on stderr in this case whenever a
write(2) fails with EAGAIN. This does not block the log flush thread in
any new way. It would always block when the stderr FIFO was full.

[1] https://github.com/containers/conmon/issues/242

Fixes: cef04bc4ed0a3b1c1e9873fbbdd023b3bdf8af03
Fixes: https://tracker.ceph.com/issues/57923
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1996599
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2108228
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 2551130bcc12c55ddaa879b4f5b77c81890b51b2)

Conflicts:
src/log/Log.cc: code moved
src/log/Log.cc
src/log/Log.h