X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lib%2Fringbuffer%2Fring_buffer_splice.c;h=eca591d80f8447fe69e6760c9902c14ca72ca3cf;hb=9f29d2129980e5b09425d069cd89b253054a9347;hp=59a1589bb1301cc32ad5372bce6a7f26d3b09d17;hpb=886d51a3d7ed5fa6b41d7f19b3e14ae6c535a44c;p=lttng-modules.git diff --git a/lib/ringbuffer/ring_buffer_splice.c b/lib/ringbuffer/ring_buffer_splice.c index 59a1589b..eca591d8 100644 --- a/lib/ringbuffer/ring_buffer_splice.c +++ b/lib/ringbuffer/ring_buffer_splice.c @@ -1,35 +1,23 @@ -/* +/* SPDX-License-Identifier: GPL-2.0 + * * ring_buffer_splice.c * * Copyright (C) 2002-2005 - Tom Zanussi , IBM Corp * Copyright (C) 1999-2005 - Karim Yaghmour * Copyright (C) 2008-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 - * * Re-using code from kernel/relay.c, which is why it is licensed under - * the GPLv2. + * the GPL-2.0. */ #include #include +#include -#include "../../wrapper/splice.h" -#include "../../wrapper/ringbuffer/backend.h" -#include "../../wrapper/ringbuffer/frontend.h" -#include "../../wrapper/ringbuffer/vfs.h" +#include +#include +#include +#include #if 0 #define printk_dbg(fmt, args...) printk(fmt, args) @@ -37,10 +25,12 @@ #define printk_dbg(fmt, args...) #endif -loff_t lib_ring_buffer_no_llseek(struct file *file, loff_t offset, int origin) +loff_t vfs_lib_ring_buffer_no_llseek(struct file *file, loff_t offset, + int origin) { return -ESPIPE; } +EXPORT_SYMBOL_GPL(vfs_lib_ring_buffer_no_llseek); /* * Release pages from the buffer so splice pipe_to_file can move them. @@ -52,6 +42,28 @@ static void lib_ring_buffer_pipe_buf_release(struct pipe_inode_info *pipe, __free_page(pbuf->page); } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)) +static const struct pipe_buf_operations ring_buffer_pipe_buf_ops = { + .release = lib_ring_buffer_pipe_buf_release, + .try_steal = generic_pipe_buf_try_steal, + .get = generic_pipe_buf_get +}; +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)) +static const struct pipe_buf_operations ring_buffer_pipe_buf_ops = { + .confirm = generic_pipe_buf_confirm, + .release = lib_ring_buffer_pipe_buf_release, + .steal = generic_pipe_buf_steal, + .get = generic_pipe_buf_get +}; +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) +static const struct pipe_buf_operations ring_buffer_pipe_buf_ops = { + .can_merge = 0, + .confirm = generic_pipe_buf_confirm, + .release = lib_ring_buffer_pipe_buf_release, + .steal = generic_pipe_buf_steal, + .get = generic_pipe_buf_get +}; +#else static const struct pipe_buf_operations ring_buffer_pipe_buf_ops = { .can_merge = 0, .map = generic_pipe_buf_map, @@ -59,8 +71,9 @@ static const struct pipe_buf_operations ring_buffer_pipe_buf_ops = { .confirm = generic_pipe_buf_confirm, .release = lib_ring_buffer_pipe_buf_release, .steal = generic_pipe_buf_steal, - .get = generic_pipe_buf_get, + .get = generic_pipe_buf_get }; +#endif /* * Page release operation after splice pipe_to_file ends. @@ -78,9 +91,9 @@ static int subbuf_splice_actor(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, - unsigned int flags) + unsigned int flags, + struct lib_ring_buffer *buf) { - struct lib_ring_buffer *buf = in->private_data; struct channel *chan = buf->backend.chan; const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned int poff, subbuf_pages, nr_pages; @@ -90,7 +103,9 @@ static int subbuf_splice_actor(struct file *in, .pages = pages, .nr_pages = 0, .partial = partial, +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0)) .flags = flags, +#endif .ops = &ring_buffer_pipe_buf_ops, .spd_release = lib_ring_buffer_page_release, }; @@ -121,7 +136,8 @@ static int subbuf_splice_actor(struct file *in, for (; spd.nr_pages < nr_pages; spd.nr_pages++) { unsigned int this_len; - struct page **page, *new_page; + unsigned long *pfnp, new_pfn; + struct page *new_page; void **virt; if (!len) @@ -138,11 +154,11 @@ static int subbuf_splice_actor(struct file *in, GFP_KERNEL | __GFP_ZERO, 0); if (!new_page) break; - + new_pfn = page_to_pfn(new_page); this_len = PAGE_SIZE - poff; - page = lib_ring_buffer_read_get_page(&buf->backend, roffset, &virt); - spd.pages[spd.nr_pages] = *page; - *page = new_page; + pfnp = lib_ring_buffer_read_get_pfn(&buf->backend, roffset, &virt); + spd.pages[spd.nr_pages] = pfn_to_page(*pfnp); + *pfnp = new_pfn; *virt = page_address(new_page); spd.partial[spd.nr_pages].offset = poff; spd.partial[spd.nr_pages].len = this_len; @@ -160,9 +176,9 @@ static int subbuf_splice_actor(struct file *in, ssize_t lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, - unsigned int flags) + unsigned int flags, + struct lib_ring_buffer *buf) { - struct lib_ring_buffer *buf = in->private_data; struct channel *chan = buf->backend.chan; const struct lib_ring_buffer_config *config = &chan->backend.config; ssize_t spliced; @@ -189,7 +205,7 @@ ssize_t lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, printk_dbg(KERN_DEBUG "SPLICE read len %zu pos %zd\n", len, (ssize_t)*ppos); while (len && !spliced) { - ret = subbuf_splice_actor(in, ppos, pipe, len, flags); + ret = subbuf_splice_actor(in, ppos, pipe, len, flags, buf); printk_dbg(KERN_DEBUG "SPLICE read loop ret %d\n", ret); if (ret < 0) break; @@ -213,3 +229,13 @@ ssize_t lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, return ret; } EXPORT_SYMBOL_GPL(lib_ring_buffer_splice_read); + +ssize_t vfs_lib_ring_buffer_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) +{ + struct lib_ring_buffer *buf = in->private_data; + + return lib_ring_buffer_splice_read(in, ppos, pipe, len, flags, buf); +} +EXPORT_SYMBOL_GPL(vfs_lib_ring_buffer_splice_read);