From: Mathieu Desnoyers Date: Wed, 27 Feb 2013 21:48:56 +0000 (-0500) Subject: Fix: don't flush-final for offset 0 if reader is on sub-buffer X-Git-Tag: v2.2.0-rc1~13 X-Git-Url: http://git.liburcu.org/?p=lttng-modules.git;a=commitdiff_plain;h=74b9312477538922f7ce3194b37ed3e0c5d7ba16 Fix: don't flush-final for offset 0 if reader is on sub-buffer Triggers rare sub-buffer corruption when a buffer is completely full and a final flush is then performed. Signed-off-by: Mathieu Desnoyers --- diff --git a/lib/ringbuffer/ring_buffer_frontend.c b/lib/ringbuffer/ring_buffer_frontend.c index dc0357f5..2626afa3 100644 --- a/lib/ringbuffer/ring_buffer_frontend.c +++ b/lib/ringbuffer/ring_buffer_frontend.c @@ -1424,6 +1424,19 @@ int lib_ring_buffer_try_switch_slow(enum switch_mode mode, */ if (mode == SWITCH_FLUSH || off > 0) { if (unlikely(off == 0)) { + /* + * A final flush that encounters an empty + * sub-buffer cannot switch buffer if a + * reader is located within this sub-buffer. + * Anyway, the purpose of final flushing of a + * sub-buffer at offset 0 is to handle the case + * of entirely empty stream. + */ + if (unlikely(subbuf_trunc(offsets->begin, chan) + - subbuf_trunc((unsigned long) + atomic_long_read(&buf->consumed), chan) + >= chan->backend.buf_size)) + return -1; /* * The client does not save any header information. * Don't switch empty subbuffer on finalize, because it