X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lib%2Fringbuffer%2Fring_buffer_vfs.c;h=034c6fdd15d4c9a23680190c12811907c4685253;hb=886d51a3d7ed5fa6b41d7f19b3e14ae6c535a44c;hp=6a9fb469ca4f73ccc4940b755a3607ec4bf3784d;hpb=f3bc08c50e1b302bceea699027d889fd6d9af525;p=lttng-modules.git diff --git a/lib/ringbuffer/ring_buffer_vfs.c b/lib/ringbuffer/ring_buffer_vfs.c index 6a9fb469..034c6fdd 100644 --- a/lib/ringbuffer/ring_buffer_vfs.c +++ b/lib/ringbuffer/ring_buffer_vfs.c @@ -1,11 +1,23 @@ /* * ring_buffer_vfs.c * - * Copyright (C) 2009-2010 - Mathieu Desnoyers - * * Ring Buffer VFS file operations. * - * Dual LGPL v2.1/GPL v2 license. + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 @@ -42,6 +54,9 @@ int lib_ring_buffer_open(struct inode *inode, struct file *file) 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; @@ -85,20 +100,25 @@ unsigned int lib_ring_buffer_poll(struct file *filp, poll_table *wait) 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) { @@ -157,7 +177,10 @@ long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long ar { 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: @@ -237,6 +260,9 @@ long lib_ring_buffer_ioctl(struct file *filp, unsigned int cmd, unsigned long ar 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; } @@ -248,7 +274,10 @@ long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, { 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: @@ -344,6 +373,9 @@ long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, return -EINVAL; return put_ulong(read_offset, arg); } + case RING_BUFFER_FLUSH: + lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE); + return 0; default: return -ENOIOCTLCMD; } @@ -351,6 +383,7 @@ long lib_ring_buffer_compat_ioctl(struct file *filp, unsigned int cmd, #endif const struct file_operations lib_ring_buffer_file_operations = { + .owner = THIS_MODULE, .open = lib_ring_buffer_open, .release = lib_ring_buffer_release, .poll = lib_ring_buffer_poll,