Fix: get_file_rcu is missing in kernels < 4.1
[lttng-modules.git] / include / wrapper / fdtable.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
83f9bb7f
MD
3 * wrapper/fdtable.h
4 *
5 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
83f9bb7f
MD
6 */
7
9f36eaed
MJ
8#ifndef _LTTNG_WRAPPER_FDTABLE_H
9#define _LTTNG_WRAPPER_FDTABLE_H
10
5f4c791e 11#include <lttng/kernel-version.h>
83f9bb7f 12#include <linux/fdtable.h>
cf41b81e 13#include <linux/sched.h>
83f9bb7f 14
9f945e81 15#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
0aebcd68 16static inline
9f945e81 17struct file *lttng_lookup_fdget_rcu(unsigned int fd)
0aebcd68 18{
9f945e81
KS
19 return lookup_fdget_rcu(fd);
20}
21
22#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
23static inline
24struct file *lttng_lookup_fdget_rcu(unsigned int fd)
25{
26 struct file* file = lookup_fd_rcu(fd);
27
28 if (unlikely(!file || !get_file_rcu(file)))
29 return NULL;
30 return file;
0aebcd68 31}
451e0627 32#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,1,0))
0aebcd68 33static inline
9f945e81 34struct file *lttng_lookup_fdget_rcu(unsigned int fd)
0aebcd68 35{
9f945e81
KS
36 struct file* file = fcheck(fd);
37
38 if (unlikely(!file || !get_file_rcu(file)))
39 return NULL;
40 return file;
0aebcd68 41}
451e0627
MD
42#else
43static inline
44struct file *lttng_lookup_fdget_rcu(unsigned int fd)
45{
46 struct file* file = fcheck(fd);
47
48 if (unlikely(!file || !atomic_long_inc_not_zero(&file->f_count)))
49 return NULL;
50 return file;
51}
0aebcd68
MJ
52#endif
53
5f4c791e 54#if (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(3,7,0))
83f9bb7f
MD
55
56int lttng_iterate_fd(struct files_struct *files,
57 unsigned int first,
58 int (*cb)(const void *, struct file *, unsigned int),
59 const void *ctx);
60
61#else
62
63/*
64 * iterate_fd() appeared at commit
65 * c3c073f808b22dfae15ef8412b6f7b998644139a in the Linux kernel (first
66 * released kernel: v3.7).
67 */
68#define lttng_iterate_fd iterate_fd
69
70#endif
c07dca48 71
5f4c791e 72#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,4,0))
c07dca48
MJ
73
74static inline bool lttng_close_on_exec(int fd, const struct fdtable *fdt)
75{
76 return close_on_exec(fd, fdt);
77}
78
79#else
80
81static inline bool lttng_close_on_exec(int fd, const struct fdtable *fdt)
82{
83 return FD_ISSET(fd, fdt->close_on_exec);
84}
85
86#endif
87
83f9bb7f 88#endif /* _LTTNG_WRAPPER_FDTABLE_H */
This page took 0.052993 seconds and 4 git commands to generate.