--- /dev/null
+/*
+ * SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ * SPDX-FileCopyrightText: 2024 Kienan Stewart <kstewart@efficios.com>
+ */
+
+#ifndef LTTNG_WRAPPER_FILE_REF_H
+#define LTTNG_WRAPPER_FILE_REF_H
+
+#include <linux/file.h>
+#include <lttng/kernel-version.h>
+
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,13,0))
+#include <linux/file_ref.h>
+
+static inline __must_check
+bool lttng_file_ref_get(struct file *file)
+{
+ return file_ref_get(&file->f_ref);
+}
+
+static inline
+bool lttng_file_ref_put(struct file *file)
+{
+ /* This is __must_check */
+ return file_ref_put(&file->f_ref);
+}
+
+#else
+static inline __must_check
+bool lttng_file_ref_get(struct file *file)
+{
+ atomic_long_add_unless(&file->f_count, 1, LONG_MAX);
+ return true;
+}
+
+static inline
+bool lttng_file_ref_put(struct file *file)
+{
+ atomic_long_dec(&file->f_count);
+ return true;
+}
+#endif
+#endif /* LTTNG_WRAPPER_FILE_REF_H */
#include <ringbuffer/backend.h>
#include <ringbuffer/frontend.h>
#include <wrapper/compiler_attributes.h>
+#include <wrapper/file_ref.h>
#include <wrapper/poll.h>
#include <wrapper/file.h>
#include <wrapper/kref.h>
transport_name = "<unknown>";
break;
}
- if (!atomic_long_add_unless(&session_file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(session_file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return chan_fd;
chan_error:
- atomic_long_dec(&session_file->f_count);
+ lttng_file_ref_put(session_file);
refcount_error:
fput(chan_file);
file_error:
return -ENOENT;
/* The event_notifier notification fd holds a reference on the event_notifier group */
- if (!atomic_long_add_unless(¬if_file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(notif_file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return ret;
fd_error:
- atomic_long_dec(¬if_file->f_count);
+ lttng_file_ref_put(notif_file);
refcount_error:
event_notifier_group->ops->priv->buffer_read_close(buf);
return ret;
goto file_error;
}
/* The event holds a reference on the channel */
- if (!atomic_long_add_unless(&channel_file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(channel_file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return event_fd;
event_error:
- atomic_long_dec(&channel_file->f_count);
+ lttng_file_ref_put(channel_file);
refcount_error:
fput(event_file);
file_error:
}
/* The event notifier holds a reference on the event notifier group. */
- if (!atomic_long_add_unless(&event_notifier_group_file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(event_notifier_group_file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return event_notifier_fd;
event_notifier_error:
- atomic_long_dec(&event_notifier_group_file->f_count);
+ lttng_file_ref_put(event_notifier_group_file);
refcount_error:
fput(event_notifier_file);
file_error:
counter_len = error_counter_conf->dimensions[0].size;
- if (!atomic_long_add_unless(&event_notifier_group_file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(event_notifier_group_file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return counter_fd;
counter_error:
- atomic_long_dec(&event_notifier_group_file->f_count);
+ lttng_file_ref_put(event_notifier_group_file);
refcount_error:
fput(counter_file);
file_error:
#include <linux/dmi.h>
#include <wrapper/compiler_attributes.h>
+#include <wrapper/file_ref.h>
#include <wrapper/uuid.h>
#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
#include <wrapper/random.h>
ret = PTR_ERR(tracker_ids_list_file);
goto file_error;
}
- if (!atomic_long_add_unless(&session->priv->file->f_count, 1, LONG_MAX)) {
+ if (!lttng_file_ref_get(session->priv->file)) {
ret = -EOVERFLOW;
goto refcount_error;
}
return file_fd;
open_error:
- atomic_long_dec(&session->priv->file->f_count);
+ lttng_file_ref_put(session->priv->file);
refcount_error:
fput(tracker_ids_list_file);
file_error: