X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lib%2Fringbuffer%2Fring_buffer_mmap.c;h=fab945887855c0eb20967721b3cdc0b3f5dd21fb;hb=2ca0c84f0b4a915c555a0b83102d94ac941619ca;hp=8ff5e46afc5f21fe829853e94c29a0abb06a5666;hpb=5a8fd222992df9bbb709836e5bf4ca053dd776c3;p=lttng-modules.git diff --git a/lib/ringbuffer/ring_buffer_mmap.c b/lib/ringbuffer/ring_buffer_mmap.c index 8ff5e46a..fab94588 100644 --- a/lib/ringbuffer/ring_buffer_mmap.c +++ b/lib/ringbuffer/ring_buffer_mmap.c @@ -1,32 +1,36 @@ -/* +/* SPDX-License-Identifier: GPL-2.0 + * * ring_buffer_mmap.c * * Copyright (C) 2002-2005 - Tom Zanussi , IBM Corp * Copyright (C) 1999-2005 - Karim Yaghmour - * Copyright (C) 2008-2010 - Mathieu Desnoyers - * - * Re-using content from kernel/relay.c. + * Copyright (C) 2008-2012 - Mathieu Desnoyers * - * This file is released under the GPL v2. + * Re-using code from kernel/relay.c, hence the GPL-2.0 license for this + * file. */ #include #include -#include "../../wrapper/ringbuffer/backend.h" -#include "../../wrapper/ringbuffer/frontend.h" -#include "../../wrapper/ringbuffer/vfs.h" +#include +#include +#include /* * fault() vm_op implementation for ring buffer file mapping. */ -static int lib_ring_buffer_fault(struct vm_area_struct *vma, struct vm_fault *vmf) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)) +static vm_fault_t lib_ring_buffer_fault_compat(struct vm_area_struct *vma, struct vm_fault *vmf) +#else +static int lib_ring_buffer_fault_compat(struct vm_area_struct *vma, struct vm_fault *vmf) +#endif { struct lib_ring_buffer *buf = vma->vm_private_data; struct channel *chan = buf->backend.chan; const struct lib_ring_buffer_config *config = &chan->backend.config; pgoff_t pgoff = vmf->pgoff; - struct page **page; + unsigned long *pfnp; void **virt; unsigned long offset, sb_bindex; @@ -41,18 +45,37 @@ static int lib_ring_buffer_fault(struct vm_area_struct *vma, struct vm_fault *vm buf->backend.chan->backend.subbuf_size)) return VM_FAULT_SIGBUS; /* - * ring_buffer_read_get_page() gets the page in the current reader's - * pages. + * ring_buffer_read_get_pfn() gets the page frame number for the + * current reader's pages. */ - page = lib_ring_buffer_read_get_page(&buf->backend, offset, &virt); - if (!*page) + pfnp = lib_ring_buffer_read_get_pfn(&buf->backend, offset, &virt); + if (!*pfnp) return VM_FAULT_SIGBUS; - get_page(*page); - vmf->page = *page; + get_page(pfn_to_page(*pfnp)); + vmf->page = pfn_to_page(*pfnp); return 0; } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)) +static vm_fault_t lib_ring_buffer_fault(struct vm_fault *vmf) +{ + struct vm_area_struct *vma = vmf->vma; + return lib_ring_buffer_fault_compat(vma, vmf); +} +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) +static int lib_ring_buffer_fault(struct vm_fault *vmf) +{ + struct vm_area_struct *vma = vmf->vma; + return lib_ring_buffer_fault_compat(vma, vmf); +} +#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */ +static int lib_ring_buffer_fault(struct vm_area_struct *vma, struct vm_fault *vmf) +{ + return lib_ring_buffer_fault_compat(vma, vmf); +} +#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */ + /* * vm_ops for ring buffer file mappings. */ @@ -94,16 +117,23 @@ static int lib_ring_buffer_mmap_buf(struct lib_ring_buffer *buf, return 0; } +int lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma, + struct lib_ring_buffer *buf) +{ + return lib_ring_buffer_mmap_buf(buf, vma); +} +EXPORT_SYMBOL_GPL(lib_ring_buffer_mmap); + /** - * lib_ring_buffer_mmap - mmap file op + * vfs_lib_ring_buffer_mmap - mmap file op * @filp: the file * @vma: the vma describing what to map * * Calls upon lib_ring_buffer_mmap_buf() to map the file into user space. */ -int lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma) +int vfs_lib_ring_buffer_mmap(struct file *filp, struct vm_area_struct *vma) { struct lib_ring_buffer *buf = filp->private_data; - return lib_ring_buffer_mmap_buf(buf, vma); + return lib_ring_buffer_mmap(filp, vma, buf); } -EXPORT_SYMBOL_GPL(lib_ring_buffer_mmap); +EXPORT_SYMBOL_GPL(vfs_lib_ring_buffer_mmap);