Cleanup: Move lib/ringbuffer/ headers to include/ringbuffer/
[lttng-modules.git] / lib / ringbuffer / ring_buffer_mmap.c
index c172fee7cfab9e2632e68adb9c617ab8e8c2fa43..34174a587ab4af1a8d601d752a89ae31e92a4b29 100644 (file)
@@ -1,44 +1,36 @@
-/*
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
  * ring_buffer_mmap.c
  *
  * Copyright (C) 2002-2005 - Tom Zanussi <zanussi@us.ibm.com>, IBM Corp
  * Copyright (C) 1999-2005 - Karim Yaghmour <karim@opersys.com>
  * Copyright (C) 2008-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; only version 2 of the License.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; 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, hence the GPLv2 license for this
+ * Re-using code from kernel/relay.c, hence the GPL-2.0-only license for this
  * file.
  */
 
 #include <linux/module.h>
 #include <linux/mm.h>
 
-#include "../../wrapper/ringbuffer/backend.h"
-#include "../../wrapper/ringbuffer/frontend.h"
-#include "../../wrapper/ringbuffer/vfs.h"
+#include <ringbuffer/backend.h>
+#include <ringbuffer/frontend.h>
+#include <ringbuffer/vfs.h>
 
 /*
  * 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;
 
@@ -53,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.
  */
This page took 0.025583 seconds and 4 git commands to generate.