+static
+int lttng_dump_one_fd(const void *p, struct file *file, unsigned int fd)
+{
+ const struct lttng_fd_ctx *ctx = p;
+ const char *s = d_path(&file->f_path, ctx->page, PAGE_SIZE);
+ unsigned int flags = file->f_flags;
+ struct fdtable *fdt;
+
+ /*
+ * We don't expose kernel internal flags, only userspace-visible
+ * flags.
+ */
+ flags &= ~FMODE_NONOTIFY;
+ fdt = files_fdtable(ctx->files);
+ /*
+ * We need to check here again whether fd is within the fdt
+ * max_fds range, because we might be seeing a different
+ * files_fdtable() than iterate_fd(), assuming only RCU is
+ * protecting the read. In reality, iterate_fd() holds
+ * file_lock, which should ensure the fdt does not change while
+ * the lock is taken, but we are not aware whether this is
+ * guaranteed or not, so play safe.
+ */
+ if (fd < fdt->max_fds && lttng_close_on_exec(fd, fdt))
+ flags |= O_CLOEXEC;
+ if (IS_ERR(s)) {
+ struct dentry *dentry = file->f_path.dentry;
+
+ /* Make sure we give at least some info */
+ spin_lock(&dentry->d_lock);
+ trace_lttng_statedump_file_descriptor(ctx->session, ctx->p, fd,
+ dentry->d_name.name, flags, file->f_mode);
+ spin_unlock(&dentry->d_lock);
+ goto end;
+ }
+ trace_lttng_statedump_file_descriptor(ctx->session, ctx->p, fd, s,
+ flags, file->f_mode);
+end:
+ return 0;
+}