/*
* ring_buffer_vfs.c
*
- * Copyright (C) 2009-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
* Ring Buffer VFS file operations.
*
- * Dual LGPL v2.1/GPL v2 license.
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <linux/module.h>
}
#endif
-/**
- * lib_ring_buffer_open - ring buffer open file operation
- * @inode: opened inode
- * @file: opened file
- *
- * Open implementation. Makes sure only one open instance of a buffer is
- * done at a given moment.
- */
-int lib_ring_buffer_open(struct inode *inode, struct file *file)
+int lib_ring_buffer_open(struct inode *inode, struct file *file,
+ struct lib_ring_buffer *buf)
{
- struct lib_ring_buffer *buf = inode->i_private;
int ret;
+ if (!buf)
+ return -EINVAL;
+
ret = lib_ring_buffer_open_read(buf);
if (ret)
return ret;
- file->private_data = buf;
ret = nonseekable_open(inode, file);
if (ret)
goto release_read;
lib_ring_buffer_release_read(buf);
return ret;
}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_open);
/**
- * lib_ring_buffer_release - ring buffer release file operation
+ * vfs_lib_ring_buffer_open - ring buffer open file operation
* @inode: opened inode
* @file: opened file
*
- * Release implementation.
+ * Open implementation. Makes sure only one open instance of a buffer is
+ * done at a given moment.
*/
-int lib_ring_buffer_release(struct inode *inode, struct file *file)
+static
+int vfs_lib_ring_buffer_open(struct inode *inode, struct file *file)
{
- struct lib_ring_buffer *buf = file->private_data;
+ struct lib_ring_buffer *buf = inode->i_private;
+ file->private_data = buf;
+ return lib_ring_buffer_open(inode, file, buf);
+}
+
+int lib_ring_buffer_release(struct inode *inode, struct file *file,
+ struct lib_ring_buffer *buf)
+{
lib_ring_buffer_release_read(buf);
return 0;
}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_release);
/**
- * lib_ring_buffer_poll - ring buffer poll file operation
- * @filp: the file
- * @wait: poll table
+ * vfs_lib_ring_buffer_release - ring buffer release file operation
+ * @inode: opened inode
+ * @file: opened file
*
- * Poll implementation.
+ * Release implementation.
*/
-unsigned int lib_ring_buffer_poll(struct file *filp, poll_table *wait)
+static
+int vfs_lib_ring_buffer_release(struct inode *inode, struct file *file)
+{
+ struct lib_ring_buffer *buf = file->private_data;
+
+ return lib_ring_buffer_release(inode, file, buf);
+}
+
+unsigned int lib_ring_buffer_poll(struct file *filp, poll_table *wait,
+ struct lib_ring_buffer *buf)
{
unsigned int mask = 0;
- struct lib_ring_buffer *buf = filp->private_data;
struct channel *chan = buf->backend.chan;
- const struct lib_ring_buffer_config *config = chan->backend.config;
- int finalized;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
+ int finalized, disabled;
if (filp->f_mode & FMODE_READ) {
poll_wait_set_exclusive(wait);
poll_wait(filp, &buf->read_wait, wait);
finalized = lib_ring_buffer_is_finalized(config, buf);
+ disabled = lib_ring_buffer_channel_is_disabled(chan);
+
/*
* lib_ring_buffer_is_finalized() contains a smp_rmb() ordering
* finalized load before offsets loads.
*/
WARN_ON(atomic_long_read(&buf->active_readers) != 1);
retry:
+ if (disabled)
+ return POLLERR;
+
if (subbuf_trunc(lib_ring_buffer_get_offset(config, buf), chan)
- subbuf_trunc(lib_ring_buffer_get_consumed(config, buf), chan)
== 0) {
}
return mask;
}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_poll);
/**
- * lib_ring_buffer_ioctl - control ring buffer reader synchronization
- *
+ * vfs_lib_ring_buffer_poll - ring buffer poll file operation
* @filp: the file
- * @cmd: the command
- * @arg: command arg
+ * @wait: poll table
*
- * This ioctl implements commands necessary for producer/consumer
- * and flight recorder reader interaction :
- * RING_BUFFER_GET_NEXT_SUBBUF
- * Get the next sub-buffer that can be read. It never blocks.
- * RING_BUFFER_PUT_NEXT_SUBBUF
- * Release the currently read sub-buffer.
- * RING_BUFFER_GET_SUBBUF_SIZE
- * returns the size of the current sub-buffer.
- * RING_BUFFER_GET_MAX_SUBBUF_SIZE
- * returns the maximum size for sub-buffers.
- * RING_BUFFER_GET_NUM_SUBBUF
- * returns the number of reader-visible sub-buffers in the per cpu
- * channel (for mmap).
- * RING_BUFFER_GET_MMAP_READ_OFFSET
- * returns the offset of the subbuffer belonging to the reader.
- * Should only be used for mmap clients.
+ * Poll implementation.
*/
-long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+static
+unsigned int vfs_lib_ring_buffer_poll(struct file *filp, poll_table *wait)
{
struct lib_ring_buffer *buf = filp->private_data;
+
+ return lib_ring_buffer_poll(filp, wait, buf);
+}
+
+long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg, struct lib_ring_buffer *buf)
+{
struct channel *chan = buf->backend.chan;
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
+
+ if (lib_ring_buffer_channel_is_disabled(chan))
+ return -EIO;
switch (cmd) {
case RING_BUFFER_SNAPSHOT:
return put_ulong(buf->backend.array[sb_bindex]->mmap_offset,
arg);
}
+ case RING_BUFFER_FLUSH:
+ lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
+ return 0;
default:
return -ENOIOCTLCMD;
}
}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_ioctl);
+
+/**
+ * vfs_lib_ring_buffer_ioctl - control ring buffer reader synchronization
+ *
+ * @filp: the file
+ * @cmd: the command
+ * @arg: command arg
+ *
+ * This ioctl implements commands necessary for producer/consumer
+ * and flight recorder reader interaction :
+ * RING_BUFFER_GET_NEXT_SUBBUF
+ * Get the next sub-buffer that can be read. It never blocks.
+ * RING_BUFFER_PUT_NEXT_SUBBUF
+ * Release the currently read sub-buffer.
+ * RING_BUFFER_GET_SUBBUF_SIZE
+ * returns the size of the current sub-buffer.
+ * RING_BUFFER_GET_MAX_SUBBUF_SIZE
+ * returns the maximum size for sub-buffers.
+ * RING_BUFFER_GET_NUM_SUBBUF
+ * returns the number of reader-visible sub-buffers in the per cpu
+ * channel (for mmap).
+ * RING_BUFFER_GET_MMAP_READ_OFFSET
+ * returns the offset of the subbuffer belonging to the reader.
+ * Should only be used for mmap clients.
+ */
+static
+long vfs_lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+ struct lib_ring_buffer *buf = filp->private_data;
+
+ return lib_ring_buffer_ioctl(filp, cmd, arg, buf);
+}
#ifdef CONFIG_COMPAT
long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd,
- unsigned long arg)
+ unsigned long arg, struct lib_ring_buffer *buf)
{
- struct lib_ring_buffer *buf = filp->private_data;
struct channel *chan = buf->backend.chan;
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
+
+ if (lib_ring_buffer_channel_is_disabled(chan))
+ return -EIO;
switch (cmd) {
- case RING_BUFFER_SNAPSHOT:
+ case RING_BUFFER_COMPAT_SNAPSHOT:
return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
&buf->prod_snapshot);
- case RING_BUFFER_SNAPSHOT_GET_CONSUMED:
+ case RING_BUFFER_COMPAT_SNAPSHOT_GET_CONSUMED:
return compat_put_ulong(buf->cons_snapshot, arg);
- case RING_BUFFER_SNAPSHOT_GET_PRODUCED:
+ case RING_BUFFER_COMPAT_SNAPSHOT_GET_PRODUCED:
return compat_put_ulong(buf->prod_snapshot, arg);
- case RING_BUFFER_GET_SUBBUF:
+ case RING_BUFFER_COMPAT_GET_SUBBUF:
{
__u32 uconsume;
unsigned long consume;
}
return ret;
}
- case RING_BUFFER_PUT_SUBBUF:
+ case RING_BUFFER_COMPAT_PUT_SUBBUF:
lib_ring_buffer_put_subbuf(buf);
return 0;
- case RING_BUFFER_GET_NEXT_SUBBUF:
+ case RING_BUFFER_COMPAT_GET_NEXT_SUBBUF:
{
long ret;
}
return ret;
}
- case RING_BUFFER_PUT_NEXT_SUBBUF:
+ case RING_BUFFER_COMPAT_PUT_NEXT_SUBBUF:
lib_ring_buffer_put_next_subbuf(buf);
return 0;
- case RING_BUFFER_GET_SUBBUF_SIZE:
+ case RING_BUFFER_COMPAT_GET_SUBBUF_SIZE:
{
unsigned long data_size;
data_size = lib_ring_buffer_get_read_data_size(config, buf);
if (data_size > UINT_MAX)
return -EFBIG;
- return put_ulong(data_size, arg);
+ return compat_put_ulong(data_size, arg);
}
- case RING_BUFFER_GET_PADDED_SUBBUF_SIZE:
+ case RING_BUFFER_COMPAT_GET_PADDED_SUBBUF_SIZE:
{
unsigned long size;
size = PAGE_ALIGN(size);
if (size > UINT_MAX)
return -EFBIG;
- return put_ulong(size, arg);
+ return compat_put_ulong(size, arg);
}
- case RING_BUFFER_GET_MAX_SUBBUF_SIZE:
+ case RING_BUFFER_COMPAT_GET_MAX_SUBBUF_SIZE:
if (chan->backend.subbuf_size > UINT_MAX)
return -EFBIG;
- return put_ulong(chan->backend.subbuf_size, arg);
- case RING_BUFFER_GET_MMAP_LEN:
+ return compat_put_ulong(chan->backend.subbuf_size, arg);
+ case RING_BUFFER_COMPAT_GET_MMAP_LEN:
{
unsigned long mmap_buf_len;
mmap_buf_len += chan->backend.subbuf_size;
if (mmap_buf_len > UINT_MAX)
return -EFBIG;
- return put_ulong(mmap_buf_len, arg);
+ return compat_put_ulong(mmap_buf_len, arg);
}
- case RING_BUFFER_GET_MMAP_READ_OFFSET:
+ case RING_BUFFER_COMPAT_GET_MMAP_READ_OFFSET:
{
unsigned long sb_bindex, read_offset;
read_offset = buf->backend.array[sb_bindex]->mmap_offset;
if (read_offset > UINT_MAX)
return -EINVAL;
- return put_ulong(read_offset, arg);
+ return compat_put_ulong(read_offset, arg);
}
+ case RING_BUFFER_COMPAT_FLUSH:
+ lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
+ return 0;
default:
return -ENOIOCTLCMD;
}
}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_compat_ioctl);
+
+static
+long vfs_lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg)
+{
+ struct lib_ring_buffer *buf = filp->private_data;
+
+ return lib_ring_buffer_compat_ioctl(filp, cmd, arg, buf);
+}
#endif
const struct file_operations lib_ring_buffer_file_operations = {
- .open = lib_ring_buffer_open,
- .release = lib_ring_buffer_release,
- .poll = lib_ring_buffer_poll,
- .splice_read = lib_ring_buffer_splice_read,
- .mmap = lib_ring_buffer_mmap,
- .unlocked_ioctl = lib_ring_buffer_ioctl,
- .llseek = lib_ring_buffer_no_llseek,
+ .owner = THIS_MODULE,
+ .open = vfs_lib_ring_buffer_open,
+ .release = vfs_lib_ring_buffer_release,
+ .poll = vfs_lib_ring_buffer_poll,
+ .splice_read = vfs_lib_ring_buffer_splice_read,
+ .mmap = vfs_lib_ring_buffer_mmap,
+ .unlocked_ioctl = vfs_lib_ring_buffer_ioctl,
+ .llseek = vfs_lib_ring_buffer_no_llseek,
#ifdef CONFIG_COMPAT
- .compat_ioctl = lib_ring_buffer_compat_ioctl,
+ .compat_ioctl = vfs_lib_ring_buffer_compat_ioctl,
#endif
};
EXPORT_SYMBOL_GPL(lib_ring_buffer_file_operations);