Cleanup: Move lttng-modules instrumentation headers
[lttng-modules.git] / probes / lttng.c
index 65f9061a641add2b413b70f5197a8936d1b8a7c8..8a0dd4b8acdcefe06015d37d2599bb01ef7b907b 100644 (file)
@@ -1,23 +1,10 @@
-/*
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
  * lttng.c
  *
  * LTTng logger ABI
  *
  * Copyright (C) 2008-2014 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>
 #include <linux/proc_fs.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
-#include "../wrapper/vmalloc.h"
-#include "../lttng-events.h"
+#include <linux/miscdevice.h>
+#include <wrapper/vmalloc.h>
+#include <lttng/events.h>
 
 #define TP_MODULE_NOAUTOLOAD
 #define LTTNG_PACKAGE_BUILD
 #define CREATE_TRACE_POINTS
-#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
+#define TRACE_INCLUDE_PATH instrumentation/events
 #define TRACE_INCLUDE_FILE lttng
+#define LTTNG_INSTRUMENTATION
 
-#include "../instrumentation/events/lttng-module/lttng.h"
+#include <instrumentation/events/lttng.h>
 
 /* Events written through logger are truncated at 1024 bytes */
 #define LTTNG_LOGGER_COUNT_MAX 1024
@@ -64,7 +53,7 @@ static
 ssize_t lttng_logger_write(struct file *file, const char __user *user_buf,
                    size_t count, loff_t *ppos)
 {
-       unsigned int nr_pages = 1, i;
+       int nr_pages = 1, i;
        unsigned long uaddr = (unsigned long) user_buf;
        struct page *pages[2];
        ssize_t written;
@@ -104,19 +93,49 @@ static const struct file_operations lttng_logger_operations = {
        .write = lttng_logger_write,
 };
 
+/*
+ * Linux 5.6 introduced a separate proc_ops struct for /proc operations
+ * to decouple it from the vfs.
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
+static const struct proc_ops lttng_logger_proc_ops = {
+       .proc_write = lttng_logger_write,
+};
+#else
+#define lttng_logger_proc_ops lttng_logger_operations
+#endif
+
+static struct miscdevice logger_dev = {
+       .minor = MISC_DYNAMIC_MINOR,
+       .name = "lttng-logger",
+       .mode = 0666,
+       .fops = &lttng_logger_operations
+};
+
 int __init lttng_logger_init(void)
 {
        int ret = 0;
 
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
+
+       /* /dev/lttng-logger */
+       ret = misc_register(&logger_dev);
+       if (ret) {
+               printk(KERN_ERR "Error creating LTTng logger device\n");
+               goto error;
+       }
+
+       /* /proc/lttng-logger */
        lttng_logger_dentry = proc_create_data(LTTNG_LOGGER_FILE,
                                S_IRUGO | S_IWUGO, NULL,
-                               &lttng_logger_operations, NULL);
+                               &lttng_logger_proc_ops, NULL);
        if (!lttng_logger_dentry) {
-               printk(KERN_ERR "Error creating LTTng logger file\n");
+               printk(KERN_ERR "Error creating LTTng logger proc file\n");
                ret = -ENOMEM;
-               goto error;
+               goto error_proc;
        }
+
+       /* Init */
        ret = __lttng_events_init__lttng();
        if (ret)
                goto error_events;
@@ -124,13 +143,16 @@ int __init lttng_logger_init(void)
 
 error_events:
        remove_proc_entry("lttng-logger", NULL);
+error_proc:
+       misc_deregister(&logger_dev);
 error:
        return ret;
 }
 
-void __exit lttng_logger_exit(void)
+void lttng_logger_exit(void)
 {
        __lttng_events_exit__lttng();
        if (lttng_logger_dentry)
                remove_proc_entry("lttng-logger", NULL);
+       misc_deregister(&logger_dev);
 }
This page took 0.026255 seconds and 4 git commands to generate.