Skip to contentSkip to conversation

fdinfo: handle large fdinfo buffers

PATCH RESEND New Josef Bacik 1 participant 1 message Feb 19, 2016

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 fdinfo: handle large fdinfo buffers

Currently the way we deal with special fdinfo information is with the fop->show_fdinfo, which seq_printf's and carries on. This works in 99% of the cases, but for things like inotify/fanotify we can have lots of stuff that we want to print out, so we can easily overflow the seq buffer and result in no output. To fix this add a few more callbacks to file_operations to handle stop/start/next in a way similar to the normal seq_operations. We keep track of what state we are in inside of fd.c and then call out to the helpers if we need to. This allows us to still get all the inotify/fanotify information from the special file descriptors without overflowing the buffer. Thanks,

---
-Just noticed that this didnt show up in linux-fsdevel for some reason,
apologies if this is the second time you are getting this email.

 drivers/net/tun.c                  |   2 +-
 fs/eventfd.c                       |   2 +-
 fs/eventpoll.c                     |   2 +-
 fs/notify/fanotify/fanotify_user.c |   3 +
 fs/notify/fdinfo.c                 |  63 ++++++++------
 fs/notify/fdinfo.h                 |  12 ++-
 fs/notify/inotify/inotify_user.c   |   3 +
 fs/proc/fd.c                       | 170 +++++++++++++++++++++++++++++++------
 fs/signalfd.c                      |   2 +-
 fs/timerfd.c                       |   2 +-
 fs/userfaultfd.c                   |   2 +-
 include/linux/fs.h                 |   5 +-
 kernel/bpf/syscall.c               |   2 +-
 13 files changed, 207 insertions(+), 63 deletions(-)
drivers/net/tun.c +1 -1
index 88bb8cc..2c8158f 100644
@@ -2251,7 +2251,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
 }
 
 #ifdef CONFIG_PROC_FS
-static void tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
+static void tun_chr_show_fdinfo(struct seq_file *m, struct file *f, void *v)
 {
 	struct tun_struct *tun;
 	struct ifreq ifr;
fs/eventfd.c +1 -1
index ed70cf9..5b10518 100644
@@ -287,7 +287,7 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
 }
 
 #ifdef CONFIG_PROC_FS
-static void eventfd_show_fdinfo(struct seq_file *m, struct file *f)
+static void eventfd_show_fdinfo(struct seq_file *m, struct file *f, void *v)
 {
 	struct eventfd_ctx *ctx = f->private_data;
 
fs/eventpoll.c +1 -1
index cde6074..29ac3fd 100644
@@ -875,7 +875,7 @@ static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
 }
 
 #ifdef CONFIG_PROC_FS
-static void ep_show_fdinfo(struct seq_file *m, struct file *f)
+static void ep_show_fdinfo(struct seq_file *m, struct file *f, void *v)
 {
 	struct eventpoll *ep = f->private_data;
 	struct rb_node *rbp;
fs/notify/fanotify/fanotify_user.c +3 -0
index 8e8e6bc..e946793 100644
@@ -420,6 +420,9 @@ static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long ar
 }
 
 static const struct file_operations fanotify_fops = {
+	.start_fdinfo	= fsnotify_start_fdinfo,
+	.next_fdinfo	= fsnotify_next_fdinfo,
+	.stop_fdinfo	= fsnotify_stop_fdinfo,
 	.show_fdinfo	= fanotify_show_fdinfo,
 	.poll		= fanotify_poll,
 	.read		= fanotify_read,
fs/notify/fdinfo.c +38 -25

104 lines not on this page · raw message

fs/notify/fdinfo.h +10 -2
index 9664c49..3547f0c 100644
@@ -10,17 +10,25 @@ struct file;
 #ifdef CONFIG_PROC_FS
 
 #ifdef CONFIG_INOTIFY_USER
-void inotify_show_fdinfo(struct seq_file *m, struct file *f);
+void inotify_show_fdinfo(struct seq_file *m, struct file *f, void *v);
 #endif
 
 #ifdef CONFIG_FANOTIFY
-void fanotify_show_fdinfo(struct seq_file *m, struct file *f);
+void fanotify_show_fdinfo(struct seq_file *m, struct file *f, void *v);
 #endif
 
+void *fsnotify_next_fdinfo(struct seq_file *seq, struct file *f, void *v,
+			   loff_t *pos);
+void *fsnotify_start_fdinfo(struct seq_file *seq, struct file *f, loff_t *pos);
+void fsnotify_stop_fdinfo(struct seq_file *seq, struct file *f, void *v);
+
 #else /* CONFIG_PROC_FS */
 
 #define inotify_show_fdinfo	NULL
 #define fanotify_show_fdinfo	NULL
+#define fsnotify_start_fdinfo	NULL
+#define fsnotify_stop_fdinfo	NULL
+#define fsnotify_next_fdinfo	NULL
 
 #endif /* CONFIG_PROC_FS */
 
fs/notify/inotify/inotify_user.c +3 -0
index b8d08d0..7301965 100644
@@ -316,6 +316,9 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
 
 static const struct file_operations inotify_fops = {
 	.show_fdinfo	= inotify_show_fdinfo,
+	.next_fdinfo	= fsnotify_next_fdinfo,
+	.stop_fdinfo	= fsnotify_stop_fdinfo,
+	.start_fdinfo	= fsnotify_start_fdinfo,
 	.poll		= inotify_poll,
 	.read		= inotify_read,
 	.fasync		= fsnotify_fasync,
fs/proc/fd.c +142 -28

209 lines not on this page · raw message

fs/signalfd.c +1 -1
index 270221f..892eb48 100644
@@ -231,7 +231,7 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,
 }
 
 #ifdef CONFIG_PROC_FS
-static void signalfd_show_fdinfo(struct seq_file *m, struct file *f)
+static void signalfd_show_fdinfo(struct seq_file *m, struct file *f, void *v)
 {
 	struct signalfd_ctx *ctx = f->private_data;
 	sigset_t sigmask;
fs/timerfd.c +1 -1
index 053818d..e8145d6 100644
@@ -288,7 +288,7 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
 }
 
 #ifdef CONFIG_PROC_FS
-static void timerfd_show(struct seq_file *m, struct file *file)
+static void timerfd_show(struct seq_file *m, struct file *file, void *v)
 {
 	struct timerfd_ctx *ctx = file->private_data;
 	struct itimerspec t;
fs/userfaultfd.c +1 -1
index 5031170..f055f0b 100644
@@ -1191,7 +1191,7 @@ static long userfaultfd_ioctl(struct file *file, unsigned cmd,
 }
 
 #ifdef CONFIG_PROC_FS
-static void userfaultfd_show_fdinfo(struct seq_file *m, struct file *f)
+static void userfaultfd_show_fdinfo(struct seq_file *m, struct file *f, void *v)
 {
 	struct userfaultfd_ctx *ctx = f->private_data;
 	wait_queue_t *wq;
include/linux/fs.h +4 -1
index ae68100..69f818a 100644
@@ -1652,7 +1652,10 @@ struct file_operations {
 	int (*setlease)(struct file *, long, struct file_lock **, void **);
 	long (*fallocate)(struct file *file, int mode, loff_t offset,
 			  loff_t len);
-	void (*show_fdinfo)(struct seq_file *m, struct file *f);
+	void *(*start_fdinfo)(struct seq_file *m, struct file *f, loff_t *pos);
+	void *(*next_fdinfo)(struct seq_file *m, struct file *f, void *v, loff_t *pos);
+	void (*show_fdinfo)(struct seq_file *m, struct file *f, void *v);
+	void (*stop_fdinfo)(struct seq_file *m, struct file *f, void *v);
 #ifndef CONFIG_MMU
 	unsigned (*mmap_capabilities)(struct file *);
 #endif
kernel/bpf/syscall.c +1 -1
index 6373970..bbc6c31 100644
@@ -114,7 +114,7 @@ static int bpf_map_release(struct inode *inode, struct file *filp)
 }
 
 #ifdef CONFIG_PROC_FS
-static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp)
+static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp, void *v)
 {
 	const struct bpf_map *map = filp->private_data;
 
Signature · 1 line
2.5.0