Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1531385

[PATCH v3] seq_file: reset iterator to first record for zero offset

From Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Newsgroups linux.kernel
Subject [PATCH v3] seq_file: reset iterator to first record for zero offset
Date 2016-11-28 16:20 +0100
Message-ID <sIvSO-3L8-25@gated-at.bofh.it> (permalink)
References <sH4rD-4E0-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 fs/seq_file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 368bfb9..ee21714 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -190,6 +190,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 	 */
 	m->version = file->f_version;
 
+	if (*ppos == 0)
+		m->index = 0;
+
 	/* Don't assume *ppos is where we left it */
 	if (unlikely(*ppos != m->read_pos)) {
 		while ((err = traverse(m, *ppos)) == -EAGAIN)
-- 
1.8.3.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v3] seq_file: reset iterator to first record for zero offset Tomasz Majchrzak <tomasz.majchrzak@intel.com> - 2016-11-28 16:20 +0100
  Re: [PATCH v3] seq_file: reset iterator to first record for zero offset Miklos Szeredi <miklos@szeredi.hu> - 2016-11-29 11:00 +0100
    [PATCH v4] seq_file: reset iterator to first record for zero offset Tomasz Majchrzak <tomasz.majchrzak@intel.com> - 2016-11-29 15:20 +0100

csiph-web