Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756419AbcK2OTi (ORCPT ); Tue, 29 Nov 2016 09:19:38 -0500 Received: from mga02.intel.com ([134.134.136.20]:30143 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753100AbcK2OTb (ORCPT ); Tue, 29 Nov 2016 09:19:31 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,717,1473145200"; d="scan'208";a="792125351" From: Tomasz Majchrzak To: linux-kernel@vger.kernel.org Cc: miklos@szeredi.hu, dan.j.williams@intel.com, aleksey.obitotskiy@intel.com, pawel.baldysiak@intel.com, artur.paszkiewicz@intel.com, maksymilian.kunt@intel.com, viro@zeniv.linux.org.uk, Tomasz Majchrzak Subject: [PATCH v4] seq_file: reset iterator to first record for zero offset Date: Tue, 29 Nov 2016 15:18:20 +0100 Message-Id: <1480429100-1452-1-git-send-email-tomasz.majchrzak@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1299 Lines: 37 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 Acked-by: Miklos Szeredi --- fs/seq_file.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index 368bfb9..a11f271 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -190,6 +190,13 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) */ 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) -- 1.8.3.1