From: Michael Jeanson Date: Fri, 2 Oct 2020 17:03:34 +0000 (-0400) Subject: Add 'kernel_read' wrapper for kernels < v4.14 X-Git-Tag: v2.13.0-rc1~165 X-Git-Url: https://git.lttng.org/?a=commitdiff_plain;ds=sidebyside;h=62d0a59ccfae6bd4a60f9f706431991a6dbf976f;p=lttng-modules.git Add 'kernel_read' wrapper for kernels < v4.14 See upstream commit: commit bdd1d2d3d251c65b74ac4493e08db18971c09240 Author: Christoph Hellwig 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/include/wrapper/fs.h b/include/wrapper/fs.h new file mode 100644 index 00000000..f11c19fc --- /dev/null +++ b/include/wrapper/fs.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * wrapper/fs.h + * + * Copyright (C) 2020 Michael Jeanson + */ + +#ifndef _LTTNG_WRAPPER_FS_H +#define _LTTNG_WRAPPER_FS_H + +#include +#include + +#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 */ diff --git a/src/wrapper/random.c b/src/wrapper/random.c index 63a30988..7a81bea6 100644 --- a/src/wrapper/random.c +++ b/src/wrapper/random.c @@ -12,7 +12,7 @@ /* boot_id depends on sysctl */ #if defined(CONFIG_SYSCTL) -#include +#include #include #include #include @@ -31,7 +31,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;