From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755112AbcK2J6g (ORCPT ); Tue, 29 Nov 2016 04:58:36 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:33915 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbcK2J62 (ORCPT ); Tue, 29 Nov 2016 04:58:28 -0500 MIME-Version: 1.0 X-Originating-IP: [217.173.44.24] In-Reply-To: <1480345919-30466-1-git-send-email-tomasz.majchrzak@intel.com> References: <1480345919-30466-1-git-send-email-tomasz.majchrzak@intel.com> From: Miklos Szeredi Date: Tue, 29 Nov 2016 10:58:27 +0100 Message-ID: Subject: Re: [PATCH v3] seq_file: reset iterator to first record for zero offset To: Tomasz Majchrzak Cc: linux-kernel@vger.kernel.org, dan.j.williams@intel.com, aleksey.obitotskiy@intel.com, pawel.baldysiak@intel.com, artur.paszkiewicz@intel.com, maksymilian.kunt@intel.com, Al Viro Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 28, 2016 at 4:11 PM, Tomasz Majchrzak wrote: > 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 A comment above the check wouldn't hurt. Otherwise Acked-by: Miklos Szeredi > --- > 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 >