Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755382AbcLSLiI (ORCPT ); Mon, 19 Dec 2016 06:38:08 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:34056 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752752AbcLSLiF (ORCPT ); Mon, 19 Dec 2016 06:38:05 -0500 Date: Mon, 19 Dec 2016 12:38:00 +0100 From: Miklos Szeredi To: Al Viro Cc: Tomasz Majchrzak , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH (resend)] seq_file: reset iterator to first record for zero offset Message-ID: <20161219113800.GE27207@veci.piliscsaba.szeredi.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1348 Lines: 44 Al, Can you please take (or NACK) this patch please? Thanks, Miklos --- From: Tomasz Majchrzak Date: Tue, 29 Nov 2016 15:18:20 +0100 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 Signed-off-by: Miklos Szeredi --- fs/seq_file.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -190,6 +190,13 @@ ssize_t seq_read(struct file *file, char */ m->version = file->f_version; + /* + * if request is to read from zero offset, reset iterator to first + * record as it might have been already advanced by previous requests + */ + 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)