print warning and return -EBUSY on double get_subbuf()
[lttng-modules.git] / lib / ringbuffer / ring_buffer_frontend.c
index dc0357f56a3e71547c7da80a4e2bd3ce7277d0f0..84341adcd4da6b2b6a06e5e286179d13a90be42b 100644 (file)
@@ -402,7 +402,7 @@ static void lib_ring_buffer_stop_read_timer(struct lib_ring_buffer *buf)
  *     Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
  */
 static
-int __cpuinit lib_ring_buffer_cpu_hp_callback(struct notifier_block *nb,
+int lib_ring_buffer_cpu_hp_callback(struct notifier_block *nb,
                                              unsigned long action,
                                              void *hcpu)
 {
@@ -927,6 +927,13 @@ int lib_ring_buffer_get_subbuf(struct lib_ring_buffer *buf,
        int ret;
        int finalized;
 
+       if (buf->get_subbuf) {
+               /*
+                * Reader is trying to get a subbuffer twice.
+                */
+               CHAN_WARN_ON(chan, 1);
+               return -EBUSY;
+       }
 retry:
        finalized = ACCESS_ONCE(buf->finalized);
        /*
@@ -1424,6 +1431,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
This page took 0.024172 seconds and 4 git commands to generate.