Add 'kernel_read' wrapper for kernels < v4.14
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 2 Oct 2020 17:03:34 +0000 (13:03 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Oct 2020 19:32:21 +0000 (15:32 -0400)
See upstream commit:

  commit bdd1d2d3d251c65b74ac4493e08db18971c09240
  Author: Christoph Hellwig <hch@lst.de>
  Date:   Fri Sep 1 17:39:13 2017 +0200

    fs: fix kernel_read prototype

    Use proper ssize_t and size_t types for the return value and count
    argument, move the offset last and make it an in/out argument like
    all other read/write helpers, and make the buf argument a void pointer
    to get rid of lots of casts in the callers.

Change-Id: I825c3fcbcc17e9b46e2a661fadc66b52a94eb2da
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/wrapper/fs.h [new file with mode: 0644]
wrapper/random.c

diff --git a/include/wrapper/fs.h b/include/wrapper/fs.h
new file mode 100644 (file)
index 0000000..f11c19f
--- /dev/null
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * wrapper/fs.h
+ *
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _LTTNG_WRAPPER_FS_H
+#define _LTTNG_WRAPPER_FS_H
+
+#include <linux/fs.h>
+#include <lttng/kernel-version.h>
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0))
+
+static inline
+ssize_t lttng_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
+{
+       return kernel_read(file, buf, count, pos);
+}
+
+#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) */
+
+static inline
+ssize_t lttng_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
+{
+       ssize_t len;
+
+       len = kernel_read(file, *pos, buf, count);
+
+       /*
+        * Move 'pos' forward since it's passed by value in this
+        * implementation of 'kernel_read'.
+        */
+       if (len > 0)
+               (*pos) += len;
+
+       return len;
+}
+
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) */
+
+#endif /* _LTTNG_WRAPPER_FS_H */
index d7e53cd140f0a7517fb6ce66b1c492e9959882c8..f67d0f0c997df27e12709135e372a6d90b09992c 100644 (file)
@@ -14,7 +14,7 @@
 /* boot_id depends on sysctl */
 #if defined(CONFIG_SYSCTL)
 
-#include <linux/fs.h>
+#include <wrapper/fs.h>
 #include <linux/file.h>
 #include <linux/sched.h>
 #include <linux/uaccess.h>
@@ -33,7 +33,7 @@ int wrapper_get_bootid(char *bootid)
        if (IS_ERR(file))
                return PTR_ERR(file);
 
-       len = kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
+       len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
        if (len != BOOT_ID_LEN - 1) {
                ret = -EINVAL;
                goto end;
This page took 0.026369 seconds and 4 git commands to generate.