See upstream commit
8fd3395ec9051a52828fcca2328cb50a69dea8ef:
commit
8fd3395ec9051a52828fcca2328cb50a69dea8ef
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Wed Jul 31 11:49:04 2024 -0400
get rid of ...lookup...fdget_rcu() family
Once upon a time, predecessors of those used to do file lookup
without bumping a refcount, provided that caller held rcu_read_lock()
across the lookup and whatever it wanted to read from the struct
file found. When struct file allocation switched to SLAB_TYPESAFE_BY_RCU,
that stopped being feasible and these primitives started to bump the
file refcount for lookup result, requiring the caller to call fput()
afterwards.
But that turned them pointless - e.g.
rcu_read_lock();
file = lookup_fdget_rcu(fd);
rcu_read_unlock();
is equivalent to
file = fget_raw(fd);
and all callers of lookup_fdget_rcu() are of that form. Similarly,
task_lookup_fdget_rcu() calls can be replaced with calling fget_task().
task_lookup_next_fdget_rcu() doesn't have direct counterparts, but
its callers would be happier if we replaced it with an analogue that
deals with RCU internally.
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Change-Id: I98f1c617e8bd7ad9db7a9af2a1fa76c5eb26e8b8
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
#define _LTTNG_WRAPPER_FDTABLE_H
#include <lttng/kernel-version.h>
+#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/sched.h>
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,13,0))
+static inline
+struct file *lttng_lookup_fdget_rcu(unsigned int fd)
+{
+ return fget_raw(fd);
+}
+#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
static inline
struct file *lttng_lookup_fdget_rcu(unsigned int fd)
{
return file_ref_get(&file->f_ref);
}
-static inline
+static inline __must_check
bool lttng_file_ref_put(struct file *file)
{
- /* This is __must_check */
return file_ref_put(&file->f_ref);
}
return true;
}
-static inline
+static inline __must_check
bool lttng_file_ref_put(struct file *file)
{
atomic_long_dec(&file->f_count);
return chan_fd;
chan_error:
- lttng_file_ref_put(session_file);
+ if (!lttng_file_ref_put(session_file)) {
+ ret = -EINVAL;
+ }
refcount_error:
fput(chan_file);
file_error:
return ret;
fd_error:
- lttng_file_ref_put(notif_file);
+ if (!lttng_file_ref_put(notif_file)) {
+ /* Don't change return code */
+ }
refcount_error:
event_notifier_group->ops->priv->buffer_read_close(buf);
return ret;
return event_fd;
event_error:
- lttng_file_ref_put(channel_file);
+ if (!lttng_file_ref_put(channel_file)) {
+ /* Don't change return code */
+ }
refcount_error:
fput(event_file);
file_error:
return event_notifier_fd;
event_notifier_error:
- lttng_file_ref_put(event_notifier_group_file);
+ if (!lttng_file_ref_put(event_notifier_group_file)) {
+ /* Don't change return code */
+ }
refcount_error:
fput(event_notifier_file);
file_error:
return counter_fd;
counter_error:
- lttng_file_ref_put(event_notifier_group_file);
+ if (!lttng_file_ref_put(event_notifier_group_file)) {
+ /* Don't change return code */
+ }
refcount_error:
fput(counter_file);
file_error: