Skip to content

Commit e522751

Browse files
Tomasz MajchrzakAl Viro
authored andcommitted
seq_file: reset iterator to first record for zero offset
If kernfs file is empty on a first read, successive read operations using the same file descriptor will return no data, even when data is available. Default kernfs 'seq_next' implementation advances iterator position even when next object is not there. Kernfs 'seq_start' for following requests will not return iterator as position is already on the second object. This defect doesn't allow to monitor badblocks sysfs files from MD raid. They are initially empty but if data appears at some stage, userspace is not able to read it. Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 22725ce commit e522751

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/seq_file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
190190
*/
191191
m->version = file->f_version;
192192

193+
/*
194+
* if request is to read from zero offset, reset iterator to first
195+
* record as it might have been already advanced by previous requests
196+
*/
197+
if (*ppos == 0)
198+
m->index = 0;
199+
193200
/* Don't assume *ppos is where we left it */
194201
if (unlikely(*ppos != m->read_pos)) {
195202
while ((err = traverse(m, *ppos)) == -EAGAIN)

0 commit comments

Comments
 (0)