Commit | Line | Data |
---|---|---|
886d51a3 MD |
1 | #ifndef _LIB_RING_BUFFER_VFS_H |
2 | #define _LIB_RING_BUFFER_VFS_H | |
f3bc08c5 MD |
3 | |
4 | /* | |
886d51a3 | 5 | * lib/ringbuffer/vfs.h |
f3bc08c5 MD |
6 | * |
7 | * Wait-free ring buffer VFS file operations. | |
8 | * | |
886d51a3 MD |
9 | * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
10 | * | |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; only | |
14 | * version 2.1 of the License. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | * | |
f3bc08c5 MD |
25 | * Author: |
26 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
f3bc08c5 MD |
27 | */ |
28 | ||
29 | #include <linux/fs.h> | |
30 | #include <linux/poll.h> | |
31 | ||
32 | /* VFS API */ | |
33 | ||
34 | extern const struct file_operations lib_ring_buffer_file_operations; | |
35 | ||
36 | /* | |
37 | * Internal file operations. | |
38 | */ | |
39 | ||
d83004aa JD |
40 | struct lib_ring_buffer; |
41 | ||
42 | int lib_ring_buffer_open(struct inode *inode, struct file *file, | |
43 | struct lib_ring_buffer *buf); | |
44 | int lib_ring_buffer_release(struct inode *inode, struct file *file, | |
45 | struct lib_ring_buffer *buf); | |
46 | unsigned int lib_ring_buffer_poll(struct file *filp, poll_table *wait, | |
47 | struct lib_ring_buffer *buf); | |
f3bc08c5 | 48 | ssize_t lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, |
d83004aa JD |
49 | struct pipe_inode_info *pipe, size_t len, |
50 | unsigned int flags, struct lib_ring_buffer *buf); | |
51 | int lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma, | |
52 | struct lib_ring_buffer *buf); | |
f3bc08c5 MD |
53 | |
54 | /* Ring Buffer ioctl() and ioctl numbers */ | |
d83004aa JD |
55 | long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, |
56 | unsigned long arg, struct lib_ring_buffer *buf); | |
f3bc08c5 MD |
57 | #ifdef CONFIG_COMPAT |
58 | long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, | |
d83004aa | 59 | unsigned long arg, struct lib_ring_buffer *buf); |
f3bc08c5 MD |
60 | #endif |
61 | ||
d83004aa JD |
62 | ssize_t vfs_lib_ring_buffer_file_splice_read(struct file *in, loff_t *ppos, |
63 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); | |
64 | loff_t vfs_lib_ring_buffer_no_llseek(struct file *file, loff_t offset, | |
65 | int origin); | |
66 | int vfs_lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma); | |
67 | ssize_t vfs_lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, | |
68 | struct pipe_inode_info *pipe, size_t len, | |
69 | unsigned int flags); | |
70 | ||
f3bc08c5 MD |
71 | /* |
72 | * Use RING_BUFFER_GET_NEXT_SUBBUF / RING_BUFFER_PUT_NEXT_SUBBUF to read and | |
73 | * consume sub-buffers sequentially. | |
74 | * | |
75 | * Reading sub-buffers without consuming them can be performed with: | |
76 | * | |
77 | * RING_BUFFER_SNAPSHOT | |
78 | * RING_BUFFER_SNAPSHOT_GET_CONSUMED | |
79 | * RING_BUFFER_SNAPSHOT_GET_PRODUCED | |
80 | * | |
81 | * to get the offset range to consume, and then by passing each sub-buffer | |
82 | * offset to RING_BUFFER_GET_SUBBUF, read the sub-buffer, and then release it | |
83 | * with RING_BUFFER_PUT_SUBBUF. | |
84 | * | |
85 | * Note that the "snapshot" API can be used to read the sub-buffer in reverse | |
86 | * order, which is useful for flight recorder snapshots. | |
87 | */ | |
88 | ||
89 | /* Get a snapshot of the current ring buffer producer and consumer positions */ | |
90 | #define RING_BUFFER_SNAPSHOT _IO(0xF6, 0x00) | |
91 | /* Get the consumer position (iteration start) */ | |
92 | #define RING_BUFFER_SNAPSHOT_GET_CONSUMED _IOR(0xF6, 0x01, unsigned long) | |
76447e2f JD |
93 | /* Get the producer position (iteration end) */ |
94 | #define RING_BUFFER_SNAPSHOT_GET_PRODUCED _IOR(0xF6, 0x02, unsigned long) | |
95 | /* Get exclusive read access to the specified sub-buffer position */ | |
96 | #define RING_BUFFER_GET_SUBBUF _IOW(0xF6, 0x03, unsigned long) | |
97 | /* Release exclusive sub-buffer access */ | |
98 | #define RING_BUFFER_PUT_SUBBUF _IO(0xF6, 0x04) | |
99 | ||
100 | /* Get exclusive read access to the next sub-buffer that can be read. */ | |
101 | #define RING_BUFFER_GET_NEXT_SUBBUF _IO(0xF6, 0x05) | |
102 | /* Release exclusive sub-buffer access, move consumer forward. */ | |
103 | #define RING_BUFFER_PUT_NEXT_SUBBUF _IO(0xF6, 0x06) | |
104 | /* returns the size of the current sub-buffer, without padding (for mmap). */ | |
105 | #define RING_BUFFER_GET_SUBBUF_SIZE _IOR(0xF6, 0x07, unsigned long) | |
106 | /* returns the size of the current sub-buffer, with padding (for splice). */ | |
107 | #define RING_BUFFER_GET_PADDED_SUBBUF_SIZE _IOR(0xF6, 0x08, unsigned long) | |
108 | /* returns the maximum size for sub-buffers. */ | |
109 | #define RING_BUFFER_GET_MAX_SUBBUF_SIZE _IOR(0xF6, 0x09, unsigned long) | |
110 | /* returns the length to mmap. */ | |
111 | #define RING_BUFFER_GET_MMAP_LEN _IOR(0xF6, 0x0A, unsigned long) | |
112 | /* returns the offset of the subbuffer belonging to the mmap reader. */ | |
113 | #define RING_BUFFER_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, unsigned long) | |
c6f05468 | 114 | /* Flush the current sub-buffer, if non-empty. */ |
76447e2f | 115 | #define RING_BUFFER_FLUSH _IO(0xF6, 0x0C) |
9616f0bf JD |
116 | /* Get the current version of the metadata cache (after a get_next). */ |
117 | #define RING_BUFFER_GET_METADATA_VERSION _IOR(0xF6, 0x0D, uint64_t) | |
4dce5a48 JG |
118 | /* |
119 | * Get a snapshot of the current ring buffer producer and consumer positions, | |
120 | * regardless of whether or not the two positions are contained within the same | |
121 | * sub-buffer. | |
122 | */ | |
123 | #define RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS _IO(0xF6, 0x0E) | |
c6f05468 MD |
124 | /* Flush the current sub-buffer, even if empty. */ |
125 | #define RING_BUFFER_FLUSH_EMPTY _IO(0xF6, 0x0F) | |
d1344afa JD |
126 | /* |
127 | * Reset the position of what has been consumed from the metadata cache to 0 | |
128 | * so it can be read again. | |
129 | */ | |
130 | #define RING_BUFFER_METADATA_CACHE_DUMP _IO(0xF6, 0x10) | |
76447e2f JD |
131 | |
132 | #ifdef CONFIG_COMPAT | |
133 | /* Get a snapshot of the current ring buffer producer and consumer positions */ | |
134 | #define RING_BUFFER_COMPAT_SNAPSHOT RING_BUFFER_SNAPSHOT | |
135 | /* Get the consumer position (iteration start) */ | |
216f7feb JD |
136 | #define RING_BUFFER_COMPAT_SNAPSHOT_GET_CONSUMED \ |
137 | _IOR(0xF6, 0x01, compat_ulong_t) | |
f3bc08c5 | 138 | /* Get the producer position (iteration end) */ |
216f7feb JD |
139 | #define RING_BUFFER_COMPAT_SNAPSHOT_GET_PRODUCED \ |
140 | _IOR(0xF6, 0x02, compat_ulong_t) | |
f3bc08c5 | 141 | /* Get exclusive read access to the specified sub-buffer position */ |
216f7feb | 142 | #define RING_BUFFER_COMPAT_GET_SUBBUF _IOW(0xF6, 0x03, compat_ulong_t) |
f3bc08c5 | 143 | /* Release exclusive sub-buffer access */ |
216f7feb | 144 | #define RING_BUFFER_COMPAT_PUT_SUBBUF RING_BUFFER_PUT_SUBBUF |
f3bc08c5 MD |
145 | |
146 | /* Get exclusive read access to the next sub-buffer that can be read. */ | |
216f7feb | 147 | #define RING_BUFFER_COMPAT_GET_NEXT_SUBBUF RING_BUFFER_GET_NEXT_SUBBUF |
f3bc08c5 | 148 | /* Release exclusive sub-buffer access, move consumer forward. */ |
216f7feb | 149 | #define RING_BUFFER_COMPAT_PUT_NEXT_SUBBUF RING_BUFFER_PUT_NEXT_SUBBUF |
f3bc08c5 | 150 | /* returns the size of the current sub-buffer, without padding (for mmap). */ |
216f7feb | 151 | #define RING_BUFFER_COMPAT_GET_SUBBUF_SIZE _IOR(0xF6, 0x07, compat_ulong_t) |
f3bc08c5 | 152 | /* returns the size of the current sub-buffer, with padding (for splice). */ |
216f7feb JD |
153 | #define RING_BUFFER_COMPAT_GET_PADDED_SUBBUF_SIZE \ |
154 | _IOR(0xF6, 0x08, compat_ulong_t) | |
f3bc08c5 | 155 | /* returns the maximum size for sub-buffers. */ |
216f7feb | 156 | #define RING_BUFFER_COMPAT_GET_MAX_SUBBUF_SIZE _IOR(0xF6, 0x09, compat_ulong_t) |
f3bc08c5 | 157 | /* returns the length to mmap. */ |
216f7feb | 158 | #define RING_BUFFER_COMPAT_GET_MMAP_LEN _IOR(0xF6, 0x0A, compat_ulong_t) |
f3bc08c5 | 159 | /* returns the offset of the subbuffer belonging to the mmap reader. */ |
216f7feb | 160 | #define RING_BUFFER_COMPAT_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, compat_ulong_t) |
c6f05468 | 161 | /* Flush the current sub-buffer, if non-empty. */ |
216f7feb | 162 | #define RING_BUFFER_COMPAT_FLUSH RING_BUFFER_FLUSH |
9616f0bf JD |
163 | /* Get the current version of the metadata cache (after a get_next). */ |
164 | #define RING_BUFFER_COMPAT_GET_METADATA_VERSION RING_BUFFER_GET_METADATA_VERSION | |
4dce5a48 JG |
165 | /* |
166 | * Get a snapshot of the current ring buffer producer and consumer positions, | |
167 | * regardless of whether or not the two positions are contained within the same | |
168 | * sub-buffer. | |
169 | */ | |
170 | #define RING_BUFFER_COMPAT_SNAPSHOT_SAMPLE_POSITIONS \ | |
171 | RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS | |
c6f05468 MD |
172 | /* Flush the current sub-buffer, even if empty. */ |
173 | #define RING_BUFFER_COMPAT_FLUSH_EMPTY \ | |
174 | RING_BUFFER_FLUSH_EMPTY | |
76447e2f | 175 | #endif /* CONFIG_COMPAT */ |
f3bc08c5 | 176 | |
886d51a3 | 177 | #endif /* _LIB_RING_BUFFER_VFS_H */ |