From patchwork Tue Dec 13 14:34:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9472449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6173C60823 for ; Tue, 13 Dec 2016 14:34:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 537D1285B0 for ; Tue, 13 Dec 2016 14:34:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46F86285B1; Tue, 13 Dec 2016 14:34:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB082285B8 for ; Tue, 13 Dec 2016 14:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933396AbcLMOe0 (ORCPT ); Tue, 13 Dec 2016 09:34:26 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:36758 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932358AbcLMOeX (ORCPT ); Tue, 13 Dec 2016 09:34:23 -0500 Received: by mail-wj0-f193.google.com with SMTP id j10so16843739wjb.3 for ; Tue, 13 Dec 2016 06:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=p4q1A4v6cthO1xfEqDfzwJMIBXy96zpbZB/KAOTltxw=; b=reZDmKcHH6azlbKMIcDgT9aFB0pdFJvqqAL3ee8znULLdZCHAZxgpnBPMq2NDNrLFG vxuaOdKYluGlLkYm93Hllm7zVNeTmn+gXQ8z/pUoHKWgo3VFNE0GIdW8UJWP1cP2NSMN Pb4N9/kFtjW15GdjZWSkSy4+4uJwLYXSGTyeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=p4q1A4v6cthO1xfEqDfzwJMIBXy96zpbZB/KAOTltxw=; b=ShLYj5v/PsNOreTlU0V3rFd302pl5Ar1NASK/8EA4LIOXBLfGDNgUb0HinzMbwqPaK LeCwUyVEG54+cadl+VHQpv/Bt/BOrrz84FyHxw5N3YVmFAWFmWPR1HbKI0Uqi9QM5IVn ph3PK+dzOXQwdueOG38goVDQSNNu0BAclV6Mwh930I5AJRGj+nFaNvT8nLyu7OEeIFg4 wMfnCYi3bAd2ZQF8ZIpgz08J6DaizF0wVB1CT0OiJv/XIJPRgy011udE4Sy/Pv5gzJOM ACc/7NGfY2pekYmFRPdEfaUp2qKs/fMsCYSOQWpmazsKFQlS8TZyK61rkbYCi2hUl/ip K45A== X-Gm-Message-State: AKaTC01bttu0JtiJc6Ziu0sJSZIVosSOYop8QAd4a2FiUtjOjudK7488Ixq3X/y1zorcXg== X-Received: by 10.194.174.39 with SMTP id bp7mr83262365wjc.5.1481639661226; Tue, 13 Dec 2016 06:34:21 -0800 (PST) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id i2sm62520893wjx.44.2016.12.13.06.34.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 06:34:20 -0800 (PST) Date: Tue, 13 Dec 2016 15:34:17 +0100 From: Miklos Szeredi To: Al Viro Cc: Tomasz Majchrzak , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] seq_file: reset iterator to first record for zero offset Message-ID: <20161213143417.GB27207@veci.piliscsaba.szeredi.hu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 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)