1 /* SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
3 * ring_buffer_iterator.c
5 * Ring buffer and channel iterators. Get each event of a channel in order. Uses
6 * a prio heap for per-cpu buffers, giving a O(log(NR_CPUS)) algorithmic
7 * complexity for the "get next event" operation.
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <wrapper/ringbuffer/iterator.h>
13 #include <wrapper/file.h>
14 #include <wrapper/uaccess.h>
15 #include <linux/jiffies.h>
16 #include <linux/delay.h>
17 #include <linux/module.h>
20 * Safety factor taking into account internal kernel interrupt latency.
21 * Assuming 250ms worse-case latency.
23 #define MAX_SYSTEM_LATENCY 250
26 * Maximum delta expected between trace clocks. At most 1 jiffy delta.
28 #define MAX_CLOCK_DELTA (jiffies_to_usecs(1) * 1000)
31 * lib_ring_buffer_get_next_record - Get the next record in a buffer.
35 * Returns the size of the event read, -EAGAIN if buffer is empty, -ENODATA if
36 * buffer is empty and finalized. The buffer must already be opened for reading.
38 ssize_t
lib_ring_buffer_get_next_record(struct channel
*chan
,
39 struct lib_ring_buffer
*buf
)
41 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
42 struct lib_ring_buffer_iter
*iter
= &buf
->iter
;
46 switch (iter
->state
) {
48 ret
= lib_ring_buffer_get_next_subbuf(buf
);
49 if (ret
&& !READ_ONCE(buf
->finalized
)
50 && config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
) {
52 * Use "pull" scheme for global buffers. The reader
53 * itself flushes the buffer to "pull" data not visible
54 * to readers yet. Flush current subbuffer and re-try.
56 * Per-CPU buffers rather use a "push" scheme because
57 * the IPI needed to flush all CPU's buffers is too
58 * costly. In the "push" scheme, the reader waits for
59 * the writer periodic timer to flush the
60 * buffers (keeping track of a quiescent state
61 * timestamp). Therefore, the writer "pushes" data out
62 * of the buffers rather than letting the reader "pull"
63 * data from the buffer.
65 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
66 ret
= lib_ring_buffer_get_next_subbuf(buf
);
70 iter
->consumed
= buf
->cons_snapshot
;
71 iter
->data_size
= lib_ring_buffer_get_read_data_size(config
, buf
);
72 iter
->read_offset
= iter
->consumed
;
74 iter
->read_offset
+= config
->cb
.subbuffer_header_size();
75 iter
->state
= ITER_TEST_RECORD
;
77 case ITER_TEST_RECORD
:
78 if (iter
->read_offset
- iter
->consumed
>= iter
->data_size
) {
79 iter
->state
= ITER_PUT_SUBBUF
;
81 CHAN_WARN_ON(chan
, !config
->cb
.record_get
);
82 config
->cb
.record_get(config
, chan
, buf
,
87 iter
->read_offset
+= iter
->header_len
;
88 subbuffer_consume_record(config
, &buf
->backend
);
89 iter
->state
= ITER_NEXT_RECORD
;
90 return iter
->payload_len
;
93 case ITER_NEXT_RECORD
:
94 iter
->read_offset
+= iter
->payload_len
;
95 iter
->state
= ITER_TEST_RECORD
;
98 lib_ring_buffer_put_next_subbuf(buf
);
99 iter
->state
= ITER_GET_SUBBUF
;
102 CHAN_WARN_ON(chan
, 1); /* Should not happen */
106 EXPORT_SYMBOL_GPL(lib_ring_buffer_get_next_record
);
108 static int buf_is_higher(void *a
, void *b
)
110 struct lib_ring_buffer
*bufa
= a
;
111 struct lib_ring_buffer
*bufb
= b
;
113 /* Consider lowest timestamps to be at the top of the heap */
114 return (bufa
->iter
.timestamp
< bufb
->iter
.timestamp
);
118 void lib_ring_buffer_get_empty_buf_records(const struct lib_ring_buffer_config
*config
,
119 struct channel
*chan
)
121 struct lttng_ptr_heap
*heap
= &chan
->iter
.heap
;
122 struct lib_ring_buffer
*buf
, *tmp
;
125 list_for_each_entry_safe(buf
, tmp
, &chan
->iter
.empty_head
,
127 len
= lib_ring_buffer_get_next_record(chan
, buf
);
130 * Deal with -EAGAIN and -ENODATA.
131 * len >= 0 means record contains data.
132 * -EBUSY should never happen, because we support only one
137 /* Keep node in empty list */
141 * Buffer is finalized. Don't add to list of empty
142 * buffer, because it has no more data to provide, ever.
144 list_del(&buf
->iter
.empty_node
);
147 CHAN_WARN_ON(chan
, 1);
151 * Insert buffer into the heap, remove from empty buffer
154 CHAN_WARN_ON(chan
, len
< 0);
155 list_del(&buf
->iter
.empty_node
);
156 CHAN_WARN_ON(chan
, lttng_heap_insert(heap
, buf
));
162 void lib_ring_buffer_wait_for_qs(const struct lib_ring_buffer_config
*config
,
163 struct channel
*chan
)
166 unsigned long wait_msecs
;
169 * No need to wait if no empty buffers are present.
171 if (list_empty(&chan
->iter
.empty_head
))
174 timestamp_qs
= config
->cb
.ring_buffer_clock_read(chan
);
176 * We need to consider previously empty buffers.
177 * Do a get next buf record on each of them. Add them to
178 * the heap if they have data. If at least one of them
179 * don't have data, we need to wait for
180 * switch_timer_interval + MAX_SYSTEM_LATENCY (so we are sure the
181 * buffers have been switched either by the timer or idle entry) and
182 * check them again, adding them if they have data.
184 lib_ring_buffer_get_empty_buf_records(config
, chan
);
187 * No need to wait if no empty buffers are present.
189 if (list_empty(&chan
->iter
.empty_head
))
193 * We need to wait for the buffer switch timer to run. If the
194 * CPU is idle, idle entry performed the switch.
195 * TODO: we could optimize further by skipping the sleep if all
196 * empty buffers belong to idle or offline cpus.
198 wait_msecs
= jiffies_to_msecs(chan
->switch_timer_interval
);
199 wait_msecs
+= MAX_SYSTEM_LATENCY
;
201 lib_ring_buffer_get_empty_buf_records(config
, chan
);
203 * Any buffer still in the empty list here cannot possibly
204 * contain an event with a timestamp prior to "timestamp_qs".
205 * The new quiescent state timestamp is the one we grabbed
206 * before waiting for buffer data. It is therefore safe to
207 * ignore empty buffers up to last_qs timestamp for fusion
210 chan
->iter
.last_qs
= timestamp_qs
;
214 * channel_get_next_record - Get the next record in a channel.
216 * @ret_buf: the buffer in which the event is located (output)
218 * Returns the size of new current event, -EAGAIN if all buffers are empty,
219 * -ENODATA if all buffers are empty and finalized. The channel must already be
220 * opened for reading.
223 ssize_t
channel_get_next_record(struct channel
*chan
,
224 struct lib_ring_buffer
**ret_buf
)
226 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
227 struct lib_ring_buffer
*buf
;
228 struct lttng_ptr_heap
*heap
;
231 if (config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
) {
232 *ret_buf
= channel_get_ring_buffer(config
, chan
, 0);
233 return lib_ring_buffer_get_next_record(chan
, *ret_buf
);
236 heap
= &chan
->iter
.heap
;
239 * get next record for topmost buffer.
241 buf
= lttng_heap_maximum(heap
);
243 len
= lib_ring_buffer_get_next_record(chan
, buf
);
245 * Deal with -EAGAIN and -ENODATA.
246 * len >= 0 means record contains data.
250 buf
->iter
.timestamp
= 0;
251 list_add(&buf
->iter
.empty_node
, &chan
->iter
.empty_head
);
252 /* Remove topmost buffer from the heap */
253 CHAN_WARN_ON(chan
, lttng_heap_remove(heap
) != buf
);
257 * Buffer is finalized. Remove buffer from heap and
258 * don't add to list of empty buffer, because it has no
259 * more data to provide, ever.
261 CHAN_WARN_ON(chan
, lttng_heap_remove(heap
) != buf
);
264 CHAN_WARN_ON(chan
, 1);
268 * Reinsert buffer into the heap. Note that heap can be
269 * partially empty, so we need to use
270 * lttng_heap_replace_max().
272 CHAN_WARN_ON(chan
, len
< 0);
273 CHAN_WARN_ON(chan
, lttng_heap_replace_max(heap
, buf
) != buf
);
278 buf
= lttng_heap_maximum(heap
);
279 if (!buf
|| buf
->iter
.timestamp
> chan
->iter
.last_qs
) {
281 * Deal with buffers previously showing no data.
282 * Add buffers containing data to the heap, update
285 lib_ring_buffer_wait_for_qs(config
, chan
);
288 *ret_buf
= buf
= lttng_heap_maximum(heap
);
291 * If this warning triggers, you probably need to check your
292 * system interrupt latency. Typical causes: too many printk()
293 * output going to a serial console with interrupts off.
294 * Allow for MAX_CLOCK_DELTA ns timestamp delta going backward.
295 * Observed on SMP KVM setups with trace_clock().
297 if (chan
->iter
.last_timestamp
298 > (buf
->iter
.timestamp
+ MAX_CLOCK_DELTA
)) {
299 printk(KERN_WARNING
"ring_buffer: timestamps going "
300 "backward. Last time %llu ns, cpu %d, "
301 "current time %llu ns, cpu %d, "
303 chan
->iter
.last_timestamp
, chan
->iter
.last_cpu
,
304 buf
->iter
.timestamp
, buf
->backend
.cpu
,
305 chan
->iter
.last_timestamp
- buf
->iter
.timestamp
);
306 CHAN_WARN_ON(chan
, 1);
308 chan
->iter
.last_timestamp
= buf
->iter
.timestamp
;
309 chan
->iter
.last_cpu
= buf
->backend
.cpu
;
310 return buf
->iter
.payload_len
;
313 if (list_empty(&chan
->iter
.empty_head
))
314 return -ENODATA
; /* All buffers finalized */
316 return -EAGAIN
; /* Temporarily empty */
319 EXPORT_SYMBOL_GPL(channel_get_next_record
);
322 void lib_ring_buffer_iterator_init(struct channel
*chan
, struct lib_ring_buffer
*buf
)
324 if (buf
->iter
.allocated
)
327 buf
->iter
.allocated
= 1;
328 if (chan
->iter
.read_open
&& !buf
->iter
.read_open
) {
329 CHAN_WARN_ON(chan
, lib_ring_buffer_open_read(buf
) != 0);
330 buf
->iter
.read_open
= 1;
333 /* Add to list of buffers without any current record */
334 if (chan
->backend
.config
.alloc
== RING_BUFFER_ALLOC_PER_CPU
)
335 list_add(&buf
->iter
.empty_node
, &chan
->iter
.empty_head
);
338 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
340 int lttng_cpuhp_rb_iter_online(unsigned int cpu
,
341 struct lttng_cpuhp_node
*node
)
343 struct channel
*chan
= container_of(node
, struct channel
,
345 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
, cpu
);
346 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
348 CHAN_WARN_ON(chan
, config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
);
350 lib_ring_buffer_iterator_init(chan
, buf
);
353 EXPORT_SYMBOL_GPL(lttng_cpuhp_rb_iter_online
);
355 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
357 #ifdef CONFIG_HOTPLUG_CPU
359 int channel_iterator_cpu_hotplug(struct notifier_block
*nb
,
360 unsigned long action
,
363 unsigned int cpu
= (unsigned long)hcpu
;
364 struct channel
*chan
= container_of(nb
, struct channel
,
366 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
, cpu
);
367 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
369 if (!chan
->hp_iter_enable
)
372 CHAN_WARN_ON(chan
, config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
);
375 case CPU_DOWN_FAILED
:
376 case CPU_DOWN_FAILED_FROZEN
:
378 case CPU_ONLINE_FROZEN
:
379 lib_ring_buffer_iterator_init(chan
, buf
);
387 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
389 int channel_iterator_init(struct channel
*chan
)
391 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
392 struct lib_ring_buffer
*buf
;
394 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
397 INIT_LIST_HEAD(&chan
->iter
.empty_head
);
398 ret
= lttng_heap_init(&chan
->iter
.heap
,
400 GFP_KERNEL
, buf_is_higher
);
404 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
405 chan
->cpuhp_iter_online
.component
= LTTNG_RING_BUFFER_ITER
;
406 ret
= cpuhp_state_add_instance(lttng_rb_hp_online
,
407 &chan
->cpuhp_iter_online
.node
);
410 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
415 * In case of non-hotplug cpu, if the ring-buffer is allocated
416 * in early initcall, it will not be notified of secondary cpus.
417 * In that off case, we need to allocate for all possible cpus.
419 #ifdef CONFIG_HOTPLUG_CPU
420 chan
->hp_iter_notifier
.notifier_call
=
421 channel_iterator_cpu_hotplug
;
422 chan
->hp_iter_notifier
.priority
= 10;
423 register_cpu_notifier(&chan
->hp_iter_notifier
);
426 for_each_online_cpu(cpu
) {
427 buf
= per_cpu_ptr(chan
->backend
.buf
, cpu
);
428 lib_ring_buffer_iterator_init(chan
, buf
);
430 chan
->hp_iter_enable
= 1;
433 for_each_possible_cpu(cpu
) {
434 buf
= per_cpu_ptr(chan
->backend
.buf
, cpu
);
435 lib_ring_buffer_iterator_init(chan
, buf
);
439 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
441 buf
= channel_get_ring_buffer(config
, chan
, 0);
442 lib_ring_buffer_iterator_init(chan
, buf
);
447 void channel_iterator_unregister_notifiers(struct channel
*chan
)
449 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
451 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
452 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
456 ret
= cpuhp_state_remove_instance(lttng_rb_hp_online
,
457 &chan
->cpuhp_iter_online
.node
);
460 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
461 chan
->hp_iter_enable
= 0;
462 unregister_cpu_notifier(&chan
->hp_iter_notifier
);
463 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
467 void channel_iterator_free(struct channel
*chan
)
469 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
471 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
472 lttng_heap_free(&chan
->iter
.heap
);
475 int lib_ring_buffer_iterator_open(struct lib_ring_buffer
*buf
)
477 struct channel
*chan
= buf
->backend
.chan
;
478 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
479 CHAN_WARN_ON(chan
, config
->output
!= RING_BUFFER_ITERATOR
);
480 return lib_ring_buffer_open_read(buf
);
482 EXPORT_SYMBOL_GPL(lib_ring_buffer_iterator_open
);
485 * Note: Iterators must not be mixed with other types of outputs, because an
486 * iterator can leave the buffer in "GET" state, which is not consistent with
487 * other types of output (mmap, splice, raw data read).
489 void lib_ring_buffer_iterator_release(struct lib_ring_buffer
*buf
)
491 lib_ring_buffer_release_read(buf
);
493 EXPORT_SYMBOL_GPL(lib_ring_buffer_iterator_release
);
495 int channel_iterator_open(struct channel
*chan
)
497 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
498 struct lib_ring_buffer
*buf
;
501 CHAN_WARN_ON(chan
, config
->output
!= RING_BUFFER_ITERATOR
);
503 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
505 /* Allow CPU hotplug to keep track of opened reader */
506 chan
->iter
.read_open
= 1;
507 for_each_channel_cpu(cpu
, chan
) {
508 buf
= channel_get_ring_buffer(config
, chan
, cpu
);
509 ret
= lib_ring_buffer_iterator_open(buf
);
512 buf
->iter
.read_open
= 1;
516 buf
= channel_get_ring_buffer(config
, chan
, 0);
517 ret
= lib_ring_buffer_iterator_open(buf
);
521 /* Error should always happen on CPU 0, hence no close is required. */
522 CHAN_WARN_ON(chan
, cpu
!= 0);
526 EXPORT_SYMBOL_GPL(channel_iterator_open
);
528 void channel_iterator_release(struct channel
*chan
)
530 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
531 struct lib_ring_buffer
*buf
;
534 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
536 for_each_channel_cpu(cpu
, chan
) {
537 buf
= channel_get_ring_buffer(config
, chan
, cpu
);
538 if (buf
->iter
.read_open
) {
539 lib_ring_buffer_iterator_release(buf
);
540 buf
->iter
.read_open
= 0;
543 chan
->iter
.read_open
= 0;
546 buf
= channel_get_ring_buffer(config
, chan
, 0);
547 lib_ring_buffer_iterator_release(buf
);
550 EXPORT_SYMBOL_GPL(channel_iterator_release
);
552 void lib_ring_buffer_iterator_reset(struct lib_ring_buffer
*buf
)
554 struct channel
*chan
= buf
->backend
.chan
;
556 if (buf
->iter
.state
!= ITER_GET_SUBBUF
)
557 lib_ring_buffer_put_next_subbuf(buf
);
558 buf
->iter
.state
= ITER_GET_SUBBUF
;
559 /* Remove from heap (if present). */
560 if (lttng_heap_cherrypick(&chan
->iter
.heap
, buf
))
561 list_add(&buf
->iter
.empty_node
, &chan
->iter
.empty_head
);
562 buf
->iter
.timestamp
= 0;
563 buf
->iter
.header_len
= 0;
564 buf
->iter
.payload_len
= 0;
565 buf
->iter
.consumed
= 0;
566 buf
->iter
.read_offset
= 0;
567 buf
->iter
.data_size
= 0;
568 /* Don't reset allocated and read_open */
571 void channel_iterator_reset(struct channel
*chan
)
573 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
574 struct lib_ring_buffer
*buf
;
577 /* Empty heap, put into empty_head */
578 while ((buf
= lttng_heap_remove(&chan
->iter
.heap
)) != NULL
)
579 list_add(&buf
->iter
.empty_node
, &chan
->iter
.empty_head
);
581 for_each_channel_cpu(cpu
, chan
) {
582 buf
= channel_get_ring_buffer(config
, chan
, cpu
);
583 lib_ring_buffer_iterator_reset(buf
);
585 /* Don't reset read_open */
586 chan
->iter
.last_qs
= 0;
587 chan
->iter
.last_timestamp
= 0;
588 chan
->iter
.last_cpu
= 0;
589 chan
->iter
.len_left
= 0;
593 * Ring buffer payload extraction read() implementation.
596 ssize_t
channel_ring_buffer_file_read(struct file
*filp
,
597 char __user
*user_buf
,
600 struct channel
*chan
,
601 struct lib_ring_buffer
*buf
,
604 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
605 size_t read_count
= 0, read_offset
;
609 if (!lttng_access_ok(VERIFY_WRITE
, user_buf
, count
))
612 /* Finish copy of previous record */
614 if (read_count
< count
) {
615 len
= chan
->iter
.len_left
;
617 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
619 buf
= lttng_heap_maximum(&chan
->iter
.heap
);
620 CHAN_WARN_ON(chan
, !buf
);
625 while (read_count
< count
) {
626 size_t copy_len
, space_left
;
629 len
= channel_get_next_record(chan
, &buf
);
631 len
= lib_ring_buffer_get_next_record(chan
, buf
);
635 * Check if buffer is finalized (end of file).
637 if (len
== -ENODATA
) {
638 /* A 0 read_count will tell about end of file */
641 if (filp
->f_flags
& O_NONBLOCK
) {
643 read_count
= -EAGAIN
;
649 * No data available at the moment, return what
656 * Wait for returned len to be >= 0 or -ENODATA.
659 error
= wait_event_interruptible(
661 ((len
= channel_get_next_record(chan
,
662 &buf
)), len
!= -EAGAIN
));
664 error
= wait_event_interruptible(
666 ((len
= lib_ring_buffer_get_next_record(
667 chan
, buf
)), len
!= -EAGAIN
));
668 CHAN_WARN_ON(chan
, len
== -EBUSY
);
673 CHAN_WARN_ON(chan
, len
< 0 && len
!= -ENODATA
);
677 read_offset
= buf
->iter
.read_offset
;
679 space_left
= count
- read_count
;
680 if (len
<= space_left
) {
682 chan
->iter
.len_left
= 0;
685 copy_len
= space_left
;
686 chan
->iter
.len_left
= len
- copy_len
;
687 *ppos
= read_offset
+ copy_len
;
689 if (__lib_ring_buffer_copy_to_user(&buf
->backend
, read_offset
,
690 &user_buf
[read_count
],
693 * Leave the len_left and ppos values at their current
694 * state, as we currently have a valid event to read.
698 read_count
+= copy_len
;
704 chan
->iter
.len_left
= 0;
709 * lib_ring_buffer_file_read - Read buffer record payload.
710 * @filp: file structure pointer.
711 * @buffer: user buffer to read data into.
712 * @count: number of bytes to read.
713 * @ppos: file read position.
715 * Returns a negative value on error, or the number of bytes read on success.
716 * ppos is used to save the position _within the current record_ between calls
720 ssize_t
lib_ring_buffer_file_read(struct file
*filp
,
721 char __user
*user_buf
,
725 struct inode
*inode
= filp
->lttng_f_dentry
->d_inode
;
726 struct lib_ring_buffer
*buf
= inode
->i_private
;
727 struct channel
*chan
= buf
->backend
.chan
;
729 return channel_ring_buffer_file_read(filp
, user_buf
, count
, ppos
,
734 * channel_file_read - Read channel record payload.
735 * @filp: file structure pointer.
736 * @buffer: user buffer to read data into.
737 * @count: number of bytes to read.
738 * @ppos: file read position.
740 * Returns a negative value on error, or the number of bytes read on success.
741 * ppos is used to save the position _within the current record_ between calls
745 ssize_t
channel_file_read(struct file
*filp
,
746 char __user
*user_buf
,
750 struct inode
*inode
= filp
->lttng_f_dentry
->d_inode
;
751 struct channel
*chan
= inode
->i_private
;
752 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
754 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
755 return channel_ring_buffer_file_read(filp
, user_buf
, count
,
756 ppos
, chan
, NULL
, 1);
758 struct lib_ring_buffer
*buf
=
759 channel_get_ring_buffer(config
, chan
, 0);
760 return channel_ring_buffer_file_read(filp
, user_buf
, count
,
766 int lib_ring_buffer_file_open(struct inode
*inode
, struct file
*file
)
768 struct lib_ring_buffer
*buf
= inode
->i_private
;
771 ret
= lib_ring_buffer_iterator_open(buf
);
775 file
->private_data
= buf
;
776 ret
= nonseekable_open(inode
, file
);
782 lib_ring_buffer_iterator_release(buf
);
787 int lib_ring_buffer_file_release(struct inode
*inode
, struct file
*file
)
789 struct lib_ring_buffer
*buf
= inode
->i_private
;
791 lib_ring_buffer_iterator_release(buf
);
796 int channel_file_open(struct inode
*inode
, struct file
*file
)
798 struct channel
*chan
= inode
->i_private
;
801 ret
= channel_iterator_open(chan
);
805 file
->private_data
= chan
;
806 ret
= nonseekable_open(inode
, file
);
812 channel_iterator_release(chan
);
817 int channel_file_release(struct inode
*inode
, struct file
*file
)
819 struct channel
*chan
= inode
->i_private
;
821 channel_iterator_release(chan
);
825 const struct file_operations channel_payload_file_operations
= {
826 .owner
= THIS_MODULE
,
827 .open
= channel_file_open
,
828 .release
= channel_file_release
,
829 .read
= channel_file_read
,
830 .llseek
= vfs_lib_ring_buffer_no_llseek
,
832 EXPORT_SYMBOL_GPL(channel_payload_file_operations
);
834 const struct file_operations lib_ring_buffer_payload_file_operations
= {
835 .owner
= THIS_MODULE
,
836 .open
= lib_ring_buffer_file_open
,
837 .release
= lib_ring_buffer_file_release
,
838 .read
= lib_ring_buffer_file_read
,
839 .llseek
= vfs_lib_ring_buffer_no_llseek
,
841 EXPORT_SYMBOL_GPL(lib_ring_buffer_payload_file_operations
);